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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
require 'spec_helper'
require 'net/ldap/dn'
describe Net::LDAP::DN do
describe "<- .construct" do
attr_reader :dn
before(:each) do
@dn = Net::LDAP::DN.new('cn', ',+"\\<>;', 'ou=company')
end
it "should construct a Net::LDAP::DN" do
dn.should be_an_instance_of(Net::LDAP::DN)
end
it "should escape all the required characters" do
dn.to_s.should == 'cn=\\,\\+\\"\\\\\\<\\>\\;,ou=company'
end
end
describe "<- .to_a" do
context "parsing" do
{
'cn=James, ou=Company\\,\\20LLC' => ['cn','James','ou','Company, LLC'],
'cn = \ James , ou = "Comp\28ny" ' => ['cn',' James','ou','Comp(ny'],
'1.23.4= #A3B4D5 ,ou=Company' => ['1.23.4','#A3B4D5','ou','Company'],
}.each do |key, value|
context "(#{key})" do
attr_reader :dn
before(:each) do
@dn = Net::LDAP::DN.new(key)
end
it "should decode into a Net::LDAP::DN" do
dn.should be_an_instance_of(Net::LDAP::DN)
end
it "should return the correct array" do
dn.to_a.should == value
end
end
end
end
context "parsing bad input" do
[
'cn=James,',
'cn=#aa aa',
'cn="James',
'cn=J\ames',
'cn=\\',
'1.2.d=Value',
'd1.2=Value',
].each do |value|
context "(#{value})" do
attr_reader :dn
before(:each) do
@dn = Net::LDAP::DN.new(value)
end
it "should decode into a Net::LDAP::DN" do
dn.should be_an_instance_of(Net::LDAP::DN)
end
it "should raise an error on parsing" do
lambda { dn.to_a }.should raise_error
end
end
end
end
end
describe "<- .escape(str)" do
it "should escape ,, +, \", \\, <, >, and ;" do
Net::LDAP::DN.escape(',+"\\<>;').should == '\\,\\+\\"\\\\\\<\\>\\;'
end
end
end
|