Debian lenny version packages
[pkg-perl] / deb-src / liburi-perl / liburi-perl-1.35.dfsg.1 / t / ldap.t
1 #!perl -w
2
3 print "1..22\n";
4
5 use strict;
6 use URI;
7
8 my $uri;
9
10 $uri = URI->new("ldap://host/dn=base?cn,sn?sub?objectClass=*");
11
12 print "not " unless $uri->host eq "host";
13 print "ok 1\n";
14
15 print "not " unless $uri->dn eq "dn=base";
16 print "ok 2\n";
17
18 print "not " unless join("-",$uri->attributes) eq "cn-sn";
19 print "ok 3\n";
20
21 print "not " unless $uri->scope eq "sub";
22 print "ok 4\n";
23
24 print "not " unless $uri->filter eq "objectClass=*";
25 print "ok 5\n";
26
27 $uri = URI->new("ldap:");
28 $uri->dn("o=University of Michigan,c=US");
29
30 print "not " unless "$uri" eq "ldap:o=University%20of%20Michigan,c=US" &&
31     $uri->dn eq "o=University of Michigan,c=US";
32 print "ok 6\n";
33
34 $uri->host("ldap.itd.umich.edu");
35 print "not " unless $uri->as_string eq "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US";
36 print "ok 7\n";
37
38 # check defaults
39 print "not " unless $uri->_scope  eq "" &&
40                     $uri->scope   eq "base" &&
41                     $uri->_filter eq "" &&
42                     $uri->filter  eq "(objectClass=*)";
43 print "ok 8\n";
44
45 # attribute
46 $uri->attributes("postalAddress");
47 print "not " unless $uri eq "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress";
48 print "ok 9\n";
49
50 # does attribute escapeing work as it should
51 $uri->attributes($uri->attributes, "foo", ",", "*", "?", "#", "\0");
52
53 print "not " unless $uri->attributes eq "postalAddress,foo,%2C,*,%3F,%23,%00" &&
54                     join("-", $uri->attributes) eq "postalAddress-foo-,-*-?-#-\0";
55 print "ok 10\n";
56 $uri->attributes("");
57
58 $uri->scope("sub?#");
59 print "not " unless $uri->query eq "?sub%3F%23" &&
60                     $uri->scope eq "sub?#";
61 print "ok 11\n";
62 $uri->scope("");
63
64 $uri->filter("f=?,#");
65 print "not " unless $uri->query eq "??f=%3F,%23" &&
66                     $uri->filter eq "f=?,#";
67
68 $uri->filter("(int=\\00\\00\\00\\04)");
69 print "not " unless $uri->query eq "??(int=%5C00%5C00%5C00%5C04)";
70 print "ok 12\n";
71
72
73 print "ok 13\n";
74 $uri->filter("");
75
76 $uri->extensions("!bindname" => "cn=Manager,co=Foo");
77 my %ext = $uri->extensions;
78
79 print "not " unless $uri->query eq "???!bindname=cn=Manager%2Cco=Foo" &&
80                     keys %ext == 1 &&
81                     $ext{"!bindname"} eq "cn=Manager,co=Foo";
82 print "ok 14\n";
83
84 $uri = URI->new("ldap://LDAP-HOST:389/o=University%20of%20Michigan,c=US?postalAddress?base?ObjectClass=*?FOO=Bar,bindname=CN%3DManager%CO%3dFoo");
85
86 print "not " unless $uri->canonical eq "ldap://ldap-host/o=University%20of%20Michigan,c=US?postaladdress???foo=Bar,bindname=CN=Manager%CO=Foo";
87 print "ok 15\n";
88
89 print "$uri\n";
90 print $uri->canonical, "\n";
91
92 $uri = URI->new("ldaps://host/dn=base?cn,sn?sub?objectClass=*");
93
94 print "not " unless $uri->host eq "host";
95 print "ok 16\n";
96 print "not " unless $uri->port eq 636;
97 print "ok 17\n";
98 print "not " unless $uri->dn eq "dn=base";
99 print "ok 18\n";
100
101 $uri = URI->new("ldapi://%2Ftmp%2Fldap.sock/????x-mod=-w--w----");
102 print "not " unless $uri->authority eq "%2Ftmp%2Fldap.sock";
103 print "ok 19\n";
104 print "not " unless $uri->un_path eq "/tmp/ldap.sock";
105 print "ok 20\n";
106
107 $uri->un_path("/var/x\@foo:bar/");
108 print "not " unless $uri eq "ldapi://%2Fvar%2Fx%40foo%3Abar%2F/????x-mod=-w--w----";
109 print "ok 21\n";
110
111 %ext = $uri->extensions;
112 print "not " unless $ext{"x-mod"} eq "-w--w----";
113 print "ok 22\n";
114