Search in sources :

Example 86 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.

the class RDNNameValuePairTestCase method testNameValuePairWithSchema.

/**
 * Tests the basic behavior of the {@code RDNNameValuePair} class when a
 * non-{@code null} {@code Schema} object is provided.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testNameValuePairWithSchema() throws Exception {
    final RDNNameValuePair p = new RDNNameValuePair("givenName", new ASN1OctetString("foo"), Schema.getDefaultStandardSchema());
    assertNotNull(p.getAttributeName());
    assertEquals(p.getAttributeName(), "givenName");
    assertNotNull(p.getNormalizedAttributeName());
    assertEquals(p.getNormalizedAttributeName(), "givenname");
    // The second time should use a cached version.
    assertNotNull(p.getNormalizedAttributeName());
    assertEquals(p.getNormalizedAttributeName(), "givenname");
    assertNotNull(p.getAttributeValue());
    assertEquals(p.getAttributeValue(), "foo");
    assertNotNull(p.getAttributeValueBytes());
    assertEquals(p.getAttributeValueBytes(), "foo".getBytes(StandardCharsets.UTF_8));
    assertNotNull(p.getRawAttributeValue());
    assertEquals(p.getRawAttributeValue(), new ASN1OctetString("foo"));
    final StringBuilder buffer = new StringBuilder();
    buffer.append("xxx");
    p.toString(buffer, false);
    assertEquals(buffer.toString(), "xxx" + p.toString());
    buffer.setLength(0);
    p.toString(buffer, false);
    assertEquals(buffer.toString(), p.toString());
    buffer.setLength(0);
    p.toString(buffer, true);
    assertEquals(buffer.toString(), p.toMinimallyEncodedString());
    assertNotNull(p.toString());
    assertEquals(p.toString(), "givenName=foo");
    assertNotNull(p.toMinimallyEncodedString());
    assertEquals(p.toMinimallyEncodedString(), "givenName=foo");
    assertNotNull(p.toNormalizedString());
    assertEquals(p.toNormalizedString(), "givenname=foo");
    // The second time should use a cached version.
    assertNotNull(p.toNormalizedString());
    assertEquals(p.toNormalizedString(), "givenname=foo");
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 87 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.

the class OAUTHBEARERBindRequestTestCase method testOnlyAccessToken.

/**
 * Tests the behavior for a bind request that only contains an access token.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testOnlyAccessToken() throws Exception {
    OAUTHBEARERBindRequest bindRequest = new OAUTHBEARERBindRequest("the-access-token");
    bindRequest = bindRequest.duplicate();
    assertNotNull(bindRequest.getSASLMechanismName());
    assertEquals(bindRequest.getSASLMechanismName(), "OAUTHBEARER");
    assertNotNull(bindRequest.getAccessToken());
    assertEquals(bindRequest.getAccessToken(), "the-access-token");
    assertNull(bindRequest.getAuthorizationID());
    assertNull(bindRequest.getServerAddress());
    assertNull(bindRequest.getServerPort());
    assertNull(bindRequest.getRequestMethod());
    assertNull(bindRequest.getRequestPath());
    assertNull(bindRequest.getRequestPostData());
    assertNull(bindRequest.getRequestQueryString());
    assertNotNull(bindRequest.getAdditionalKeyValuePairs());
    assertTrue(bindRequest.getAdditionalKeyValuePairs().isEmpty());
    assertNotNull(bindRequest.encodeCredentials());
    assertEquals(bindRequest.encodeCredentials(), new ASN1OctetString("n,,\u0001auth=Bearer the-access-token\u0001"));
    assertNotNull(bindRequest.toString());
    final List<String> toCodeLines = new ArrayList<>();
    bindRequest.toCode(toCodeLines, "testRequestID", 4, true);
    assertFalse(toCodeLines.isEmpty());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ArrayList(java.util.ArrayList) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 88 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.

the class OAUTHBEARERBindResultTestCase method testFailureResultWithCredentials.

/**
 * Tests the behavior for a failure result that includes server SASL
 * credentials that has all elements.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testFailureResultWithCredentials() throws Exception {
    final String[] initialReferralURLs = { "ldap://ds1.example.com:389/o=initial" };
    final Control[] initialControls = { new Control("1.2.3.4") };
    final JSONObject initialFailureDetails = new JSONObject(new JSONField("status", "invalid_token"), new JSONField("scope", "scope1 scope2 scope3"), new JSONField("openid-configuration", "https://openid.example.com/config"), new JSONField("some-other-field", "foo"));
    final ASN1OctetString initialServerSASLCredentials = new ASN1OctetString(initialFailureDetails.toSingleLineString());
    final String[] finalReferralURLs = { "ldap://ds1.example.com:389/o=final" };
    final Control[] finalControls = { new Control("1.2.3.5") };
    final BindResult initialBindResult = new BindResult(3, ResultCode.SASL_BIND_IN_PROGRESS, "initial diagnostic message", "o=initial matched DN", initialReferralURLs, initialControls, initialServerSASLCredentials);
    final BindResult finalBindResult = new BindResult(4, ResultCode.INVALID_CREDENTIALS, "final diagnostic message", "o=final matched DN", finalReferralURLs, finalControls, null);
    final OAUTHBEARERBindResult bindResult = new OAUTHBEARERBindResult(initialBindResult, finalBindResult);
    assertEquals(bindResult.getMessageID(), 4);
    assertNotNull(bindResult.getResultCode());
    assertEquals(bindResult.getResultCode(), ResultCode.INVALID_CREDENTIALS);
    assertNotNull(bindResult.getDiagnosticMessage());
    assertEquals(bindResult.getDiagnosticMessage(), "final diagnostic message");
    assertNotNull(bindResult.getMatchedDN());
    assertDNsEqual(bindResult.getMatchedDN(), "o=final matched DN");
    assertNotNull(bindResult.getReferralURLs());
    assertEquals(bindResult.getReferralURLs().length, 1);
    assertEquals(bindResult.getReferralURLs()[0], finalReferralURLs[0]);
    assertNotNull(bindResult.getResponseControls());
    assertEquals(bindResult.getResponseControls().length, 1);
    assertEquals(bindResult.getResponseControls()[0], finalControls[0]);
    assertNotNull(bindResult.getServerSASLCredentials());
    assertTrue(bindResult.getServerSASLCredentials().equalsIgnoreType(initialServerSASLCredentials));
    assertNotNull(bindResult.getInitialBindResult());
    assertEquals(bindResult.getInitialBindResult(), initialBindResult);
    assertNotNull(bindResult.getFinalBindResult());
    assertEquals(bindResult.getFinalBindResult(), finalBindResult);
    assertNotNull(bindResult.getFailureDetailsObject());
    assertEquals(bindResult.getFailureDetailsObject(), initialFailureDetails);
    assertNotNull(bindResult.getAuthorizationErrorCode());
    assertEquals(bindResult.getAuthorizationErrorCode(), "invalid_token");
    assertNotNull(bindResult.getScopes());
    assertFalse(bindResult.getScopes().isEmpty());
    assertEquals(bindResult.getScopes(), StaticUtils.setOf("scope1", "scope2", "scope3"));
    assertNotNull(bindResult.getOpenIDConfigurationURL());
    assertEquals(bindResult.getOpenIDConfigurationURL(), "https://openid.example.com/config");
    assertNotNull(bindResult.toString());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) JSONObject(com.unboundid.util.json.JSONObject) JSONField(com.unboundid.util.json.JSONField) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 89 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.

the class SASLBindInProgressExceptionTestCase method testWithServerSASLCredentials.

/**
 * Provides test coverage for the case in which the bind response includes
 * server SASL credentials.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testWithServerSASLCredentials() throws Exception {
    final BindResult bindResult = new BindResult(1, ResultCode.SASL_BIND_IN_PROGRESS, null, null, null, null, new ASN1OctetString("server creds"));
    final SASLBindInProgressException e = new SASLBindInProgressException(bindResult);
    assertNotNull(e.getBindResult());
    assertNotNull(e.getServerSASLCredentials());
    assertEquals(e.getServerSASLCredentials().stringValue(), "server creds");
    assertNotNull(e.getMessage());
    assertEquals(e.getResultCode(), ResultCode.SASL_BIND_IN_PROGRESS);
    assertNull(e.getDiagnosticMessage());
    assertNull(e.getMatchedDN());
    assertNotNull(e.getReferralURLs());
    assertEquals(e.getReferralURLs().length, 0);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 90 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.

the class SCRAMClientFinalMessageTestCase method testSCRAMSHA1.

/**
 * Tests the behavior when creating a client final message for a
 * SCRAM-SHA-1 bind request.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSCRAMSHA1() throws Exception {
    final SCRAMSHA1BindRequest bindRequest = new SCRAMSHA1BindRequest("user", "pencil");
    final SCRAMClientFirstMessage clientFirstMessage = new SCRAMClientFirstMessage(bindRequest, "fyko+d2lbbFgONRv9qkxdawL");
    final String serverFirstMessageString = "r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,s=QSXCR+Q6sek8bf92," + "i=4096";
    final BindResult serverFirstBindResult = new BindResult(1, ResultCode.SUCCESS, null, null, null, null, new ASN1OctetString(serverFirstMessageString));
    final SCRAMServerFirstMessage serverFirstMessage = new SCRAMServerFirstMessage(bindRequest, clientFirstMessage, serverFirstBindResult);
    final SCRAMClientFinalMessage clientFinalMessage = new SCRAMClientFinalMessage(bindRequest, clientFirstMessage, serverFirstMessage);
    assertNotNull(clientFinalMessage.getBindRequest());
    assertNotNull(clientFinalMessage.getClientFirstMessage());
    assertNotNull(clientFinalMessage.getServerFirstMessage());
    assertNotNull(clientFinalMessage.getSaltedPassword());
    assertNotNull(clientFinalMessage.getAuthMessageBytes());
    assertNotNull(clientFinalMessage.getClientProofBase64());
    assertEquals(clientFinalMessage.getClientProofBase64(), "v0X8v3Bz2T0CJGbJQyF0X+HI4Ts=");
    assertNotNull(clientFinalMessage.getClientFinalMessage());
    assertEquals(clientFinalMessage.getClientFinalMessage(), "c=biws,r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j," + "p=v0X8v3Bz2T0CJGbJQyF0X+HI4Ts=");
    assertNotNull(clientFinalMessage.toString());
    assertEquals(clientFinalMessage.toString(), "c=biws,r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j," + "p=v0X8v3Bz2T0CJGbJQyF0X+HI4Ts=");
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Aggregations

ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1173 Test (org.testng.annotations.Test)852 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)382 Control (com.unboundid.ldap.sdk.Control)310 ASN1Element (com.unboundid.asn1.ASN1Element)237 ArrayList (java.util.ArrayList)204 NotNull (com.unboundid.util.NotNull)191 LDAPException (com.unboundid.ldap.sdk.LDAPException)142 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)133 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)99 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)92 IOException (java.io.IOException)88 ASN1Integer (com.unboundid.asn1.ASN1Integer)80 ExtendedRequest (com.unboundid.ldap.sdk.ExtendedRequest)69 DN (com.unboundid.ldap.sdk.DN)65 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)64 ByteArrayInputStream (java.io.ByteArrayInputStream)56 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)53 ASN1Boolean (com.unboundid.asn1.ASN1Boolean)52 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)49