use of com.nimbusds.oauth2.sdk.id.Subject in project di-authentication-api by alphagov.
the class RemoveAccountIntegrationTest method shouldRemoveAccountAndReturn204WhenUserExists.
@Test
public void shouldRemoveAccountAndReturn204WhenUserExists() {
String email = "joe.bloggs+3@digital.cabinet-office.gov.uk";
String password = "password-1";
Subject subject = new Subject();
String subjectId = userStore.signUp(email, password, subject);
var response = makeRequest(Optional.of(new RemoveAccountRequest(email)), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Map.of("principalId", subjectId));
assertThat(response, hasStatus(HttpStatus.SC_NO_CONTENT));
assertFalse(userStore.userExists(email));
assertEventTypesReceived(auditTopic, List.of(DELETE_ACCOUNT));
}
use of com.nimbusds.oauth2.sdk.id.Subject in project di-authentication-api by alphagov.
the class UpdateEmailIntegrationTest method shouldThrowExceptionWhenUserAttemptsToUpdateDifferentAccount.
@Test
void shouldThrowExceptionWhenUserAttemptsToUpdateDifferentAccount() {
String correctSubjectID = userStore.signUp(EXISTING_EMAIL_ADDRESS, "password-1", SUBJECT);
String otherSubjectID = userStore.signUp("other.user@digital.cabinet-office.gov.uk", "password-2", new Subject());
String otp = redis.generateAndSaveEmailCode(NEW_EMAIL_ADDRESS, 300);
Exception ex = assertThrows(RuntimeException.class, () -> makeRequest(Optional.of(new UpdateEmailRequest(EXISTING_EMAIL_ADDRESS, NEW_EMAIL_ADDRESS, otp)), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Map.of("principalId", otherSubjectID)));
assertThat(ex.getMessage(), is("Subject ID does not match principalId"));
}
use of com.nimbusds.oauth2.sdk.id.Subject in project di-authentication-api by alphagov.
the class UpdatePasswordIntegrationTest method shouldThrowExceptionWhenUserAttemptsToUpdateDifferentAccount.
@Test
void shouldThrowExceptionWhenUserAttemptsToUpdateDifferentAccount() {
String correctSubjectID = userStore.signUp(TEST_EMAIL, "password-1", SUBJECT);
String otherSubjectID = userStore.signUp("other.user@digital.cabinet-office.gov.uk", "password-2", new Subject());
Exception ex = assertThrows(RuntimeException.class, () -> makeRequest(Optional.of(new UpdatePasswordRequest(TEST_EMAIL, "password-2")), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Map.of("principalId", otherSubjectID)));
assertThat(ex.getMessage(), is("Subject ID does not match principalId"));
}
use of com.nimbusds.oauth2.sdk.id.Subject in project di-authentication-api by alphagov.
the class LogoutIntegrationTest method setupClientAndSession.
private SignedJWT setupClientAndSession(String sessionId, String clientSessionId) throws ParseException, Json.JsonException {
Nonce nonce = new Nonce();
Date expiryDate = NowHelper.nowPlus(10, ChronoUnit.MINUTES);
IDTokenClaimsSet idTokenClaims = new IDTokenClaimsSet(new Issuer(BASE_URL), new Subject(), List.of(new Audience("client-id")), expiryDate, new Date());
idTokenClaims.setNonce(nonce);
SignedJWT signedJWT = tokenSigner.signJwt(idTokenClaims.toJWTClaimsSet());
redis.createSession(sessionId);
redis.addAuthRequestToSession(clientSessionId, sessionId, generateAuthRequest(nonce).toParameters());
redis.addIDTokenToSession(clientSessionId, signedJWT.serialize());
clientStore.registerClient("client-id", "client-name", singletonList("http://localhost:8080/redirect"), singletonList("client-1"), singletonList("openid"), "public-key", singletonList(REDIRECT_URL), "http://example.com", String.valueOf(ServiceType.MANDATORY), "https://test.com", "public", true);
return signedJWT;
}
use of com.nimbusds.oauth2.sdk.id.Subject in project di-authentication-api by alphagov.
the class ResetPasswordIntegrationTest method shouldUpdatePasswordAndReturn204ForRequestWithCode.
@Test
public void shouldUpdatePasswordAndReturn204ForRequestWithCode() throws Json.JsonException {
String subject = "new-subject";
String sessionId = redis.createSession();
userStore.signUp(EMAIL_ADDRESS, "password-1", new Subject(subject));
redis.generateAndSavePasswordResetCode(subject, CODE, 900l);
var response = makeRequest(Optional.of(new ResetPasswordCompletionRequest(CODE, PASSWORD)), constructFrontendHeaders(sessionId), Map.of());
assertThat(response, hasStatus(204));
List<NotifyRequest> requests = notificationsQueue.getMessages(NotifyRequest.class);
assertThat(requests, hasSize(1));
assertThat(requests.get(0).getDestination(), equalTo(EMAIL_ADDRESS));
assertThat(requests.get(0).getNotificationType(), equalTo(PASSWORD_RESET_CONFIRMATION));
assertEventTypesReceived(auditTopic, List.of(PASSWORD_RESET_SUCCESSFUL));
}
Aggregations