Skip to content

Commit 2b3e277

Browse files
author
Jamstah
committed
Spec for a DN class which escapes values and can parse a DN.
1 parent 5bc73d3 commit 2b3e277

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

spec/unit/ldap/dn_spec.rb

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
require 'spec_helper'
2+
require 'net/ldap/dn'
3+
4+
describe Net::LDAP::DN do
5+
describe "<- .construct" do
6+
attr_reader :dn
7+
before(:each) do
8+
@dn = Net::LDAP::DN.new('cn', ',+"\\<>;', 'ou=company')
9+
end
10+
it "should construct a Net::LDAP::DN" do
11+
dn.should be_an_instance_of(Net::LDAP::DN)
12+
end
13+
it "should escape all the required characters" do
14+
dn.to_s.should == 'cn=\\,\\+\\"\\\\\\<\\>\\;,ou=company'
15+
end
16+
end
17+
describe "<- .to_a" do
18+
context "parsing" do
19+
{
20+
'cn=James, ou=Company\\,\\20LLC' => ['cn','James','ou','Company, LLC'],
21+
'cn = \ James , ou = "Comp\28ny" ' => ['cn',' James','ou','Comp(ny'],
22+
'1.23.4= #A3B4D5 ,ou=Company' => ['1.23.4','#A3B4D5','ou','Company'],
23+
}.each do |key, value|
24+
context "(#{key})" do
25+
attr_reader :dn
26+
before(:each) do
27+
@dn = Net::LDAP::DN.new(key)
28+
end
29+
it "should decode into a Net::LDAP::DN" do
30+
dn.should be_an_instance_of(Net::LDAP::DN)
31+
end
32+
it "should return the correct array" do
33+
dn.to_a.should == value
34+
end
35+
end
36+
end
37+
end
38+
39+
context "parsing bad input" do
40+
[
41+
'cn=James,',
42+
'cn=#aa aa',
43+
'cn="James',
44+
'cn=J\ames',
45+
'cn=\\',
46+
'1.2.d=Value',
47+
'd1.2=Value',
48+
].each do |value|
49+
context "(#{value})" do
50+
attr_reader :dn
51+
before(:each) do
52+
@dn = Net::LDAP::DN.new(value)
53+
end
54+
it "should decode into a Net::LDAP::DN" do
55+
dn.should be_an_instance_of(Net::LDAP::DN)
56+
end
57+
it "should raise an error on parsing" do
58+
lambda { dn.to_a }.should raise_error
59+
end
60+
end
61+
end
62+
end
63+
end
64+
65+
describe "<- .escape(str)" do
66+
it "should escape ,, +, \", \\, <, >, and ;" do
67+
Net::LDAP::DN.escape(',+"\\<>;').should == '\\,\\+\\"\\\\\\<\\>\\;'
68+
end
69+
end
70+
end

0 commit comments

Comments
 (0)