You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2013/04/17 11:35:29 UTC
svn commit: r1468814 - in /directory/shared/trunk/ldap/extras/codec/src:
main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/
test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/
Author: elecharny
Date: Wed Apr 17 09:35:29 2013
New Revision: 1468814
URL: http://svn.apache.org/r1468814
Log:
o Added the missing grammar transition for the pwdModifyRequest
o Fixed some error in the encode and decode method
o Added some tests
Modified:
directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequest.java
directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestGrammar.java
directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/PasswordModifyRequestTest.java
Modified: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequest.java?rev=1468814&r1=1468813&r2=1468814&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequest.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequest.java Wed Apr 17 09:35:29 2013
@@ -62,6 +62,8 @@ public class PasswordModifyRequest exten
*/
public int computeLength()
{
+ requestLength = 0;
+
if ( pwdModifyRequest.getUserIdentity() != null )
{
int len = pwdModifyRequest.getUserIdentity().length;
@@ -71,13 +73,13 @@ public class PasswordModifyRequest exten
if ( pwdModifyRequest.getOldPassword() != null )
{
int len = pwdModifyRequest.getOldPassword().length;
- requestLength = 1 + BerValue.getNbBytes( len ) + len;
+ requestLength += 1 + BerValue.getNbBytes( len ) + len;
}
if ( pwdModifyRequest.getNewPassword() != null )
{
int len = pwdModifyRequest.getNewPassword().length;
- requestLength = 1 + BerValue.getNbBytes( len ) + len;
+ requestLength += 1 + BerValue.getNbBytes( len ) + len;
}
return 1 + BerValue.getNbBytes( requestLength ) + requestLength;
Modified: directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestGrammar.java?rev=1468814&r1=1468813&r2=1468814&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestGrammar.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/pwdModify/PasswordModifyRequestGrammar.java Wed Apr 17 09:35:29 2013
@@ -138,6 +138,89 @@ public class PasswordModifyRequestGramma
} );
/**
+ * Transition from userIdentity to oldPassword
+ *
+ * PasswdModifyRequestValue ::= SEQUENCE {
+ * userIdentity [0] OCTET STRING OPTIONAL
+ * oldPassword [1] OCTET STRING OPTIONAL
+ * ...
+ *
+ * Set the oldPassword into the PasswdModifyRequest instance.
+ */
+ super.transitions[PasswordModifyRequestStatesEnum.USER_IDENTITY_STATE.ordinal()][PasswordModifyRequestConstants.OLD_PASSWORD_TAG] =
+ new GrammarTransition<PasswordModifyRequestContainer>(
+ PasswordModifyRequestStatesEnum.USER_IDENTITY_STATE,
+ PasswordModifyRequestStatesEnum.OLD_PASSWORD_STATE,
+ PasswordModifyRequestConstants.OLD_PASSWORD_TAG,
+ new GrammarAction<PasswordModifyRequestContainer>( "Set PasswordModifyRequest oldPassword" )
+ {
+ public void action( PasswordModifyRequestContainer container ) throws DecoderException
+ {
+ BerValue value = container.getCurrentTLV().getValue();
+
+ byte[] oldPassword = value.getData();
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "oldPassword = " + Strings.dumpBytes( oldPassword ) );
+ }
+
+ if ( oldPassword == null )
+ {
+ oldPassword = Strings.EMPTY_BYTES;
+ }
+
+ ( ( PwdModifyRequestImpl ) container.getPasswordModifyRequest().getDecorated() )
+ .setOldPassword( oldPassword );
+
+ // We may have nothing left
+ container.setGrammarEndAllowed( true );
+ }
+ } );
+
+ /**
+ * Transition from userIdentity to newPassword
+ *
+ * PasswdModifyRequestValue ::= SEQUENCE {
+ * userIdentity [0] OCTET STRING OPTIONAL
+ * ...
+ * newPassword [2] OCTET STRING OPTIONAL
+ *
+ *
+ * Set the newPassword into the PasswdModifyRequest instance.
+ */
+ super.transitions[PasswordModifyRequestStatesEnum.USER_IDENTITY_STATE.ordinal()][PasswordModifyRequestConstants.NEW_PASSWORD_TAG] =
+ new GrammarTransition<PasswordModifyRequestContainer>(
+ PasswordModifyRequestStatesEnum.USER_IDENTITY_STATE,
+ PasswordModifyRequestStatesEnum.NEW_PASSWORD_STATE,
+ PasswordModifyRequestConstants.NEW_PASSWORD_TAG,
+ new GrammarAction<PasswordModifyRequestContainer>( "Set PasswordModifyRequest newPassword" )
+ {
+ public void action( PasswordModifyRequestContainer container ) throws DecoderException
+ {
+ BerValue value = container.getCurrentTLV().getValue();
+
+ byte[] newPassword = value.getData();
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "newPassword = " + Strings.dumpBytes( newPassword ) );
+ }
+
+ if ( newPassword == null )
+ {
+ newPassword = Strings.EMPTY_BYTES;
+ }
+
+ ( ( PwdModifyRequestImpl ) container.getPasswordModifyRequest().getDecorated() )
+ .setNewPassword( newPassword );
+
+ // We may have nothing left
+ container.setGrammarEndAllowed( true );
+ }
+ } );
+
+ /**
* Transition from PasswordModify Request Value to oldPassword
*
* PasswdModifyRequestValue ::= SEQUENCE {
@@ -218,6 +301,47 @@ public class PasswordModifyRequestGramma
container.setGrammarEndAllowed( true );
}
} );
+
+ /**
+ * Transition from oldPassword to newPassword
+ *
+ * ...
+ * oldPassword [1] OCTET STRING OPTIONAL
+ * newPassword [2] OCTET STRING OPTIONAL
+ * }
+ *
+ * Set the newPassword into the PasswdModifyRequest instance.
+ */
+ super.transitions[PasswordModifyRequestStatesEnum.OLD_PASSWORD_STATE.ordinal()][PasswordModifyRequestConstants.NEW_PASSWORD_TAG] =
+ new GrammarTransition<PasswordModifyRequestContainer>(
+ PasswordModifyRequestStatesEnum.OLD_PASSWORD_STATE,
+ PasswordModifyRequestStatesEnum.NEW_PASSWORD_STATE,
+ PasswordModifyRequestConstants.NEW_PASSWORD_TAG,
+ new GrammarAction<PasswordModifyRequestContainer>( "Set PasswordModifyRequest newPassword" )
+ {
+ public void action( PasswordModifyRequestContainer container ) throws DecoderException
+ {
+ BerValue value = container.getCurrentTLV().getValue();
+
+ byte[] newPassword = value.getData();
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "NewPassword = " + Strings.dumpBytes( newPassword ) );
+ }
+
+ if ( newPassword == null )
+ {
+ newPassword = Strings.EMPTY_BYTES;
+ }
+
+ ( ( PwdModifyRequestImpl ) container.getPasswordModifyRequest().getDecorated() )
+ .setNewPassword( newPassword );
+
+ // We may have nothing left
+ container.setGrammarEndAllowed( true );
+ }
+ } );
}
Modified: directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/PasswordModifyRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/PasswordModifyRequestTest.java?rev=1468814&r1=1468813&r2=1468814&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/PasswordModifyRequestTest.java (original)
+++ directory/shared/trunk/ldap/extras/codec/src/test/java/org/apache/directory/api/ldap/extras/extended/ads_impl/PasswordModifyRequestTest.java Wed Apr 17 09:35:29 2013
@@ -30,8 +30,6 @@ import java.nio.ByteBuffer;
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.EncoderException;
import org.apache.directory.api.asn1.ber.Asn1Decoder;
-import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdown;
-import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownContainer;
import org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyRequestContainer;
import org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyRequestDecorator;
import org.apache.directory.api.util.Strings;
@@ -52,29 +50,75 @@ import com.mycila.junit.concurrent.Concu
public class PasswordModifyRequestTest
{
/**
- * Test the decoding of a PasswordModifyRequest
+ * Test the decoding of a PasswordModifyRequest with nothing in it
*/
@Test
- public void testDecodePasswordModifyRequestSuccess()
+ public void testDecodePasswordModifyRequestEmpty()
{
Asn1Decoder decoder = new Asn1Decoder();
- ByteBuffer bb = ByteBuffer.allocate( 0x08 );
+ ByteBuffer bb = ByteBuffer.allocate( 0x02 );
+ bb.put( new byte[]
+ { 0x30, 0x00, // PasswordModifyRequest ::= SEQUENCE {
+ } );
+
+ String decodedPdu = Strings.dumpBytes( bb.array() );
+ bb.flip();
+
+ PasswordModifyRequestContainer container = new PasswordModifyRequestContainer();
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ PasswordModifyRequestDecorator pwdModifyRequestDecorator = container.getPasswordModifyRequest();
+ assertNull( pwdModifyRequestDecorator.getUserIdentity() );
+ assertNull( pwdModifyRequestDecorator.getOldPassword() );
+ assertNull( pwdModifyRequestDecorator.getNewPassword() );
+
+ // Check the length
+ assertEquals( 0x02, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = pwdModifyRequestDecorator.getPasswordModifyRequest().encode();
+
+ String encodedPdu = Strings.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+
+
+ /**
+ * Test the decoding of a PasswordModifyRequest with an empty user identity
+ */
+ @Test
+ public void testDecodePasswordModifyRequestUserIdentityNull()
+ {
+ Asn1Decoder decoder = new Asn1Decoder();
+ ByteBuffer bb = ByteBuffer.allocate( 0x04 );
bb.put( new byte[]
- { 0x30, 0x06, // GracefulShutdown ::= SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // timeOffline INTEGER (0..720) DEFAULT 0,
+ { 0x30, 0x02, // PasswordModifyRequest ::= SEQUENCE {
( byte ) 0x80,
- 0x01,
- 0x01 // delay INTEGER (0..86400) DEFAULT
- // 0
- // }
+ 0x00 // userIdentity [0] OCTET STRING OPTIONAL
} );
String decodedPdu = Strings.dumpBytes( bb.array() );
bb.flip();
- GracefulShutdownContainer container = new GracefulShutdownContainer();
+ PasswordModifyRequestContainer container = new PasswordModifyRequestContainer();
try
{
@@ -86,17 +130,19 @@ public class PasswordModifyRequestTest
fail( de.getMessage() );
}
- GracefulShutdown gracefulShutdown = container.getGracefulShutdown();
- assertEquals( 1, gracefulShutdown.getTimeOffline() );
- assertEquals( 1, gracefulShutdown.getDelay() );
+ PasswordModifyRequestDecorator pwdModifyRequestDecorator = container.getPasswordModifyRequest();
+ assertNotNull( pwdModifyRequestDecorator.getUserIdentity() );
+ assertEquals( 0, pwdModifyRequestDecorator.getUserIdentity().length );
+ assertNull( pwdModifyRequestDecorator.getOldPassword() );
+ assertNull( pwdModifyRequestDecorator.getNewPassword() );
// Check the length
- assertEquals( 0x08, gracefulShutdown.computeLength() );
+ assertEquals( 0x04, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
// Check the encoding
try
{
- ByteBuffer bb1 = gracefulShutdown.encode();
+ ByteBuffer bb1 = pwdModifyRequestDecorator.getPasswordModifyRequest().encode();
String encodedPdu = Strings.dumpBytes( bb1.array() );
@@ -111,16 +157,22 @@ public class PasswordModifyRequestTest
/**
- * Test the decoding of a PasswordModifyRequest with nothing in it
+ * Test the decoding of a PasswordModifyRequest with a user identity
*/
@Test
- public void testDecodePasswordModifyRequestEmpty()
+ public void testDecodePasswordModifyRequestUserIdentityValue()
{
Asn1Decoder decoder = new Asn1Decoder();
- ByteBuffer bb = ByteBuffer.allocate( 0x02 );
+ ByteBuffer bb = ByteBuffer.allocate( 0x08 );
bb.put( new byte[]
- { 0x30, 0x00, // PasswordModifyRequest ::= SEQUENCE {
- } );
+ { 0x30, 0x06, // PasswordModifyRequest ::= SEQUENCE {
+ ( byte ) 0x80,
+ 0x04, // userIdentity [0] OCTET STRING OPTIONAL
+ 'a',
+ 'b',
+ 'c',
+ 'd'
+ } );
String decodedPdu = Strings.dumpBytes( bb.array() );
bb.flip();
@@ -138,12 +190,13 @@ public class PasswordModifyRequestTest
}
PasswordModifyRequestDecorator pwdModifyRequestDecorator = container.getPasswordModifyRequest();
- assertNull( pwdModifyRequestDecorator.getUserIdentity() );
+ assertNotNull( pwdModifyRequestDecorator.getUserIdentity() );
+ assertEquals( "abcd", Strings.utf8ToString( pwdModifyRequestDecorator.getUserIdentity() ) );
assertNull( pwdModifyRequestDecorator.getOldPassword() );
assertNull( pwdModifyRequestDecorator.getNewPassword() );
// Check the length
- assertEquals( 0x02, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
+ assertEquals( 0x08, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
// Check the encoding
try
@@ -163,17 +216,24 @@ public class PasswordModifyRequestTest
/**
- * Test the decoding of a PasswordModifyRequest with an empty user identity
+ * Test the decoding of a PasswordModifyRequest with a user identity and
+ * an empty newPassword
*/
@Test
- public void testDecodePasswordModifyRequestUserIdentityNull()
+ public void testDecodePasswordModifyRequestUserIdentityValueNewPasswordEmpty()
{
Asn1Decoder decoder = new Asn1Decoder();
- ByteBuffer bb = ByteBuffer.allocate( 0x04 );
+ ByteBuffer bb = ByteBuffer.allocate( 0x0A );
bb.put( new byte[]
- { 0x30, 0x02, // PasswordModifyRequest ::= SEQUENCE {
+ { 0x30, 0x08, // PasswordModifyRequest ::= SEQUENCE {
( byte ) 0x80,
- 0x00 // userIdentity [0] OCTET STRING OPTIONAL
+ 0x04, // userIdentity [0] OCTET STRING OPTIONAL
+ 'a',
+ 'b',
+ 'c',
+ 'd',
+ ( byte ) 0x82, // newPassword [2] OCTET STRING OPTIONAL
+ 0x00
} );
String decodedPdu = Strings.dumpBytes( bb.array() );
@@ -193,12 +253,142 @@ public class PasswordModifyRequestTest
PasswordModifyRequestDecorator pwdModifyRequestDecorator = container.getPasswordModifyRequest();
assertNotNull( pwdModifyRequestDecorator.getUserIdentity() );
- assertEquals( 0, pwdModifyRequestDecorator.getUserIdentity().length );
+ assertEquals( "abcd", Strings.utf8ToString( pwdModifyRequestDecorator.getUserIdentity() ) );
+ assertNull( pwdModifyRequestDecorator.getOldPassword() );
+ assertNotNull( pwdModifyRequestDecorator.getNewPassword() );
+ assertEquals( 0, pwdModifyRequestDecorator.getNewPassword().length );
+
+ // Check the length
+ assertEquals( 0x0A, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = pwdModifyRequestDecorator.getPasswordModifyRequest().encode();
+
+ String encodedPdu = Strings.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+
+
+ /**
+ * Test the decoding of a PasswordModifyRequest with a user identity and
+ * a newPassword
+ */
+ @Test
+ public void testDecodePasswordModifyRequestUserIdentityValueNewPassword()
+ {
+ Asn1Decoder decoder = new Asn1Decoder();
+ ByteBuffer bb = ByteBuffer.allocate( 0x0E );
+ bb.put( new byte[]
+ { 0x30, 0x0C, // PasswordModifyRequest ::= SEQUENCE {
+ ( byte ) 0x80,
+ 0x04, // userIdentity [0] OCTET STRING OPTIONAL
+ 'a',
+ 'b',
+ 'c',
+ 'd',
+ ( byte ) 0x82, // newPassword [2] OCTET STRING OPTIONAL
+ 0x04,
+ 'e',
+ 'f',
+ 'g',
+ 'h'
+ } );
+
+ String decodedPdu = Strings.dumpBytes( bb.array() );
+ bb.flip();
+
+ PasswordModifyRequestContainer container = new PasswordModifyRequestContainer();
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ PasswordModifyRequestDecorator pwdModifyRequestDecorator = container.getPasswordModifyRequest();
+ assertNotNull( pwdModifyRequestDecorator.getUserIdentity() );
+ assertEquals( "abcd", Strings.utf8ToString( pwdModifyRequestDecorator.getUserIdentity() ) );
assertNull( pwdModifyRequestDecorator.getOldPassword() );
+ assertNotNull( pwdModifyRequestDecorator.getNewPassword() );
+ assertEquals( "efgh", Strings.utf8ToString( pwdModifyRequestDecorator.getNewPassword() ) );
+
+ // Check the length
+ assertEquals( 0x0E, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = pwdModifyRequestDecorator.getPasswordModifyRequest().encode();
+
+ String encodedPdu = Strings.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+
+
+ /**
+ * Test the decoding of a PasswordModifyRequest with a user identity
+ */
+ @Test
+ public void testDecodePasswordModifyRequestUserIdentityValueOldPasswordEmpty()
+ {
+ Asn1Decoder decoder = new Asn1Decoder();
+ ByteBuffer bb = ByteBuffer.allocate( 0x0A );
+ bb.put( new byte[]
+ { 0x30, 0x08, // PasswordModifyRequest ::= SEQUENCE {
+ ( byte ) 0x80,
+ 0x04, // userIdentity [0] OCTET STRING OPTIONAL
+ 'a',
+ 'b',
+ 'c',
+ 'd',
+ ( byte ) 0x81,
+ 0x00 // oldPassword [1] OCTET STRING OPTIONAL
+ } );
+
+ String decodedPdu = Strings.dumpBytes( bb.array() );
+ bb.flip();
+
+ PasswordModifyRequestContainer container = new PasswordModifyRequestContainer();
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ PasswordModifyRequestDecorator pwdModifyRequestDecorator = container.getPasswordModifyRequest();
+ assertNotNull( pwdModifyRequestDecorator.getUserIdentity() );
+ assertEquals( "abcd", Strings.utf8ToString( pwdModifyRequestDecorator.getUserIdentity() ) );
+ assertNotNull( pwdModifyRequestDecorator.getOldPassword() );
+ assertEquals( 0, pwdModifyRequestDecorator.getOldPassword().length );
assertNull( pwdModifyRequestDecorator.getNewPassword() );
// Check the length
- assertEquals( 0x04, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
+ assertEquals( 0x0A, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
// Check the encoding
try
@@ -221,18 +411,24 @@ public class PasswordModifyRequestTest
* Test the decoding of a PasswordModifyRequest with a user identity
*/
@Test
- public void testDecodePasswordModifyRequestUserIdentityValue()
+ public void testDecodePasswordModifyRequestUserIdentityValueOldPasswordValue()
{
Asn1Decoder decoder = new Asn1Decoder();
- ByteBuffer bb = ByteBuffer.allocate( 0x08 );
+ ByteBuffer bb = ByteBuffer.allocate( 0x0E );
bb.put( new byte[]
- { 0x30, 0x06, // PasswordModifyRequest ::= SEQUENCE {
+ { 0x30, 0x0C, // PasswordModifyRequest ::= SEQUENCE {
( byte ) 0x80,
0x04, // userIdentity [0] OCTET STRING OPTIONAL
'a',
'b',
'c',
- 'd'
+ 'd',
+ ( byte ) 0x81,
+ 0x04, // oldPassword [1] OCTET STRING OPTIONAL
+ 'e',
+ 'f',
+ 'g',
+ 'h'
} );
String decodedPdu = Strings.dumpBytes( bb.array() );
@@ -253,11 +449,156 @@ public class PasswordModifyRequestTest
PasswordModifyRequestDecorator pwdModifyRequestDecorator = container.getPasswordModifyRequest();
assertNotNull( pwdModifyRequestDecorator.getUserIdentity() );
assertEquals( "abcd", Strings.utf8ToString( pwdModifyRequestDecorator.getUserIdentity() ) );
- assertNull( pwdModifyRequestDecorator.getOldPassword() );
+ assertNotNull( pwdModifyRequestDecorator.getOldPassword() );
+ assertEquals( "efgh", Strings.utf8ToString( pwdModifyRequestDecorator.getOldPassword() ) );
assertNull( pwdModifyRequestDecorator.getNewPassword() );
// Check the length
- assertEquals( 0x08, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
+ assertEquals( 0x0E, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = pwdModifyRequestDecorator.getPasswordModifyRequest().encode();
+
+ String encodedPdu = Strings.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+
+
+ /**
+ * Test the decoding of a PasswordModifyRequest with a user identity, and oldPassword and
+ * and empty newPassword
+ */
+ @Test
+ public void testDecodePasswordModifyRequestUserIdentityValueOldPasswordValueNewPasswordNull()
+ {
+ Asn1Decoder decoder = new Asn1Decoder();
+ ByteBuffer bb = ByteBuffer.allocate( 0x10 );
+ bb.put( new byte[]
+ { 0x30, 0x0E, // PasswordModifyRequest ::= SEQUENCE {
+ ( byte ) 0x80,
+ 0x04, // userIdentity [0] OCTET STRING OPTIONAL
+ 'a',
+ 'b',
+ 'c',
+ 'd',
+ ( byte ) 0x81,
+ 0x04, // oldPassword [1] OCTET STRING OPTIONAL
+ 'e',
+ 'f',
+ 'g',
+ 'h',
+ ( byte ) 0x82, // newPassword [2] OCTET STRING OPTIONAL
+ 0x00
+ } );
+
+ String decodedPdu = Strings.dumpBytes( bb.array() );
+ bb.flip();
+
+ PasswordModifyRequestContainer container = new PasswordModifyRequestContainer();
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ PasswordModifyRequestDecorator pwdModifyRequestDecorator = container.getPasswordModifyRequest();
+ assertNotNull( pwdModifyRequestDecorator.getUserIdentity() );
+ assertEquals( "abcd", Strings.utf8ToString( pwdModifyRequestDecorator.getUserIdentity() ) );
+ assertNotNull( pwdModifyRequestDecorator.getOldPassword() );
+ assertEquals( "efgh", Strings.utf8ToString( pwdModifyRequestDecorator.getOldPassword() ) );
+ assertNotNull( pwdModifyRequestDecorator.getNewPassword() );
+ assertEquals( 0, pwdModifyRequestDecorator.getNewPassword().length );
+
+ // Check the length
+ assertEquals( 0x10, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = pwdModifyRequestDecorator.getPasswordModifyRequest().encode();
+
+ String encodedPdu = Strings.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+
+
+ /**
+ * Test the decoding of a PasswordModifyRequest with a user identity, and oldPassword and
+ * and a newPassword
+ */
+ @Test
+ public void testDecodePasswordModifyRequestUserIdentityValueOldPasswordValueNewPasswordValue()
+ {
+ Asn1Decoder decoder = new Asn1Decoder();
+ ByteBuffer bb = ByteBuffer.allocate( 0x14 );
+ bb.put( new byte[]
+ { 0x30, 0x12, // PasswordModifyRequest ::= SEQUENCE {
+ ( byte ) 0x80,
+ 0x04, // userIdentity [0] OCTET STRING OPTIONAL
+ 'a',
+ 'b',
+ 'c',
+ 'd',
+ ( byte ) 0x81,
+ 0x04, // oldPassword [1] OCTET STRING OPTIONAL
+ 'e',
+ 'f',
+ 'g',
+ 'h',
+ ( byte ) 0x82, // newPassword [2] OCTET STRING OPTIONAL
+ 0x04,
+ 'i',
+ 'j',
+ 'k',
+ 'l'
+ } );
+
+ String decodedPdu = Strings.dumpBytes( bb.array() );
+ bb.flip();
+
+ PasswordModifyRequestContainer container = new PasswordModifyRequestContainer();
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ PasswordModifyRequestDecorator pwdModifyRequestDecorator = container.getPasswordModifyRequest();
+ assertNotNull( pwdModifyRequestDecorator.getUserIdentity() );
+ assertEquals( "abcd", Strings.utf8ToString( pwdModifyRequestDecorator.getUserIdentity() ) );
+ assertNotNull( pwdModifyRequestDecorator.getOldPassword() );
+ assertEquals( "efgh", Strings.utf8ToString( pwdModifyRequestDecorator.getOldPassword() ) );
+ assertNotNull( pwdModifyRequestDecorator.getNewPassword() );
+ assertEquals( "ijkl", Strings.utf8ToString( pwdModifyRequestDecorator.getNewPassword() ) );
+
+ // Check the length
+ assertEquals( 0x14, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
// Check the encoding
try
@@ -342,7 +683,7 @@ public class PasswordModifyRequestTest
bb.put( new byte[]
{ 0x30, 0x06, // PasswordModifyRequest ::= SEQUENCE {
( byte ) 0x81,
- 0x04, // oldPassword [0] OCTET STRING OPTIONAL
+ 0x04, // oldPassword [1] OCTET STRING OPTIONAL
'a',
'b',
'c',
@@ -388,4 +729,134 @@ public class PasswordModifyRequestTest
fail( ee.getMessage() );
}
}
+
+
+ /**
+ * Test the decoding of a PasswordModifyRequest with an oldPassword and an
+ * empty newPassword
+ */
+ @Test
+ public void testDecodePasswordModifyRequestOldPasswordValueNewPasswordEmpty()
+ {
+ Asn1Decoder decoder = new Asn1Decoder();
+ ByteBuffer bb = ByteBuffer.allocate( 0x0A );
+ bb.put( new byte[]
+ { 0x30, 0x08, // PasswordModifyRequest ::= SEQUENCE {
+ ( byte ) 0x81,
+ 0x04, // oldPassword [1] OCTET STRING OPTIONAL
+ 'a',
+ 'b',
+ 'c',
+ 'd',
+ ( byte ) 0x82, // newPassword [2] OCTET STRING OPTIONAL
+ 0x00
+ } );
+
+ String decodedPdu = Strings.dumpBytes( bb.array() );
+ bb.flip();
+
+ PasswordModifyRequestContainer container = new PasswordModifyRequestContainer();
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ PasswordModifyRequestDecorator pwdModifyRequestDecorator = container.getPasswordModifyRequest();
+ assertNull( pwdModifyRequestDecorator.getUserIdentity() );
+ assertNotNull( pwdModifyRequestDecorator.getOldPassword() );
+ assertEquals( "abcd", Strings.utf8ToString( pwdModifyRequestDecorator.getOldPassword() ) );
+ assertNotNull( pwdModifyRequestDecorator.getNewPassword() );
+ assertEquals( 0, pwdModifyRequestDecorator.getNewPassword().length );
+
+ // Check the length
+ assertEquals( 0x0A, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = pwdModifyRequestDecorator.getPasswordModifyRequest().encode();
+
+ String encodedPdu = Strings.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+
+
+ /**
+ * Test the decoding of a PasswordModifyRequest with an oldPassword and an
+ * newPassword
+ */
+ @Test
+ public void testDecodePasswordModifyRequestOldPasswordValueNewPasswordValue()
+ {
+ Asn1Decoder decoder = new Asn1Decoder();
+ ByteBuffer bb = ByteBuffer.allocate( 0x0E );
+ bb.put( new byte[]
+ { 0x30, 0x0C, // PasswordModifyRequest ::= SEQUENCE {
+ ( byte ) 0x81,
+ 0x04, // oldPassword [1] OCTET STRING OPTIONAL
+ 'a',
+ 'b',
+ 'c',
+ 'd',
+ ( byte ) 0x82, // newPassword [2] OCTET STRING OPTIONAL
+ 0x04,
+ 'e',
+ 'f',
+ 'g',
+ 'h'
+ } );
+
+ String decodedPdu = Strings.dumpBytes( bb.array() );
+ bb.flip();
+
+ PasswordModifyRequestContainer container = new PasswordModifyRequestContainer();
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ PasswordModifyRequestDecorator pwdModifyRequestDecorator = container.getPasswordModifyRequest();
+ assertNull( pwdModifyRequestDecorator.getUserIdentity() );
+ assertNotNull( pwdModifyRequestDecorator.getOldPassword() );
+ assertEquals( "abcd", Strings.utf8ToString( pwdModifyRequestDecorator.getOldPassword() ) );
+ assertNotNull( pwdModifyRequestDecorator.getNewPassword() );
+ assertEquals( "efgh", Strings.utf8ToString( pwdModifyRequestDecorator.getNewPassword() ) );
+
+ // Check the length
+ assertEquals( 0x0E, pwdModifyRequestDecorator.getPasswordModifyRequest().computeLength() );
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb1 = pwdModifyRequestDecorator.getPasswordModifyRequest().encode();
+
+ String encodedPdu = Strings.dumpBytes( bb1.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
}