String dn3 = "cn=toto,cn=titi,dc=domain,dc=tld";
String revdn3 = CertTools.reverseDN(dn3);
assertEquals("dc=tld,dc=domain,cn=titi,cn=toto", revdn3);
X509Name dn4 = CertTools.stringToBcX509Name(dn3, new X509DefaultEntryConverter(), true);
assertEquals("CN=toto,CN=titi,DC=domain,DC=tld", dn4.toString());
X509Name dn5 = CertTools.stringToBcX509Name(dn3, new X509DefaultEntryConverter(), false);
assertEquals("DC=tld,DC=domain,CN=titi,CN=toto", dn5.toString());
assertEquals("CN=toto,CN=titi,DC=domain,DC=tld", CertTools.stringToBCDNString(dn3));
String dn6 = "dc=tld,dc=domain,cn=titi,cn=toto";
String revdn6 = CertTools.reverseDN(dn6);
assertEquals("cn=toto,cn=titi,dc=domain,dc=tld", revdn6);
assertEquals("CN=toto,CN=titi,DC=domain,DC=tld", CertTools.stringToBCDNString(dn3));
X509Name dn7 = CertTools.stringToBcX509Name(dn6, new X509DefaultEntryConverter(), true);
assertEquals("CN=toto,CN=titi,DC=domain,DC=tld", dn7.toString());
X509Name revdn7 = CertTools.stringToBcX509Name(dn6, new X509DefaultEntryConverter(), false);
assertEquals("DC=tld,DC=domain,CN=titi,CN=toto", revdn7.toString());
// Test the test strings from ECA-1699, to prove that we fixed this issue
String dn8 = "dc=org,dc=foo,o=FOO,cn=FOO Root CA";
String dn9 = "cn=FOO Root CA,o=FOO,dc=foo,dc=org";
String revdn8 = CertTools.reverseDN(dn8);
assertEquals("cn=FOO Root CA,o=FOO,dc=foo,dc=org", revdn8);
String revdn9 = CertTools.reverseDN(dn9);
assertEquals("dc=org,dc=foo,o=FOO,cn=FOO Root CA", revdn9);
X509Name xdn8ldap = CertTools.stringToBcX509Name(dn8, new X509DefaultEntryConverter(), true);
X509Name xdn8x500 = CertTools.stringToBcX509Name(dn8, new X509DefaultEntryConverter(), false);
assertEquals("CN=FOO Root CA,O=FOO,DC=foo,DC=org", xdn8ldap.toString());
assertEquals("DC=org,DC=foo,O=FOO,CN=FOO Root CA", xdn8x500.toString());
X509Name xdn9ldap = CertTools.stringToBcX509Name(dn9, new X509DefaultEntryConverter(), true);
X509Name xdn9x500 = CertTools.stringToBcX509Name(dn9, new X509DefaultEntryConverter(), false);
assertEquals("CN=FOO Root CA,O=FOO,DC=foo,DC=org", xdn9ldap.toString());
assertEquals("DC=org,DC=foo,O=FOO,CN=FOO Root CA", xdn9x500.toString());
assertEquals("CN=FOO Root CA,O=FOO,DC=foo,DC=org", CertTools.stringToBCDNString(dn8));
assertEquals("CN=FOO Root CA,O=FOO,DC=foo,DC=org", CertTools.stringToBCDNString(dn9));
// Test reversing DNs with multiple OU
String dn10 = "CN=something,OU=A,OU=B,O=someO,C=SE";
X509Name x509dn10 = CertTools.stringToBcX509Name(dn10, new X509DefaultEntryConverter(), true);
assertEquals("CN=something,OU=A,OU=B,O=someO,C=SE", x509dn10.toString());
assertEquals("CN=something,OU=A,OU=B,O=someO,C=SE", CertTools.stringToBCDNString(dn10));
// When we order forwards (LdapOrder) from the beginning, and request !LdapOrder, everything should be reversed
X509Name ldapdn11 = CertTools.stringToBcX509Name(dn10, new X509DefaultEntryConverter(), false);
assertEquals("C=SE,O=someO,OU=B,OU=A,CN=something", ldapdn11.toString());
// When we order backwards (X.509, !LdapOrder) from the beginning, we should not reorder anything
String dn11 = "C=SE,O=someO,OU=B,OU=A,CN=something";
X509Name x509dn11 = CertTools.stringToBcX509Name(dn11, new X509DefaultEntryConverter(), false);
assertEquals("C=SE,O=someO,OU=B,OU=A,CN=something", x509dn11.toString());
assertEquals("CN=something,OU=A,OU=B,O=someO,C=SE", CertTools.stringToBCDNString(dn11));
log.trace("<test09TestReverse()");
}