1#!perl 2 3use Net::LDAP::Util qw(canonical_dn); 4 5# Each line has an opcode and a DN, opcode are 6# bad cacnonical_dn should return undef 7# ref Set new reference DN 8# same Should be the same as the current refdn 9# diff Should be different to the current refdn 10 11my @tests = map { /^(\w+)\s+(.*)/ } <DATA>; 12 13print "1..", scalar(@tests)>>1, "\n"; 14my $testno = 0; 15my $refdn; 16while(my($op,$dn) = splice(@tests,0,2)) { 17 18 my $canon = canonical_dn($dn); 19 my $failed = 0; 20 21 if ($op eq 'ref') { 22 $refdn=$dn; 23 if ($failed = !defined $canon) { 24 print "'$dn' should have parsed\n"; 25 } 26 } 27 elsif ($op eq 'bad') { 28 if ($failed = defined $canon) { 29 print "'$dn' should not have parsed\n '$canon'\n"; 30 } 31 } 32 elsif ( $op eq 'same' ) { 33 if ($failed = !defined $canon) { 34 print "'$dn' failed to parse\n"; 35 } 36 elsif ($failed = $canon ne $refdn) { 37 print "'$refdn'\n\ndid not match\n\n from '$dn'\n got '$canon'\n"; 38 } 39 } 40 elsif ($op eq 'diff' ) { 41 if ($failed = !defined $canon) { 42 print "'$dn' failed to parse\n"; 43 } 44 elsif ($failed = $canon eq $refdn) { 45 print "'$refdn'\n\nmatched\n\n'$dn'\n'$canon'\n"; 46 } 47 } 48 else { 49 $failed = 1; 50 warn "Bad opcode $op\n"; 51 } 52 53 print +($failed ? "not ok " : "ok "),++$testno,"\n"; 54} 55 56__DATA__ 57 58bad OU=Sales+CN=J. Smith,O=Widget Inc.,C=US, 59 60ref CN=J. Smith+OU=Sales,O=Widget Inc.,C=US 61same ou=Sales+cn=J. Smith,O=Widget Inc.,C=US 62same cn=J. Smith+ou=Sales,O=Widget Inc.,C=US 63same cn=J.\20Smith+ou=Sales,O=Widget\20Inc.,C=US 64same OU=Sales+CN=J. Smith;O=Widget Inc.;C=US 65same OU=Sales + CN=J. Smith,O=Widget Inc.,C=US 66same OU=Sales+CN=J. Smith , O=Widget Inc. , C=US 67same OU = Sales+CN =J. Smith,O= Widget Inc.,C=US 68same OU="Sales"+CN=J. Smith,O=Widget Inc.,C=US 69diff OU="Sales+CN=J. Smith",O=Widget Inc.,C=US 70 71bad cn=J.\20Smith\+ou=Sales,O=Widget\20Inc.,C=US 72 73ref CN=Babs Jensen,O=Widget Inc.,C=US 74same cn=Babs Jensen,o=Widget Inc.,c=US 75 76# This is here to test a restriction that 77# canonical_dn does not decode BER encoded values 78ref 1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB 79same 1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB 80diff 1.3.6.1.4.1.1466.0=\04\02Hi,O=Test,C=GB 81 82ref 1.3.6.1.4.1.1466.0=Hi,O=Test,C=GB 83same oid.1.3.6.1.4.1.1466.0=Hi,O=Test,C=GB 84same OID.1.3.6.1.4.1.1466.0=Hi,O=Test,C=GB 85 86ref CN=Clif Harden+IDNUMBER=a0125589\20,OU=tiPerson,OU=person,O=ti,C=us 87diff cn=Clif Harden+IDNumber=a0125589,ou=tiPerson,ou=person,o=ti,c=us 88same cn=Clif Harden+IDNumber=a0125589\ ,ou=tiPerson,ou=person,o=ti,c=us 89same cn=Clif Harden+IDNumber=a0125589\20 ,ou=tiPerson,ou=person,o=ti,c=us 90same cn=Clif Harden+IDNumber="a0125589 ",ou=tiPerson,ou=person,o=ti,c=us 91 92 93ref CN=\20\20Graham Barr\20\20,OU=person,O=vc,C=us 94same Cn=" Graham Barr ",OU=person,O=vc,C=us 95same cn=" Graham \20Barr\20 ",OU=person,O=vc,C=us 96 97# empty 98ref 99 100ref UID=jsmith,DC=example,DC=net 101same UID=jsmith,DC=example,DC=net 102 103ref CN=J. Smith+OU=Sales,DC=example,DC=net 104same OU=Sales+CN=J. Smith,DC=example,DC=net 105 106ref CN=John Smith\2c III,DC=example,DC=net 107same CN=John Smith\, III,DC=example,DC=net 108same CN=John Smith\2C III,DC=example,DC=net 109 110ref CN=Before\0dAfter,DC=example,DC=net 111same CN=Before\0dAfter,DC=example,DC=net 112 113ref CN=\23John Smith\20,DC=example,DC=net 114same CN=\23John Smith\20,DC=example,DC=net 115same CN=\#John Smith\ ,DC=example,DC=net 116 117ref 1.3.6.1.4.1.1466.0=#04024869,DC=example,DC=com 118same 1.3.6.1.4.1.1466.0=#04024869,DC=example,DC=com 119 120ref CN=Lučić 121same CN=Lu\C4\8Di\C4\87 122 123# empty value 124ref 1.1.1= 125 126# option 127bad uid;x-option=jsmith 128 129# invalid attribute type name 130bad at_tr=jsmith 131 132# invalid attribute type name 133bad -attr=jsmith 134 135# invalid attribute type name 136#bad OID.1.1=jsmith 137 138# invalid numeric OID 139bad 1..1=jsmith 140 141# invalid numeric OID 142bad 1.1.=jsmith 143 144# invalid numeric OID 145#bad 01.1=jsmith 146 147# invalid numeric OID 148bad 1.ff=jsmith 149 150# invalid HEX form 151bad 1.1.1=#GG 152 153# invalid HEX form 154bad 1.1.1=#000 155 156# invalid HEX form 157bad 1.1.1=#F 158 159# invalid HEX form 160bad 1.1.1=# 161 162# spaces 163#bad UID=jsmith, DC=example, DC=net 164 165# extra comma 166bad UID=jsmith,,DC=example,DC=net 167 168# semi-colons 169#bad UID=jsmith;DC=example;DC=net 170 171# quotes 172#bad CN="John Smith",DC=example,DC=net 173 174# brackets 175bad <UID=jsmith,DC=example,DC=net> 176 177# unescaped , 178bad UID=john,smith 179 180# unescaped + 181bad UID=john+smith 182 183# invalid escape of ? or unescaped \ 184bad UID=john\?smith 185 186# invalid hex escape 187bad UID=john\Fsmith 188 189# invalid hex escape 190bad UID=john\GGsmith 191 192ref CN=John Smith \2c III,DC=example,DC=net 193same CN=John Smith \, III,DC=example,DC=net 194same CN=John Smith \2C III,DC=example,DC=net 195 196ref DISTINGUISHEDNAMETABLEKEY=cn\3dDSA\2c c\3dGB,CN=bilateral table,CN=DSA,C=US 197same distinguishedNameTableKey=cn\=DSA\, c\=GB, cn=bilateral table, cn=DSA, c=US 198