adauth 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/adauth.rb +1 -0
- data/lib/adauth/ad_object.rb +25 -10
- data/lib/adauth/ad_objects/group.rb +1 -1
- data/lib/adauth/ad_objects/user.rb +1 -1
- data/lib/adauth/search_results.rb +18 -0
- data/lib/adauth/version.rb +1 -1
- data/spec/adauth_ad_object_user_spec.rb +8 -2
- data/spec/adauth_rails_model_bridge_spec.rb +6 -2
- data/spec/adauth_search_results_spec.rb +41 -0
- data/spec/spec_helper.rb +0 -12
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a01855a1bb516984482d2cbdaa7020445431786
|
4
|
+
data.tar.gz: 077068256ee217f616c28322931be7500e8fb967
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e9fd1e2c0af98fff7ce34b6bfe0300490a718c5408d4d7da9f49f84d709070c4ec1163a9fa4ebc90f579295ffa10b7068ba819f3822d4d39241561790af6db5
|
7
|
+
data.tar.gz: 120341150092ad1327e8cac8a20ba4c321215c504c2964265920cd33762a4670b87bbeaf9b66c86cce5c99f6ce5827673531f4aaaa91d7f2a2d743fad48838cc
|
data/Gemfile.lock
CHANGED
data/lib/adauth.rb
CHANGED
data/lib/adauth/ad_object.rb
CHANGED
@@ -16,11 +16,33 @@ module Adauth
|
|
16
16
|
# Provides all the common functions for Active Directory.
|
17
17
|
class AdObject
|
18
18
|
include Expects
|
19
|
-
|
19
|
+
|
20
|
+
def self.method_missing(method, *args)
|
21
|
+
return super unless method =~ /^find_by_/
|
22
|
+
method_field = method.to_s.split("_").last
|
23
|
+
field = self::Fields[method_field.to_sym]
|
24
|
+
return super unless field
|
25
|
+
self.where(field, args.first)
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_missing(method, *args)
|
29
|
+
field = self.class::Fields[method]
|
30
|
+
return handle_field(field) if field
|
31
|
+
return super
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.reverse_field(search)
|
35
|
+
hash = {}
|
36
|
+
self::Fields.each do |k, v|
|
37
|
+
hash[v] = k
|
38
|
+
end
|
39
|
+
return hash[search]
|
40
|
+
end
|
41
|
+
|
20
42
|
# Returns all objects which have the ObjectClass of the inherited class
|
21
43
|
def self.all
|
22
44
|
Adauth.logger.info(self.class.inspect) { "Searching for all objects matching filter \"#{self::ObjectFilter}\"" }
|
23
|
-
self.filter(self::ObjectFilter)
|
45
|
+
Adauth::SearchResults.new(self.filter(self::ObjectFilter))
|
24
46
|
end
|
25
47
|
|
26
48
|
# Returns all the objects which match the supplied query
|
@@ -29,7 +51,7 @@ module Adauth
|
|
29
51
|
def self.where(field, value)
|
30
52
|
search_filter = Net::LDAP::Filter.eq(field, value)
|
31
53
|
Adauth.logger.info(self.class.inspect) { "Searching for all \"#{self::ObjectFilter}\" where #{field} = #{value}" }
|
32
|
-
filter(add_object_filter(search_filter))
|
54
|
+
Adauth::SearchResults.new(filter(add_object_filter(search_filter)))
|
33
55
|
end
|
34
56
|
|
35
57
|
# Returns all LDAP objects that match the given filter
|
@@ -65,13 +87,6 @@ module Adauth
|
|
65
87
|
@ldap_object
|
66
88
|
end
|
67
89
|
|
68
|
-
# Over ride method missing to see if the object has a field by that name
|
69
|
-
def method_missing(method, *args)
|
70
|
-
field = self.class::Fields[method]
|
71
|
-
return handle_field(field) if field
|
72
|
-
return super
|
73
|
-
end
|
74
|
-
|
75
90
|
# Handle the output for the given field
|
76
91
|
def handle_field(field)
|
77
92
|
case field
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Adauth
|
2
|
+
class SearchResults < Array
|
3
|
+
def limit(x)
|
4
|
+
return self[0..(x-1)]
|
5
|
+
end
|
6
|
+
|
7
|
+
def order(field, direction = :asc)
|
8
|
+
case direction
|
9
|
+
when :asc
|
10
|
+
return sort! { |x, y| x.send(field) <=> y.send(field) }
|
11
|
+
when :desc
|
12
|
+
return order(field, :asc).reverse!
|
13
|
+
else
|
14
|
+
raise "Invalid Order Provided, please use :asc or :desc"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/adauth/version.rb
CHANGED
@@ -46,9 +46,9 @@ describe Adauth::AdObjects::User do
|
|
46
46
|
it "should allow for additional methods" do
|
47
47
|
default_config
|
48
48
|
Adauth.add_field(Adauth::AdObjects::User, :description, :description)
|
49
|
-
|
49
|
+
user.description.should be_a String
|
50
50
|
Adauth.add_field(Adauth::AdObjects::User, :objectguid, :objectguid)
|
51
|
-
|
51
|
+
user.objectguid.should be_a String
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should allow you to reset the password" do
|
@@ -86,4 +86,10 @@ describe Adauth::AdObjects::User do
|
|
86
86
|
rq_user.member_of?("Adauth Test Group").should be_false
|
87
87
|
new_group.delete
|
88
88
|
end
|
89
|
+
|
90
|
+
it "should have find_by methods (and not break method_missing)" do
|
91
|
+
default_config
|
92
|
+
lambda { Adauth::AdObjects::User.fooooooooo }.should raise_exception
|
93
|
+
Adauth::AdObjects::User.find_by_login(test_data("domain", "breakable_user")).should be_a Adauth::SearchResults
|
94
|
+
end
|
89
95
|
end
|
@@ -21,17 +21,21 @@ class TestUserModel
|
|
21
21
|
end
|
22
22
|
|
23
23
|
describe Adauth::Rails::ModelBridge do
|
24
|
+
let(:user) do
|
25
|
+
Adauth::AdObjects::User.where('sAMAccountName', test_data("domain", "breakable_user")).first
|
26
|
+
end
|
27
|
+
|
24
28
|
it "should extend", :no_ad => true do
|
25
29
|
TestUserModel.should respond_to :create_from_adauth
|
26
30
|
end
|
27
31
|
|
28
32
|
it "should create the model" do
|
29
33
|
default_config
|
30
|
-
TestUserModel.create_from_adauth(
|
34
|
+
TestUserModel.create_from_adauth(user)
|
31
35
|
end
|
32
36
|
|
33
37
|
it "should return and create the model" do
|
34
38
|
default_config
|
35
|
-
TestUserModel.return_and_create_from_adauth(
|
39
|
+
TestUserModel.return_and_create_from_adauth(user)
|
36
40
|
end
|
37
41
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Adauth::SearchResults, :no_ad => true do
|
4
|
+
let(:test_array) do
|
5
|
+
[OpenStruct.new({name: "foo"}), OpenStruct.new({name: "bar"}), OpenStruct.new({name: "widget"})]
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:sorted_array) do
|
9
|
+
[OpenStruct.new({name: "bar"}), OpenStruct.new({name: "foo"}), OpenStruct.new({name: "widget"})]
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:search_results) do
|
13
|
+
Adauth::SearchResults.new(test_array)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should create self from_array" do
|
17
|
+
Adauth::SearchResults.new(test_array).should be_a Adauth::SearchResults
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have the limit function" do
|
21
|
+
search_results.limit(2).length.should eq 2
|
22
|
+
search_results.limit(2).last.should_not eq test_array.last
|
23
|
+
search_results.limit(2).should be_a Adauth::SearchResults
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have the order function" do
|
27
|
+
search_results.order(:name, :asc).should eq sorted_array
|
28
|
+
search_results.order(:name, :asc).should be_a Adauth::SearchResults
|
29
|
+
search_results.order(:name, :desc).should eq sorted_array.reverse
|
30
|
+
search_results.order(:name, :desc).should be_a Adauth::SearchResults
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should handle having a wrong direction passed to it" do
|
34
|
+
lambda { search_results.order(:name, :foo) }.should raise_exception
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should default to :asc for order" do
|
38
|
+
search_results.order(:name).should eq sorted_array
|
39
|
+
search_results.order(:name).should be_a Adauth::SearchResults
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -23,15 +23,3 @@ def test_data(set, key)
|
|
23
23
|
@yaml ||= YAML::load(File.open('spec/test_data.yml'))
|
24
24
|
@yaml[set][key]
|
25
25
|
end
|
26
|
-
|
27
|
-
def administrator
|
28
|
-
Adauth::AdObjects::User.where('sAMAccountName', "administrator").first
|
29
|
-
end
|
30
|
-
|
31
|
-
#def breakable_user
|
32
|
-
# Adauth::AdObjects::User.where('sAMAccountName', test_data("domain", "breakable_user")).first
|
33
|
-
#end
|
34
|
-
|
35
|
-
def query_user
|
36
|
-
Adauth::AdObjects::User.where('sAMAccountName', test_data("domain", "query_user")).first
|
37
|
-
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam "Arcath" Laycock
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- lib/adauth/rails.rb
|
125
125
|
- lib/adauth/rails/helpers.rb
|
126
126
|
- lib/adauth/rails/model_bridge.rb
|
127
|
+
- lib/adauth/search_results.rb
|
127
128
|
- lib/adauth/version.rb
|
128
129
|
- lib/generators/adauth/config/USAGE
|
129
130
|
- lib/generators/adauth/config/config_generator.rb
|
@@ -144,6 +145,7 @@ files:
|
|
144
145
|
- spec/adauth_connection_spec.rb
|
145
146
|
- spec/adauth_issue_spec.rb
|
146
147
|
- spec/adauth_rails_model_bridge_spec.rb
|
148
|
+
- spec/adauth_search_results_spec.rb
|
147
149
|
- spec/adauth_spec.rb
|
148
150
|
- spec/spec_helper.rb
|
149
151
|
- spec/test_data.example.yml
|
@@ -183,6 +185,7 @@ test_files:
|
|
183
185
|
- spec/adauth_connection_spec.rb
|
184
186
|
- spec/adauth_issue_spec.rb
|
185
187
|
- spec/adauth_rails_model_bridge_spec.rb
|
188
|
+
- spec/adauth_search_results_spec.rb
|
186
189
|
- spec/adauth_spec.rb
|
187
190
|
- spec/spec_helper.rb
|
188
191
|
- spec/test_data.example.yml
|