forked from ruby-ldap/ruby-net-ldap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_dn.rb
More file actions
57 lines (48 loc) · 1.59 KB
/
test_dn.rb
File metadata and controls
57 lines (48 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require_relative 'test_helper'
require_relative '../lib/net/ldap/dn'
class TestDN < Test::Unit::TestCase
def test_escape
assert_equal '\\,\\+\\"\\\\\\<\\>\\;', Net::LDAP::DN.escape(',+"\\<>;')
end
def test_escape_pound_sign
assert_equal '\\#test', Net::LDAP::DN.escape('#test')
end
def test_escape_space
assert_equal '\\ before_after\\ ', Net::LDAP::DN.escape(' before_after ')
end
def test_retain_spaces
dn = Net::LDAP::DN.new('CN=Foo.bar.baz, OU=Foo \ ,OU=\ Bar, O=Baz')
assert_equal "CN=Foo.bar.baz, OU=Foo \\ ,OU=\\ Bar, O=Baz", dn.to_s
assert_equal ["CN", "Foo.bar.baz", "OU", "Foo ", "OU", " Bar", "O", "Baz"], dn.to_a
end
def test_escape_on_initialize
dn = Net::LDAP::DN.new('cn', ',+"\\<>;', 'ou=company')
assert_equal 'cn=\\,\\+\\"\\\\\\<\\>\\;,ou=company', dn.to_s
end
def test_to_a
dn = Net::LDAP::DN.new('cn=James, ou=Company\\,\\20LLC')
assert_equal ['cn', 'James', 'ou', 'Company, LLC'], dn.to_a
end
def test_to_a_parenthesis
dn = Net::LDAP::DN.new('cn = \ James , ou = "Comp\28ny" ')
assert_equal ['cn', ' James ', 'ou', 'Comp(ny'], dn.to_a
end
def test_to_a_hash_symbol
dn = Net::LDAP::DN.new('1.23.4= #A3B4D5 ,ou=Company')
assert_equal ['1.23.4', '#A3B4D5', 'ou', 'Company'], dn.to_a
end
def test_bad_input_raises_error
[
'cn=James,',
'cn=#aa aa',
'cn="James',
'cn=J\ames',
'cn=\\',
'1.2.d=Value',
'd1.2=Value',
].each do |input|
dn = Net::LDAP::DN.new(input)
assert_raises(Net::LDAP::InvalidDNError) { dn.to_a }
end
end
end