sheffield_ldap_lookup 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -0
- data/lib/sheffield_ldap_lookup/ldap_finder.rb +10 -2
- data/lib/sheffield_ldap_lookup/version.rb +1 -1
- data/sheffield_ldap_lookup.gemspec +6 -6
- data/spec/lib/ldap_finder_spec.rb +83 -24
- metadata +19 -18
- data/.rvmrc +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3090dd3270a42985506f6077318966d175fb5460a058f397b71f1f70577e283e
|
4
|
+
data.tar.gz: 60717cc86c1e4302bc2d559678cac466a8fde864f716749f9729cef676a29116
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cd3d1d61454854acee77fd4ce9e508596f2f5b915dd55cc1a8ca72812154e0e23da960c0c0abf0d4d51364146261fc46f4f17215e2e0bd62e704fb47aa4c52f
|
7
|
+
data.tar.gz: 229b7266dd482ef161b6544906d1c51847ddc7b28bd027687d295e28474d7fa9a8006386c3bd83d3e032beb1445d6d6400a5fd781f2b947626955605bb973e73
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.1
|
@@ -41,7 +41,9 @@ module SheffieldLdapLookup
|
|
41
41
|
|
42
42
|
def connection_settings
|
43
43
|
base_settings = {
|
44
|
-
host: ldap_config["#{@config_prefix}host"],
|
44
|
+
host: ldap_config["#{@config_prefix}host"],
|
45
|
+
port: ldap_config["#{@config_prefix}port"],
|
46
|
+
base: ldap_config["#{@config_prefix}base"]
|
45
47
|
}
|
46
48
|
|
47
49
|
if ldap_config.key?("#{@config_prefix}username") && ldap_config.key?("#{@config_prefix}password")
|
@@ -51,8 +53,14 @@ module SheffieldLdapLookup
|
|
51
53
|
password: ldap_config["#{@config_prefix}password"]
|
52
54
|
}
|
53
55
|
end
|
56
|
+
|
57
|
+
if ldap_config["#{@config_prefix}ssl"] == true
|
58
|
+
base_settings[:port] ||= 636
|
59
|
+
base_settings[:encryption] = :simple_tls
|
60
|
+
end
|
61
|
+
|
54
62
|
base_settings
|
55
63
|
end
|
56
64
|
|
57
65
|
end
|
58
|
-
end
|
66
|
+
end
|
@@ -6,20 +6,20 @@ require 'sheffield_ldap_lookup/version'
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "sheffield_ldap_lookup"
|
8
8
|
gem.version = SheffieldLdapLookup::VERSION
|
9
|
-
gem.authors = ["Shuo Chen"]
|
10
|
-
gem.email = ["
|
9
|
+
gem.authors = ["James Gregory-Monk", "Shuo Chen"]
|
10
|
+
gem.email = ["james.gregory@epigenesys.org.uk", "shuo.chen@epigenesys.org.uk"]
|
11
11
|
gem.description = "A gem to fetch information from University of Sheffield LDAP server based on username or email address."
|
12
12
|
gem.summary = "LDAP lookup"
|
13
|
-
gem.homepage = "
|
13
|
+
gem.homepage = "https://www.epigenesys.org.uk"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
|
-
|
19
|
+
|
20
20
|
gem.add_dependency('net-ldap')
|
21
|
-
|
21
|
+
|
22
22
|
gem.add_development_dependency('rake')
|
23
23
|
gem.add_development_dependency('rails', '>= 3.2')
|
24
24
|
gem.add_development_dependency('rspec')
|
25
|
-
end
|
25
|
+
end
|
@@ -2,68 +2,127 @@ require 'spec_helper'
|
|
2
2
|
require 'sheffield_ldap_lookup/ldap_finder.rb'
|
3
3
|
|
4
4
|
describe SheffieldLdapLookup::LdapFinder do
|
5
|
-
|
5
|
+
let(:ldap_config) { { 'host' => 'localhost', 'port' => '389', 'base' => 'ou=Users' } }
|
6
|
+
|
6
7
|
describe "#connection" do
|
7
8
|
it "should create a new LDAP connection" do
|
8
|
-
subject.
|
9
|
+
allow(subject).to receive(:ldap_config).and_return(ldap_config)
|
9
10
|
ldap_class = double
|
10
|
-
ldap_class.
|
11
|
+
expect(ldap_class).to receive(:new).with(host: ldap_config['host'], port: ldap_config['port'], base: ldap_config['base'])
|
11
12
|
subject.connection(ldap_class)
|
12
13
|
end
|
13
14
|
end
|
14
|
-
|
15
|
+
|
15
16
|
describe "#ldap_config" do
|
16
17
|
it "should load the LDAP configuration" do
|
17
|
-
SheffieldLdapLookup::LdapFinder.ldap_config =
|
18
|
-
subject.ldap_config.
|
18
|
+
SheffieldLdapLookup::LdapFinder.ldap_config = ldap_config
|
19
|
+
expect(subject.ldap_config).to eq ldap_config
|
19
20
|
end
|
20
21
|
end
|
21
|
-
|
22
|
+
|
22
23
|
describe "#search_attribute" do
|
23
24
|
describe "determine to search against uid or email based on the format of the keyword" do
|
24
25
|
it "should use 'uid' attribute for username" do
|
25
26
|
finder = SheffieldLdapLookup::LdapFinder.new('username')
|
26
|
-
finder.search_attribute.
|
27
|
+
expect(finder.search_attribute).to eq 'uid'
|
27
28
|
end
|
28
|
-
|
29
|
+
|
29
30
|
it "should use 'mail' attribute for email" do
|
30
31
|
finder = SheffieldLdapLookup::LdapFinder.new('test@test.com')
|
31
|
-
finder.search_attribute.
|
32
|
+
expect(finder.search_attribute).to eq 'mail'
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
35
|
-
|
36
|
+
|
36
37
|
describe "#ldap_filter" do
|
37
38
|
it "should create a LDAP filter for the attribute and keyword" do
|
38
39
|
finder = SheffieldLdapLookup::LdapFinder.new('username')
|
39
|
-
finder.
|
40
|
+
allow(finder).to receive(:search_attribute).and_return('uid')
|
40
41
|
filter_class = double
|
41
|
-
filter_class.
|
42
|
+
expect(filter_class).to receive(:eq).with('uid', 'username')
|
42
43
|
finder.ldap_filter filter_class
|
43
44
|
end
|
44
45
|
end
|
45
|
-
|
46
|
+
|
47
|
+
context "load config prefix" do
|
48
|
+
let(:ldap_config) { { 'host' => 'localhost', 'port' => '389', 'base' => 'ou=Users',
|
49
|
+
'prefix_host' => 'prefix_localhost', 'prefix_port' => '400', 'prefix_base' => 'ou=BigUsers' } }
|
50
|
+
subject { SheffieldLdapLookup::LdapFinder.new('123', 'prefix_') }
|
51
|
+
|
52
|
+
it "should create a new LDAP connection" do
|
53
|
+
allow(subject).to receive(:ldap_config).and_return(ldap_config)
|
54
|
+
ldap_class = double
|
55
|
+
expect(ldap_class).to receive(:new).with(host: ldap_config['prefix_host'], port: ldap_config['prefix_port'], base: ldap_config['prefix_base'])
|
56
|
+
subject.connection(ldap_class)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'with an ssl config' do
|
61
|
+
let(:ldap_config) { { 'host' => 'localhost', 'port' => '389', 'base' => 'ou=Users', 'ssl' => true } }
|
62
|
+
|
63
|
+
it "should create a new secure LDAP connection" do
|
64
|
+
allow(subject).to receive(:ldap_config).and_return(ldap_config)
|
65
|
+
ldap_class = double
|
66
|
+
expect(ldap_class).to receive(:new).with(host: ldap_config['host'],
|
67
|
+
port: ldap_config['port'], base: ldap_config['base'],
|
68
|
+
encryption: :simple_tls)
|
69
|
+
subject.connection(ldap_class)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'with a username and password config' do
|
74
|
+
let(:ldap_config) { { 'host' => 'localhost', 'port' => '389', 'base' => 'ou=Users',
|
75
|
+
'username' => 'ldapusername', 'password' => 'ldappassword' } }
|
76
|
+
|
77
|
+
it "should create a new secure LDAP connection" do
|
78
|
+
allow(subject).to receive(:ldap_config).and_return(ldap_config)
|
79
|
+
ldap_class = double
|
80
|
+
expect(ldap_class).to receive(:new).with(host: ldap_config['host'],
|
81
|
+
port: ldap_config['port'], base: ldap_config['base'],
|
82
|
+
auth: { method: :simple, username: 'ldapusername', password: 'ldappassword' } )
|
83
|
+
subject.connection(ldap_class)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'with a username, password and ssl config' do
|
88
|
+
let(:ldap_config) { { 'host' => 'localhost', 'port' => '389', 'base' => 'ou=Users',
|
89
|
+
'username' => 'ldapusername', 'password' => 'ldappassword', 'ssl' => true } }
|
90
|
+
|
91
|
+
it "should create a new secure LDAP connection" do
|
92
|
+
allow(subject).to receive(:ldap_config).and_return(ldap_config)
|
93
|
+
ldap_class = double
|
94
|
+
expect(ldap_class).to receive(:new).with(host: ldap_config['host'],
|
95
|
+
port: ldap_config['port'], base: ldap_config['base'], encryption: :simple_tls,
|
96
|
+
auth: { method: :simple, username: 'ldapusername', password: 'ldappassword' } )
|
97
|
+
subject.connection(ldap_class)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
46
101
|
describe "#lookup" do
|
47
102
|
describe "use the LDAP filter to search for the entity and return the first result" do
|
48
103
|
let(:ldap_filter) { double }
|
49
104
|
let(:connection) { double }
|
50
|
-
|
51
|
-
|
105
|
+
|
106
|
+
before do
|
107
|
+
allow(subject).to receive(:ldap_filter).and_return(ldap_filter)
|
108
|
+
allow(subject).to receive(:connection).and_return(connection)
|
109
|
+
end
|
110
|
+
|
52
111
|
it "should search the LDAP connection using the filter" do
|
53
|
-
connection.
|
112
|
+
expect(connection).to receive(:search).with(filter: ldap_filter).and_return([])
|
54
113
|
subject.lookup
|
55
114
|
end
|
56
|
-
|
115
|
+
|
57
116
|
it "should return the first result" do
|
58
117
|
result = double
|
59
|
-
connection.
|
60
|
-
subject.lookup.
|
118
|
+
allow(connection).to receive(:search).and_return([result])
|
119
|
+
expect(subject.lookup).to eq result
|
61
120
|
end
|
62
|
-
|
121
|
+
|
63
122
|
it "should return an empty hash if cannot connect to LDAP" do
|
64
|
-
connection.
|
65
|
-
subject.lookup.
|
123
|
+
allow(connection).to receive(:search).and_return(->{raise})
|
124
|
+
expect(subject.lookup).to eq({})
|
66
125
|
end
|
67
126
|
end
|
68
127
|
end
|
69
|
-
end
|
128
|
+
end
|
metadata
CHANGED
@@ -1,81 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sheffield_ldap_lookup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- James Gregory-Monk
|
7
8
|
- Shuo Chen
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2023-01-05 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: net-ldap
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- -
|
18
|
+
- - ">="
|
18
19
|
- !ruby/object:Gem::Version
|
19
20
|
version: '0'
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
|
-
- -
|
25
|
+
- - ">="
|
25
26
|
- !ruby/object:Gem::Version
|
26
27
|
version: '0'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: rake
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
|
-
- -
|
32
|
+
- - ">="
|
32
33
|
- !ruby/object:Gem::Version
|
33
34
|
version: '0'
|
34
35
|
type: :development
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
|
-
- -
|
39
|
+
- - ">="
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '0'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
43
|
name: rails
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
|
-
- -
|
46
|
+
- - ">="
|
46
47
|
- !ruby/object:Gem::Version
|
47
48
|
version: '3.2'
|
48
49
|
type: :development
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
|
-
- -
|
53
|
+
- - ">="
|
53
54
|
- !ruby/object:Gem::Version
|
54
55
|
version: '3.2'
|
55
56
|
- !ruby/object:Gem::Dependency
|
56
57
|
name: rspec
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
|
-
- -
|
60
|
+
- - ">="
|
60
61
|
- !ruby/object:Gem::Version
|
61
62
|
version: '0'
|
62
63
|
type: :development
|
63
64
|
prerelease: false
|
64
65
|
version_requirements: !ruby/object:Gem::Requirement
|
65
66
|
requirements:
|
66
|
-
- -
|
67
|
+
- - ">="
|
67
68
|
- !ruby/object:Gem::Version
|
68
69
|
version: '0'
|
69
70
|
description: A gem to fetch information from University of Sheffield LDAP server based
|
70
71
|
on username or email address.
|
71
72
|
email:
|
72
|
-
-
|
73
|
+
- james.gregory@epigenesys.org.uk
|
74
|
+
- shuo.chen@epigenesys.org.uk
|
73
75
|
executables: []
|
74
76
|
extensions: []
|
75
77
|
extra_rdoc_files: []
|
76
78
|
files:
|
77
|
-
- .gitignore
|
78
|
-
- .
|
79
|
+
- ".gitignore"
|
80
|
+
- ".ruby-version"
|
79
81
|
- Gemfile
|
80
82
|
- LICENSE.txt
|
81
83
|
- README.md
|
@@ -88,7 +90,7 @@ files:
|
|
88
90
|
- sheffield_ldap_lookup.gemspec
|
89
91
|
- spec/lib/ldap_finder_spec.rb
|
90
92
|
- spec/spec_helper.rb
|
91
|
-
homepage:
|
93
|
+
homepage: https://www.epigenesys.org.uk
|
92
94
|
licenses: []
|
93
95
|
metadata: {}
|
94
96
|
post_install_message:
|
@@ -97,17 +99,16 @@ require_paths:
|
|
97
99
|
- lib
|
98
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
99
101
|
requirements:
|
100
|
-
- -
|
102
|
+
- - ">="
|
101
103
|
- !ruby/object:Gem::Version
|
102
104
|
version: '0'
|
103
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
106
|
requirements:
|
105
|
-
- -
|
107
|
+
- - ">="
|
106
108
|
- !ruby/object:Gem::Version
|
107
109
|
version: '0'
|
108
110
|
requirements: []
|
109
|
-
|
110
|
-
rubygems_version: 2.4.6
|
111
|
+
rubygems_version: 3.1.6
|
111
112
|
signing_key:
|
112
113
|
specification_version: 4
|
113
114
|
summary: LDAP lookup
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm use --create @sheffield_ldap_lookup
|