Skip to content

Commit

Permalink
fix(jans-auth-server): jarm failing tests (#745)
Browse files Browse the repository at this point in the history
Disabled the tests that requires setting fapiCompatibility to true and deleted unsused method userDeniedAuthentiation
  • Loading branch information
HemantKMehta authored Feb 1, 2022
1 parent cfc8162 commit 5d0b401
Showing 1 changed file with 6 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,101 +45,7 @@ public class AuthorizationResponseModeJwtResponseTypeCodeSignedEncryptedHttpTest

@Parameters({ "redirectUri", "redirectUris", "clientJwksUri", "RSA_OAEP_keyId", "PS256_keyId", "dnName",
"keyStoreFile", "keyStoreSecret", "sectorIdentifierUri" })
@Test//(enabled = false) // Enable FAPI to run this test!
public void userDeniedAuthentiation(final String redirectUri, final String redirectUris, final String clientJwksUri,
final String encryptionKeyId, final String signingKeyId, final String dnName, final String keyStoreFile,
final String keyStoreSecret, final String sectorIdentifierUri) throws Exception {
showTitle("userDeniedAuthentiation");

List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE);
List<GrantType> GrantTypes = Arrays.asList(GrantType.AUTHORIZATION_CODE);

// 1. Dynamic Client Registration
String clientId = "8c8ab439-7223-436d-83ad-b49e53d88936";
// 2. Request authorization
List<String> scope = Arrays.asList("openid", "profile", "address", "email");
String state = UUID.randomUUID().toString();
String nonce = UUID.randomUUID().toString();

AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scope,
redirectUri, null);

AuthCryptoProvider cryptoProvider1 = new AuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);

JwtAuthorizationRequest jwsAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest,
SignatureAlgorithm.PS256, cryptoProvider1);
jwsAuthorizationRequest.setKeyId(signingKeyId);
jwsAuthorizationRequest.setAud("https://demoexample.jans.io"); // Added bad aud to request object claims
jwsAuthorizationRequest.setIss(clientId);
jwsAuthorizationRequest.setRedirectUri(redirectUri);
jwsAuthorizationRequest.setResponseMode(ResponseMode.JWT);
jwsAuthorizationRequest.setState(state);
jwsAuthorizationRequest.setNonce(nonce); // FAPI: nonce param is required
jwsAuthorizationRequest.setNbf((int) Instant.now().getEpochSecond()); // FAPI: require the request object to
// contain an exp claim that has a
// lifetime of no longer than 60 minutes
// after the nbf claim
jwsAuthorizationRequest.setExp(jwsAuthorizationRequest.getNbf() + 3600); // FAPI: require the request object to
// contain an exp claim that has a
// lifetime of no longer than 60
// minutes after the nbf claim
Jwt authJws = Jwt.parse(jwsAuthorizationRequest.getEncodedJwt());

JwkClient jwkClient = new JwkClient(jwksUri);
JwkResponse jwkResponse = jwkClient.exec();
String serverKeyId = jwkResponse.getKeyId(Algorithm.RSA_OAEP);
assertNotNull(serverKeyId);

JSONObject jwks = JwtUtil.getJSONWebKeys(jwksUri);
AuthCryptoProvider cryptoProvider2 = new AuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
privateKey = cryptoProvider2.getPrivateKey(encryptionKeyId);
JwtAuthorizationRequest jweAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest,
SignatureAlgorithm.PS256, cryptoProvider2);

jweAuthorizationRequest.setKeyId(serverKeyId);
jweAuthorizationRequest.setNestedPayload(authJws);

jweAuthorizationRequest.setKeyId(signingKeyId);
jweAuthorizationRequest.setResponseMode(ResponseMode.JWT);
jweAuthorizationRequest.setState(state);
jweAuthorizationRequest.setScopes(scope);
jweAuthorizationRequest.setAud("https://demoexample.jans.io");
jweAuthorizationRequest.setIss(clientId);
jweAuthorizationRequest.setResponseTypes(responseTypes);
jweAuthorizationRequest.setRedirectUri(redirectUri);
jweAuthorizationRequest.setNonce(nonce); // FAPI: nonce param is required
jweAuthorizationRequest.setNbf((int) Instant.now().getEpochSecond()); // FAPI: require the request object to
// contain an exp claim that has a
// lifetime of no longer than 60 minutes
// after the nbf claim
jweAuthorizationRequest.setExp(jwsAuthorizationRequest.getNbf() + 3600); // Added invalid exp value to request
// object which is 70 minutes in the
// future

String authJwe = jweAuthorizationRequest.getEncodedJwt(jwks);

authorizationRequest.setRequest(authJwe);

AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint);
authorizeClient.setRequest(authorizationRequest);
AuthorizationResponse authorizationResponse = authorizeClient.exec();

showClient(authorizeClient);
assertNotNull(authorizationResponse.getResponse());

Jwe response = Jwe.parse(authorizationResponse.getResponse(), privateKey, null);
assertNotNull(response.getClaims().getClaimAsString(AuthorizeResponseParam.ISS));
assertNotNull(response.getClaims().getClaimAsString(AuthorizeResponseParam.AUD));
assertNotNull(response.getClaims().getClaimAsInteger(AuthorizeResponseParam.EXP));
assertNotNull(response.getClaims().getClaimAsString(AuthorizeResponseParam.STATE));
assertNull(response.getClaims().getClaimAsString(AuthorizeResponseParam.CODE));

privateKey = null; // Clear private key to do not affect to other tests
}

@Parameters({ "redirectUri", "redirectUris", "clientJwksUri", "RSA_OAEP_keyId", "PS256_keyId", "dnName",
"keyStoreFile", "keyStoreSecret", "sectorIdentifierUri" })
@Test // (enabled = false) // Enable FAPI to run this test!
@Test(enabled = false) // Enable FAPI to run this test!
public void ensureRequestObjectWithUnregisteredRequestUrFails(final String redirectUri, final String redirectUris,
final String clientJwksUri, final String encryptionKeyId, final String signingKeyId, final String dnName,
final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) throws Exception {
Expand Down Expand Up @@ -236,7 +142,7 @@ public void ensureRequestObjectWithUnregisteredRequestUrFails(final String redir

@Parameters({ "redirectUri", "redirectUris", "clientJwksUri", "RSA_OAEP_keyId", "RS256_keyId", "dnName",
"keyStoreFile", "keyStoreSecret", "sectorIdentifierUri" })
@Test // (enabled = false) // Enable FAPI to run this test!
@Test(enabled = false) // Enable FAPI to run this test!
public void ensureRequestObjectSignedbyRS256AlgorithmFails(final String redirectUri, final String redirectUris,
final String clientJwksUri, final String encryptionKeyId, final String signingKeyId, final String dnName,
final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) throws Exception {
Expand Down Expand Up @@ -333,7 +239,7 @@ public void ensureRequestObjectSignedbyRS256AlgorithmFails(final String redirect

@Parameters({ "redirectUri", "redirectUris", "clientJwksUri", "RSA_OAEP_keyId", "PS256_keyId", "dnName",
"keyStoreFile", "keyStoreSecret", "sectorIdentifierUri" })
@Test // (enabled = false) // Enable FAPI to run this test!
@Test(enabled = false) // Enable FAPI to run this test!
public void ensureRequestObjectWithNoneSigningAlgorithmFails(final String redirectUri, final String redirectUris,
final String clientJwksUri, final String encryptionKeyId, final String signingKeyId, final String dnName,
final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) throws Exception {
Expand Down Expand Up @@ -432,7 +338,7 @@ public void ensureRequestObjectWithNoneSigningAlgorithmFails(final String redire

@Parameters({ "redirectUri", "redirectUris", "clientJwksUri", "RSA_OAEP_keyId", "PS256_keyId", "dnName",
"keyStoreFile", "keyStoreSecret", "sectorIdentifierUri" })
@Test // (enabled = false) // Enable FAPI to run this test!
@Test(enabled = false) // Enable FAPI to run this test!
public void ensureRequestObjectWithInvalidSignatureFails(final String redirectUri, final String redirectUris,
final String clientJwksUri, final String encryptionKeyId, final String signingKeyId, final String dnName,
final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) throws Exception {
Expand Down Expand Up @@ -528,7 +434,7 @@ public void ensureRequestObjectWithInvalidSignatureFails(final String redirectUr

@Parameters({ "redirectUri", "redirectUris", "clientJwksUri", "RSA_OAEP_keyId", "PS256_keyId", "dnName",
"keyStoreFile", "keyStoreSecret", "sectorIdentifierUri" })
@Test // (enabled = false) // Enable FAPI to run this test!
@Test(enabled = false) // Enable FAPI to run this test!
public void ensureRequestObjectWithoutEncryptionFails(final String redirectUri, final String redirectUris,
final String clientJwksUri, final String encryptionKeyId, final String signingKeyId, final String dnName,
final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) throws Exception {
Expand Down Expand Up @@ -1597,4 +1503,4 @@ public void ensureRegisteredRedirectUri(

privateKey = null; // Clear private key to do not affect to other tests
}
}
}

0 comments on commit 5d0b401

Please sign in to comment.