use of org.pac4j.http.credentials.authenticator.test.SimpleTestDigestAuthenticator in project pac4j by pac4j.
the class DirectDigestAuthClientTests method testAuthentication.
@Test
public void testAuthentication() {
final DirectDigestAuthClient client = new DirectDigestAuthClient(new SimpleTestDigestAuthenticator());
client.setRealm(REALM);
final MockWebContext context = MockWebContext.create();
context.addRequestHeader(AUTHORIZATION_HEADER, DIGEST_AUTHORIZATION_HEADER_VALUE);
context.setRequestMethod(HTTP_METHOD.GET.name());
final DigestCredentials credentials = client.getCredentials(context);
final CommonProfile profile = client.getUserProfile(credentials, context);
String ha1 = CredentialUtil.encryptMD5(USERNAME + ":" + REALM + ":" + PASSWORD);
String serverDigest1 = credentials.calculateServerDigest(true, ha1);
String serverDigest2 = credentials.calculateServerDigest(false, PASSWORD);
assertEquals(DIGEST_RESPONSE, serverDigest1);
assertEquals(DIGEST_RESPONSE, serverDigest2);
assertEquals(USERNAME, profile.getId());
}
Aggregations