ldap_fluff 0.1.4 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ldap_fluff might be problematic. Click here for more details.
- data/lib/ldap_fluff/active_directory.rb +20 -0
- data/lib/ldap_fluff/ad_member_service.rb +15 -1
- data/lib/ldap_fluff/freeipa.rb +20 -0
- data/lib/ldap_fluff/freeipa_member_service.rb +20 -2
- data/lib/ldap_fluff/ldap_fluff.rb +11 -0
- data/lib/ldap_fluff/posix.rb +18 -0
- data/lib/ldap_fluff/posix_member_service.rb +19 -1
- data/lib/ldap_fluff.rb +8 -8
- data/test/ad_member_services_test.rb +29 -1
- data/test/ad_test.rb +39 -1
- data/test/config_test.rb +1 -2
- data/test/ipa_member_services_test.rb +29 -1
- data/test/ipa_test.rb +39 -1
- data/test/ldap_test.rb +29 -1
- data/test/lib/ldap_test_helper.rb +24 -2
- data/test/posix_member_services_test.rb +55 -1
- data/test/posix_test.rb +35 -1
- metadata +2 -2
@@ -58,6 +58,26 @@ class LdapFluff::ActiveDirectory
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
def user_exists?(uid)
|
62
|
+
begin
|
63
|
+
service_bind
|
64
|
+
user = @member_service.find_user(uid)
|
65
|
+
rescue MemberService::UIDNotFoundException
|
66
|
+
return false
|
67
|
+
end
|
68
|
+
return true
|
69
|
+
end
|
70
|
+
|
71
|
+
def group_exists?(gid)
|
72
|
+
begin
|
73
|
+
service_bind
|
74
|
+
group = @member_service.find_group(gid)
|
75
|
+
rescue MemberService::GIDNotFoundException
|
76
|
+
return false
|
77
|
+
end
|
78
|
+
return true
|
79
|
+
end
|
80
|
+
|
61
81
|
class UnauthenticatedActiveDirectoryException < StandardError
|
62
82
|
end
|
63
83
|
end
|
@@ -13,9 +13,20 @@ class LdapFluff::ActiveDirectory::MemberService
|
|
13
13
|
# get a list [] of ldap groups for a given user
|
14
14
|
# in active directory, this means a recursive lookup
|
15
15
|
def find_user_groups(uid)
|
16
|
+
data = find_user(uid)
|
17
|
+
_groups_from_ldap_data(data.first)
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_user(uid)
|
16
21
|
data = @ldap.search(:filter => name_filter(uid))
|
17
22
|
raise UIDNotFoundException if (data == nil || data.empty?)
|
18
|
-
|
23
|
+
data
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_group(gid)
|
27
|
+
data = @ldap.search(:filter => group_filter(gid), :base => @group_base)
|
28
|
+
raise GIDNotFoundException if (data == nil || data.empty?)
|
29
|
+
data
|
19
30
|
end
|
20
31
|
|
21
32
|
# return the :memberof attrs + parents, recursively
|
@@ -72,4 +83,7 @@ class LdapFluff::ActiveDirectory::MemberService
|
|
72
83
|
|
73
84
|
class UIDNotFoundException < StandardError
|
74
85
|
end
|
86
|
+
|
87
|
+
class GIDNotFoundException < StandardError
|
88
|
+
end
|
75
89
|
end
|
data/lib/ldap_fluff/freeipa.rb
CHANGED
@@ -58,6 +58,26 @@ class LdapFluff::FreeIPA
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
def user_exists?(uid)
|
62
|
+
begin
|
63
|
+
service_bind
|
64
|
+
user = @member_service.find_user(uid)
|
65
|
+
rescue MemberService::UIDNotFoundException
|
66
|
+
return false
|
67
|
+
end
|
68
|
+
return true
|
69
|
+
end
|
70
|
+
|
71
|
+
def group_exists?(gid)
|
72
|
+
begin
|
73
|
+
service_bind
|
74
|
+
group = @member_service.find_group(gid)
|
75
|
+
rescue MemberService::GIDNotFoundException
|
76
|
+
return false
|
77
|
+
end
|
78
|
+
return true
|
79
|
+
end
|
80
|
+
|
61
81
|
class UnauthenticatedFreeIPAException < StandardError
|
62
82
|
end
|
63
83
|
|
@@ -13,18 +13,33 @@ class LdapFluff::FreeIPA::MemberService
|
|
13
13
|
# return an ldap user with groups attached
|
14
14
|
# note : this method is not particularly fast for large ldap systems
|
15
15
|
def find_user_groups(uid)
|
16
|
-
user =
|
17
|
-
raise UIDNotFoundException if (user == nil || user.empty?)
|
16
|
+
user = find_user(uid)
|
18
17
|
# if group data is missing, they aren't querying with a user
|
19
18
|
# with enough privileges
|
20
19
|
raise InsufficientQueryPrivilegesException if user.size <= 1
|
21
20
|
_group_names_from_cn(user[1][:memberof])
|
22
21
|
end
|
23
22
|
|
23
|
+
def find_user(uid)
|
24
|
+
user = @ldap.search(:filter => name_filter(uid))
|
25
|
+
raise UIDNotFoundException if (user == nil || user.empty?)
|
26
|
+
user
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_group(gid)
|
30
|
+
group = @ldap.search(:filter => group_filter(gid), :base => @group_base)
|
31
|
+
raise GIDNotFoundException if (group == nil || group.empty?)
|
32
|
+
group
|
33
|
+
end
|
34
|
+
|
24
35
|
def name_filter(uid)
|
25
36
|
Net::LDAP::Filter.eq("uid",uid)
|
26
37
|
end
|
27
38
|
|
39
|
+
def group_filter(gid)
|
40
|
+
Net::LDAP::Filter.eq("cn",gid)
|
41
|
+
end
|
42
|
+
|
28
43
|
def _group_names_from_cn(grouplist)
|
29
44
|
p = Proc.new { |g| g.sub(/.*?cn=(.*?),.*/, '\1') }
|
30
45
|
grouplist.collect(&p)
|
@@ -33,6 +48,9 @@ class LdapFluff::FreeIPA::MemberService
|
|
33
48
|
class UIDNotFoundException < StandardError
|
34
49
|
end
|
35
50
|
|
51
|
+
class GIDNotFoundException < StandardError
|
52
|
+
end
|
53
|
+
|
36
54
|
class InsufficientQueryPrivilegesException < StandardError
|
37
55
|
end
|
38
56
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'net/ldap'
|
2
3
|
|
3
4
|
class LdapFluff
|
@@ -43,4 +44,14 @@ class LdapFluff
|
|
43
44
|
@ldap.is_in_groups(uid, grouplist, true)
|
44
45
|
end
|
45
46
|
|
47
|
+
# return true if uid exists
|
48
|
+
def valid_user?(uid)
|
49
|
+
@ldap.user_exists? uid
|
50
|
+
end
|
51
|
+
|
52
|
+
# return true if group exists
|
53
|
+
def valid_group?(gid)
|
54
|
+
@ldap.group_exists? gid
|
55
|
+
end
|
56
|
+
|
46
57
|
end
|
data/lib/ldap_fluff/posix.rb
CHANGED
@@ -33,4 +33,22 @@ class LdapFluff::Posix
|
|
33
33
|
(gids.empty? || @member_service.times_in_groups(uid, gids, all) > 0)
|
34
34
|
end
|
35
35
|
|
36
|
+
def user_exists?(uid)
|
37
|
+
begin
|
38
|
+
user = @member_service.find_user(uid)
|
39
|
+
rescue MemberService::UIDNotFoundException
|
40
|
+
return false
|
41
|
+
end
|
42
|
+
return true
|
43
|
+
end
|
44
|
+
|
45
|
+
def group_exists?(gid)
|
46
|
+
begin
|
47
|
+
group = @member_service.find_group(gid)
|
48
|
+
rescue MemberService::GIDNotFoundException
|
49
|
+
return false
|
50
|
+
end
|
51
|
+
return true
|
52
|
+
end
|
53
|
+
|
36
54
|
end
|
@@ -14,12 +14,24 @@ class LdapFluff::Posix::MemberService
|
|
14
14
|
# note : this method is not particularly fast for large ldap systems
|
15
15
|
def find_user_groups(uid)
|
16
16
|
groups = []
|
17
|
-
|
17
|
+
find_user(uid).each do |entry|
|
18
18
|
groups << entry[:cn][0]
|
19
19
|
end
|
20
20
|
groups
|
21
21
|
end
|
22
22
|
|
23
|
+
def find_user(uid)
|
24
|
+
user = @ldap.search(:filter => name_filter(uid), :base => @group_base)
|
25
|
+
raise UIDNotFoundException if (user == nil || user.empty?)
|
26
|
+
user
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_group(gid)
|
30
|
+
group = @ldap.search(:filter => group_filter(gid), :base => @group_base)
|
31
|
+
raise GIDNotFoundException if (group == nil || group.empty?)
|
32
|
+
group
|
33
|
+
end
|
34
|
+
|
23
35
|
def times_in_groups(uid, gids, all)
|
24
36
|
matches = 0
|
25
37
|
filters = []
|
@@ -53,4 +65,10 @@ class LdapFluff::Posix::MemberService
|
|
53
65
|
return filter
|
54
66
|
end
|
55
67
|
end
|
68
|
+
|
69
|
+
class UIDNotFoundException < StandardError
|
70
|
+
end
|
71
|
+
|
72
|
+
class GIDNotFoundException < StandardError
|
73
|
+
end
|
56
74
|
end
|
data/lib/ldap_fluff.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
require_relative 'ldap_fluff/config'
|
2
|
+
require_relative 'ldap_fluff/ldap_fluff'
|
3
|
+
require_relative 'ldap_fluff/active_directory'
|
4
|
+
require_relative 'ldap_fluff/ad_member_service'
|
5
|
+
require_relative 'ldap_fluff/posix'
|
6
|
+
require_relative 'ldap_fluff/posix_member_service'
|
7
|
+
require_relative 'ldap_fluff/freeipa'
|
8
|
+
require_relative 'ldap_fluff/freeipa_member_service'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative './lib/ldap_test_helper'
|
2
2
|
|
3
3
|
class TestADMemberService < MiniTest::Unit::TestCase
|
4
4
|
include LdapTestHelper
|
@@ -15,6 +15,10 @@ class TestADMemberService < MiniTest::Unit::TestCase
|
|
15
15
|
@ldap.expect(:search, ad_parent_payload(1), [:filter => @gfilter, :base => @config.group_base])
|
16
16
|
end
|
17
17
|
|
18
|
+
def basic_group
|
19
|
+
@ldap.expect(:search, ad_group_payload, [:filter => ad_group_filter("broze"), :base => @config.group_base])
|
20
|
+
end
|
21
|
+
|
18
22
|
def nest_deep(n)
|
19
23
|
# add all the expects
|
20
24
|
for i in 1..(n-1)
|
@@ -82,4 +86,28 @@ class TestADMemberService < MiniTest::Unit::TestCase
|
|
82
86
|
@ldap.verify
|
83
87
|
end
|
84
88
|
|
89
|
+
def test_find_good_user
|
90
|
+
basic_user
|
91
|
+
@adms.ldap = @ldap
|
92
|
+
assert_equal ad_user_payload, @adms.find_user('john')
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_find_missing_user
|
96
|
+
@ldap.expect(:search, nil, [:filter => ad_name_filter("john")])
|
97
|
+
@adms.ldap = @ldap
|
98
|
+
assert_raises(LdapFluff::ActiveDirectory::MemberService::UIDNotFoundException) { @adms.find_user('john') }
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_find_good_group
|
102
|
+
basic_group
|
103
|
+
@adms.ldap = @ldap
|
104
|
+
assert_equal ad_group_payload, @adms.find_group('broze')
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_find_missing_group
|
108
|
+
@ldap.expect(:search, nil, [:filter => ad_group_filter("broze"), :base => @config.group_base])
|
109
|
+
@adms.ldap = @ldap
|
110
|
+
assert_raises(LdapFluff::ActiveDirectory::MemberService::GIDNotFoundException) { @adms.find_group('broze') }
|
111
|
+
end
|
112
|
+
|
85
113
|
end
|
data/test/ad_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative './lib/ldap_test_helper'
|
2
2
|
|
3
3
|
class TestAD < MiniTest::Unit::TestCase
|
4
4
|
include LdapTestHelper
|
@@ -97,4 +97,42 @@ class TestAD < MiniTest::Unit::TestCase
|
|
97
97
|
bigtime_user
|
98
98
|
assert_equal @ad.is_in_groups("john", ["broskies"],true), true
|
99
99
|
end
|
100
|
+
|
101
|
+
def test_user_exists
|
102
|
+
@md = MiniTest::Mock.new
|
103
|
+
@md.expect(:find_user, 'notnilluser', ["john"])
|
104
|
+
@ad.member_service = @md
|
105
|
+
service_bind
|
106
|
+
assert @ad.user_exists?('john')
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_missing_user
|
110
|
+
@md = MiniTest::Mock.new
|
111
|
+
@md.expect(:find_user, nil, ['john'])
|
112
|
+
def @md.find_user uid
|
113
|
+
raise LdapFluff::ActiveDirectory::MemberService::UIDNotFoundException
|
114
|
+
end
|
115
|
+
@ad.member_service = @md
|
116
|
+
service_bind
|
117
|
+
assert !@ad.user_exists?('john')
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_group_exists
|
121
|
+
@md = MiniTest::Mock.new
|
122
|
+
@md.expect(:find_group, 'notnillgroup', ["broskies"])
|
123
|
+
@ad.member_service = @md
|
124
|
+
service_bind
|
125
|
+
assert @ad.group_exists?('broskies')
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_missing_group
|
129
|
+
@md = MiniTest::Mock.new
|
130
|
+
@md.expect(:find_group, nil, ['broskies'])
|
131
|
+
def @md.find_group uid
|
132
|
+
raise LdapFluff::ActiveDirectory::MemberService::GIDNotFoundException
|
133
|
+
end
|
134
|
+
@ad.member_service = @md
|
135
|
+
service_bind
|
136
|
+
assert !@ad.group_exists?('broskies')
|
137
|
+
end
|
100
138
|
end
|
data/test/config_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative './lib/ldap_test_helper'
|
2
2
|
|
3
3
|
class TestIPAMemberService < MiniTest::Unit::TestCase
|
4
4
|
include LdapTestHelper
|
@@ -13,6 +13,10 @@ class TestIPAMemberService < MiniTest::Unit::TestCase
|
|
13
13
|
@ldap.expect(:search, ipa_user_payload, [:filter => ipa_name_filter("john")])
|
14
14
|
end
|
15
15
|
|
16
|
+
def basic_group
|
17
|
+
@ldap.expect(:search, ipa_group_payload, [:filter => ipa_group_filter("broze"), :base => @config.group_base])
|
18
|
+
end
|
19
|
+
|
16
20
|
def test_find_user
|
17
21
|
basic_user
|
18
22
|
@ipams.ldap = @ldap
|
@@ -33,4 +37,28 @@ class TestIPAMemberService < MiniTest::Unit::TestCase
|
|
33
37
|
assert_equal [], @ipams.find_user_groups('john')
|
34
38
|
@ldap.verify
|
35
39
|
end
|
40
|
+
|
41
|
+
def test_find_good_user
|
42
|
+
basic_user
|
43
|
+
@ipams.ldap = @ldap
|
44
|
+
assert_equal ipa_user_payload, @ipams.find_user('john')
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_find_missing_user
|
48
|
+
@ldap.expect(:search, nil, [:filter => ipa_name_filter("john")])
|
49
|
+
@ipams.ldap = @ldap
|
50
|
+
assert_raises(LdapFluff::FreeIPA::MemberService::UIDNotFoundException) { @ipams.find_user('john') }
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_find_good_group
|
54
|
+
basic_group
|
55
|
+
@ipams.ldap = @ldap
|
56
|
+
assert_equal ipa_group_payload, @ipams.find_group('broze')
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_find_missing_group
|
60
|
+
@ldap.expect(:search, nil, [:filter => ipa_group_filter("broze"), :base => @config.group_base])
|
61
|
+
@ipams.ldap = @ldap
|
62
|
+
assert_raises(LdapFluff::FreeIPA::MemberService::GIDNotFoundException) { @ipams.find_group('broze') }
|
63
|
+
end
|
36
64
|
end
|
data/test/ipa_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative './lib/ldap_test_helper'
|
2
2
|
|
3
3
|
class TestIPA < MiniTest::Unit::TestCase
|
4
4
|
include LdapTestHelper
|
@@ -97,5 +97,43 @@ class TestIPA < MiniTest::Unit::TestCase
|
|
97
97
|
bigtime_user
|
98
98
|
assert_equal @ipa.is_in_groups('john',["broskies"],true), true
|
99
99
|
end
|
100
|
+
|
101
|
+
def test_user_exists
|
102
|
+
@md = MiniTest::Mock.new
|
103
|
+
@md.expect(:find_user, 'notnilluser', ["john"])
|
104
|
+
@ipa.member_service = @md
|
105
|
+
service_bind
|
106
|
+
assert @ipa.user_exists?('john')
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_missing_user
|
110
|
+
@md = MiniTest::Mock.new
|
111
|
+
@md.expect(:find_user, nil, ['john'])
|
112
|
+
def @md.find_user uid
|
113
|
+
raise LdapFluff::FreeIPA::MemberService::UIDNotFoundException
|
114
|
+
end
|
115
|
+
@ipa.member_service = @md
|
116
|
+
service_bind
|
117
|
+
assert !@ipa.user_exists?('john')
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_group_exists
|
121
|
+
@md = MiniTest::Mock.new
|
122
|
+
@md.expect(:find_group, 'notnillgroup', ["broskies"])
|
123
|
+
@ipa.member_service = @md
|
124
|
+
service_bind
|
125
|
+
assert @ipa.group_exists?('broskies')
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_missing_group
|
129
|
+
@md = MiniTest::Mock.new
|
130
|
+
@md.expect(:find_group, nil, ['broskies'])
|
131
|
+
def @md.find_group uid
|
132
|
+
raise LdapFluff::FreeIPA::MemberService::GIDNotFoundException
|
133
|
+
end
|
134
|
+
@ipa.member_service = @md
|
135
|
+
service_bind
|
136
|
+
assert !@ipa.group_exists?('broskies')
|
137
|
+
end
|
100
138
|
end
|
101
139
|
|
data/test/ldap_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative './lib/ldap_test_helper'
|
2
2
|
|
3
3
|
class TestLDAP < MiniTest::Unit::TestCase
|
4
4
|
include LdapTestHelper
|
@@ -29,6 +29,34 @@ class TestLDAP < MiniTest::Unit::TestCase
|
|
29
29
|
assert_equal @fluff.is_in_groups?('john',['broskies','girlfriends']), false
|
30
30
|
@ldap.verify
|
31
31
|
end
|
32
|
+
|
33
|
+
def test_valid_user
|
34
|
+
@ldap.expect(:user_exists?, true, ['john'])
|
35
|
+
@fluff.ldap = @ldap
|
36
|
+
assert @fluff.valid_user? 'john'
|
37
|
+
@ldap.verify
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_valid_group
|
41
|
+
@ldap.expect(:group_exists?, true, ['broskies'])
|
42
|
+
@fluff.ldap = @ldap
|
43
|
+
assert @fluff.valid_group? 'broskies'
|
44
|
+
@ldap.verify
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_invalid_group
|
48
|
+
@ldap.expect(:group_exists?, false, ['broskerinos'])
|
49
|
+
@fluff.ldap = @ldap
|
50
|
+
assert !@fluff.valid_group?('broskerinos')
|
51
|
+
@ldap.verify
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_invalid_user
|
55
|
+
@ldap.expect(:user_exists?, false, ['johnny rotten'])
|
56
|
+
@fluff.ldap = @ldap
|
57
|
+
assert !@fluff.valid_user?('johnny rotten')
|
58
|
+
@ldap.verify
|
59
|
+
end
|
32
60
|
end
|
33
61
|
|
34
62
|
|
@@ -1,5 +1,7 @@
|
|
1
|
-
|
1
|
+
require_relative '../../lib/ldap_fluff'
|
2
2
|
require 'ostruct'
|
3
|
+
require 'net/ldap'
|
4
|
+
require 'minitest/autorun'
|
3
5
|
|
4
6
|
module LdapTestHelper
|
5
7
|
attr_accessor :group_base, :class_filter, :user
|
@@ -21,10 +23,18 @@ module LdapTestHelper
|
|
21
23
|
Net::LDAP::Filter.eq("samaccountname",name)
|
22
24
|
end
|
23
25
|
|
26
|
+
def ad_group_filter(name)
|
27
|
+
Net::LDAP::Filter.eq("cn",name)
|
28
|
+
end
|
29
|
+
|
24
30
|
def ipa_name_filter(name)
|
25
31
|
Net::LDAP::Filter.eq("uid",name)
|
26
32
|
end
|
27
33
|
|
34
|
+
def ipa_group_filter(name)
|
35
|
+
Net::LDAP::Filter.eq("cn",name)
|
36
|
+
end
|
37
|
+
|
28
38
|
def group_filter(g)
|
29
39
|
Net::LDAP::Filter.eq("cn", g)
|
30
40
|
end
|
@@ -41,6 +51,10 @@ module LdapTestHelper
|
|
41
51
|
[{ :memberof => ["CN=group,dc=internet,dc=com"] }]
|
42
52
|
end
|
43
53
|
|
54
|
+
def ad_group_payload
|
55
|
+
[{:cn => "broze", :memberof => ["CN=group,dc=internet,dc=com"] }]
|
56
|
+
end
|
57
|
+
|
44
58
|
def ad_parent_payload(num)
|
45
59
|
[{ :memberof => ["CN=bros#{num},dc=internet,dc=com"] }]
|
46
60
|
end
|
@@ -53,7 +67,15 @@ module LdapTestHelper
|
|
53
67
|
[{:cn => ["bros"]}]
|
54
68
|
end
|
55
69
|
|
70
|
+
def posix_group_payload
|
71
|
+
[{:cn => ["broze"]}]
|
72
|
+
end
|
73
|
+
|
56
74
|
def ipa_user_payload
|
57
|
-
[{:cn => '
|
75
|
+
[{:cn => 'john'},{:memberof => ['cn=group,dc=internet,dc=com','cn=bros,dc=internet,dc=com']}]
|
76
|
+
end
|
77
|
+
|
78
|
+
def ipa_group_payload
|
79
|
+
[{:cn => 'group'},{:memberof => ['cn=group,dc=internet,dc=com','cn=bros,dc=internet,dc=com']}]
|
58
80
|
end
|
59
81
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative './lib/ldap_test_helper'
|
2
2
|
|
3
3
|
class TestPosixMemberService < MiniTest::Unit::TestCase
|
4
4
|
include LdapTestHelper
|
@@ -22,4 +22,58 @@ class TestPosixMemberService < MiniTest::Unit::TestCase
|
|
22
22
|
assert_equal ['bros'], @ms.find_user_groups('john')
|
23
23
|
@ldap.verify
|
24
24
|
end
|
25
|
+
|
26
|
+
def test_user_exists
|
27
|
+
user = posix_user_payload
|
28
|
+
@ldap.expect(:search,
|
29
|
+
user,
|
30
|
+
[
|
31
|
+
:filter => @ms.name_filter('john'),
|
32
|
+
:base =>config.group_base
|
33
|
+
]
|
34
|
+
)
|
35
|
+
@ms.ldap = @ldap
|
36
|
+
assert @ms.find_user('john')
|
37
|
+
@ldap.verify
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_user_doesnt_exists
|
41
|
+
@ldap.expect(:search,
|
42
|
+
nil,
|
43
|
+
[
|
44
|
+
:filter => @ms.name_filter('john'),
|
45
|
+
:base =>config.group_base
|
46
|
+
]
|
47
|
+
)
|
48
|
+
@ms.ldap = @ldap
|
49
|
+
assert_raises(LdapFluff::Posix::MemberService::UIDNotFoundException) { @ms.find_user('john') }
|
50
|
+
@ldap.verify
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_group_exists
|
54
|
+
group = posix_group_payload
|
55
|
+
@ldap.expect(:search,
|
56
|
+
group,
|
57
|
+
[
|
58
|
+
:filter => @ms.group_filter('broze'),
|
59
|
+
:base =>config.group_base
|
60
|
+
]
|
61
|
+
)
|
62
|
+
@ms.ldap = @ldap
|
63
|
+
assert @ms.find_group('broze')
|
64
|
+
@ldap.verify
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_group_doesnt_exists
|
68
|
+
@ldap.expect(:search,
|
69
|
+
nil,
|
70
|
+
[
|
71
|
+
:filter => @ms.group_filter('broze'),
|
72
|
+
:base =>config.group_base
|
73
|
+
]
|
74
|
+
)
|
75
|
+
@ms.ldap = @ldap
|
76
|
+
assert_raises(LdapFluff::Posix::MemberService::GIDNotFoundException) { @ms.find_group('broze') }
|
77
|
+
@ldap.verify
|
78
|
+
end
|
25
79
|
end
|
data/test/posix_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative './lib/ldap_test_helper'
|
2
2
|
|
3
3
|
class TestPosix < MiniTest::Unit::TestCase
|
4
4
|
include LdapTestHelper
|
@@ -61,4 +61,38 @@ class TestPosix < MiniTest::Unit::TestCase
|
|
61
61
|
@posix.ldap = @ldap
|
62
62
|
assert_equal @posix.bind?("internet", "password"), false
|
63
63
|
end
|
64
|
+
|
65
|
+
def test_user_exists
|
66
|
+
@md = MiniTest::Mock.new
|
67
|
+
@md.expect(:find_user, 'notnilluser', ["john"])
|
68
|
+
@posix.member_service = @md
|
69
|
+
assert @posix.user_exists?('john')
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_missing_user
|
73
|
+
@md = MiniTest::Mock.new
|
74
|
+
@md.expect(:find_user, nil, ['john'])
|
75
|
+
def @md.find_user uid
|
76
|
+
raise LdapFluff::Posix::MemberService::UIDNotFoundException
|
77
|
+
end
|
78
|
+
@posix.member_service = @md
|
79
|
+
assert !@posix.user_exists?('john')
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_group_exists
|
83
|
+
@md = MiniTest::Mock.new
|
84
|
+
@md.expect(:find_group, 'notnillgroup', ["broskies"])
|
85
|
+
@posix.member_service = @md
|
86
|
+
assert @posix.group_exists?('broskies')
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_missing_group
|
90
|
+
@md = MiniTest::Mock.new
|
91
|
+
@md.expect(:find_group, nil, ['broskies'])
|
92
|
+
def @md.find_group uid
|
93
|
+
raise LdapFluff::Posix::MemberService::GIDNotFoundException
|
94
|
+
end
|
95
|
+
@posix.member_service = @md
|
96
|
+
assert !@posix.group_exists?('broskies')
|
97
|
+
end
|
64
98
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ldap_fluff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-ldap
|