Search in sources :

Example 1 with SignupRequest

use of uk.gov.di.authentication.frontendapi.entity.SignupRequest in project di-authentication-api by alphagov.

the class SignupIntegrationTest method shouldReturn200WhenValidSignUpRequest.

@ParameterizedTest
@MethodSource("consentValues")
void shouldReturn200WhenValidSignUpRequest(boolean consentRequired) throws IOException, Json.JsonException {
    String sessionId = redis.createSession();
    Map<String, String> headers = new HashMap<>();
    headers.put("Session-Id", sessionId);
    headers.put("Client-Session-Id", CLIENT_SESSION_ID);
    headers.put("X-API-Key", FRONTEND_API_KEY);
    Scope scope = new Scope();
    scope.add(OIDCScopeValue.OPENID);
    AuthenticationRequest authRequest = new AuthenticationRequest.Builder(ResponseType.CODE, scope, new ClientID(CLIENT_ID), URI.create(REDIRECT_URI)).nonce(new Nonce()).build();
    redis.createClientSession(CLIENT_SESSION_ID, authRequest.toParameters());
    clientStore.registerClient(CLIENT_ID, "The test client", singletonList(REDIRECT_URI), singletonList("test-client@test.com"), singletonList(scope.toString()), Base64.getMimeEncoder().encodeToString(GENERATE_RSA_KEY_PAIR().getPublic().getEncoded()), singletonList("http://localhost/post-redirect-logout"), "http://example.com", String.valueOf(ServiceType.MANDATORY), "https://test.com", "public", consentRequired);
    var response = makeRequest(Optional.of(new SignupRequest("joe.bloggs+5@digital.cabinet-office.gov.uk", "password-1")), headers, Map.of());
    assertThat(response, hasStatus(200));
    SignUpResponse signUpResponse = objectMapper.readValue(response.getBody(), SignUpResponse.class);
    assertThat(signUpResponse.isConsentRequired(), equalTo(consentRequired));
    assertTrue(userStore.userExists("joe.bloggs+5@digital.cabinet-office.gov.uk"));
    assertEventTypesReceived(auditTopic, List.of(CREATE_ACCOUNT));
}
Also used : Nonce(com.nimbusds.openid.connect.sdk.Nonce) SignUpResponse(uk.gov.di.authentication.frontendapi.entity.SignUpResponse) Scope(com.nimbusds.oauth2.sdk.Scope) HashMap(java.util.HashMap) ClientID(com.nimbusds.oauth2.sdk.id.ClientID) SignupRequest(uk.gov.di.authentication.frontendapi.entity.SignupRequest) AuthenticationRequest(com.nimbusds.openid.connect.sdk.AuthenticationRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

Scope (com.nimbusds.oauth2.sdk.Scope)1 ClientID (com.nimbusds.oauth2.sdk.id.ClientID)1 AuthenticationRequest (com.nimbusds.openid.connect.sdk.AuthenticationRequest)1 Nonce (com.nimbusds.openid.connect.sdk.Nonce)1 HashMap (java.util.HashMap)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 SignUpResponse (uk.gov.di.authentication.frontendapi.entity.SignUpResponse)1 SignupRequest (uk.gov.di.authentication.frontendapi.entity.SignupRequest)1