Search in sources :

Example 1 with PasswordModifyResponseContainer

use of org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseContainer in project directory-ldap-api by apache.

the class PasswordModifyResponseTest method testDecodePasswordModifyResponseEmpty.

/**
 * Test the decoding of a PasswordModifyResponse with nothing in it
 */
@Test
public void testDecodePasswordModifyResponseEmpty() {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x02);
    bb.put(new byte[] { // PasswordModifyResponse ::= SEQUENCE {
    0x30, // PasswordModifyResponse ::= SEQUENCE {
    0x00 });
    String decodedPdu = Strings.dumpBytes(bb.array());
    bb.flip();
    PasswordModifyResponseContainer container = new PasswordModifyResponseContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    PasswordModifyResponse pwdModifyResponse = container.getPwdModifyResponse();
    assertNull(pwdModifyResponse.getGenPassword());
    // Check the length
    assertEquals(0x02, ((PasswordModifyResponseDecorator) pwdModifyResponse).computeLengthInternal());
    // Check the encoding
    ByteBuffer bb1 = ((PasswordModifyResponseDecorator) pwdModifyResponse).encodeInternal();
    String encodedPdu = Strings.dumpBytes(bb1.array());
    assertEquals(encodedPdu, decodedPdu);
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) PasswordModifyResponseContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseContainer) PasswordModifyResponse(org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponse) PasswordModifyResponseDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseDecorator) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with PasswordModifyResponseContainer

use of org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseContainer in project directory-ldap-api by apache.

the class PasswordModifyResponseTest method testDecodePasswordModifyResponseUserIdentityNull.

/**
 * Test the decoding of a PasswordModifyResponse with an empty genPassword
 */
@Test
public void testDecodePasswordModifyResponseUserIdentityNull() {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x04);
    bb.put(new byte[] { // PasswordModifyResponse ::= SEQUENCE {
    0x30, // PasswordModifyResponse ::= SEQUENCE {
    0x02, (byte) 0x80, // genPassword    [0]  OCTET STRING OPTIONAL
    0x00 });
    String decodedPdu = Strings.dumpBytes(bb.array());
    bb.flip();
    PasswordModifyResponseContainer container = new PasswordModifyResponseContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    PasswordModifyResponse pwdModifyResponse = container.getPwdModifyResponse();
    assertNotNull(pwdModifyResponse.getGenPassword());
    assertEquals(0, pwdModifyResponse.getGenPassword().length);
    // Check the length
    assertEquals(0x04, ((PasswordModifyResponseDecorator) pwdModifyResponse).computeLengthInternal());
    // Check the encoding
    ByteBuffer bb1 = ((PasswordModifyResponseDecorator) pwdModifyResponse).encodeInternal();
    String encodedPdu = Strings.dumpBytes(bb1.array());
    assertEquals(encodedPdu, decodedPdu);
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) PasswordModifyResponseContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseContainer) PasswordModifyResponse(org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponse) PasswordModifyResponseDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseDecorator) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with PasswordModifyResponseContainer

use of org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseContainer in project directory-ldap-api by apache.

the class PasswordModifyResponseTest method testDecodePasswordModifyResponseUserIdentityValue.

/**
 * Test the decoding of a PasswordModifyResponse with a genPassword
 */
@Test
public void testDecodePasswordModifyResponseUserIdentityValue() {
    Asn1Decoder decoder = new Asn1Decoder();
    ByteBuffer bb = ByteBuffer.allocate(0x08);
    bb.put(new byte[] { // PasswordModifyResponse ::= SEQUENCE {
    0x30, // PasswordModifyResponse ::= SEQUENCE {
    0x06, (byte) 0x80, // genPassword    [0]  OCTET STRING OPTIONAL
    0x04, 'a', 'b', 'c', 'd' });
    String decodedPdu = Strings.dumpBytes(bb.array());
    bb.flip();
    PasswordModifyResponseContainer container = new PasswordModifyResponseContainer();
    try {
        decoder.decode(bb, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    PasswordModifyResponse pwdModifyResponse = container.getPwdModifyResponse();
    assertNotNull(pwdModifyResponse.getGenPassword());
    assertEquals("abcd", Strings.utf8ToString(pwdModifyResponse.getGenPassword()));
    // Check the length
    assertEquals(0x08, ((PasswordModifyResponseDecorator) pwdModifyResponse).computeLengthInternal());
    // Check the encoding
    ByteBuffer bb1 = ((PasswordModifyResponseDecorator) pwdModifyResponse).encodeInternal();
    String encodedPdu = Strings.dumpBytes(bb1.array());
    assertEquals(encodedPdu, decodedPdu);
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) PasswordModifyResponseContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseContainer) PasswordModifyResponse(org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponse) PasswordModifyResponseDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseDecorator) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)3 DecoderException (org.apache.directory.api.asn1.DecoderException)3 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)3 PasswordModifyResponseContainer (org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseContainer)3 PasswordModifyResponseDecorator (org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyResponseDecorator)3 PasswordModifyResponse (org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponse)3 Test (org.junit.Test)3