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");
}
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());
}
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());
}
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);
}
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=");
}
Aggregations