mit-ldap 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module MIT
2
2
  module LDAP
3
- VERSION = "0.0.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/lib/mit/ldap.rb CHANGED
@@ -1,2 +1,23 @@
1
- require 'mit/ldap/version'
2
- require 'mit/ldap/search'
1
+ module MIT
2
+ module LDAP
3
+
4
+ class << self
5
+ attr_accessor :connection
6
+ end
7
+
8
+ def self.connect!
9
+ if MIT.on_campus?
10
+ self.connection = ::LDAP::Conn.new('ldap-too.mit.edu')
11
+ singleton_class.send(:include,
12
+ Ldaptic::Module(
13
+ adapter: :ldap_conn,
14
+ connection: connection,
15
+ host: 'ldap-too.mit.edu',
16
+ base: 'dc=mit,dc=edu',
17
+ )
18
+ )
19
+ end
20
+ return !self.connection.nil?
21
+ end
22
+ end
23
+ end
data/lib/mit-ldap.rb CHANGED
@@ -1,14 +1,26 @@
1
+ require 'rbconfig'
2
+ require 'ldap'
3
+ require 'ldaptic'
4
+
1
5
  module MIT
2
6
 
3
- def self.on_campus_network?
4
- !(hostname =~ /\.mit\.edu$/i).nil?
5
- end
7
+ class << self
8
+
9
+ def on_campus?
10
+ ip_addresses.split(/\n/).map { |ip| !(ip =~ /^18\./).nil? }.any?
11
+ end
6
12
 
7
- private
13
+ private
8
14
 
9
- def self.hostname
10
- @hostname ||= `hostname`
15
+ def ip_addresses
16
+ if RbConfig::CONFIG['host_os'] =~ /darwin/
17
+ `ifconfig | awk '/inet / {print $2}'`
18
+ else
19
+ `ifconfig | sed -rn 's/.*r:([^ ]+) .*/\1/p'`
20
+ end
21
+ end
11
22
  end
12
23
  end
13
24
 
14
25
  require 'mit/ldap'
26
+ require 'mit/ldap/version'
data/mit-ldap.gemspec CHANGED
@@ -7,9 +7,9 @@ Gem::Specification.new do |s|
7
7
  s.version = MIT::LDAP::VERSION
8
8
  s.authors = ["Eduardo Gutierrez"]
9
9
  s.email = ["edd_d@mit.edu"]
10
- s.homepage = ""
11
- s.summary = %q{Wrapper for MIT LDAP server}
12
- s.description = %q{Configure Ldaptic to search MIT LDAP server}
10
+ s.homepage = "https://github.com/ecbypi/mit-ldap"
11
+ s.summary = %q{Ruby interface for querying MIT LDAP server}
12
+ s.description = %q{Ruby interface for querying MIT LDAP server (only if you're on MITnet)}
13
13
 
14
14
  s.rubyforge_project = "mit-ldap"
15
15
 
data/spec/ldap_spec.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'mit-ldap'
2
+
3
+ module MIT
4
+ describe LDAP do
5
+
6
+ # Use the legacy MIT ldap server that is accessible from off campus
7
+ # so we can use a LDAP::Conn instance for stubbing tests
8
+ #
9
+ # Server is not properly configured so the attributes required
10
+ # by Ldaptic when configuring class hierarchy do not exist resulting
11
+ # searches failing (i.e., this method should only be used to get around
12
+ # ldap-too only being accessible from campus
13
+ def stub_ldap_connection
14
+ @connection = ::LDAP::Conn.new('ldap.mit.edu')
15
+ ::LDAP::Conn.stub(:new).and_return(@connection)
16
+ end
17
+
18
+ def stub_ldaptic_include
19
+ Ldaptic.stub(:Module).and_return(MIT::LDAP)
20
+ end
21
+
22
+ describe ".connect!" do
23
+ describe "when off campus" do
24
+ it "returns false" do
25
+ MIT.stub(:on_campus?).and_return(false)
26
+ LDAP.connect!.should be_false
27
+ end
28
+ end
29
+
30
+ describe "when on campus" do
31
+ before :each do
32
+ MIT.stub(:on_campus?).and_return(true)
33
+ stub_ldap_connection
34
+ stub_ldaptic_include
35
+ end
36
+
37
+ it "sets up ldap connection" do
38
+ ::LDAP::Conn.should_receive(:new).with('ldap-too.mit.edu')
39
+ LDAP.connect!
40
+ end
41
+
42
+ it "includes Ldaptic::Module" do
43
+ Ldaptic.should_receive(:Module).
44
+ with(adapter: :ldap_conn,
45
+ base: 'dc=mit,dc=edu',
46
+ connection: @connection,
47
+ host: 'ldap-too.mit.edu'
48
+ )
49
+ LDAP.connect!
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
data/spec/mit_spec.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'mit-ldap'
2
+
3
+ describe MIT do
4
+
5
+ describe ".on_campus?" do
6
+ it "returns true if IP starts with 18" do
7
+ MIT.stub(:ip_addresses).and_return("18.0.0.0\n127.0.0.1")
8
+ MIT.on_campus?.should be_true
9
+ end
10
+
11
+ it "returns false if no network device has a campus address" do
12
+ MIT.stub(:ip_addresses).and_return("192.168.1.2\n127.0.0.1")
13
+ MIT.on_campus?.should be_false
14
+ end
15
+ end
16
+ 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.0.1
4
+ version: 0.2.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-03-09 00:00:00.000000000 Z
12
+ date: 2012-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ldaptic
16
- requirement: &70209240826340 !ruby/object:Gem::Requirement
16
+ requirement: &70244886779820 !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: *70209240826340
24
+ version_requirements: *70244886779820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: ruby-ldap
27
- requirement: &70209240825840 !ruby/object:Gem::Requirement
27
+ requirement: &70244886779300 !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: *70209240825840
35
+ version_requirements: *70244886779300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70209240825380 !ruby/object:Gem::Requirement
38
+ requirement: &70244886778820 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,8 +43,8 @@ dependencies:
43
43
  version: '2.0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70209240825380
47
- description: Configure Ldaptic to search MIT LDAP server
46
+ version_requirements: *70244886778820
47
+ description: Ruby interface for querying MIT LDAP server (only if you're on MITnet)
48
48
  email:
49
49
  - edd_d@mit.edu
50
50
  executables: []
@@ -59,12 +59,11 @@ files:
59
59
  - Rakefile
60
60
  - lib/mit-ldap.rb
61
61
  - lib/mit/ldap.rb
62
- - lib/mit/ldap/search.rb
63
62
  - lib/mit/ldap/version.rb
64
63
  - mit-ldap.gemspec
65
- - spec/lib/ldap/search_spec.rb
66
- - spec/lib/mit_spec.rb
67
- homepage: ''
64
+ - spec/ldap_spec.rb
65
+ - spec/mit_spec.rb
66
+ homepage: https://github.com/ecbypi/mit-ldap
68
67
  licenses: []
69
68
  post_install_message:
70
69
  rdoc_options: []
@@ -87,8 +86,7 @@ rubyforge_project: mit-ldap
87
86
  rubygems_version: 1.8.11
88
87
  signing_key:
89
88
  specification_version: 3
90
- summary: Wrapper for MIT LDAP server
89
+ summary: Ruby interface for querying MIT LDAP server
91
90
  test_files:
92
- - spec/lib/ldap/search_spec.rb
93
- - spec/lib/mit_spec.rb
94
- has_rdoc:
91
+ - spec/ldap_spec.rb
92
+ - spec/mit_spec.rb
@@ -1,27 +0,0 @@
1
- require 'ldap'
2
- require 'ldaptic'
3
-
4
- module MIT
5
- module LDAP
6
- module Search
7
- if MIT.on_campus_network?
8
- include Ldaptic::Module(
9
- host: 'ldap-too.mit.edu',
10
- base: 'dc=mit,dc=edu',
11
- adapter: :ldap_conn
12
- )
13
- else
14
- class InetOrgPerson
15
- end
16
-
17
- def self.search(*args)
18
- []
19
- end
20
-
21
- def self.find(*args)
22
- InetOrgPerson.new
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,19 +0,0 @@
1
- require 'mit-ldap'
2
-
3
- module MIT
4
- module LDAP
5
- describe Search do
6
- if MIT.on_campus_network?
7
- it "includes Ldaptic::Module" do
8
- should respond_to :search
9
- should respond_to :find
10
- end
11
- else
12
- it "defines stubs that return empty arrays" do
13
- Search.search.should eq []
14
- Search.find.should be_instance_of Search::InetOrgPerson
15
- end
16
- end
17
- end
18
- end
19
- end
data/spec/lib/mit_spec.rb DELETED
@@ -1,15 +0,0 @@
1
- require 'mit-ldap'
2
-
3
- describe MIT do
4
-
5
- describe ".on_campus_network?" do
6
- it "confirms if we're on the campus network meaning we have a .mit.edu hostname" do
7
-
8
- MIT.stub(:hostname).and_return('localhost')
9
- MIT.on_campus_network?.should eq false
10
-
11
- MIT.stub(:hostname).and_return('server.mit.edu')
12
- MIT.on_campus_network?.should eq true
13
- end
14
- end
15
- end