Search in sources :

Example 1 with AuthParams

use of uk.gov.di.ipv.cri.passport.library.domain.AuthParams in project di-ipv-cri-uk-passport-back by alphagov.

the class JwtAuthorizationRequestHandlerTest method shouldReturnClaimsAsJsonFromJWT.

@Test
void shouldReturnClaimsAsJsonFromJWT() throws Exception {
    when(jarValidator.validateRequestJwt(any(), anyString())).thenReturn(signedJWT.getJWTClaimsSet());
    var event = new APIGatewayProxyRequestEvent();
    Map<String, String> map = new HashMap<>();
    map.put("client_id", "TEST");
    event.setHeaders(map);
    event.setBody(signedJWT.serialize());
    var response = underTest.handleRequest(event, context);
    Map<String, Object> claims = OBJECT_MAPPER.readValue(response.getBody(), new TypeReference<>() {
    });
    AuthParams authParams = OBJECT_MAPPER.convertValue(claims.get("authParams"), new TypeReference<>() {
    });
    assertEquals("test-user-id", claims.get("user_id"));
    assertEquals("code", authParams.getResponseType());
    assertEquals("test-client", authParams.getClientId());
    assertEquals("test-state", authParams.getState());
    assertEquals("http://example.com", authParams.getRedirectUri());
    Map<String, Object> sharedClaims = OBJECT_MAPPER.convertValue(claims.get("shared_claims"), new TypeReference<>() {
    });
    assertEquals(Arrays.asList("01/01/1980", "02/01/1980"), sharedClaims.get("dateOfBirths"));
    assertEquals(Collections.singletonList("123 random street, M13 7GE"), sharedClaims.get("addresses"));
    assertEquals(Arrays.asList("Daniel", "Dan", "Danny"), sharedClaims.get("givenNames"));
}
Also used : AuthParams(uk.gov.di.ipv.cri.passport.library.domain.AuthParams) APIGatewayProxyRequestEvent(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent) HashMap(java.util.HashMap) ErrorObject(com.nimbusds.oauth2.sdk.ErrorObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

APIGatewayProxyRequestEvent (com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent)1 ErrorObject (com.nimbusds.oauth2.sdk.ErrorObject)1 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 AuthParams (uk.gov.di.ipv.cri.passport.library.domain.AuthParams)1