You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2019/10/23 10:42:57 UTC
[cxf-fediz] branch master updated: Fixing OIDC system tests
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf-fediz.git
The following commit(s) were added to refs/heads/master by this push:
new dc09544 Fixing OIDC system tests
dc09544 is described below
commit dc09544dda5052c89b76d5e7fbc9cb66452cf942
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Wed Oct 23 11:42:39 2019 +0100
Fixing OIDC system tests
---
.../cxf/fediz/systests/oidc/AbstractOIDCTest.java | 58 ++++++++++++++++------
.../resources/oidc/spring/applicationContext.xml | 3 +-
2 files changed, 46 insertions(+), 15 deletions(-)
diff --git a/systests/oidc/src/test/java/org/apache/cxf/fediz/systests/oidc/AbstractOIDCTest.java b/systests/oidc/src/test/java/org/apache/cxf/fediz/systests/oidc/AbstractOIDCTest.java
index 9857421..aa5283d 100644
--- a/systests/oidc/src/test/java/org/apache/cxf/fediz/systests/oidc/AbstractOIDCTest.java
+++ b/systests/oidc/src/test/java/org/apache/cxf/fediz/systests/oidc/AbstractOIDCTest.java
@@ -104,6 +104,7 @@ abstract class AbstractOIDCTest {
private static String storedClientId;
private static String storedClient2Id;
private static String storedClientPassword;
+ private static String storedClient2Password;
protected static void startServer(String servletContextName, String fedizConfigPath) throws Exception {
assertNotNull("Property 'idp.https.port' null", IDP_HTTPS_PORT);
@@ -258,6 +259,12 @@ abstract class AbstractOIDCTest {
}
assertNotNull(storedClient2Id);
+ // Get the password
+ registeredClientPage = webClient.getPage(url + "/" + storedClient2Id);
+ table = registeredClientPage.getHtmlElementById("client");
+ storedClient2Password = table.getCellAt(1, 2).asText().trim();
+ assertNotNull(storedClient2Password);
+
webClient.close();
}
@@ -422,8 +429,12 @@ abstract class AbstractOIDCTest {
new NameValuePair("grant_type", "authorization_code"),
new NameValuePair("code", authorizationCode)));
- webClient.getOptions().setJavaScriptEnabled(false);
- final UnexpectedPage responsePage = webClient.getPage(request);
+ WebClient webClient2 = setupWebClient("", "");
+ String data = storedClientId + ":" + storedClientPassword;
+ String authorizationHeader = "Basic "
+ + Base64.getEncoder().encodeToString(data.getBytes(StandardCharsets.UTF_8));
+ webClient2.addRequestHeader("Authorization", authorizationHeader);
+ final UnexpectedPage responsePage = webClient2.getPage(request);
String response = responsePage.getWebResponse().getContentAsString();
// Check the IdToken
@@ -432,6 +443,7 @@ abstract class AbstractOIDCTest {
validateIdToken(idToken, storedClientId);
webClient.close();
+ webClient2.close();
}
@org.junit.Test
@@ -459,8 +471,12 @@ abstract class AbstractOIDCTest {
new NameValuePair("grant_type", "authorization_code"),
new NameValuePair("code", authorizationCode)));
- webClient.getOptions().setJavaScriptEnabled(false);
- final UnexpectedPage responsePage = webClient.getPage(request);
+ WebClient webClient2 = setupWebClient("", "");
+ String data = storedClient2Id + ":" + storedClient2Password;
+ String authorizationHeader = "Basic "
+ + Base64.getEncoder().encodeToString(data.getBytes(StandardCharsets.UTF_8));
+ webClient2.addRequestHeader("Authorization", authorizationHeader);
+ final UnexpectedPage responsePage = webClient2.getPage(request);
String response = responsePage.getWebResponse().getContentAsString();
// Check the IdToken
@@ -469,6 +485,7 @@ abstract class AbstractOIDCTest {
validateIdToken(idToken, storedClient2Id);
webClient.close();
+ webClient2.close();
}
@org.junit.Test
@@ -491,19 +508,24 @@ abstract class AbstractOIDCTest {
WebRequest request = new WebRequest(new URL(url), HttpMethod.POST);
request.setRequestParameters(Arrays.asList(
- new NameValuePair("client_id", storedClient2Id),
+ new NameValuePair("client_id", storedClientId),
new NameValuePair("grant_type", "authorization_code"),
new NameValuePair("code", authorizationCode)));
- webClient.getOptions().setJavaScriptEnabled(false);
+ WebClient webClient2 = setupWebClient("", "");
+ String data = storedClient2Id + ":" + storedClient2Password;
+ String authorizationHeader = "Basic "
+ + Base64.getEncoder().encodeToString(data.getBytes(StandardCharsets.UTF_8));
+ webClient2.addRequestHeader("Authorization", authorizationHeader);
+ webClient2.getOptions().setJavaScriptEnabled(false);
try {
- webClient.getPage(request);
+ webClient2.getPage(request);
fail();
} catch (FailingHttpStatusCodeException ex) {
assertEquals(Status.BAD_REQUEST.getStatusCode(), ex.getStatusCode());
}
- webClient.close();
+ webClient2.close();
}
@org.junit.Test
@@ -881,8 +903,12 @@ abstract class AbstractOIDCTest {
new NameValuePair("grant_type", "authorization_code"),
new NameValuePair("code", authorizationCode)));
- webClient.getOptions().setJavaScriptEnabled(false);
- final UnexpectedPage responsePage = webClient.getPage(request);
+ WebClient webClient2 = setupWebClient("", "");
+ String data = storedClientId + ":" + storedClientPassword;
+ String authorizationHeader = "Basic "
+ + Base64.getEncoder().encodeToString(data.getBytes(StandardCharsets.UTF_8));
+ webClient2.addRequestHeader("Authorization", authorizationHeader);
+ final UnexpectedPage responsePage = webClient2.getPage(request);
String response = responsePage.getWebResponse().getContentAsString();
// Check the IdToken
@@ -891,6 +917,7 @@ abstract class AbstractOIDCTest {
validateIdToken(idToken, storedClientId, "User");
webClient.close();
+ webClient2.close();
}
@org.junit.Test
@@ -918,8 +945,12 @@ abstract class AbstractOIDCTest {
new NameValuePair("grant_type", "authorization_code"),
new NameValuePair("code", authorizationCode)));
- webClient.getOptions().setJavaScriptEnabled(false);
- final UnexpectedPage responsePage = webClient.getPage(request);
+ WebClient webClient2 = setupWebClient("", "");
+ String data = storedClientId + ":" + storedClientPassword;
+ String authorizationHeader = "Basic "
+ + Base64.getEncoder().encodeToString(data.getBytes(StandardCharsets.UTF_8));
+ webClient2.addRequestHeader("Authorization", authorizationHeader);
+ final UnexpectedPage responsePage = webClient2.getPage(request);
String response = responsePage.getWebResponse().getContentAsString();
// Check the IdToken
@@ -928,10 +959,9 @@ abstract class AbstractOIDCTest {
validateIdToken(idToken, storedClientId, "User");
webClient.close();
+ webClient2.close();
}
-
-
private static WebClient setupWebClient(String user, String password) {
final WebClient webClient = new WebClient();
webClient.getOptions().setUseInsecureSSL(true);
diff --git a/systests/oidc/src/test/resources/oidc/spring/applicationContext.xml b/systests/oidc/src/test/resources/oidc/spring/applicationContext.xml
index 2733334..35bf5a5 100644
--- a/systests/oidc/src/test/resources/oidc/spring/applicationContext.xml
+++ b/systests/oidc/src/test/resources/oidc/spring/applicationContext.xml
@@ -54,7 +54,8 @@
<springsec:debug />
<springsec:http entry-point-ref="federationEntryPoint" use-expressions="true">
- <springsec:intercept-url pattern="/**" access="isAuthenticated()"/>
+ <springsec:intercept-url pattern="/idp/*" access="isAuthenticated()"/>
+ <springsec:intercept-url pattern="/console/*" access="isAuthenticated()"/>
<springsec:custom-filter ref="federationFilter" after="BASIC_AUTH_FILTER" />
<springsec:custom-filter ref="logoutFilter" position="LOGOUT_FILTER"/>
<springsec:custom-filter ref="federationSignOutCleanupFilter" position="PRE_AUTH_FILTER"/>