use of org.apache.directory.api.ldap.extras.controls.ad_impl.AdDirSyncDecorator in project directory-ldap-api by apache.
the class AdDirSyncControlTest method testAdDirSyncControlAbsentParentFirst.
@Test
public void testAdDirSyncControlAbsentParentFirst() throws Exception {
ByteBuffer bb = ByteBuffer.allocate(0x07);
bb.put(new byte[] { 0x30, 0x05, // maxReturnLength (no limit)
0x02, // maxReturnLength (no limit)
0x01, // maxReturnLength (no limit)
0x00, // cookie
0x04, // cookie
0x00 });
bb.flip();
AdDirSync decorator = new AdDirSyncDecorator(codec);
try {
((AdDirSyncDecorator) decorator).decode(bb.array());
fail();
} catch (DecoderException de) {
// expected
}
}
use of org.apache.directory.api.ldap.extras.controls.ad_impl.AdDirSyncDecorator in project directory-ldap-api by apache.
the class AdDirSyncControlTest method testAdDirSyncControl.
@Test
public void testAdDirSyncControl() throws Exception {
ByteBuffer bb = ByteBuffer.allocate(0x0F);
bb.put(new byte[] { 0x30, 0x0D, // flag (LDAP_DIRSYNC_OBJECT_SECURITY, LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER)
0x02, // flag (LDAP_DIRSYNC_OBJECT_SECURITY, LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER)
0x02, // flag (LDAP_DIRSYNC_OBJECT_SECURITY, LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER)
0x08, // flag (LDAP_DIRSYNC_OBJECT_SECURITY, LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER)
0x01, // maxReturnLength (no limit)
0x02, // maxReturnLength (no limit)
0x01, // maxReturnLength (no limit)
0x00, // the cookie
0x04, // the cookie
0x04, // the cookie
'x', // the cookie
'k', // the cookie
'c', // the cookie
'd' });
bb.flip();
AdDirSync decorator = new AdDirSyncDecorator(codec);
AdDirSync adDirSync = (AdDirSync) ((AdDirSyncDecorator) decorator).decode(bb.array());
assertEquals(EnumSet.of(AdDirSyncFlag.LDAP_DIRSYNC_OBJECT_SECURITY, AdDirSyncFlag.LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER), adDirSync.getFlags());
assertEquals(0, adDirSync.getMaxReturnLength());
assertEquals("xkcd", Strings.utf8ToString(adDirSync.getCookie()));
// test encoding
try {
ByteBuffer buffer = ((AdDirSyncDecorator) adDirSync).encode(ByteBuffer.allocate(((AdDirSyncDecorator) adDirSync).computeLength()));
String expected = "0x30 0x0D 0x02 0x02 0x08 0x01 0x02 0x01 0x00 0x04 0x04 0x78 0x6B 0x63 0x64 ";
String decoded = Strings.dumpBytes(buffer.array());
assertEquals(expected, decoded);
} catch (EncoderException e) {
fail(e.getMessage());
}
}
use of org.apache.directory.api.ldap.extras.controls.ad_impl.AdDirSyncDecorator in project directory-ldap-api by apache.
the class AdDirSyncControlTest method testAdDirSyncControlEmpty.
@Test
public void testAdDirSyncControlEmpty() throws Exception {
ByteBuffer bb = ByteBuffer.allocate(0x02);
bb.put(new byte[] { 0x30, 0x00 });
bb.flip();
AdDirSync decorator = new AdDirSyncDecorator(codec);
try {
((AdDirSyncDecorator) decorator).decode(bb.array());
fail();
} catch (DecoderException de) {
// expected
}
}
use of org.apache.directory.api.ldap.extras.controls.ad_impl.AdDirSyncDecorator in project directory-ldap-api by apache.
the class AdDirSyncControlTest method testAdDirSyncControlAbsentCookie.
@Test
public void testAdDirSyncControlAbsentCookie() throws Exception {
ByteBuffer bb = ByteBuffer.allocate(0x08);
bb.put(new byte[] { 0x30, 0x06, // parentFirst (false)
0x02, // parentFirst (false)
0x01, // parentFirst (false)
0x00, // maxReturnLength (no limit)
0x02, // maxReturnLength (no limit)
0x01, // maxReturnLength (no limit)
0x00 });
bb.flip();
AdDirSync decorator = new AdDirSyncDecorator(codec);
try {
((AdDirSyncDecorator) decorator).decode(bb.array());
fail();
} catch (DecoderException de) {
// expected
}
}
use of org.apache.directory.api.ldap.extras.controls.ad_impl.AdDirSyncDecorator in project directory-ldap-api by apache.
the class AdDirSyncControlTest method testAdDirSyncControlNoCookie.
@Test
public void testAdDirSyncControlNoCookie() throws Exception {
ByteBuffer bb = ByteBuffer.allocate(0x0A);
bb.put(new byte[] { 0x30, 0x08, // flag (LDAP_DIRSYNC_OBJECT_SECURITY)
0x02, // flag (LDAP_DIRSYNC_OBJECT_SECURITY)
0x01, // flag (LDAP_DIRSYNC_OBJECT_SECURITY)
0x01, // maxReturnLength (no limit)
0x02, // maxReturnLength (no limit)
0x01, // maxReturnLength (no limit)
0x00, // the cookie
0x04, // the cookie
0x00 });
bb.flip();
AdDirSync decorator = new AdDirSyncDecorator(codec);
AdDirSync adDirSync = (AdDirSync) ((AdDirSyncDecorator) decorator).decode(bb.array());
assertEquals(EnumSet.of(AdDirSyncFlag.LDAP_DIRSYNC_OBJECT_SECURITY), adDirSync.getFlags());
assertEquals(0, adDirSync.getMaxReturnLength());
assertEquals("", Strings.utf8ToString(adDirSync.getCookie()));
// test encoding
try {
ByteBuffer buffer = ((AdDirSyncDecorator) adDirSync).encode(ByteBuffer.allocate(((AdDirSyncDecorator) adDirSync).computeLength()));
String expected = "0x30 0x08 0x02 0x01 0x01 0x02 0x01 0x00 0x04 0x00 ";
String decoded = Strings.dumpBytes(buffer.array());
assertEquals(expected, decoded);
} catch (EncoderException e) {
fail(e.getMessage());
}
}
Aggregations