ldap_groups_lookup 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 204d6f964fd4220ed8043e376bd0d373d127968853b88559f66df7c9edf518ab
|
4
|
+
data.tar.gz: 9cdb88255825aba6bef3f71c78be2ed20edbac518a5cebda8535ec663497a51b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f079510a9a3c4349c3164d8abc8cd6f99e65c826dee864d31188e4379fd345cda75c70292a73f3b0d682f2611351da23bbe6d1381f22d00b022aee4a695fb8e
|
7
|
+
data.tar.gz: d2b11fe898402af8662feedd335f44bf7392213721ae5f98a9eb930085f44c5270613e24c89ba0b07448cad35b6c99ca7057f52d6b9c9b43069e45254c6a81d3
|
@@ -4,6 +4,12 @@ module LDAPGroupsLookup
|
|
4
4
|
module Behavior
|
5
5
|
require 'ldap_groups_lookup'
|
6
6
|
|
7
|
+
# @return String object's mail attribute
|
8
|
+
def ldap_mail
|
9
|
+
return '' unless respond_to? :ldap_lookup_key
|
10
|
+
LDAPGroupsLookup.lookup_mail(ldap_lookup_key)
|
11
|
+
end
|
12
|
+
|
7
13
|
# Searches object's nested LDAP groups by value of ldap_lookup_key
|
8
14
|
# @return [Array] all of the object's LDAP groups, sorted
|
9
15
|
def ldap_groups
|
@@ -33,6 +33,13 @@ module LDAPGroupsLookup
|
|
33
33
|
service.search(base: tree, filter: Net::LDAP::Filter.equals('cn', cn), attributes: 'dn').first&.dn
|
34
34
|
end
|
35
35
|
|
36
|
+
# Returns the mail for a given CN attribute
|
37
|
+
def lookup_mail(cn)
|
38
|
+
service&.search(base: tree,
|
39
|
+
filter: Net::LDAP::Filter.equals('cn', cn),
|
40
|
+
attributes: 'mail')&.first&.mail&.first.to_s
|
41
|
+
end
|
42
|
+
|
36
43
|
# Strips a DN string down to just its CN segment.
|
37
44
|
def dn_to_cn(dn)
|
38
45
|
dn.match(/CN=(.+?),/)[1]
|
@@ -65,6 +65,36 @@ RSpec.describe LDAPGroupsLookup do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
describe '#ldap_mail' do
|
69
|
+
before(:each) do
|
70
|
+
entry = Net::LDAP::Entry.new('CN=user,DC=ads,DC=example,DC=net')
|
71
|
+
entry['mail'] = ['user@domain.ext']
|
72
|
+
allow_any_instance_of(Net::LDAP).to receive(:search).and_return([entry])
|
73
|
+
allow_any_instance_of(Net::LDAP).to receive(:bind).and_return(true)
|
74
|
+
end
|
75
|
+
context 'when subject does not provide ldap_lookup_key' do
|
76
|
+
before(:each) { user.class.send(:remove_method, :ldap_lookup_key) }
|
77
|
+
it 'should return ''' do
|
78
|
+
expect(user.ldap_mail).to eq('')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
context 'when subject provides ldap_lookup_key' do
|
82
|
+
context 'when LDAP is not configured' do
|
83
|
+
before(:each) do
|
84
|
+
config[:enabled] = false
|
85
|
+
end
|
86
|
+
it 'should return a blank string' do
|
87
|
+
expect(user.ldap_mail).to eq('')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
context 'when LDAP is configured' do
|
91
|
+
it 'user should should have a mail attribute in mock LDAP' do
|
92
|
+
expect(user.ldap_mail).to eq 'user@domain.ext'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
68
98
|
describe '#ldap_groups' do
|
69
99
|
before(:each) do
|
70
100
|
entry = Net::LDAP::Entry.new('CN=user,DC=ads,DC=example,DC=net')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ldap_groups_lookup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Ploshay
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-
|
13
|
+
date: 2018-12-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: net-ldap
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
requirements: []
|
114
114
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.6
|
115
|
+
rubygems_version: 2.7.6
|
116
116
|
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: Provides easy access to the list of LDAP groups a username is a member of.
|