use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.
the class EndTransactionRequestTest method testEndTransactionRequestNoCommitIdentifier.
/**
* Test the decoding of a EndTransactionRequest with an identifier but no commit
* @throws EncoderException
*/
@Test
public void testEndTransactionRequestNoCommitIdentifier() throws EncoderException {
Asn1Decoder decoder = new Asn1Decoder();
ByteBuffer bb = ByteBuffer.allocate(0x08);
bb.put(new byte[] { // EndTransactionRequest ::= SEQUENCE {
0x30, // EndTransactionRequest ::= SEQUENCE {
0x06, // identifier (test)
0x04, // identifier (test)
0x04, // identifier (test)
't', // identifier (test)
'e', // identifier (test)
's', // identifier (test)
't' });
String decodedPdu = Strings.dumpBytes(bb.array());
bb.flip();
EndTransactionRequestContainer container = new EndTransactionRequestContainer();
try {
decoder.decode(bb, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
EndTransactionRequest endTransactionRequest = container.getEndTransactionRequest();
assertTrue(endTransactionRequest.getCommit());
assertEquals("test", Strings.utf8ToString(endTransactionRequest.getTransactionId()));
// Check the length
assertEquals(0x08, ((EndTransactionRequestDecorator) endTransactionRequest).computeLengthInternal());
// Check the encoding
ByteBuffer bb1 = ((EndTransactionRequestDecorator) endTransactionRequest).encodeInternal();
String encodedPdu = Strings.dumpBytes(bb1.array());
assertEquals(encodedPdu, decodedPdu);
}
use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.
the class EndTransactionResponseTest method testEndTransactionResponseMessageId.
/**
* Test the decoding of a EndTransactionResponse with a messageId and no updateControls
*/
@Test
public void testEndTransactionResponseMessageId() throws DecoderException, EncoderException {
Asn1Decoder decoder = new Asn1Decoder();
ByteBuffer bb = ByteBuffer.allocate(0x05);
bb.put(new byte[] { // EndTransactionResponse ::= SEQUENCE {
0x30, // EndTransactionResponse ::= SEQUENCE {
0x03, // MessageId
0x02, // MessageId
0x01, // MessageId
0x04 });
String decodedPdu = Strings.dumpBytes(bb.array());
bb.flip();
EndTransactionResponseContainer container = new EndTransactionResponseContainer();
try {
decoder.decode(bb, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
EndTransactionResponse endTransactionResponse = container.getEndTransactionResponse();
assertEquals(4, endTransactionResponse.getFailedMessageId());
assertEquals(0, endTransactionResponse.getUpdateControls().size());
// Check the length
assertEquals(0x05, ((EndTransactionResponseDecorator) endTransactionResponse).computeLengthInternal());
// Check the encoding
ByteBuffer bb1 = ((EndTransactionResponseDecorator) endTransactionResponse).encodeInternal();
String encodedPdu = Strings.dumpBytes(bb1.array());
assertEquals(encodedPdu, decodedPdu);
}
use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.
the class EndTransactionResponseTest method testEndTransactionResponseUpdateControls.
/**
* Test the decoding of a EndTransactionResponse with updateControls
*/
@Test
public void testEndTransactionResponseUpdateControls() throws DecoderException, EncoderException {
Asn1Decoder decoder = new Asn1Decoder();
ByteBuffer bb = ByteBuffer.allocate(0xAC);
bb.put(new byte[] { // EndTransactionResponse ::= SEQUENCE {
0x30, // EndTransactionResponse ::= SEQUENCE {
(byte) 0x81, // EndTransactionResponse ::= SEQUENCE {
(byte) 0xA9, // UpdateControls
0x30, // UpdateControls
(byte) 0x81, // UpdateControls
(byte) 0xA6, // updateControl
0x30, // updateControl
0x5F, // messageID
0x02, // messageID
0x01, // messageID
0x01, // controls
0x30, // controls
0x5A, // Control ::= SEQUENCE {
0x30, // Control ::= SEQUENCE {
0x1A, // controlType LDAPOID,
0x04, // controlType LDAPOID,
0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1', // criticality BOOLEAN DEFAULT FALSE,
0x01, // criticality BOOLEAN DEFAULT FALSE,
0x01, // criticality BOOLEAN DEFAULT FALSE,
(byte) 0xFF, // controlValue OCTET STRING OPTIONAL }
0x04, // controlValue OCTET STRING OPTIONAL }
0x06, 'a', 'b', 'c', 'd', 'e', 'f', // Control ::= SEQUENCE {
0x30, // Control ::= SEQUENCE {
0x17, // controlType LDAPOID,
0x04, // controlType LDAPOID,
0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2', // controlValue OCTET STRING OPTIONAL }
0x04, // controlValue OCTET STRING OPTIONAL }
0x06, 'g', 'h', 'i', 'j', 'k', 'l', // Control ::= SEQUENCE {
0x30, // Control ::= SEQUENCE {
0x12, // controlType LDAPOID,
0x04, // controlType LDAPOID,
0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '3', // criticality BOOLEAN DEFAULT FALSE}
0x01, // criticality BOOLEAN DEFAULT FALSE}
0x01, // criticality BOOLEAN DEFAULT FALSE}
(byte) 0xFF, // Control ::= SEQUENCE {
0x30, // Control ::= SEQUENCE {
0x0F, // controlType LDAPOID}
0x04, // controlType LDAPOID}
0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4', // updateControl
0x30, // updateControl
0x43, // messageID
0x02, // messageID
0x01, // messageID
0x02, // controls
0x30, // controls
0x3E, // Control ::= SEQUENCE {
0x30, // Control ::= SEQUENCE {
0x17, // controlType LDAPOID,
0x04, // controlType LDAPOID,
0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2', // controlValue OCTET STRING OPTIONAL }
0x04, // controlValue OCTET STRING OPTIONAL }
0x06, 'g', 'h', 'i', 'j', 'k', 'l', // Control ::= SEQUENCE {
0x30, // Control ::= SEQUENCE {
0x12, // controlType LDAPOID,
0x04, // controlType LDAPOID,
0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '3', // criticality BOOLEAN DEFAULT FALSE}
0x01, // criticality BOOLEAN DEFAULT FALSE}
0x01, // criticality BOOLEAN DEFAULT FALSE}
(byte) 0xFF, // Control ::= SEQUENCE {
0x30, // Control ::= SEQUENCE {
0x0F, // controlType LDAPOID}
0x04, // controlType LDAPOID}
0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4' });
String decodedPdu = Strings.dumpBytes(bb.array());
bb.flip();
EndTransactionResponseContainer container = new EndTransactionResponseContainer();
try {
decoder.decode(bb, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
EndTransactionResponse endTransactionResponse = container.getEndTransactionResponse();
assertEquals(-1, endTransactionResponse.getFailedMessageId());
assertEquals(2, endTransactionResponse.getUpdateControls().size());
UpdateControls updateControls1 = endTransactionResponse.getUpdateControls().get(0);
assertEquals(1, updateControls1.getMessageId());
assertNotNull(updateControls1.getControls());
assertEquals(4, updateControls1.getControls().size());
for (Control control : updateControls1.getControls()) {
switch(control.getOid()) {
case "1.3.6.1.5.5.1":
assertTrue(control.isCritical());
assertEquals("abcdef", Strings.utf8ToString(((CodecControl<?>) control).getValue()));
break;
case "1.3.6.1.5.5.2":
assertFalse(control.isCritical());
assertEquals("ghijkl", Strings.utf8ToString(((CodecControl<?>) control).getValue()));
break;
case "1.3.6.1.5.5.3":
assertTrue(control.isCritical());
assertNull(((CodecControl<?>) control).getValue());
break;
case "1.3.6.1.5.5.4":
assertFalse(control.isCritical());
assertNull(((CodecControl<?>) control).getValue());
break;
default:
fail();
break;
}
}
UpdateControls updateControls2 = endTransactionResponse.getUpdateControls().get(1);
assertEquals(2, updateControls2.getMessageId());
assertNotNull(updateControls2.getControls());
assertEquals(3, updateControls2.getControls().size());
for (Control control : updateControls2.getControls()) {
switch(control.getOid()) {
case "1.3.6.1.5.5.2":
assertFalse(control.isCritical());
assertEquals("ghijkl", Strings.utf8ToString(((CodecControl<?>) control).getValue()));
break;
case "1.3.6.1.5.5.3":
assertTrue(control.isCritical());
assertNull(((CodecControl<?>) control).getValue());
break;
case "1.3.6.1.5.5.4":
assertFalse(control.isCritical());
assertNull(((CodecControl<?>) control).getValue());
break;
default:
fail();
break;
}
}
// Check the length
assertEquals(0xAC, ((EndTransactionResponseDecorator) endTransactionResponse).computeLengthInternal());
// Check the encoding
ByteBuffer bb1 = ((EndTransactionResponseDecorator) endTransactionResponse).encodeInternal();
String encodedPdu = Strings.dumpBytes(bb1.array());
assertEquals(encodedPdu, decodedPdu);
}
use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.
the class GracefulDisconnectResponseTest method testDecodeGracefulDisconnectReplicatedContextsOnly.
/**
* Test the decoding of a GracefulDisconnect with replicatedContexts only
*/
@Test
public void testDecodeGracefulDisconnectReplicatedContextsOnly() {
Asn1Decoder decoder = new GracefulDisconnectDecoder();
ByteBuffer stream = ByteBuffer.allocate(0x6A);
stream.put(new byte[] { // GracefulDisconnec ::= SEQUENCE {
0x30, // GracefulDisconnec ::= SEQUENCE {
0x68, 0x30, // replicatedContexts Referral OPTIONAL
0x66, 0x04, 0x1F, 'l', 'd', 'a', 'p', ':', '/', '/', 'd', 'i', 'r', 'e', 'c', 't', 'o', 'r', 'y', '.', 'a', 'p', 'a', 'c', 'h', 'e', '.', 'o', 'r', 'g', ':', '8', '0', '/', 0x04, 0x43, 'l', 'd', 'a', 'p', ':', '/', '/', 'l', 'd', 'a', 'p', '.', 'n', 'e', 't', 's', 'c', 'a', 'p', 'e', '.', 'c', 'o', 'm', '/', 'o', '=', 'B', 'a', 'b', 's', 'c', 'o', ',', 'c', '=', 'U', 'S', '?', '?', '?', '(', 'i', 'n', 't', '=', '%', '5', 'c', '0', '0', '%', '5', 'c', '0', '0', '%', '5', 'c', '0', '0', '%', '5', 'c', '0', '4', ')' });
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
GracefulDisconnectContainer container = new GracefulDisconnectContainer();
try {
decoder.decode(stream, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
GracefulDisconnectResponseDecorator gracefulDisconnect = container.getGracefulDisconnectResponse();
assertEquals(0, gracefulDisconnect.getTimeOffline());
assertEquals(0, gracefulDisconnect.getDelay());
assertEquals(2, gracefulDisconnect.getReplicatedContexts().getLdapUrls().size());
Iterator<String> ldapUrls = gracefulDisconnect.getReplicatedContexts().getLdapUrls().iterator();
assertEquals("ldap://directory.apache.org:80/", ldapUrls.next());
assertEquals("ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)", ldapUrls.next());
// Check the length
assertEquals(0x6A, gracefulDisconnect.computeLengthInternal());
// Check the encoding
try {
ByteBuffer bb = gracefulDisconnect.encodeInternal();
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.
the class GracefulShutdownTest method testDecodeGracefulShutdownSuccess.
/**
* Test the decoding of a GracefulShutdown
*/
@Test
public void testDecodeGracefulShutdownSuccess() {
Asn1Decoder decoder = new Asn1Decoder();
ByteBuffer bb = ByteBuffer.allocate(0x08);
bb.put(new byte[] { // GracefulShutdown ::= SEQUENCE {
0x30, // GracefulShutdown ::= SEQUENCE {
0x06, 0x02, 0x01, // timeOffline INTEGER (0..720) DEFAULT 0,
0x01, (byte) 0x80, 0x01, // delay INTEGER (0..86400) DEFAULT
0x01 // 0
// }
});
String decodedPdu = Strings.dumpBytes(bb.array());
bb.flip();
GracefulShutdownContainer container = new GracefulShutdownContainer();
try {
decoder.decode(bb, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
GracefulShutdownRequestDecorator gracefulShutdownRequest = container.getGracefulShutdownRequest();
assertEquals(1, gracefulShutdownRequest.getTimeOffline());
assertEquals(1, gracefulShutdownRequest.getDelay());
// Check the length
assertEquals(0x08, gracefulShutdownRequest.computeLengthInternal());
// Check the encoding
try {
ByteBuffer bb1 = gracefulShutdownRequest.encodeInternal();
String encodedPdu = Strings.dumpBytes(bb1.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
Aggregations