Skip to content

Commit

Permalink
test(jans-auth-server): corrected assertions in tests Issue#804 (#895)
Browse files Browse the repository at this point in the history
* fix jans-auth-client build tests

* fix 2 jans-auth-client build tests

* fix 3 jans-auth-client build tests

* fix 4 jans-auth-client build tests
  • Loading branch information
jmunozherbas authored Feb 24, 2022
1 parent 500a773 commit 370ac91
Show file tree
Hide file tree
Showing 29 changed files with 360 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public void backchannelTokenDeliveryModePush2(final String sectorIdentifierUri,

showClient(clientReadClient);
assertRegisterResponseOk(clientReadResponse, 200, true);
assertRegisterResponseClaimsNotNull(clientReadResponse, APPLICATION_TYPE, SECTOR_IDENTIFIER_URI, SUBJECT_TYPE, ID_TOKEN_SIGNED_RESPONSE_ALG, JWKS, CLIENT_NAME, SCOPE);
assertRegisterResponseClaimsNotNull(clientReadResponse, APPLICATION_TYPE, SECTOR_IDENTIFIER_URI, SUBJECT_TYPE, ID_TOKEN_SIGNED_RESPONSE_ALG, CLIENT_NAME, SCOPE);
assertRegisterResponseClaimsAreContained(clientReadResponse, SECTOR_IDENTIFIER_URI);
assertRegisterResponseClaimsBackChannel(clientReadResponse, AsymmetricSignatureAlgorithm.RS256, BackchannelTokenDeliveryMode.PUSH, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ public static void assertTokenResponseOk(TokenResponse response, boolean checkRe
}
}

public static void assertTokenResponseOk(TokenResponse response, boolean checkRefreshToken, boolean checkIdToken) {
assertNotNull(response);
assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getStatus());
assertNotNull(response.getEntity(), "The entity is null");
assertNotNull(response.getAccessToken(), "The access token is null");
assertNotNull(response.getExpiresIn(), "The expires in value is null");
assertNotNull(response.getTokenType(), "The token type is null");
if (checkIdToken) {
assertNotNull(response.getIdToken(), "The id token is null");
}
if (checkRefreshToken) {
assertNotNull(response.getRefreshToken(), "The refresh token is null");
}
}

public static void assertTokenResponseFail(TokenResponse tokenResponse, int status, TokenErrorResponseType errorResponseType) {
assertEquals(tokenResponse.getStatus(), status, "Unexpected HTTP status resposne: " + tokenResponse.getEntity());
assertNotNull(tokenResponse.getEntity(), "The entity is null");
Expand All @@ -139,6 +154,29 @@ public static void assertAuthorizationResponse(AuthorizationResponse response, b
}
}

public static void assertAuthorizationResponse(AuthorizationResponse authorizationResponse, List<ResponseType> responseTypes, boolean checkState, boolean checkScope) {
assertNotNull(authorizationResponse);
assertNotNull(authorizationResponse.getLocation(), "The location is null");
if (checkScope) {
assertNotNull(authorizationResponse.getScope(), "The scope is null");
}

if (checkState) {
assertNotNull(authorizationResponse.getState(), "The state is null");
}
if (responseTypes.contains(ResponseType.CODE)) {
assertNotNull(authorizationResponse.getCode(), "The authorization code is null");
}
if (responseTypes.contains(ResponseType.TOKEN)) {
assertNotNull(authorizationResponse.getAccessToken(), "The access_token is null");
assertNotNull(authorizationResponse.getTokenType());
assertNotNull(authorizationResponse.getExpiresIn());
}
if (responseTypes.contains(ResponseType.ID_TOKEN)) {
assertNotNull(authorizationResponse.getIdToken(), "The id_token is null");
}
}

public static void assertAuthorizationResponse(AuthorizationResponse authorizationResponse, List<ResponseType> responseTypes, boolean checkState) {
assertNotNull(authorizationResponse);
assertNotNull(authorizationResponse.getLocation(), "The location is null");
Expand Down Expand Up @@ -218,6 +256,11 @@ public static void assertUserInfoBasicResponseOk(UserInfoResponse userInfoRespon
assertNotNull(userInfoResponse.getClaim(JwtClaimName.AUDIENCE));
}

public static void assertUserInfoBasicMinimumResponseOk(UserInfoResponse userInfoResponse, int status) {
assertEquals(userInfoResponse.getStatus(), status, "Unexpected response code: " + userInfoResponse.getEntity());
assertNotNull(userInfoResponse.getClaim(JwtClaimName.SUBJECT_IDENTIFIER));
}

public static void assertUserInfoAddressNotNull(UserInfoResponse userInfoResponse) {
assertNotNull(userInfoResponse.getClaim(JwtClaimName.ADDRESS_STREET_ADDRESS));
assertNotNull(userInfoResponse.getClaim(JwtClaimName.ADDRESS_COUNTRY));
Expand All @@ -229,6 +272,15 @@ public static void assertUserInfoAddressNotNull(UserInfoResponse userInfoRespons
JwtClaimName.ADDRESS_REGION)));
}

public static void assertUserInfoAddressMinimumNotNull(UserInfoResponse userInfoResponse) {
assertNotNull(userInfoResponse.getClaim(JwtClaimName.ADDRESS));
assertNotNull(userInfoResponse.getClaim(JwtClaimName.ADDRESS).containsAll(Arrays.asList(
JwtClaimName.ADDRESS_STREET_ADDRESS,
JwtClaimName.ADDRESS_COUNTRY,
JwtClaimName.ADDRESS_LOCALITY,
JwtClaimName.ADDRESS_REGION)));
}

public static void assertUserInfoPersonalDataNotNull(UserInfoResponse userInfoResponse) {
assertNotNull(userInfoResponse.getClaim(JwtClaimName.NAME));
assertNotNull(userInfoResponse.getClaim(JwtClaimName.GIVEN_NAME));
Expand All @@ -239,6 +291,18 @@ public static void assertUserInfoPersonalDataNotNull(UserInfoResponse userInfoRe
assertNotNull(userInfoResponse.getClaim(JwtClaimName.LOCALE));
}

public static void assertUserInfoPersonalDataNotNull(UserInfoResponse userInfoResponse, boolean checkEmail) {
assertNotNull(userInfoResponse.getClaim(JwtClaimName.NAME));
assertNotNull(userInfoResponse.getClaim(JwtClaimName.GIVEN_NAME));
assertNotNull(userInfoResponse.getClaim(JwtClaimName.FAMILY_NAME));
assertNotNull(userInfoResponse.getClaim(JwtClaimName.PICTURE));
if (checkEmail) {
assertNotNull(userInfoResponse.getClaim(JwtClaimName.EMAIL));
}
assertNotNull(userInfoResponse.getClaim(JwtClaimName.ZONEINFO));
assertNotNull(userInfoResponse.getClaim(JwtClaimName.LOCALE));
}

public static void assertJweStandarClaimsNotNull(Jwe jwe, boolean checkAccessTokenHash) {
assertNotNull(jwe);
assertNotNull(jwe.getHeader().getClaimAsString(JwtHeaderName.TYPE));
Expand Down Expand Up @@ -271,6 +335,24 @@ public static void assertJwtStandarClaimsNotNull(Jwt jwt, boolean checkAccessTok
}
}

public static void assertJwtStandarClaimsNotNull(Jwt jwt, boolean checkAccessTokenHash, boolean checkAuthenticationTime) {
assertNotNull(jwt);
assertNotNull(jwt.getHeader().getClaimAsString(JwtHeaderName.TYPE));
assertNotNull(jwt.getHeader().getClaimAsString(JwtHeaderName.ALGORITHM));
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.ISSUER));
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.AUDIENCE));
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.EXPIRATION_TIME));
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.ISSUED_AT));
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.SUBJECT_IDENTIFIER));
if(checkAuthenticationTime){
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.AUTHENTICATION_TIME));
}

if (checkAccessTokenHash) {
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.ACCESS_TOKEN_HASH));
}
}

public static void assertJwtAddressClaimsNotNull(Jwt jwt) {
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.ADDRESS_STREET_ADDRESS));
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.ADDRESS_COUNTRY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void canProvideEncryptedUserInfoResponseAlgA128KWEncA128GCM(
showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
assertUserInfoAddressNotNull(userInfoResponse);
assertUserInfoAddressMinimumNotNull(userInfoResponse);
}

@Parameters({"userId", "userSecret", "redirectUri", "redirectUris", "sectorIdentifierUri"})
Expand Down Expand Up @@ -153,7 +153,7 @@ public void canProvideEncryptedUserInfoResponseAlgA256KWEncA256GCM(
showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
assertUserInfoAddressNotNull(userInfoResponse);
assertUserInfoAddressMinimumNotNull(userInfoResponse);
}

@Parameters({"userId", "userSecret", "redirectUri", "redirectUris",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void canProvideSignedUserInfoResponseHS256(
showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
assertUserInfoAddressNotNull(userInfoResponse);
assertUserInfoAddressMinimumNotNull(userInfoResponse);
}

@Parameters({"userId", "userSecret", "redirectUri", "redirectUris", "sectorIdentifierUri"})
Expand Down Expand Up @@ -147,7 +147,7 @@ public void canProvideSignedUserInfoResponseHS384(
showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
assertUserInfoAddressNotNull(userInfoResponse);
assertUserInfoAddressMinimumNotNull(userInfoResponse);
}

@Parameters({"userId", "userSecret", "redirectUri", "redirectUris", "sectorIdentifierUri"})
Expand Down Expand Up @@ -202,7 +202,7 @@ public void canProvideSignedUserInfoResponseHS512(
showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
assertUserInfoAddressNotNull(userInfoResponse);
assertUserInfoAddressMinimumNotNull(userInfoResponse);
}

@Parameters({"userId", "userSecret", "redirectUri", "redirectUris", "sectorIdentifierUri"})
Expand Down Expand Up @@ -256,7 +256,7 @@ public void canProvideSignedUserInfoResponseRS256(
showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
assertUserInfoAddressNotNull(userInfoResponse);
assertUserInfoAddressMinimumNotNull(userInfoResponse);
}

@Parameters({"userId", "userSecret", "redirectUri", "redirectUris", "sectorIdentifierUri"})
Expand Down Expand Up @@ -310,7 +310,7 @@ public void canProvideSignedUserInfoResponseRS384(
showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
assertUserInfoAddressNotNull(userInfoResponse);
assertUserInfoAddressMinimumNotNull(userInfoResponse);
}

@Parameters({"userId", "userSecret", "redirectUri", "redirectUris", "sectorIdentifierUri"})
Expand Down Expand Up @@ -364,7 +364,7 @@ public void canProvideSignedUserInfoResponseRS512(
showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
assertUserInfoAddressNotNull(userInfoResponse);
assertUserInfoAddressMinimumNotNull(userInfoResponse);
}

@Parameters({"userId", "userSecret", "redirectUri", "redirectUris", "sectorIdentifierUri"})
Expand Down Expand Up @@ -418,7 +418,7 @@ public void canProvideSignedUserInfoResponseES256(
showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
assertUserInfoAddressNotNull(userInfoResponse);
assertUserInfoAddressMinimumNotNull(userInfoResponse);
}

@Parameters({"userId", "userSecret", "redirectUri", "redirectUris", "sectorIdentifierUri"})
Expand Down Expand Up @@ -472,7 +472,7 @@ public void canProvideSignedUserInfoResponseES384(
showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
assertUserInfoAddressNotNull(userInfoResponse);
assertUserInfoAddressMinimumNotNull(userInfoResponse);
}

@Parameters({"userId", "userSecret", "redirectUri", "redirectUris", "sectorIdentifierUri"})
Expand Down Expand Up @@ -526,6 +526,6 @@ public void canProvideSignedUserInfoResponseES512(
showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
assertUserInfoAddressNotNull(userInfoResponse);
assertUserInfoAddressMinimumNotNull(userInfoResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ public void canRequestAndUseSignedUserInfoResponse(
showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
assertUserInfoAddressNotNull(userInfoResponse);
assertUserInfoAddressMinimumNotNull(userInfoResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public void rejectsSecondUseOfAccessCode(
UserInfoResponse userInfoResponse = userInfoClient.execUserInfo(accessToken);

showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
assertUserInfoBasicMinimumResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
}

// 5. Request access token using the same authorization code one more time. This call must fail.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void requestingUserInfoClaimsWithOpenIdRequestObject(
UserInfoResponse userInfoResponse = userInfoClient.execUserInfo(accessToken);

showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoBasicMinimumResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
assertNotNull(userInfoResponse.getClaim(JwtClaimName.PICTURE));
assertNotNull(userInfoResponse.getClaim(JwtClaimName.ADDRESS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void requestingUserInfoClaimsWithScopeValues(
UserInfoResponse userInfoResponse = userInfoClient.execUserInfo(accessToken);

showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoBasicMinimumResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
assertNotNull(userInfoResponse.getClaim(JwtClaimName.PICTURE));
assertNotNull(userInfoResponse.getClaim(JwtClaimName.ADDRESS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void secondUseOfAccessCodeRevokesPreviouslyIssuedAccessToken(
UserInfoResponse userInfoResponse = userInfoClient.execUserInfo(accessToken);

showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoBasicMinimumResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public void supportScopeRequestingProfileClaims(

// 4. Request user info
UserInfoResponse userInfoResponse = requestUserInfo(accessToken);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
assertUserInfoBasicMinimumResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse, false);
assertNotNull(userInfoResponse.getClaim(JwtClaimName.WEBSITE));
assertNotNull(userInfoResponse.getClaim(JwtClaimName.BIRTHDATE));
assertNotNull(userInfoResponse.getClaim(JwtClaimName.GENDER));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void userInfoEndpointAccessWithFormEncodedBodyMethod(
UserInfoResponse userInfoResponse = userInfoClient.exec();

showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoBasicMinimumResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void userInfoEndpointAccessWithHeaderMethod(
UserInfoResponse userInfoResponse = userInfoClient.execUserInfo(accessToken);

showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoBasicMinimumResponseOk(userInfoResponse, 200);
assertUserInfoPersonalDataNotNull(userInfoResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void authorizationRequestDefault(
UserInfoResponse userInfoResponse = userInfoClient.exec();

showClient(userInfoClient);
assertUserInfoBasicResponseOk(userInfoResponse, 200);
assertUserInfoBasicMinimumResponseOk(userInfoResponse, 200);
assertUserInfoAddressNotNull(userInfoResponse);
}

Expand Down
Loading

0 comments on commit 370ac91

Please sign in to comment.