~ubuntu-branches/ubuntu/utopic/ruby-net-ldap/utopic-proposed

« back to all changes in this revision

Viewing changes to spec/unit/ldap/dn_spec.rb

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2012-05-14 17:25:45 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120514172545-m08z3m92de2n2pfn
Tags: 0.3.1-1
* Upstream update.
* debian/watch: refer to latest net-ldap project.
* debian/copyright:
  + license changed to Expat, with permission from Ondřej Surý for the
    debian/* part.
  + format 1.0
  + add a lintian-override because Comment mentions old GPL license.
* debian/control:
  + Standards-Version 3.9.3 (no changes required)
  + Use anonscm.d.o in Vcs-* fields.
  + Update Homepage url.
  + XS-Ruby-Versions: all, this module is fine with ruby 1.8 and 1.9.
* debian/patches:
  + Unapply unneeded patches
  + 0003-fix_require_in_tests.patch: tests are called from CURDIR.
* Update debian/ruby-test-files.yaml

Show diffs side-by-side

added added

removed removed

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