From: Graham B. <gb...@us...> - 2002-06-03 15:26:52
|
Update of /cvsroot/perl-ldap/ldap/t In directory usw-pr-cvs1:/tmp/cvs-serv27465/t Modified Files: 01canon_dn.t Log Message: New implementation of canonical_dn and ldap_explode_dn, thanks to Norbert Klasen Index: 01canon_dn.t =================================================================== RCS file: /cvsroot/perl-ldap/ldap/t/01canon_dn.t,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- 01canon_dn.t 31 Jan 2002 15:25:52 -0000 1.7 +++ 01canon_dn.t 3 Jun 2002 15:26:46 -0000 1.8 @@ -8,184 +8,190 @@ # same Should be the same as the current refdn # diff Should be different to the current refdn -my @tests = map { /^\s*(\w\S+)\s+(.*)/ } split(/\n/,<<'EOS'); +my @tests = map { /^(\w+)\s+(.*)/ } <DATA>; - bad OU=Sales+CN=J. Smith,O=Widget Inc.,C=US, +print "1..", scalar(@tests)>>1, "\n"; +my $testno = 0; +my $refdn; +while(my($op,$dn) = splice(@tests,0,2)) { - ref CN=J. Smith+OU=Sales,O=Widget Inc.,C=US - same ou=Sales+cn=J. Smith,O=Widget Inc.,C=US - same cn=J. Smith+ou=Sales,O=Widget Inc.,C=US - same cn=J.\20Smith+ou=Sales,O=Widget\20Inc.,C=US - same OU=Sales+CN=J. Smith;O=Widget Inc.;C=US - same OU=Sales + CN=J. Smith,O=Widget Inc.,C=US - same OU=Sales+CN=J. Smith , O=Widget Inc. , C=US - same OU = Sales+CN =J. Smith,O= Widget Inc.,C=US - same OU="Sales"+CN=J. Smith,O=Widget Inc.,C=US - diff OU="Sales+CN=J. Smith",O=Widget Inc.,C=US + my $canon = canonical_dn($dn); + my $failed = 0; - bad cn=J.\20Smith\+ou=Sales,O=Widget\20Inc.,C=US + if ($op eq 'ref') { + $refdn=$dn; + if ($failed = !defined $canon) { + print "'$dn' should have parsed\n"; + } + } + elsif ($op eq 'bad') { + if ($failed = defined $canon) { + print "'$dn' should not have parsed\n '$canon'\n"; + } + } + elsif ( $op eq 'same' ) { + if ($failed = !defined $canon) { + print "'$dn' failed to parse\n"; + } + elsif ($failed = $canon ne $refdn) { + print "'$refdn'\n\ndid not match\n\n from '$dn'\n got '$canon'\n"; + } + } + elsif ($op eq 'diff' ) { + if ($failed = !defined $canon) { + print "'$dn' failed to parse\n"; + } + elsif ($failed = $canon eq $refdn) { + print "'$refdn'\n\nmatched\n\n'$dn'\n'$canon'\n"; + } + } + else { + $failed = 1; + warn "Bad opcode $op\n"; + } - ref CN=Babs Jensen,O=Widget Inc.,C=US - same cn=Babs Jensen,o=Widget Inc.,c=US + print +($failed ? "not ok " : "ok "),++$testno,"\n"; +} - # This is here to test a restriction that - # canonical_dn does not decode BER encoded values - ref 1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB - same 1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB - diff 1.3.6.1.4.1.1466.0=\04\02Hi,O=Test,C=GB +__DATA__ - ref 1.3.6.1.4.1.1466.0=Hi,O=Test,C=GB - same oid.1.3.6.1.4.1.1466.0=Hi,O=Test,C=GB - same OID.1.3.6.1.4.1.1466.0=Hi,O=Test,C=GB +bad OU=Sales+CN=J. Smith,O=Widget Inc.,C=US, - ref CN=Clif Harden+IDNUMBER=a0125589\20,OU=tiPerson,OU=person,O=ti,C=us - diff cn=Clif Harden+IDNumber=a0125589,ou=tiPerson,ou=person,o=ti,c=us - same cn=Clif Harden+IDNumber=a0125589\ ,ou=tiPerson,ou=person,o=ti,c=us - same cn=Clif Harden+IDNumber=a0125589\20 ,ou=tiPerson,ou=person,o=ti,c=us - same cn=Clif Harden+IDNumber="a0125589 ",ou=tiPerson,ou=person,o=ti,c=us +ref CN=J. Smith+OU=Sales,O=Widget Inc.,C=US +same ou=Sales+cn=J. Smith,O=Widget Inc.,C=US +same cn=J. Smith+ou=Sales,O=Widget Inc.,C=US +same cn=J.\20Smith+ou=Sales,O=Widget\20Inc.,C=US +same OU=Sales+CN=J. Smith;O=Widget Inc.;C=US +same OU=Sales + CN=J. Smith,O=Widget Inc.,C=US +same OU=Sales+CN=J. Smith , O=Widget Inc. , C=US +same OU = Sales+CN =J. Smith,O= Widget Inc.,C=US +same OU="Sales"+CN=J. Smith,O=Widget Inc.,C=US +diff OU="Sales+CN=J. Smith",O=Widget Inc.,C=US +bad cn=J.\20Smith\+ou=Sales,O=Widget\20Inc.,C=US - ref CN=\20\20Graham Barr\20\20,OU=person,O=vc,C=us - same Cn=" Graham Barr ",OU=person,O=vc,C=us - same cn=" Graham \20Barr\20 ",OU=person,O=vc,C=us +ref CN=Babs Jensen,O=Widget Inc.,C=US +same cn=Babs Jensen,o=Widget Inc.,c=US - # empty - ref +# This is here to test a restriction that +# canonical_dn does not decode BER encoded values +ref 1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB +same 1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB +diff 1.3.6.1.4.1.1466.0=\04\02Hi,O=Test,C=GB - ref UID=jsmith,DC=example,DC=net - same UID=jsmith,DC=example,DC=net +ref 1.3.6.1.4.1.1466.0=Hi,O=Test,C=GB +same oid.1.3.6.1.4.1.1466.0=Hi,O=Test,C=GB +same OID.1.3.6.1.4.1.1466.0=Hi,O=Test,C=GB - ref CN=J. Smith+OU=Sales,DC=example,DC=net - same OU=Sales+CN=J. Smith,DC=example,DC=net +ref CN=Clif Harden+IDNUMBER=a0125589\20,OU=tiPerson,OU=person,O=ti,C=us +diff cn=Clif Harden+IDNumber=a0125589,ou=tiPerson,ou=person,o=ti,c=us +same cn=Clif Harden+IDNumber=a0125589\ ,ou=tiPerson,ou=person,o=ti,c=us +same cn=Clif Harden+IDNumber=a0125589\20 ,ou=tiPerson,ou=person,o=ti,c=us +same cn=Clif Harden+IDNumber="a0125589 ",ou=tiPerson,ou=person,o=ti,c=us - ref CN=John Smith\, III,DC=example,DC=net - same CN=John Smith\, III,DC=example,DC=net - same CN=John Smith\2C III,DC=example,DC=net - ref CN=Before\\0dAfter,DC=example,DC=net - same CN=Before\\0dAfter,DC=example,DC=net +ref CN=\20\20Graham Barr\20\20,OU=person,O=vc,C=us +same Cn=" Graham Barr ",OU=person,O=vc,C=us +same cn=" Graham \20Barr\20 ",OU=person,O=vc,C=us - ref CN=\#John Smith\20,DC=example,DC=net - same CN=\23John Smith\20,DC=example,DC=net - same CN=\#John Smith\ ,DC=example,DC=net +# empty +ref - ref 1.3.6.1.4.1.1466.0=#04024869,DC=example,DC=com - same 1.3.6.1.4.1.1466.0=#04024869,DC=example,DC=com +ref UID=jsmith,DC=example,DC=net +same UID=jsmith,DC=example,DC=net - ref CN=Lu\\C4\\8Di\\C4\\87 - same CN=Lu\\C4\\8Di\\C4\\87 +ref CN=J. Smith+OU=Sales,DC=example,DC=net +same OU=Sales+CN=J. Smith,DC=example,DC=net - # empty value - ref 1.1.1= +ref CN=John Smith\2c III,DC=example,DC=net +same CN=John Smith\, III,DC=example,DC=net +same CN=John Smith\2C III,DC=example,DC=net - # option - bad uid;x-option=jsmith +ref CN=Before\0dAfter,DC=example,DC=net +same CN=Before\0dAfter,DC=example,DC=net - # invalid attribute type name - bad at_tr=jsmith +ref CN=\23John Smith\20,DC=example,DC=net +same CN=\23John Smith\20,DC=example,DC=net +same CN=\#John Smith\ ,DC=example,DC=net - # invalid attribute type name - bad -attr=jsmith +ref 1.3.6.1.4.1.1466.0=#04024869,DC=example,DC=com +same 1.3.6.1.4.1.1466.0=#04024869,DC=example,DC=com - # invalid attribute type name - #bad OID.1.1=jsmith +ref CN=LuÄiÄ +same CN=Lu\C4\8Di\C4\87 - # invalid numeric OID - bad 1..1=jsmith +# empty value +ref 1.1.1= - # invalid numeric OID - bad 1.1.=jsmith +# option +bad uid;x-option=jsmith - # invalid numeric OID - #bad 01.1=jsmith +# invalid attribute type name +bad at_tr=jsmith - # invalid numeric OID - bad 1.ff=jsmith +# invalid attribute type name +bad -attr=jsmith - # invalid HEX form - bad 1.1.1=#GG +# invalid attribute type name +#bad OID.1.1=jsmith - # invalid HEX form - bad 1.1.1=#000 +# invalid numeric OID +bad 1..1=jsmith - # invalid HEX form - bad 1.1.1=#F +# invalid numeric OID +bad 1.1.=jsmith - # invalid HEX form - bad 1.1.1=# +# invalid numeric OID +#bad 01.1=jsmith - # spaces - #bad UID=jsmith, DC=example, DC=net +# invalid numeric OID +bad 1.ff=jsmith - # extra comma - bad UID=jsmith,,DC=example,DC=net +# invalid HEX form +bad 1.1.1=#GG - # semi-colons - #bad UID=jsmith;DC=example;DC=net +# invalid HEX form +bad 1.1.1=#000 - # quotes - #bad CN="John Smith",DC=example,DC=net +# invalid HEX form +bad 1.1.1=#F - # brackets - bad <UID=jsmith,DC=example,DC=net> +# invalid HEX form +bad 1.1.1=# - # unescaped , - bad UID=john,smith +# spaces +#bad UID=jsmith, DC=example, DC=net - # unescaped + - bad UID=john+smith +# extra comma +bad UID=jsmith,,DC=example,DC=net - # invalid escape of ? or unescaped \ - bad UID=john\?smith +# semi-colons +#bad UID=jsmith;DC=example;DC=net - # invalid hex escape - bad UID=john\Fsmith +# quotes +#bad CN="John Smith",DC=example,DC=net - # invalid hex escape - bad UID=john\GGsmith +# brackets +bad <UID=jsmith,DC=example,DC=net> +# unescaped , +bad UID=john,smith -EOS +# unescaped + +bad UID=john+smith -print "1..", scalar(@tests)>>1, "\n"; -my $testno = 0; -my $refdn; -while(my($op,$dn) = splice(@tests,0,2)) { +# invalid escape of ? or unescaped \ +bad UID=john\?smith - my $canon = canonical_dn($dn); - my $failed = 0; +# invalid hex escape +bad UID=john\Fsmith - if ($op eq 'ref') { - $refdn=$dn; - if ($failed = !defined $canon) { - print "'$dn' should have parsed\n"; - } - } - elsif ($op eq 'bad') { - if ($failed = defined $canon) { - print "'$dn' should not have parsed\n '$canon'\n"; - } - } - elsif ( $op eq 'same' ) { - if ($failed = !defined $canon) { - print "'$dn' failed to parse\n"; - } - elsif ($failed = $canon ne $refdn) { - print "'$refdn'\n\ndid not match\n\n'$dn'\n'$canon'\n"; - } - } - elsif ($op eq 'diff' ) { - if ($failed = !defined $canon) { - print "'$dn' failed to parse\n"; - } - elsif ($failed = $canon eq $refdn) { - print "'$refdn'\n\nmatched\n\n'$dn'\n'$canon'\n"; - } - } - else { - $failed = 1; - warn "Bad opcode $op\n"; - } +# invalid hex escape +bad UID=john\GGsmith - print +($failed ? "not ok " : "ok "),++$testno,"\n"; -} +ref CN=John Smith \2c III,DC=example,DC=net +same CN=John Smith \, III,DC=example,DC=net +same CN=John Smith \2C III,DC=example,DC=net + +ref DISTINGUISHEDNAMETABLEKEY=cn\3dDSA\2c c\3dGB,CN=bilateral table,CN=DSA,C=US +same distinguishedNameTableKey=cn\=DSA\, c\=GB, cn=bilateral table, cn=DSA, c=US |