net-ldap 0.16.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/History.rdoc +64 -0
- data/README.rdoc +18 -6
- data/lib/net/ber/core_ext.rb +6 -6
- data/lib/net/ber.rb +2 -2
- data/lib/net/ldap/auth_adapter/gss_spnego.rb +2 -2
- data/lib/net/ldap/auth_adapter/sasl.rb +1 -1
- data/lib/net/ldap/auth_adapter/simple.rb +1 -1
- data/lib/net/ldap/connection.rb +23 -16
- data/lib/net/ldap/dataset.rb +1 -3
- data/lib/net/ldap/dn.rb +14 -22
- data/lib/net/ldap/entry.rb +11 -2
- data/lib/net/ldap/error.rb +2 -26
- data/lib/net/ldap/filter.rb +10 -3
- data/lib/net/ldap/instrumentation.rb +2 -2
- data/lib/net/ldap/password.rb +7 -5
- data/lib/net/ldap/pdu.rb +1 -1
- data/lib/net/ldap/version.rb +1 -1
- data/lib/net/ldap.rb +40 -17
- data/lib/net/snmp.rb +1 -1
- data/lib/net-ldap.rb +1 -1
- metadata +16 -106
- data/.gitignore +0 -9
- data/.rubocop.yml +0 -20
- data/.rubocop_todo.yml +0 -753
- data/.travis.yml +0 -33
- data/CONTRIBUTING.md +0 -54
- data/Gemfile +0 -2
- data/Rakefile +0 -23
- data/net-ldap.gemspec +0 -37
- data/script/changelog +0 -47
- data/script/generate-fixture-ca +0 -48
- data/script/install-openldap +0 -134
- data/script/package +0 -7
- data/script/release +0 -16
- data/test/ber/core_ext/test_array.rb +0 -22
- data/test/ber/core_ext/test_string.rb +0 -25
- data/test/ber/test_ber.rb +0 -153
- data/test/fixtures/ca/ca.info +0 -4
- data/test/fixtures/ca/cacert.pem +0 -24
- data/test/fixtures/ca/cakey.pem +0 -190
- data/test/fixtures/openldap/memberof.ldif +0 -33
- data/test/fixtures/openldap/retcode.ldif +0 -76
- data/test/fixtures/openldap/slapd.conf.ldif +0 -67
- data/test/fixtures/seed.ldif +0 -374
- data/test/integration/test_add.rb +0 -28
- data/test/integration/test_ber.rb +0 -30
- data/test/integration/test_bind.rb +0 -244
- data/test/integration/test_delete.rb +0 -31
- data/test/integration/test_open.rb +0 -88
- data/test/integration/test_password_modify.rb +0 -80
- data/test/integration/test_return_codes.rb +0 -38
- data/test/integration/test_search.rb +0 -77
- data/test/support/vm/openldap/.gitignore +0 -1
- data/test/support/vm/openldap/README.md +0 -64
- data/test/support/vm/openldap/Vagrantfile +0 -34
- data/test/test_auth_adapter.rb +0 -15
- data/test/test_dn.rb +0 -44
- data/test/test_entry.rb +0 -65
- data/test/test_filter.rb +0 -223
- data/test/test_filter_parser.rb +0 -24
- data/test/test_helper.rb +0 -74
- data/test/test_ldap.rb +0 -114
- data/test/test_ldap_connection.rb +0 -491
- data/test/test_ldif.rb +0 -104
- data/test/test_password.rb +0 -10
- data/test/test_rename.rb +0 -77
- data/test/test_search.rb +0 -39
- data/test/test_snmp.rb +0 -119
- data/test/test_ssl_ber.rb +0 -40
- data/test/testdata.ldif +0 -101
- data/testserver/ldapserver.rb +0 -209
- data/testserver/testdata.ldif +0 -101
@@ -1,88 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
class TestBindIntegration < LDAPIntegrationTestCase
|
4
|
-
def test_binds_without_open
|
5
|
-
events = @service.subscribe "bind.net_ldap_connection"
|
6
|
-
|
7
|
-
@ldap.search(filter: "uid=user1", base: "ou=People,dc=rubyldap,dc=com", ignore_server_caps: true)
|
8
|
-
@ldap.search(filter: "uid=user1", base: "ou=People,dc=rubyldap,dc=com", ignore_server_caps: true)
|
9
|
-
|
10
|
-
assert_equal 2, events.size
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_binds_with_open
|
14
|
-
events = @service.subscribe "bind.net_ldap_connection"
|
15
|
-
|
16
|
-
@ldap.open do
|
17
|
-
@ldap.search(filter: "uid=user1", base: "ou=People,dc=rubyldap,dc=com", ignore_server_caps: true)
|
18
|
-
@ldap.search(filter: "uid=user1", base: "ou=People,dc=rubyldap,dc=com", ignore_server_caps: true)
|
19
|
-
end
|
20
|
-
|
21
|
-
assert_equal 1, events.size
|
22
|
-
end
|
23
|
-
|
24
|
-
# NOTE: query for two or more entries so that the socket must be read
|
25
|
-
# multiple times.
|
26
|
-
# See The Problem: https://github.com/ruby-ldap/ruby-net-ldap/issues/136
|
27
|
-
|
28
|
-
def test_nested_search_without_open
|
29
|
-
entries = []
|
30
|
-
nested_entry = nil
|
31
|
-
|
32
|
-
@ldap.search(filter: "(|(uid=user1)(uid=user2))", base: "ou=People,dc=rubyldap,dc=com") do |entry|
|
33
|
-
entries << entry.uid.first
|
34
|
-
nested_entry ||= @ldap.search(filter: "uid=user3", base: "ou=People,dc=rubyldap,dc=com").first
|
35
|
-
end
|
36
|
-
|
37
|
-
assert_equal "user3", nested_entry.uid.first
|
38
|
-
assert_equal %w(user1 user2), entries
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_nested_search_with_open
|
42
|
-
entries = []
|
43
|
-
nested_entry = nil
|
44
|
-
|
45
|
-
@ldap.open do
|
46
|
-
@ldap.search(filter: "(|(uid=user1)(uid=user2))", base: "ou=People,dc=rubyldap,dc=com") do |entry|
|
47
|
-
entries << entry.uid.first
|
48
|
-
nested_entry ||= @ldap.search(filter: "uid=user3", base: "ou=People,dc=rubyldap,dc=com").first
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
assert_equal "user3", nested_entry.uid.first
|
53
|
-
assert_equal %w(user1 user2), entries
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_nested_add_with_open
|
57
|
-
entries = []
|
58
|
-
nested_entry = nil
|
59
|
-
|
60
|
-
dn = "uid=nested-open-added-user1,ou=People,dc=rubyldap,dc=com"
|
61
|
-
attrs = {
|
62
|
-
objectclass: %w(top inetOrgPerson organizationalPerson person),
|
63
|
-
uid: "nested-open-added-user1",
|
64
|
-
cn: "nested-open-added-user1",
|
65
|
-
sn: "nested-open-added-user1",
|
66
|
-
mail: "nested-open-added-user1@rubyldap.com",
|
67
|
-
}
|
68
|
-
|
69
|
-
@ldap.authenticate "cn=admin,dc=rubyldap,dc=com", "passworD1"
|
70
|
-
@ldap.delete dn: dn
|
71
|
-
|
72
|
-
@ldap.open do
|
73
|
-
@ldap.search(filter: "(|(uid=user1)(uid=user2))", base: "ou=People,dc=rubyldap,dc=com") do |entry|
|
74
|
-
entries << entry.uid.first
|
75
|
-
|
76
|
-
nested_entry ||= begin
|
77
|
-
assert @ldap.add(dn: dn, attributes: attrs), @ldap.get_operation_result.inspect
|
78
|
-
@ldap.search(base: dn, scope: Net::LDAP::SearchScope_BaseObject).first
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
assert_equal %w(user1 user2), entries
|
84
|
-
assert_equal "nested-open-added-user1", nested_entry.uid.first
|
85
|
-
ensure
|
86
|
-
@ldap.delete dn: dn
|
87
|
-
end
|
88
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
class TestPasswordModifyIntegration < LDAPIntegrationTestCase
|
4
|
-
def setup
|
5
|
-
super
|
6
|
-
@ldap.authenticate 'cn=admin,dc=rubyldap,dc=com', 'passworD1'
|
7
|
-
|
8
|
-
@dn = 'uid=modify-password-user1,ou=People,dc=rubyldap,dc=com'
|
9
|
-
|
10
|
-
attrs = {
|
11
|
-
objectclass: %w(top inetOrgPerson organizationalPerson person),
|
12
|
-
uid: 'modify-password-user1',
|
13
|
-
cn: 'modify-password-user1',
|
14
|
-
sn: 'modify-password-user1',
|
15
|
-
mail: 'modify-password-user1@rubyldap.com',
|
16
|
-
userPassword: 'passworD1',
|
17
|
-
}
|
18
|
-
unless @ldap.search(base: @dn, scope: Net::LDAP::SearchScope_BaseObject)
|
19
|
-
assert @ldap.add(dn: @dn, attributes: attrs), @ldap.get_operation_result.inspect
|
20
|
-
end
|
21
|
-
assert @ldap.search(base: @dn, scope: Net::LDAP::SearchScope_BaseObject)
|
22
|
-
|
23
|
-
@auth = {
|
24
|
-
method: :simple,
|
25
|
-
username: @dn,
|
26
|
-
password: 'passworD1',
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_password_modify
|
31
|
-
assert @ldap.password_modify(dn: @dn,
|
32
|
-
auth: @auth,
|
33
|
-
old_password: 'passworD1',
|
34
|
-
new_password: 'passworD2')
|
35
|
-
|
36
|
-
assert @ldap.get_operation_result.extended_response.nil?,
|
37
|
-
'Should not have generated a new password'
|
38
|
-
|
39
|
-
refute @ldap.bind(username: @dn, password: 'passworD1', method: :simple),
|
40
|
-
'Old password should no longer be valid'
|
41
|
-
|
42
|
-
assert @ldap.bind(username: @dn, password: 'passworD2', method: :simple),
|
43
|
-
'New password should be valid'
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_password_modify_generate
|
47
|
-
assert @ldap.password_modify(dn: @dn,
|
48
|
-
auth: @auth,
|
49
|
-
old_password: 'passworD1')
|
50
|
-
|
51
|
-
generated_password = @ldap.get_operation_result.extended_response[0][0]
|
52
|
-
|
53
|
-
assert generated_password, 'Should have generated a password'
|
54
|
-
|
55
|
-
refute @ldap.bind(username: @dn, password: 'passworD1', method: :simple),
|
56
|
-
'Old password should no longer be valid'
|
57
|
-
|
58
|
-
assert @ldap.bind(username: @dn, password: generated_password, method: :simple),
|
59
|
-
'New password should be valid'
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_password_modify_generate_no_old_password
|
63
|
-
assert @ldap.password_modify(dn: @dn,
|
64
|
-
auth: @auth)
|
65
|
-
|
66
|
-
generated_password = @ldap.get_operation_result.extended_response[0][0]
|
67
|
-
|
68
|
-
assert generated_password, 'Should have generated a password'
|
69
|
-
|
70
|
-
refute @ldap.bind(username: @dn, password: 'passworD1', method: :simple),
|
71
|
-
'Old password should no longer be valid'
|
72
|
-
|
73
|
-
assert @ldap.bind(username: @dn, password: generated_password, method: :simple),
|
74
|
-
'New password should be valid'
|
75
|
-
end
|
76
|
-
|
77
|
-
def teardown
|
78
|
-
@ldap.delete dn: @dn
|
79
|
-
end
|
80
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
# NOTE: These tests depend on the OpenLDAP retcode overlay.
|
4
|
-
# See: section 12.12 http://www.openldap.org/doc/admin24/overlays.html
|
5
|
-
|
6
|
-
class TestReturnCodeIntegration < LDAPIntegrationTestCase
|
7
|
-
def test_operations_error
|
8
|
-
refute @ldap.search(filter: "cn=operationsError", base: "ou=Retcodes,dc=rubyldap,dc=com")
|
9
|
-
assert result = @ldap.get_operation_result
|
10
|
-
|
11
|
-
assert_equal Net::LDAP::ResultCodeOperationsError, result.code
|
12
|
-
assert_equal Net::LDAP::ResultStrings[Net::LDAP::ResultCodeOperationsError], result.message
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_protocol_error
|
16
|
-
refute @ldap.search(filter: "cn=protocolError", base: "ou=Retcodes,dc=rubyldap,dc=com")
|
17
|
-
assert result = @ldap.get_operation_result
|
18
|
-
|
19
|
-
assert_equal Net::LDAP::ResultCodeProtocolError, result.code
|
20
|
-
assert_equal Net::LDAP::ResultStrings[Net::LDAP::ResultCodeProtocolError], result.message
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_time_limit_exceeded
|
24
|
-
assert @ldap.search(filter: "cn=timeLimitExceeded", base: "ou=Retcodes,dc=rubyldap,dc=com")
|
25
|
-
assert result = @ldap.get_operation_result
|
26
|
-
|
27
|
-
assert_equal Net::LDAP::ResultCodeTimeLimitExceeded, result.code
|
28
|
-
assert_equal Net::LDAP::ResultStrings[Net::LDAP::ResultCodeTimeLimitExceeded], result.message
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_size_limit_exceeded
|
32
|
-
assert @ldap.search(filter: "cn=sizeLimitExceeded", base: "ou=Retcodes,dc=rubyldap,dc=com")
|
33
|
-
assert result = @ldap.get_operation_result
|
34
|
-
|
35
|
-
assert_equal Net::LDAP::ResultCodeSizeLimitExceeded, result.code
|
36
|
-
assert_equal Net::LDAP::ResultStrings[Net::LDAP::ResultCodeSizeLimitExceeded], result.message
|
37
|
-
end
|
38
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
class TestSearchIntegration < LDAPIntegrationTestCase
|
4
|
-
def test_search
|
5
|
-
entries = []
|
6
|
-
|
7
|
-
result = @ldap.search(base: "dc=rubyldap,dc=com") do |entry|
|
8
|
-
assert_kind_of Net::LDAP::Entry, entry
|
9
|
-
entries << entry
|
10
|
-
end
|
11
|
-
|
12
|
-
refute entries.empty?
|
13
|
-
assert_equal entries, result
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_search_without_result
|
17
|
-
entries = []
|
18
|
-
|
19
|
-
result = @ldap.search(base: "dc=rubyldap,dc=com", return_result: false) do |entry|
|
20
|
-
assert_kind_of Net::LDAP::Entry, entry
|
21
|
-
entries << entry
|
22
|
-
end
|
23
|
-
|
24
|
-
assert result
|
25
|
-
refute_equal entries, result
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_search_filter_string
|
29
|
-
entries = @ldap.search(base: "dc=rubyldap,dc=com", filter: "(uid=user1)")
|
30
|
-
assert_equal 1, entries.size
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_search_filter_object
|
34
|
-
filter = Net::LDAP::Filter.eq("uid", "user1") | Net::LDAP::Filter.eq("uid", "user2")
|
35
|
-
entries = @ldap.search(base: "dc=rubyldap,dc=com", filter: filter)
|
36
|
-
assert_equal 2, entries.size
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_search_constrained_attributes
|
40
|
-
entry = @ldap.search(base: "uid=user1,ou=People,dc=rubyldap,dc=com", attributes: ["cn", "sn"]).first
|
41
|
-
assert_equal [:cn, :dn, :sn], entry.attribute_names.sort # :dn is always included
|
42
|
-
assert_empty entry[:mail]
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_search_attributes_only
|
46
|
-
entry = @ldap.search(base: "uid=user1,ou=People,dc=rubyldap,dc=com", attributes_only: true).first
|
47
|
-
|
48
|
-
assert_empty entry[:cn], "unexpected attribute value: #{entry[:cn]}"
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_search_timeout
|
52
|
-
entries = []
|
53
|
-
events = @service.subscribe "search.net_ldap_connection"
|
54
|
-
|
55
|
-
result = @ldap.search(base: "dc=rubyldap,dc=com", time: 5) do |entry|
|
56
|
-
assert_kind_of Net::LDAP::Entry, entry
|
57
|
-
entries << entry
|
58
|
-
end
|
59
|
-
|
60
|
-
payload, = events.pop
|
61
|
-
assert_equal 5, payload[:time]
|
62
|
-
assert_equal entries, result
|
63
|
-
end
|
64
|
-
|
65
|
-
# http://tools.ietf.org/html/rfc4511#section-4.5.1.4
|
66
|
-
def test_search_with_size
|
67
|
-
entries = []
|
68
|
-
|
69
|
-
result = @ldap.search(base: "dc=rubyldap,dc=com", size: 1) do |entry|
|
70
|
-
assert_kind_of Net::LDAP::Entry, entry
|
71
|
-
entries << entry
|
72
|
-
end
|
73
|
-
|
74
|
-
assert_equal 1, result.size
|
75
|
-
assert_equal entries, result
|
76
|
-
end
|
77
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
/.vagrant
|
@@ -1,64 +0,0 @@
|
|
1
|
-
# Local OpenLDAP Integration Testing
|
2
|
-
|
3
|
-
Set up a [Vagrant](http://www.vagrantup.com/) VM to run integration
|
4
|
-
tests against OpenLDAP locally. *NOTE*: To support some of the SSL tests,
|
5
|
-
Vagrant forwards localhost port 9389 to VM host port 9389. The port mapping
|
6
|
-
goes away when you run `vagrant destroy`.
|
7
|
-
|
8
|
-
## Install Vagrant
|
9
|
-
|
10
|
-
*NOTE*: The Vagrant gem (`gem install vagrant`) is
|
11
|
-
[no longer supported](https://www.vagrantup.com/docs/installation/). If you've
|
12
|
-
previously installed it, run `gem uninstall vagrant`. If you're an rbenv
|
13
|
-
user, you probably want to follow that up with `rbenv rehash; hash -r`.
|
14
|
-
|
15
|
-
If you use Homebrew on macOS:
|
16
|
-
``` bash
|
17
|
-
$ brew update
|
18
|
-
$ brew cask install virtualbox
|
19
|
-
$ brew cask install vagrant
|
20
|
-
$ brew cask install vagrant-manager
|
21
|
-
$ vagrant plugin install vagrant-vbguest
|
22
|
-
```
|
23
|
-
|
24
|
-
Installing Vagrant and virtualbox on other operating systems is left
|
25
|
-
as an exercise to the reader. Note the `vagrant-vbguest` plugin is required
|
26
|
-
to update the VirtualBox guest extensions in the guest VM image.
|
27
|
-
|
28
|
-
## Run the tests
|
29
|
-
|
30
|
-
``` bash
|
31
|
-
# start VM (from the correct directory)
|
32
|
-
$ cd test/support/vm/openldap/
|
33
|
-
$ vagrant up
|
34
|
-
|
35
|
-
# get the IP address of the VM
|
36
|
-
$ ip=$(vagrant ssh -- "ifconfig eth1 | grep -o -E '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -n1")
|
37
|
-
|
38
|
-
# change back to root project directory
|
39
|
-
$ cd ../../../..
|
40
|
-
|
41
|
-
# set the TCP port for testing
|
42
|
-
$ export INTEGRATION_PORT=9389
|
43
|
-
|
44
|
-
# run all tests, including integration tests
|
45
|
-
$ time INTEGRATION=openldap INTEGRATION_HOST=$ip bundle exec rake
|
46
|
-
|
47
|
-
# run a specific integration test file
|
48
|
-
$ time INTEGRATION=openldap INTEGRATION_HOST=$ip bundle exec ruby test/integration/test_search.rb
|
49
|
-
|
50
|
-
# run integration tests by default
|
51
|
-
$ export INTEGRATION=openldap
|
52
|
-
$ export INTEGRATION_HOST=$ip
|
53
|
-
|
54
|
-
# now run tests without having to set ENV variables
|
55
|
-
$ time bundle exec rake
|
56
|
-
|
57
|
-
# Once you're all done
|
58
|
-
$ cd test/support/vm/openldap
|
59
|
-
$ vagrant destroy
|
60
|
-
```
|
61
|
-
|
62
|
-
If at any point your VM appears to have broken itself, `vagrant destroy`
|
63
|
-
from the `test/support/vm/openldap` directory will blow it away. You can
|
64
|
-
then do `vagrant up` and start over.
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# -*- mode: ruby -*-
|
2
|
-
# vi: set ft=ruby :
|
3
|
-
|
4
|
-
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
5
|
-
VAGRANTFILE_API_VERSION = "2"
|
6
|
-
|
7
|
-
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
8
|
-
config.vm.hostname = "rubyldap.com"
|
9
|
-
|
10
|
-
config.vm.box = "hashicorp/precise64"
|
11
|
-
|
12
|
-
config.vm.network "private_network", type: :dhcp
|
13
|
-
config.vm.network "forwarded_port", guest: 389, host: 9389
|
14
|
-
|
15
|
-
config.ssh.forward_agent = true
|
16
|
-
|
17
|
-
config.vm.provision "shell", inline: "apt-get update; exec env /vagrant_data/script/install-openldap"
|
18
|
-
|
19
|
-
config.vm.synced_folder "../../../..", "/vagrant_data"
|
20
|
-
|
21
|
-
config.vm.provider "vmware_fusion" do |vb, override|
|
22
|
-
override.vm.box = "hashicorp/precise64"
|
23
|
-
vb.memory = 4596
|
24
|
-
vb.vmx["displayname"] = "integration tests vm"
|
25
|
-
vb.vmx["numvcpus"] = "2"
|
26
|
-
end
|
27
|
-
|
28
|
-
config.vm.provider "virtualbox" do |vb, override|
|
29
|
-
vb.memory = 4096
|
30
|
-
vb.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"]
|
31
|
-
vb.customize ["modifyvm", :id, "--chipset", "ich9"]
|
32
|
-
vb.customize ["modifyvm", :id, "--vram", "16"]
|
33
|
-
end
|
34
|
-
end
|
data/test/test_auth_adapter.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TestAuthAdapter < Test::Unit::TestCase
|
4
|
-
class FakeSocket
|
5
|
-
def initialize(*args)
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_undefined_auth_adapter
|
10
|
-
conn = Net::LDAP::Connection.new(host: 'ldap.example.com', port: 379, :socket_class => FakeSocket)
|
11
|
-
assert_raise Net::LDAP::AuthMethodUnsupportedError, "Unsupported auth method (foo)" do
|
12
|
-
conn.bind(method: :foo)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/test/test_dn.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
require 'net/ldap/dn'
|
3
|
-
|
4
|
-
class TestDN < Test::Unit::TestCase
|
5
|
-
def test_escape
|
6
|
-
assert_equal '\\,\\+\\"\\\\\\<\\>\\;', Net::LDAP::DN.escape(',+"\\<>;')
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_escape_on_initialize
|
10
|
-
dn = Net::LDAP::DN.new('cn', ',+"\\<>;', 'ou=company')
|
11
|
-
assert_equal 'cn=\\,\\+\\"\\\\\\<\\>\\;,ou=company', dn.to_s
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_to_a
|
15
|
-
dn = Net::LDAP::DN.new('cn=James, ou=Company\\,\\20LLC')
|
16
|
-
assert_equal ['cn', 'James', 'ou', 'Company, LLC'], dn.to_a
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_to_a_parenthesis
|
20
|
-
dn = Net::LDAP::DN.new('cn = \ James , ou = "Comp\28ny" ')
|
21
|
-
assert_equal ['cn', ' James', 'ou', 'Comp(ny'], dn.to_a
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_to_a_hash_symbol
|
25
|
-
dn = Net::LDAP::DN.new('1.23.4= #A3B4D5 ,ou=Company')
|
26
|
-
assert_equal ['1.23.4', '#A3B4D5', 'ou', 'Company'], dn.to_a
|
27
|
-
end
|
28
|
-
|
29
|
-
# TODO: raise a more specific exception than RuntimeError
|
30
|
-
def test_bad_input_raises_error
|
31
|
-
[
|
32
|
-
'cn=James,',
|
33
|
-
'cn=#aa aa',
|
34
|
-
'cn="James',
|
35
|
-
'cn=J\ames',
|
36
|
-
'cn=\\',
|
37
|
-
'1.2.d=Value',
|
38
|
-
'd1.2=Value',
|
39
|
-
].each do |input|
|
40
|
-
dn = Net::LDAP::DN.new(input)
|
41
|
-
assert_raises(RuntimeError) { dn.to_a }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/test/test_entry.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
|
3
|
-
class TestEntry < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@entry = Net::LDAP::Entry.new 'cn=Barbara,o=corp'
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_dn
|
9
|
-
assert_equal 'cn=Barbara,o=corp', @entry.dn
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_empty_array_when_accessing_nonexistent_attribute
|
13
|
-
assert_equal [], @entry['sn']
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_attribute_assignment
|
17
|
-
@entry['sn'] = 'Jensen'
|
18
|
-
assert_equal ['Jensen'], @entry['sn']
|
19
|
-
assert_equal ['Jensen'], @entry.sn
|
20
|
-
assert_equal ['Jensen'], @entry[:sn]
|
21
|
-
|
22
|
-
@entry[:sn] = 'Jensen'
|
23
|
-
assert_equal ['Jensen'], @entry['sn']
|
24
|
-
assert_equal ['Jensen'], @entry.sn
|
25
|
-
assert_equal ['Jensen'], @entry[:sn]
|
26
|
-
|
27
|
-
@entry.sn = 'Jensen'
|
28
|
-
assert_equal ['Jensen'], @entry['sn']
|
29
|
-
assert_equal ['Jensen'], @entry.sn
|
30
|
-
assert_equal ['Jensen'], @entry[:sn]
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_case_insensitive_attribute_names
|
34
|
-
@entry['sn'] = 'Jensen'
|
35
|
-
assert_equal ['Jensen'], @entry.sn
|
36
|
-
assert_equal ['Jensen'], @entry.Sn
|
37
|
-
assert_equal ['Jensen'], @entry.SN
|
38
|
-
assert_equal ['Jensen'], @entry['sn']
|
39
|
-
assert_equal ['Jensen'], @entry['Sn']
|
40
|
-
assert_equal ['Jensen'], @entry['SN']
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class TestEntryLDIF < Test::Unit::TestCase
|
45
|
-
def setup
|
46
|
-
@entry = Net::LDAP::Entry.from_single_ldif_string(
|
47
|
-
%Q{dn: something
|
48
|
-
foo: foo
|
49
|
-
barAttribute: bar
|
50
|
-
})
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_attribute
|
54
|
-
assert_equal ['foo'], @entry.foo
|
55
|
-
assert_equal ['foo'], @entry.Foo
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_modify_attribute
|
59
|
-
@entry.foo = 'bar'
|
60
|
-
assert_equal ['bar'], @entry.foo
|
61
|
-
|
62
|
-
@entry.fOo= 'baz'
|
63
|
-
assert_equal ['baz'], @entry.foo
|
64
|
-
end
|
65
|
-
end
|