Repository: cxf-fediz Updated Branches: refs/heads/master d4f862d93 -> bd0511cab
Fixing ForceAuthn SAML SSO tests Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/bf460dd0 Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/bf460dd0 Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/bf460dd0 Branch: refs/heads/master Commit: bf460dd06658df18a348dff3ccb4bf13a8786b17 Parents: d4f862d Author: Colm O hEigeartaigh <[email protected]> Authored: Thu Dec 8 11:15:43 2016 +0000 Committer: Colm O hEigeartaigh <[email protected]> Committed: Thu Dec 8 11:15:43 2016 +0000 ---------------------------------------------------------------------- .../apache/cxf/fediz/systests/idp/IdpTest.java | 45 +++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/bf460dd0/systests/samlsso/src/test/java/org/apache/cxf/fediz/systests/idp/IdpTest.java ---------------------------------------------------------------------- diff --git a/systests/samlsso/src/test/java/org/apache/cxf/fediz/systests/idp/IdpTest.java b/systests/samlsso/src/test/java/org/apache/cxf/fediz/systests/idp/IdpTest.java index 186fb41..00a8b78 100644 --- a/systests/samlsso/src/test/java/org/apache/cxf/fediz/systests/idp/IdpTest.java +++ b/systests/samlsso/src/test/java/org/apache/cxf/fediz/systests/idp/IdpTest.java @@ -38,6 +38,7 @@ import javax.servlet.ServletException; import org.w3c.dom.Document; import org.w3c.dom.Element; +import com.gargoylesoftware.htmlunit.CookieManager; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.WebClient; @@ -546,6 +547,8 @@ public class IdpTest { String password = "ecila"; final WebClient webClient = new WebClient(); + CookieManager cookieManager = new CookieManager(); + webClient.setCookieManager(cookieManager); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), @@ -595,8 +598,27 @@ public class IdpTest { Assert.assertTrue(parsedResponse.contains(claim)); claim = ClaimTypes.EMAILADDRESS.toString(); Assert.assertTrue(parsedResponse.contains(claim)); - + webClient.close(); + + // + // Third invocation - create a new WebClient with no credentials (but with the same CookieManager) + // ...this should fail + // + + WebClient newWebClient = new WebClient(); + newWebClient.setCookieManager(cookieManager); + newWebClient.getOptions().setUseInsecureSSL(true); + newWebClient.getOptions().setJavaScriptEnabled(false); + + try { + newWebClient.getPage(url); + Assert.fail("Failure expected on no credentials"); + } catch (FailingHttpStatusCodeException ex) { + Assert.assertEquals(ex.getStatusCode(), 401); + } + + newWebClient.close(); } @org.junit.Test @@ -654,6 +676,8 @@ public class IdpTest { String password = "ecila"; final WebClient webClient = new WebClient(); + CookieManager cookieManager = new CookieManager(); + webClient.setCookieManager(cookieManager); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), @@ -705,6 +729,25 @@ public class IdpTest { Assert.assertTrue(parsedResponse.contains(claim)); webClient.close(); + + // + // Third invocation - create a new WebClient with no credentials (but with the same CookieManager) + // ...this should fail + // + + WebClient newWebClient = new WebClient(); + newWebClient.setCookieManager(cookieManager); + newWebClient.getOptions().setUseInsecureSSL(true); + newWebClient.getOptions().setJavaScriptEnabled(false); + + try { + newWebClient.getPage(url); + Assert.fail("Failure expected on no credentials"); + } catch (FailingHttpStatusCodeException ex) { + Assert.assertEquals(ex.getStatusCode(), 401); + } + + newWebClient.close(); } //
