Search in sources :

Example 26 with ASN1Sequence

use of com.github.zhenwei.core.asn1.ASN1Sequence in project ldapsdk by pingidentity.

the class ModificationTestCase method testConstructor2.

/**
 * Tests the second constructor, which takes a modification type, an attribute
 * name, and a single string value.
 *
 * @param  modificationType  The modification type to use for the test
 *                           modification.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(dataProvider = "testModificationTypes")
public void testConstructor2(ModificationType modificationType) throws Exception {
    Modification mod = new Modification(modificationType, "cn", "John Doe");
    assertEquals(mod.getModificationType(), modificationType);
    assertEquals(mod.getAttribute(), new Attribute("cn", "John Doe"));
    assertEquals(mod.getAttributeName(), "cn");
    assertTrue(mod.hasValue());
    assertEquals(mod.getValues().length, 1);
    assertEquals(mod.getValueByteArrays().length, 1);
    ASN1Sequence modSequence = mod.encode();
    Modification decodedMod = Modification.decode(modSequence);
    assertEquals(decodedMod, mod);
    assertEquals(decodedMod.hashCode(), mod.hashCode());
    assertNotNull(mod.toString());
    final ArrayList<String> toCodeLines = new ArrayList<String>(10);
    mod.toCode(toCodeLines, 0, null, null);
    assertFalse(toCodeLines.isEmpty());
    toCodeLines.clear();
    mod.toCode(toCodeLines, 4, "FirstLinePrefix-", "-LastLineSuffix");
    assertFalse(toCodeLines.isEmpty());
}
Also used : ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ArrayList(java.util.ArrayList) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 27 with ASN1Sequence

use of com.github.zhenwei.core.asn1.ASN1Sequence in project ldapsdk by pingidentity.

the class ModificationTestCase method testConstructor1.

/**
 * Tests the first constructor, which takes a modification type and an
 * attribute name.
 *
 * @param  modificationType  The modification type to use for the test
 *                           modification.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(dataProvider = "testModificationTypes")
public void testConstructor1(ModificationType modificationType) throws Exception {
    Modification mod = new Modification(modificationType, "cn");
    assertEquals(mod.getModificationType(), modificationType);
    assertEquals(mod.getAttribute(), new Attribute("cn"));
    assertEquals(mod.getAttributeName(), "cn");
    assertFalse(mod.hasValue());
    assertEquals(mod.getValues().length, 0);
    assertEquals(mod.getValueByteArrays().length, 0);
    ASN1Sequence modSequence = mod.encode();
    Modification decodedMod = Modification.decode(modSequence);
    assertEquals(decodedMod, mod);
    assertEquals(decodedMod.hashCode(), mod.hashCode());
    assertNotNull(mod.toString());
    final ArrayList<String> toCodeLines = new ArrayList<String>(10);
    mod.toCode(toCodeLines, 0, null, null);
    assertFalse(toCodeLines.isEmpty());
    toCodeLines.clear();
    mod.toCode(toCodeLines, 4, "FirstLinePrefix-", "-LastLineSuffix");
    assertFalse(toCodeLines.isEmpty());
}
Also used : ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ArrayList(java.util.ArrayList) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 28 with ASN1Sequence

use of com.github.zhenwei.core.asn1.ASN1Sequence in project ldapsdk by pingidentity.

the class GenerateTOTPSharedSecretExtendedRequestTestCase method testDecodeRequestValueEmptySequence.

/**
 * Tests the behavior of the extended request when trying to decode a generic
 * request that has a value that is an empty ASN.1 sequence.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeRequestValueEmptySequence() throws Exception {
    final ExtendedRequest r = new ExtendedRequest("1.3.6.1.4.1.30221.2.6.56", new ASN1OctetString(new ASN1Sequence().encode()));
    new GenerateTOTPSharedSecretExtendedRequest(r);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ExtendedRequest(com.unboundid.ldap.sdk.ExtendedRequest) Test(org.testng.annotations.Test)

Example 29 with ASN1Sequence

use of com.github.zhenwei.core.asn1.ASN1Sequence in project ldapsdk by pingidentity.

the class GenerateTOTPSharedSecretExtendedRequestTestCase method testDecodeRequestValueSequenceUnrecognizedElementType.

/**
 * Tests the behavior of the extended request when trying to decode a generic
 * request that has a value that is an ASN.1 sequence with an unrecognized
 * element type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeRequestValueSequenceUnrecognizedElementType() throws Exception {
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1OctetString((byte) 0x80, "u:test.user"), new ASN1OctetString((byte) 0x12, "invalid-type"));
    final ExtendedRequest r = new ExtendedRequest("1.3.6.1.4.1.30221.2.6.56", new ASN1OctetString(valueSequence.encode()));
    new GenerateTOTPSharedSecretExtendedRequest(r);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ExtendedRequest(com.unboundid.ldap.sdk.ExtendedRequest) Test(org.testng.annotations.Test)

Example 30 with ASN1Sequence

use of com.github.zhenwei.core.asn1.ASN1Sequence in project ldapsdk by pingidentity.

the class GetChangelogBatchExtendedRequestTestCase method testDecodeValueSequenceInvalidChangeType.

/**
 * Provides test coverage for an attempt to decode an extended request with a
 * value sequence with an invalid change type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceInvalidChangeType() throws Exception {
    final ASN1Set changeTypeSet = new ASN1Set((byte) 0xA4, new ASN1Enumerated(0), new ASN1Enumerated(5));
    final ASN1Sequence valueSequence = new ASN1Sequence(new EndOfChangelogStartingPoint().encode(), new ASN1Integer(0), changeTypeSet);
    new GetChangelogBatchExtendedRequest(new ExtendedRequest(GetChangelogBatchExtendedRequest.GET_CHANGELOG_BATCH_REQUEST_OID, new ASN1OctetString(valueSequence.encode())));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Set(com.unboundid.asn1.ASN1Set) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ExtendedRequest(com.unboundid.ldap.sdk.ExtendedRequest) ASN1Integer(com.unboundid.asn1.ASN1Integer) Test(org.testng.annotations.Test)

Aggregations

ASN1Sequence (com.unboundid.asn1.ASN1Sequence)455 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)397 Test (org.testng.annotations.Test)311 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)297 ASN1Element (com.unboundid.asn1.ASN1Element)231 ArrayList (java.util.ArrayList)184 IOException (java.io.IOException)141 NotNull (com.unboundid.util.NotNull)116 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)95 ASN1Integer (com.unboundid.asn1.ASN1Integer)94 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)85 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)76 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)73 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)69 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)64 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)57 Enumeration (java.util.Enumeration)54 ASN1Boolean (com.unboundid.asn1.ASN1Boolean)53 X509Certificate (java.security.cert.X509Certificate)53 BigInteger (java.math.BigInteger)50