mit-ldap 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mit/ldap.rb +27 -14
- data/lib/mit/ldap/version.rb +1 -1
- data/spec/ldap_spec.rb +21 -42
- metadata +8 -8
data/lib/mit/ldap.rb
CHANGED
@@ -1,27 +1,40 @@
|
|
1
1
|
module MIT
|
2
2
|
module LDAP
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
Ldaptic::Module(
|
4
|
+
class << self
|
5
|
+
def connect!
|
6
|
+
if MIT.on_campus?
|
7
|
+
include Ldaptic::Module(
|
9
8
|
:adapter => :ldap_conn,
|
10
|
-
:connection =>
|
9
|
+
:connection => ::LDAP::Conn.new('ldap-too.mit.edu'),
|
11
10
|
:host => 'ldap-too.mit.edu',
|
12
11
|
:base => 'dc=mit,dc=edu',
|
13
12
|
)
|
14
|
-
|
13
|
+
end
|
14
|
+
return connected?
|
15
15
|
end
|
16
|
-
return connected?
|
17
|
-
end
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
def connected?
|
18
|
+
!connection.nil?
|
19
|
+
end
|
20
|
+
|
21
|
+
def reconnect!
|
22
|
+
if adapter_present? && !connected?
|
23
|
+
adapter.instance_variable_set(:@connection, ::LDAP::Conn.new('ldap-too.mit.edu'))
|
24
|
+
elsif !adapter_present?
|
25
|
+
connect!
|
26
|
+
end
|
27
|
+
end
|
22
28
|
|
23
|
-
|
24
|
-
|
29
|
+
private
|
30
|
+
|
31
|
+
def connection
|
32
|
+
adapter.instance_variable_get(:@connection) if adapter_present?
|
33
|
+
end
|
34
|
+
|
35
|
+
def adapter_present?
|
36
|
+
respond_to?(:adapter)
|
37
|
+
end
|
25
38
|
end
|
26
39
|
end
|
27
40
|
end
|
data/lib/mit/ldap/version.rb
CHANGED
data/spec/ldap_spec.rb
CHANGED
@@ -1,36 +1,10 @@
|
|
1
1
|
require 'mit-ldap'
|
2
|
-
require 'ldaptic/adapters/ldap_conn_adapter'
|
3
2
|
|
4
3
|
module MIT
|
5
4
|
describe LDAP do
|
6
|
-
|
7
|
-
# Use the legacy MIT ldap server that is accessible from off campus
|
8
|
-
# so we can use a LDAP::Conn instance for stubbing tests
|
9
|
-
#
|
10
|
-
# Server is not properly configured so the attributes required
|
11
|
-
# by Ldaptic when configuring class hierarchy do not exist resulting
|
12
|
-
# searches failing (i.e., this method should only be used to get around
|
13
|
-
# ldap-too only being accessible from campus)
|
14
|
-
let!(:connection) { ::LDAP::Conn.new('ldap.mit.edu') }
|
15
|
-
|
16
|
-
def stub_ldap_connection
|
17
|
-
::LDAP::Conn.stub(:new).and_return(connection)
|
18
|
-
stub_ldaptic_adapter(connection)
|
19
|
-
end
|
20
|
-
|
21
|
-
def stub_ldaptic_adapter(connection = nil)
|
22
|
-
adapter = double('adapter')
|
23
|
-
adapter.stub(:instance_variable_get).with(:@connection).and_return(connection)
|
24
|
-
LDAP.stub(:adapter).and_return(adapter)
|
25
|
-
end
|
26
|
-
|
27
|
-
def stub_ldaptic_include
|
28
|
-
Ldaptic.stub(:Module).and_return(MIT::LDAP)
|
29
|
-
end
|
30
|
-
|
31
5
|
describe ".connect!" do
|
32
|
-
describe "when off campus" do
|
33
6
|
|
7
|
+
describe "when off campus" do
|
34
8
|
it "returns false" do
|
35
9
|
MIT.stub(:on_campus?).and_return(false)
|
36
10
|
LDAP.connect!.should be_false
|
@@ -38,27 +12,32 @@ module MIT
|
|
38
12
|
end
|
39
13
|
|
40
14
|
describe "when on campus" do
|
41
|
-
before :
|
42
|
-
|
43
|
-
stub_ldap_connection
|
44
|
-
stub_ldaptic_include
|
15
|
+
before :all do
|
16
|
+
LDAP.connect!
|
45
17
|
end
|
46
18
|
|
47
|
-
it "
|
48
|
-
|
49
|
-
LDAP.connect!
|
19
|
+
it ":connected? is true" do
|
20
|
+
LDAP.connected?.should be_true
|
50
21
|
end
|
51
22
|
|
52
|
-
it "
|
53
|
-
|
54
|
-
with(:adapter => :ldap_conn,
|
55
|
-
:base => 'dc=mit,dc=edu',
|
56
|
-
:connection => connection,
|
57
|
-
:host => 'ldap-too.mit.edu'
|
58
|
-
)
|
59
|
-
LDAP.connect!
|
23
|
+
it "an Ldaptic::Adapter is set" do
|
24
|
+
LDAP.adapter.should be_a Ldaptic::Adapters::LDAPConnAdapter
|
60
25
|
end
|
61
26
|
end
|
62
27
|
end
|
28
|
+
|
29
|
+
describe ".reconnect!" do
|
30
|
+
it "reloads connection object if nil" do
|
31
|
+
LDAP.adapter.instance_variable_set(:@connection, nil)
|
32
|
+
LDAP.reconnect!
|
33
|
+
LDAP.adapter.instance_variable_get(:@connection).should be_a ::LDAP::Conn
|
34
|
+
end
|
35
|
+
|
36
|
+
it "calls .connect! if not connected" do
|
37
|
+
LDAP.stub(:adapter_present?).and_return(false)
|
38
|
+
LDAP.should_receive(:connect!)
|
39
|
+
LDAP.reconnect!
|
40
|
+
end
|
41
|
+
end
|
63
42
|
end
|
64
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mit-ldap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ldaptic
|
16
|
-
requirement: &
|
16
|
+
requirement: &70320703308640 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70320703308640
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: ruby-ldap
|
27
|
-
requirement: &
|
27
|
+
requirement: &70320703308140 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0.9'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70320703308140
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70320703307680 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '2.0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70320703307680
|
47
47
|
description: Ruby interface for querying MIT LDAP server (only if you're on MITnet)
|
48
48
|
email:
|
49
49
|
- edd_d@mit.edu
|