adauth 1.2.1 → 2.0.0pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +12 -0
- data/Gemfile.lock +13 -26
- data/Rakefile +1 -0
- data/Readme.md +48 -0
- data/adauth.gemspec +2 -1
- data/lib/adauth.rb +40 -28
- data/lib/adauth/ad_object.rb +104 -0
- data/lib/adauth/ad_objects/computer.rb +28 -0
- data/lib/adauth/ad_objects/group.rb +40 -0
- data/lib/adauth/ad_objects/ou.rb +41 -0
- data/lib/adauth/ad_objects/user.rb +45 -0
- data/lib/adauth/authenticate.rb +25 -46
- data/lib/adauth/config.rb +11 -28
- data/lib/adauth/connection.rb +19 -18
- data/lib/adauth/rails.rb +9 -0
- data/lib/adauth/rails/helpers.rb +29 -0
- data/lib/adauth/rails/model_bridge.rb +59 -0
- data/lib/adauth/version.rb +2 -3
- data/lib/generators/adauth/config/config_generator.rb +1 -1
- data/lib/generators/adauth/config/templates/config.rb.erb +18 -22
- data/lib/generators/adauth/sessions/sessions_generator.rb +2 -3
- data/lib/generators/adauth/sessions/templates/sessions_controller.rb.erb +1 -1
- data/spec/adauth_ad_object_computer_spec.rb +15 -0
- data/spec/adauth_ad_object_group_spec.rb +21 -0
- data/spec/adauth_ad_object_ou_spec.rb +18 -0
- data/spec/adauth_ad_object_user_spec.rb +27 -0
- data/spec/adauth_authenticate_spec.rb +39 -0
- data/spec/adauth_config_spec.rb +15 -0
- data/spec/adauth_rails_model_bridge_spec.rb +37 -0
- data/spec/adauth_spec.rb +2 -30
- data/spec/spec_helper.rb +34 -0
- metadata +52 -38
- data/Readme.rdoc +0 -66
- data/lib/adauth/admin_connection.rb +0 -26
- data/lib/adauth/group.rb +0 -100
- data/lib/adauth/helpers.rb +0 -28
- data/lib/adauth/user.rb +0 -114
- data/lib/adauth/user_model.rb +0 -76
- data/lib/generators/adauth/all/USAGE +0 -5
- data/lib/generators/adauth/all/all_generator.rb +0 -18
- data/lib/generators/adauth/user_model/USAGE +0 -14
- data/lib/generators/adauth/user_model/templates/model.rb.erb +0 -3
- data/lib/generators/adauth/user_model/user_model_generator.rb +0 -32
- data/spec/adauth_group_spec.rb +0 -51
- data/spec/adauth_user_model_spec.rb +0 -80
- data/spec/adauth_user_spec.rb +0 -213
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'lib/adauth'
|
2
|
-
require 'yaml'
|
3
|
-
|
4
|
-
ReturnDataForTest = []
|
5
|
-
|
6
|
-
class TestModel
|
7
|
-
include Adauth::UserModel
|
8
|
-
|
9
|
-
attr_accessor :login, :group_strings, :name, :ou_strings
|
10
|
-
|
11
|
-
def self.create!
|
12
|
-
@user = self.new
|
13
|
-
yield(@user)
|
14
|
-
return @user
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.find_by_login(login)
|
18
|
-
ReturnDataForTest.last
|
19
|
-
end
|
20
|
-
|
21
|
-
def save
|
22
|
-
true
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe TestModel, "creations" do
|
27
|
-
before :each do
|
28
|
-
@yaml = YAML::load(File.open('spec/test_data.yml'))
|
29
|
-
Adauth.configure do |c|
|
30
|
-
c.domain = @yaml["domain"]["domain"]
|
31
|
-
c.server = @yaml["domain"]["server"]
|
32
|
-
c.port = @yaml["domain"]["port"]
|
33
|
-
c.base = @yaml["domain"]["base"]
|
34
|
-
end
|
35
|
-
@user = Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"])
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should create a new user for method `create_user_with_adauth`" do
|
39
|
-
TestModel.create_user_with_adauth(@user).should be_a TestModel
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return a user for method `return_and_create_with_adauth`, if no user exists in the db" do
|
43
|
-
ReturnDataForTest.push nil
|
44
|
-
TestModel.return_and_create_with_adauth(@user).should be_a TestModel
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should return a user for method `return_and_create_with_adauth`, if the user does exist" do
|
48
|
-
ReturnDataForTest.push TestModel.create_user_with_adauth(@user)
|
49
|
-
TestModel.return_and_create_with_adauth(@user).should be_a TestModel
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe TestModel, "methods" do
|
54
|
-
before :each do
|
55
|
-
@yaml = YAML::load(File.open('spec/test_data.yml'))
|
56
|
-
Adauth.configure do |c|
|
57
|
-
c.domain = @yaml["domain"]["domain"]
|
58
|
-
c.server = @yaml["domain"]["server"]
|
59
|
-
c.port = @yaml["domain"]["port"]
|
60
|
-
c.base = @yaml["domain"]["base"]
|
61
|
-
end
|
62
|
-
@user = Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"])
|
63
|
-
@model = TestModel.create_user_with_adauth(@user)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should return an array of groups for .groups" do
|
67
|
-
@model.groups.should be_a Array
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should return an array of ous for .ous" do
|
71
|
-
@model.ous.should be_a Array
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should update from adauth" do
|
75
|
-
@model.name = "Adauth Testing user that should be different"
|
76
|
-
@model.name.should_not eq(@user.name)
|
77
|
-
@model.update_from_adauth(@user)
|
78
|
-
@model.name.should eq(@user.name)
|
79
|
-
end
|
80
|
-
end
|
data/spec/adauth_user_spec.rb
DELETED
@@ -1,213 +0,0 @@
|
|
1
|
-
require 'lib/adauth'
|
2
|
-
require 'yaml'
|
3
|
-
|
4
|
-
describe Adauth, "#authenticate" do
|
5
|
-
before :each do
|
6
|
-
@yaml = YAML::load(File.open('spec/test_data.yml'))
|
7
|
-
Adauth.configure do |c|
|
8
|
-
c.domain = @yaml["domain"]["domain"]
|
9
|
-
c.server = @yaml["domain"]["server"]
|
10
|
-
c.port = @yaml["domain"]["port"]
|
11
|
-
c.base = @yaml["domain"]["base"]
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should succesfully authenticate with the example user" do
|
16
|
-
Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"]).should be_a Adauth::User
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should return nil for a failed bind" do
|
20
|
-
Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["group"]).should == nil
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should return nil for a failed bind whilst using allowed groups" do
|
24
|
-
Adauth.config.allowed_groups = @yaml["domain"]["pass_allowed_groups"]
|
25
|
-
Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["group"]).should be_nil
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should allow users who are in an allowed group" do
|
29
|
-
Adauth.config.allowed_groups = @yaml["domain"]["pass_allowed_groups"]
|
30
|
-
Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"]).should be_a Adauth::User
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should dis-allow users who are not in an allowed group" do
|
34
|
-
Adauth.config.allowed_groups = @yaml["domain"]["fail_allowed_groups"]
|
35
|
-
Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"]).should be_nil
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should dis-allow users who are in a denied group" do
|
39
|
-
Adauth.config.denied_groups = @yaml["domain"]["pass_allowed_groups"]
|
40
|
-
Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"]).should be_nil
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should allow users who are in a denied group" do
|
44
|
-
Adauth.config.denied_groups = @yaml["domain"]["fail_allowed_groups"]
|
45
|
-
Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"]).should be_a Adauth::User
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should allow users who are in an allowed ou" do
|
49
|
-
Adauth.config.allowed_ous = @yaml["domain"]["pass_allowed_ous"]
|
50
|
-
Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"]).should be_a Adauth::User
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should dis-allow users who are not in an allowed ou" do
|
54
|
-
Adauth.config.allowed_ous = @yaml["domain"]["fail_allowed_ous"]
|
55
|
-
Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"]).should be_nil
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should dis-allow users who are in a denied ou" do
|
59
|
-
Adauth.config.denied_ous = @yaml["domain"]["pass_allowed_ous"]
|
60
|
-
Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"]).should be_nil
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should allow users who are not in a denied ou" do
|
64
|
-
Adauth.config.denied_ous = @yaml["domain"]["fail_allowed_ous"]
|
65
|
-
Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"]).should be_a Adauth::User
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should dis-allow a user who is in an allowed ou but not an allowed group" do
|
69
|
-
Adauth.config.allowed_ous = @yaml["domain"]["pass_allowed_ous"]
|
70
|
-
Adauth.config.denied_groups = @yaml["domain"]["pass_allowed_groups"]
|
71
|
-
Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"]).should be_nil
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should dis-allow a user who is in an allowed group but not an allowed ou" do
|
75
|
-
Adauth.config.denied_ous = @yaml["domain"]["pass_allowed_ous"]
|
76
|
-
Adauth.config.allowed_groups = @yaml["domain"]["pass_allowed_groups"]
|
77
|
-
Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"]).should be_nil
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should allow a user who is in an allowed ou and an allowed group" do
|
81
|
-
Adauth.config.allowed_ous = @yaml["domain"]["pass_allowed_ous"]
|
82
|
-
Adauth.config.allowed_groups = @yaml["domain"]["pass_allowed_groups"]
|
83
|
-
Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"]).should be_a Adauth::User
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should dis-allow a user who is in a dis-allowed ou and a dis-allowed group" do
|
87
|
-
Adauth.config.denied_ous = @yaml["domain"]["pass_allowed_ous"]
|
88
|
-
Adauth.config.denied_groups = @yaml["domain"]["pass_allowed_groups"]
|
89
|
-
Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"]).should be_nil
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe Adauth::User do
|
94
|
-
before :each do
|
95
|
-
@yaml = YAML::load(File.open('spec/test_data.yml'))
|
96
|
-
Adauth.configure do |c|
|
97
|
-
c.domain = @yaml["domain"]["domain"]
|
98
|
-
c.server = @yaml["domain"]["server"]
|
99
|
-
c.port = @yaml["domain"]["port"]
|
100
|
-
c.base = @yaml["domain"]["base"]
|
101
|
-
end
|
102
|
-
@user = Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"])
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should return groups for an authenticated user" do
|
106
|
-
@user.groups.should be_a Array
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should return ous for an authenticated user" do
|
110
|
-
@user.ous.should be_a Array
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should have all the ous from the data file" do
|
114
|
-
@yaml["user"]["ous"].each do |ou|
|
115
|
-
@user.ous.include?(ou).should be_true
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should return true for a member_of test using the users group" do
|
120
|
-
@user.member_of?(@yaml["user"]["group"]).should == true
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should return false for a member_of test using the users password" do
|
124
|
-
@user.member_of?(@yaml["user"]["password"]).should == false
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should have the correct user" do
|
128
|
-
@user.login.should == @yaml["user"]["login"]
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
describe "Adauth::User custom returns" do
|
133
|
-
before :each do
|
134
|
-
@yaml = YAML::load(File.open('spec/test_data.yml'))
|
135
|
-
Adauth.configure do |c|
|
136
|
-
c.domain = @yaml["domain"]["domain"]
|
137
|
-
c.server = @yaml["domain"]["server"]
|
138
|
-
c.port = @yaml["domain"]["port"]
|
139
|
-
c.base = @yaml["domain"]["base"]
|
140
|
-
c.ad_sv_attrs = { :phone => :telephonenumber }
|
141
|
-
c.ad_mv_attrs = { :ous => [ :memberof,
|
142
|
-
Proc.new {|g| g.sub(/.*?OU=(.*?),.*/, '\1')} ] }
|
143
|
-
end
|
144
|
-
@user = Adauth.authenticate(@yaml["user"]["login"], @yaml["user"]["password"])
|
145
|
-
end
|
146
|
-
|
147
|
-
it "should pickup the custom single value from AD" do
|
148
|
-
@user.phone.should be_a String
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should pickup the custom multi value from AD" do
|
152
|
-
@user.ous.should be_a Array
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
describe Adauth::AdminConnection do
|
157
|
-
before :each do
|
158
|
-
@yaml = YAML::load(File.open('spec/test_data.yml'))
|
159
|
-
Adauth.configure do |c|
|
160
|
-
c.domain = @yaml["domain"]["domain"]
|
161
|
-
c.server = @yaml["domain"]["server"]
|
162
|
-
c.port = @yaml["domain"]["port"]
|
163
|
-
c.base = @yaml["domain"]["base"]
|
164
|
-
c.admin_user = @yaml["domain"]["admin_user"]
|
165
|
-
c.admin_password = @yaml["domain"]["admin_password"]
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
it "should create a connection" do
|
170
|
-
Adauth::AdminConnection.bind.should be_a Net::LDAP
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should raise an exception if the password is wrong" do
|
174
|
-
Adauth.config.admin_password = @yaml["domain"]["admin_password"][1]
|
175
|
-
lambda { Adauth::AdminConnection.bind }.should raise_error
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
describe Adauth, "passwordless_login" do
|
180
|
-
before :each do
|
181
|
-
@yaml = YAML::load(File.open('spec/test_data.yml'))
|
182
|
-
Adauth.configure do |c|
|
183
|
-
c.domain = @yaml["domain"]["domain"]
|
184
|
-
c.server = @yaml["domain"]["server"]
|
185
|
-
c.port = @yaml["domain"]["port"]
|
186
|
-
c.base = @yaml["domain"]["base"]
|
187
|
-
c.admin_user = @yaml["domain"]["admin_user"]
|
188
|
-
c.admin_password = @yaml["domain"]["admin_password"]
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
it "should return an user when asked to" do
|
193
|
-
Adauth.passwordless_login(@yaml["user"]["login"]).should be_a Adauth::User
|
194
|
-
end
|
195
|
-
|
196
|
-
it "should be a viable user when passwordless login is used" do
|
197
|
-
Adauth.passwordless_login(@yaml["user"]["login"]).login.should eq(@yaml["user"]["login"])
|
198
|
-
end
|
199
|
-
|
200
|
-
it "should raise an exception on timeout" do
|
201
|
-
Adauth.configure do |c|
|
202
|
-
c.domain = @yaml["domain"]["domain"]
|
203
|
-
c.server = "127.0.0.2"
|
204
|
-
c.port = @yaml["domain"]["port"]
|
205
|
-
c.base = @yaml["domain"]["base"]
|
206
|
-
c.admin_user = @yaml["domain"]["admin_user"]
|
207
|
-
c.admin_password = @yaml["domain"]["admin_password"]
|
208
|
-
end
|
209
|
-
|
210
|
-
lambda { Adauth::AdminConnection.bind }.should raise_error
|
211
|
-
|
212
|
-
end
|
213
|
-
end
|