[java-idp-oidc] 02/02: Improved flow testing.
Henri Mikkonen
henri.mikkonen at iki.fi
Wed Apr 20 18:09:21 UTC 2022
This is an automated email from the git hooks/post-receive script.
hjmikkon pushed a commit to branch main
in repository java-idp-oidc.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-oidc.git;a=commit;h=3402dc451c5dd06b98f0a9897f0aca469928a284
commit 3402dc451c5dd06b98f0a9897f0aca469928a284
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Wed Apr 20 21:09:08 2022 +0300
Improved flow testing.
---
.../plugin/oidc/op/profile/flow/TokenFlowTest.java | 37 +++++++++++++++++-----
1 file changed, 29 insertions(+), 8 deletions(-)
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/TokenFlowTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/TokenFlowTest.java
index adc7467c..01fd363e 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/TokenFlowTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/TokenFlowTest.java
@@ -113,7 +113,7 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
}
@Test
- public void testUnauthorized() throws IOException, ParseException {
+ public void testUnauthorizedGrant() throws IOException, ParseException {
setHttpFormRequest("POST", createRequestParameters(redirectUri, "authorization_code", "mockCode", clientId));
storeMetadata(storageService, clientId, clientSecret, scope);
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
@@ -144,18 +144,20 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
protected void initializeGrantAndRequest(final String clientId, final Map<String, String> requestParameters)
throws IOException {
- initializeGrantAndRequest(clientId, requestParameters, true);
+ initializeGrantAndRequest(clientId, requestParameters, true, null);
}
protected void initializeGrantAndRequest(final String clientId, final Map<String, String> requestParameters,
- final boolean doBasicAuth)
+ final boolean doBasicAuth, final ClientAuthenticationMethod registeredMethod)
throws IOException {
setHttpFormRequest("POST", requestParameters);
if (doBasicAuth) {
setBasicAuth(clientId, clientSecret);
- storeMetadata(storageService, clientId, clientSecret, scope);
+ }
+ if (registeredMethod != null) {
+ storeMetadata(storageService, clientId, clientSecret, scope, null, registeredMethod);
} else {
- storeMetadata(storageService, clientId, clientSecret, scope, null, ClientAuthenticationMethod.NONE);
+ storeMetadata(storageService, clientId, clientSecret, scope);
}
}
@@ -170,6 +172,25 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
Assert.assertNotNull(response.getTokens().getRefreshToken());
Assert.assertNotNull(response.getOIDCTokens().getIDToken());
}
+
+ @Test
+ public void testValidGrantWithWrongRegisteredAuthType() throws Exception {
+ initializeGrantAndRequest(clientId, createRequestParameters(redirectUri, "authorization_code",
+ buildAuthorizationCode(clientId), clientId), true, ClientAuthenticationMethod.NONE);
+ storeConsent(storageService, "jdoe", clientId, "mail");
+ final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
+ assertErrorCode(result, OAuth2Error.INVALID_REQUEST_CODE);
+ }
+
+ @Test
+ public void testValidGrantWithoutAuthentication() throws Exception {
+ initializeGrantAndRequest(clientId, createRequestParameters(redirectUri, "authorization_code",
+ buildAuthorizationCode(clientId), clientId), false, ClientAuthenticationMethod.CLIENT_SECRET_BASIC);
+ storeConsent(storageService, "jdoe", clientId, "mail");
+ final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
+ assertErrorCode(result, OAuth2Error.INVALID_CLIENT_CODE);
+ }
+
@Test
public void testValidGrantRefreshTokensDisabledInSSOProfile() throws Exception {
final String clientId = "mockClientIdNoRefreshTokensInSSOProfile";
@@ -357,7 +378,7 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
public void testValidGrantValidPlainPKCE_publicClient() throws Exception {
initializeGrantAndRequest(clientIdPkcePlainPublic, createRequestParameters(redirectUri, "authorization_code",
buildAuthorizationCode(clientIdPkcePlainPublic, plainVerifier()), clientIdPkcePlainPublic, null, null,
- codeVerifier), false);
+ codeVerifier), false, ClientAuthenticationMethod.NONE);
storeConsent(storageService, "jdoe", clientIdPkcePlainPublic, "mail");
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final OIDCTokenResponse response = parseSuccessResponse(result, OIDCTokenResponse.class);
@@ -380,7 +401,7 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
public void testValidGrantValidUnforcedPlainPKCE_publicClient() throws Exception {
initializeGrantAndRequest(clientIdPkcePlainUnforcedPublic, createRequestParameters(redirectUri, "authorization_code",
buildAuthorizationCode(clientIdPkcePlainUnforcedPublic, plainVerifier()), clientIdPkcePlainUnforcedPublic, null,
- null, codeVerifier), false);
+ null, codeVerifier), false, ClientAuthenticationMethod.NONE);
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final OIDCTokenResponse response = parseSuccessResponse(result, OIDCTokenResponse.class);
Assert.assertNotNull(response.getTokens().getAccessToken());
@@ -429,7 +450,7 @@ public class TokenFlowTest extends AbstractOidcClientAuthenticationFlowTest {
public void testValidGrantValidS256PKCE_publicClient() throws Exception {
initializeGrantAndRequest(clientIdPkceS256Public, createRequestParameters(redirectUri, "authorization_code",
buildAuthorizationCode(clientIdPkceS256Public, s256Verifier()), clientIdPkceS256Public, null, "S256",
- codeVerifier), false);
+ codeVerifier), false, ClientAuthenticationMethod.NONE);
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
final OIDCTokenResponse response = parseSuccessResponse(result, OIDCTokenResponse.class);
Assert.assertNotNull(response.getTokens().getAccessToken());
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list