use of org.apache.directory.api.ldap.model.url.LdapUrl.Extension in project directory-ldap-api by apache.
the class LdapUrlTest method testLdapURLExtensionWithCommaValue.
/**
* Test comma in extension value.
*/
@Test
public void testLdapURLExtensionWithCommaValue() throws Exception {
LdapUrl url1 = new LdapUrl();
url1.setHost("localhost");
url1.setPort(123);
url1.setDn(Dn.EMPTY_DN);
url1.getExtensions().add(new Extension(false, "X-CONNECTION-NAME", ","));
assertEquals("ldap://localhost:123/????X-CONNECTION-NAME=%2c", url1.toString());
LdapUrl url2 = new LdapUrl("ldap://localhost:123/????X-CONNECTION-NAME=%2c");
assertEquals(",", url1.getExtensionValue("X-CONNECTION-NAME"));
assertEquals("ldap://localhost:123/????X-CONNECTION-NAME=%2c", url2.toString());
}
use of org.apache.directory.api.ldap.model.url.LdapUrl.Extension in project directory-ldap-api by apache.
the class LdapUrlTest method testLdapURLExtensionOrder.
/**
* Test the extension order of an LdapUrl.
*/
@Test
public void testLdapURLExtensionOrder() throws LdapURLEncodingException {
LdapUrl url = new LdapUrl("ldap://localhost:123/????!a=b,!c,!x,d=e,f=g,!h=i");
assertEquals("ldap://localhost:123/????!a=b,!c,!x,d=e,f=g,!h=i", url.toString());
List<Extension> extensions = url.getExtensions();
assertTrue(extensions.get(0).isCritical());
assertEquals("a", extensions.get(0).getType());
assertEquals("b", extensions.get(0).getValue());
assertTrue(extensions.get(1).isCritical());
assertEquals("c", extensions.get(1).getType());
assertNull(extensions.get(1).getValue());
assertTrue(extensions.get(2).isCritical());
assertEquals("x", extensions.get(2).getType());
assertNull(extensions.get(2).getValue());
assertFalse(extensions.get(3).isCritical());
assertEquals("d", extensions.get(3).getType());
assertEquals("e", extensions.get(3).getValue());
assertFalse(extensions.get(4).isCritical());
assertEquals("f", extensions.get(4).getType());
assertEquals("g", extensions.get(4).getValue());
assertTrue(extensions.get(5).isCritical());
assertEquals("h", extensions.get(5).getType());
assertEquals("i", extensions.get(5).getValue());
}
use of org.apache.directory.api.ldap.model.url.LdapUrl.Extension in project directory-ldap-api by apache.
the class LdapUrlTest method testLdapURLExtensionWithUtf8Values.
/**
* Test UTF-8 values in extension values.
*/
@Test
public void testLdapURLExtensionWithUtf8Values() throws Exception {
String germanChars = new String(new byte[] { (byte) 0xC3, (byte) 0x84, (byte) 0xC3, (byte) 0x96, (byte) 0xC3, (byte) 0x9C, (byte) 0xC3, (byte) 0x9F, (byte) 0xC3, (byte) 0xA4, (byte) 0xC3, (byte) 0xB6, (byte) 0xC3, (byte) 0xBC }, "UTF-8");
LdapUrl url1 = new LdapUrl();
url1.setHost("localhost");
url1.setPort(123);
url1.setDn(Dn.EMPTY_DN);
url1.getExtensions().add(new Extension(false, "X-CONNECTION-NAME", germanChars));
assertEquals("ldap://localhost:123/????X-CONNECTION-NAME=%C3%84%C3%96%C3%9C%C3%9F%C3%A4%C3%B6%C3%BC", url1.toString());
LdapUrl url2 = new LdapUrl("ldap://localhost:123/????X-CONNECTION-NAME=%c3%84%c3%96%c3%9c%c3%9f%c3%a4%c3%b6%c3%bc");
assertEquals(germanChars, url1.getExtensionValue("X-CONNECTION-NAME"));
assertEquals("ldap://localhost:123/????X-CONNECTION-NAME=%C3%84%C3%96%C3%9C%C3%9F%C3%A4%C3%B6%C3%BC", url2.toString());
}
use of org.apache.directory.api.ldap.model.url.LdapUrl.Extension in project directory-ldap-api by apache.
the class LdapUrlTest method testLdapURLExtensionWithRFC3986UnreservedChars.
/**
* Test with RFC 3986 unreserved characters in extension value.
*
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
*/
@Test
public void testLdapURLExtensionWithRFC3986UnreservedChars() throws Exception {
LdapUrl url1 = new LdapUrl();
url1.setHost("localhost");
url1.setPort(123);
url1.setDn(Dn.EMPTY_DN);
url1.getExtensions().add(new Extension(false, "X-CONNECTION-NAME", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~"));
assertEquals("ldap://localhost:123/????X-CONNECTION-NAME=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~", url1.toString());
LdapUrl url2 = new LdapUrl("ldap://localhost:123/????X-CONNECTION-NAME=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~");
assertEquals("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~", url1.getExtensionValue("X-CONNECTION-NAME"));
assertEquals("ldap://localhost:123/????X-CONNECTION-NAME=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~", url2.toString());
}
use of org.apache.directory.api.ldap.model.url.LdapUrl.Extension in project directory-ldap-api by apache.
the class LdapUrlTest method testLdapURLExtensionWithRFC3986ReservedCharsAndRFC4616Exception.
/**
* Test with RFC 3986 reserved characters in extension value.
*
* reserved = gen-delims / sub-delims
* gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
* / "*" / "+" / "," / ";" / "="
*
* RFC 4516 specifies that '?' and a ',' must be percent encoded.
*/
@Test
public void testLdapURLExtensionWithRFC3986ReservedCharsAndRFC4616Exception() throws Exception {
LdapUrl url1 = new LdapUrl();
url1.setHost("localhost");
url1.setPort(123);
url1.setDn(Dn.EMPTY_DN);
url1.getExtensions().add(new Extension(false, "X-CONNECTION-NAME", ":/?#[]@!$&'()*+,;="));
assertEquals("ldap://localhost:123/????X-CONNECTION-NAME=:/%3F#[]@!$&'()*+%2c;=", url1.toString());
LdapUrl url2 = new LdapUrl("ldap://localhost:123/????X-CONNECTION-NAME=:/%3f#[]@!$&'()*+%2c;=");
assertEquals(":/?#[]@!$&'()*+,;=", url1.getExtensionValue("X-CONNECTION-NAME"));
assertEquals("ldap://localhost:123/????X-CONNECTION-NAME=:/%3F#[]@!$&'()*+%2c;=", url2.toString());
}