fakeGenLdap 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Aanand Prasad
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ Install: `gem install fakeldap`
2
+
3
+ Only supports bind operations for now.
4
+
5
+ Have a look at [server_spec.rb](http://github.com/aanand/fakeldap/blob/master/spec/server_spec.rb) for usage.
@@ -0,0 +1,66 @@
1
+ $:.unshift(File.expand_path('../../vendor/ruby-ldapserver/lib', __FILE__))
2
+ require 'ldap/server'
3
+
4
+ module FakeLDAP
5
+ class Server < LDAP::Server
6
+ def initialize(options={})
7
+ @users = {}
8
+ super(default_options.merge(options))
9
+ end
10
+
11
+ def add_user(user, pass)
12
+ @users[user] = pass
13
+ end
14
+
15
+ def valid_credentials?(user, pass)
16
+ @users.has_key?(user) && @users[user] == pass
17
+ end
18
+
19
+ def find_users(basedn, filter)
20
+ basedn_regex = /#{Regexp.escape(basedn)}$/
21
+ filter_regex = /^#{filter[1]}=#{filter[3]}$/
22
+
23
+ @users.keys.select { |dn|
24
+ dn =~ basedn_regex && dn.split(",").grep(filter_regex).any?
25
+ }
26
+ end
27
+
28
+ def default_options
29
+ {
30
+ :operation_class => ::FakeLDAP::Operation,
31
+ :operation_args => [self]
32
+ }
33
+ end
34
+ end
35
+
36
+ class Operation < LDAP::Server::Operation
37
+ def initialize(connection, messageID, server)
38
+ super(connection, messageID)
39
+ @server = server
40
+ end
41
+
42
+ def simple_bind(version, dn, password)
43
+ unless dn
44
+ raise LDAP::ResultError::InappropriateAuthentication,
45
+ "This server does not support anonymous bind"
46
+ end
47
+
48
+ unless @server.valid_credentials?(dn, password)
49
+ raise LDAP::ResultError::InvalidCredentials,
50
+ "Invalid credentials"
51
+ end
52
+ end
53
+
54
+ def search(basedn, scope, deref, filter, attrs=nil)
55
+ unless filter.first == :eq
56
+ raise LDAP::ResultError::UnwillingToPerform,
57
+ "Only equality matches are supported"
58
+ end
59
+
60
+ @server.find_users(basedn, filter).each do |dn|
61
+ send_SearchResultEntry(dn, {})
62
+ end
63
+ end
64
+ end
65
+ end
66
+
@@ -0,0 +1,4 @@
1
+ module FakeLDAP
2
+ VERSION = "0.0.1"
3
+ end
4
+
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fakeGenLdap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aanand Prasad
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.0.beta.22
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0.beta.22
30
+ - !ruby/object:Gem::Dependency
31
+ name: net-ldap
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: ruby-debug19
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description:
63
+ email:
64
+ - aanand.prasad@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - lib/fakeldap/version.rb
70
+ - lib/fakeldap.rb
71
+ - LICENSE
72
+ - README.md
73
+ homepage: http://github.com/aanand/fakeldap
74
+ licenses: []
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.24
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: A fake LDAP server for use in testing
97
+ test_files: []