Java Code Examples for com.gargoylesoftware.htmlunit.html.DomElement#setAttributeNS()
The following examples show how to use
com.gargoylesoftware.htmlunit.html.DomElement#setAttributeNS() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringTest.java From cxf-fediz with Apache License 2.0 | 4 votes |
@org.junit.Test public void testNoRequestValidation() throws Exception { String url = "https://localhost:" + getRpHttpsPort() + "/fedizhelloworldspringnoreqvalidation/secure/fedservlet"; String user = "alice"; String password = "ecila"; // Get the initial token CookieManager cookieManager = new CookieManager(); final WebClient webClient = new WebClient(); webClient.setCookieManager(cookieManager); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); webClient.getOptions().setJavaScriptEnabled(true); Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); // Parse the form to remove the context DomNodeList<DomElement> results = idpPage.getElementsByTagName("input"); for (DomElement result : results) { if (getContextName().equals(result.getAttributeNS(null, "name"))) { result.setAttributeNS(null, "value", ""); } } // Invoke back on the RP final HtmlForm form = idpPage.getFormByName(getLoginFormName()); final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); final HtmlPage rpPage = button.click(); Assert.assertTrue("WS Federation Systests Examples".equals(rpPage.getTitleText()) || "WS Federation Systests Spring Examples".equals(rpPage.getTitleText())); webClient.close(); }
Example 2
Source File: TomcatTest.java From cxf-fediz with Apache License 2.0 | 4 votes |
@Test public void testAliceModifiedContext() throws Exception { String url = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet"; String user = "alice"; String password = "ecila"; // Get the initial token CookieManager cookieManager = new CookieManager(); final WebClient webClient = new WebClient(); webClient.setCookieManager(cookieManager); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); webClient.getOptions().setJavaScriptEnabled(true); Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); // Parse the form to get the token (wresult) DomNodeList<DomElement> results = idpPage.getElementsByTagName("input"); for (DomElement result : results) { if (getContextName().equals(result.getAttributeNS(null, "name"))) { // Now modify the context String value = result.getAttributeNS(null, "value"); value = "H" + value; result.setAttributeNS(null, "value", value); } } // Invoke back on the RP final HtmlForm form = idpPage.getFormByName(getLoginFormName()); final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); try { button.click(); Assert.fail("Failure expected on a modified context"); } catch (FailingHttpStatusCodeException ex) { // Request Timeout expected here, as the context isn't known - the session is presumed to have expired Assert.assertTrue(408 == ex.getStatusCode()); } webClient.close(); }
Example 3
Source File: FederationTest.java From cxf-fediz with Apache License 2.0 | 4 votes |
@org.junit.Test public void testNoRequestValidation() throws Exception { String url = "https://localhost:" + getRpHttpsPort() + "/fedizhelloworldnoreqvalidation/secure/fedservlet"; String user = "alice"; String password = "ecila"; // Get the initial token CookieManager cookieManager = new CookieManager(); final WebClient webClient = new WebClient(); webClient.setCookieManager(cookieManager); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); webClient.getOptions().setJavaScriptEnabled(true); Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); // Parse the form to remove the context DomNodeList<DomElement> results = idpPage.getElementsByTagName("input"); for (DomElement result : results) { if (getContextName().equals(result.getAttributeNS(null, "name"))) { result.setAttributeNS(null, "value", ""); } } // Invoke back on the RP final HtmlForm form = idpPage.getFormByName(getLoginFormName()); final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); final HtmlPage rpPage = button.click(); Assert.assertTrue("WS Federation Systests Examples".equals(rpPage.getTitleText()) || "WS Federation Systests Spring Examples".equals(rpPage.getTitleText())); webClient.close(); }
Example 4
Source File: AbstractTests.java From cxf-fediz with Apache License 2.0 | 4 votes |
@Test public void testAliceModifiedSignature() throws Exception { String url = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet"; String user = "alice"; String password = "ecila"; // Get the initial token CookieManager cookieManager = new CookieManager(); final WebClient webClient = new WebClient(); webClient.setCookieManager(cookieManager); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); webClient.getOptions().setJavaScriptEnabled(true); Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); // Parse the form to get the token (wresult) DomNodeList<DomElement> results = idpPage.getElementsByTagName("input"); for (DomElement result : results) { if (getTokenName().equals(result.getAttributeNS(null, "name"))) { // Now modify the Signature String value = result.getAttributeNS(null, "value"); if (value.contains("alice")) { value = value.replace("alice", "bob"); } else { value = "H" + value; } result.setAttributeNS(null, "value", value); } } // Invoke back on the RP final HtmlForm form = idpPage.getFormByName(getLoginFormName()); final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); try { button.click(); Assert.fail("Failure expected on a modified signature"); } catch (FailingHttpStatusCodeException ex) { // expected Assert.assertTrue(401 == ex.getStatusCode() || 403 == ex.getStatusCode()); } webClient.close(); }
Example 5
Source File: AbstractTests.java From cxf-fediz with Apache License 2.0 | 4 votes |
@Test public void testEntityExpansionAttack() throws Exception { String url = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet"; String user = "alice"; String password = "ecila"; // Get the initial token CookieManager cookieManager = new CookieManager(); final WebClient webClient = new WebClient(); webClient.setCookieManager(cookieManager); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); webClient.getOptions().setJavaScriptEnabled(true); Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); // Parse the form to get the token (wresult) DomNodeList<DomElement> results = idpPage.getElementsByTagName("input"); String entity = getResourceAsString("/entity.xml"); String reference = "&m;"; for (DomElement result : results) { if (getTokenName().equals(result.getAttributeNS(null, "name"))) { // Now modify the Signature String value = result.getAttributeNS(null, "value"); if (isWSFederation()) { value = entity + value; value = value.replace("alice", reference); result.setAttributeNS(null, "value", value); } else { // Decode response byte[] deflatedToken = Base64Utility.decode(value); InputStream inputStream = new ByteArrayInputStream(deflatedToken); Document responseDoc = StaxUtils.read(new InputStreamReader(inputStream, "UTF-8")); // Modify SignatureValue to include the entity String signatureNamespace = "http://www.w3.org/2000/09/xmldsig#"; Node signatureValue = responseDoc.getElementsByTagNameNS(signatureNamespace, "SignatureValue").item(0); signatureValue.setTextContent(reference + signatureValue.getTextContent()); // Re-encode response String responseMessage = DOM2Writer.nodeToString(responseDoc); result.setAttributeNS(null, "value", Base64Utility.encode((entity + responseMessage).getBytes())); } } } // Invoke back on the RP final HtmlForm form = idpPage.getFormByName(getLoginFormName()); final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); try { button.click(); Assert.fail("Failure expected on an entity expansion attack"); } catch (FailingHttpStatusCodeException ex) { // expected Assert.assertTrue(401 == ex.getStatusCode() || 403 == ex.getStatusCode()); } webClient.close(); }
Example 6
Source File: AbstractTests.java From cxf-fediz with Apache License 2.0 | 4 votes |
@Test public void testEntityExpansionAttack2() throws Exception { String url = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet"; String user = "alice"; String password = "ecila"; // Get the initial token CookieManager cookieManager = new CookieManager(); final WebClient webClient = new WebClient(); webClient.setCookieManager(cookieManager); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); webClient.getOptions().setJavaScriptEnabled(true); Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); // Parse the form to get the token (wresult) DomNodeList<DomElement> results = idpPage.getElementsByTagName("input"); String entity = getResourceAsString("/entity2.xml"); String reference = "&m;"; for (DomElement result : results) { if (getTokenName().equals(result.getAttributeNS(null, "name"))) { // Now modify the Signature String value = result.getAttributeNS(null, "value"); if (isWSFederation()) { value = entity + value; value = value.replace("alice", reference); result.setAttributeNS(null, "value", value); } else { // Decode response byte[] deflatedToken = Base64Utility.decode(value); InputStream inputStream = new ByteArrayInputStream(deflatedToken); Document responseDoc = StaxUtils.read(new InputStreamReader(inputStream, "UTF-8")); // Modify SignatureValue to include the entity String signatureNamespace = "http://www.w3.org/2000/09/xmldsig#"; Node signatureValue = responseDoc.getElementsByTagNameNS(signatureNamespace, "SignatureValue").item(0); signatureValue.setTextContent(reference + signatureValue.getTextContent()); // Re-encode response String responseMessage = DOM2Writer.nodeToString(responseDoc); result.setAttributeNS(null, "value", Base64Utility.encode((entity + responseMessage).getBytes())); } } } // Invoke back on the RP final HtmlForm form = idpPage.getFormByName(getLoginFormName()); final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); try { button.click(); Assert.fail("Failure expected on an entity expansion attack"); } catch (FailingHttpStatusCodeException ex) { // expected Assert.assertTrue(401 == ex.getStatusCode() || 403 == ex.getStatusCode()); } webClient.close(); }
Example 7
Source File: TomcatPluginTest.java From cxf-fediz with Apache License 2.0 | 4 votes |
@Test public void testModifiedSignatureValue() throws Exception { String url = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet"; String user = "alice"; String password = "ecila"; // Get the initial token CookieManager cookieManager = new CookieManager(); final WebClient webClient = new WebClient(); webClient.setCookieManager(cookieManager); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); webClient.getOptions().setJavaScriptEnabled(true); Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); // Parse the form to get the token (wresult) DomNodeList<DomElement> results = idpPage.getElementsByTagName("input"); for (DomElement result : results) { if (getTokenName().equals(result.getAttributeNS(null, "name"))) { String value = result.getAttributeNS(null, "value"); // Decode response byte[] deflatedToken = Base64Utility.decode(value); InputStream inputStream = new ByteArrayInputStream(deflatedToken); Document responseDoc = StaxUtils.read(new InputStreamReader(inputStream, "UTF-8")); // Modify SignatureValue String signatureNamespace = "http://www.w3.org/2000/09/xmldsig#"; Node signatureValue = responseDoc.getElementsByTagNameNS(signatureNamespace, "SignatureValue").item(0); signatureValue.setTextContent("H" + signatureValue.getTextContent()); // Re-encode response String responseMessage = DOM2Writer.nodeToString(responseDoc); result.setAttributeNS(null, "value", Base64Utility.encode(responseMessage.getBytes())); } } // Invoke back on the RP final HtmlForm form = idpPage.getFormByName(getLoginFormName()); final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); try { button.click(); Assert.fail("Failure expected on a modified signature"); } catch (FailingHttpStatusCodeException ex) { // expected Assert.assertTrue(401 == ex.getStatusCode() || 403 == ex.getStatusCode()); } webClient.close(); }
Example 8
Source File: TomcatPluginTest.java From cxf-fediz with Apache License 2.0 | 4 votes |
@Test public void testAliceModifiedContext() throws Exception { String url = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet"; String user = "alice"; String password = "ecila"; // Get the initial token CookieManager cookieManager = new CookieManager(); final WebClient webClient = new WebClient(); webClient.setCookieManager(cookieManager); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); webClient.getOptions().setJavaScriptEnabled(true); Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); // Parse the form to get the token (wresult) DomNodeList<DomElement> results = idpPage.getElementsByTagName("input"); for (DomElement result : results) { if (getContextName().equals(result.getAttributeNS(null, "name"))) { // Now modify the context String value = result.getAttributeNS(null, "value"); value = "H" + value; result.setAttributeNS(null, "value", value); } } // Invoke back on the RP final HtmlForm form = idpPage.getFormByName(getLoginFormName()); final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); try { button.click(); Assert.fail("Failure expected on a modified context"); } catch (FailingHttpStatusCodeException ex) { // Request Timeout expected here, as the context isn't known - the session is presumed to have expired Assert.assertTrue(408 == ex.getStatusCode()); } webClient.close(); }
Example 9
Source File: CXFTest.java From cxf-fediz with Apache License 2.0 | 4 votes |
@org.junit.Test public void testNoRequestValidation() throws Exception { String url = "https://localhost:" + getRpHttpsPort() + "/fedizhelloworldcxfnoreqvalidation/secure/fedservlet"; String user = "alice"; String password = "ecila"; // Get the initial token CookieManager cookieManager = new CookieManager(); final WebClient webClient = new WebClient(); webClient.setCookieManager(cookieManager); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); webClient.getOptions().setJavaScriptEnabled(true); Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); // Parse the form to remove the context DomNodeList<DomElement> results = idpPage.getElementsByTagName("input"); for (DomElement result : results) { if (getContextName().equals(result.getAttributeNS(null, "name"))) { result.setAttributeNS(null, "value", ""); } } // Invoke back on the RP final HtmlForm form = idpPage.getFormByName(getLoginFormName()); final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); final HtmlPage rpPage = button.click(); Assert.assertTrue("WS Federation Systests Examples".equals(rpPage.getTitleText()) || "WS Federation Systests Spring Examples".equals(rpPage.getTitleText())); webClient.close(); }
Example 10
Source File: SpringTest.java From cxf-fediz with Apache License 2.0 | 4 votes |
@org.junit.Test public void testNoRequestValidation() throws Exception { String url = "https://localhost:" + getRpHttpsPort() + "/fedizhelloworldspringnoreqvalidation/secure/fedservlet"; String user = "alice"; String password = "ecila"; // Get the initial token CookieManager cookieManager = new CookieManager(); final WebClient webClient = new WebClient(); webClient.setCookieManager(cookieManager); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); webClient.getOptions().setJavaScriptEnabled(true); Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); // Parse the form to remove the context DomNodeList<DomElement> results = idpPage.getElementsByTagName("input"); for (DomElement result : results) { if (getContextName().equals(result.getAttributeNS(null, "name"))) { result.setAttributeNS(null, "value", ""); } } // Invoke back on the RP final HtmlForm form = idpPage.getFormByName(getLoginFormName()); final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); final HtmlPage rpPage = button.click(); Assert.assertTrue("WS Federation Systests Examples".equals(rpPage.getTitleText()) || "WS Federation Systests Spring Examples".equals(rpPage.getTitleText())); webClient.close(); }