com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException Java Examples
The following examples show how to use
com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException.
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: ValidationIT.java From ozark with Apache License 2.0 | 6 votes |
@Test public void testFormControllerFail() throws Exception { final HtmlPage page = webClient.getPage(webUrl); final HtmlForm form = page.getFormByName("form"); final HtmlTextInput name = form.getInputByName("name"); final HtmlTextInput age = form.getInputByName("age"); final HtmlSubmitInput button = form.getInputByName("button"); name.setValueAttribute("john"); age.setValueAttribute("2"); // Not old enough! try { button.click(); fail("Validation error expected in form submission"); } catch (FailingHttpStatusCodeException e) { assertTrue(e.getStatusCode() == 400); assertTrue(e.getResponse().getContentAsString().contains("<h1>Form Error</h1>")); assertTrue(e.getResponse().getContentAsString().contains("<p>Param: age</p>")); } }
Example #2
Source File: AbstractOIDCTest.java From cxf-fediz with Apache License 2.0 | 6 votes |
@org.junit.Test public void testUsingCodeForOtherClient() throws Exception { // Get the code for the first client final UriBuilder authorizationUrl = oidcEndpointBuilder("/idp/authorize") .queryParam("client_id", confidentialClientId) .queryParam("response_type", "code") .queryParam("scope", "openid"); // Login to the OIDC token endpoint + get the authorization code final String authorizationCode = loginAndGetAuthorizationCode(authorizationUrl, "alice", "ecila"); try { // Now try and get a token for the second client getTokenJson(authorizationCode, publicClientId, null); fail(); } catch (FailingHttpStatusCodeException ex) { assertEquals(Status.BAD_REQUEST.getStatusCode(), ex.getStatusCode()); } }
Example #3
Source File: DemoApplicationTests.java From keycloak-springsecurity5-sample with GNU General Public License v3.0 | 6 votes |
@Test public void requestAuthorizeClientWhenInvalidClientThenStatusBadRequest() throws Exception { HtmlPage page = this.webClient.getPage("/"); ClientRegistration clientRegistration = this.clientRegistrationRepository.findByRegistrationId("google"); HtmlAnchor clientAnchorElement = this.getClientAnchorElement(page, clientRegistration); assertThat(clientAnchorElement).isNotNull(); clientAnchorElement.setAttribute("href", clientAnchorElement.getHrefAttribute() + "-invalid"); WebResponse response = null; try { clientAnchorElement.click(); } catch (FailingHttpStatusCodeException ex) { response = ex.getResponse(); } assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value()); }
Example #4
Source File: CodeFlowTest.java From quarkus with Apache License 2.0 | 6 votes |
@Test public void testAuthenticationCompletionFailedWrongRedirectUri() throws IOException, InterruptedException { // CustomTenantResolver will return null for an empty tenantId which will lead to the default configuration // being used and result in '/web-app/callback-before-redirect' be used as an initial redirect_uri parameter. // When the user is redirected back, CustomTenantResolver will resolve a 'tenant-1' configuration with // a redirect_uri '/web-app/callback-after-redirect' which will cause a code to token exchange failure try (final WebClient webClient = createWebClient()) { HtmlPage page = webClient.getPage("http://localhost:8081/web-app/callback-before-redirect?tenantId"); assertEquals("Log in to quarkus", page.getTitleText()); HtmlForm loginForm = page.getForms().get(0); loginForm.getInputByName("username").setValueAttribute("alice"); loginForm.getInputByName("password").setValueAttribute("alice"); try { page = loginForm.getInputByName("login").click(); fail("401 status error is expected: " + page.getBody().asText()); } catch (FailingHttpStatusCodeException ex) { assertEquals(401, ex.getStatusCode()); } webClient.getCookieManager().clearCookies(); } }
Example #5
Source File: CodeFlowTest.java From quarkus with Apache License 2.0 | 6 votes |
@Test public void testAuthenticationCompletionFailedNoStateCookie() throws IOException, InterruptedException { // tenant-3 configuration uses a '/some/other/path' redirect parameter which does not have the same root // as the original request which is 'web-app', as a result, when the user is returned back to Quarkus // to '/some/other/path' no state cookie is detected. try (final WebClient webClient = createWebClient()) { HtmlPage page = webClient.getPage("http://localhost:8081/web-app/callback-before-redirect?tenantId=tenant-3"); assertEquals("Log in to quarkus", page.getTitleText()); HtmlForm loginForm = page.getForms().get(0); loginForm.getInputByName("username").setValueAttribute("alice"); loginForm.getInputByName("password").setValueAttribute("alice"); try { loginForm.getInputByName("login").click(); fail("401 status error is expected"); } catch (FailingHttpStatusCodeException ex) { assertEquals(401, ex.getStatusCode()); } webClient.getCookieManager().clearCookies(); } }
Example #6
Source File: CodeFlowTest.java From quarkus with Apache License 2.0 | 6 votes |
@Test public void testIdTokenInjectionJwtMethodButPostMethodUsed() throws IOException, InterruptedException { try (final WebClient webClient = createWebClient()) { HtmlPage page = webClient.getPage("http://localhost:8081/web-app/callback-jwt-not-used-before-redirect"); assertNotNull(getStateCookieStateParam(webClient, "tenant-jwt-not-used")); assertNull(getStateCookieSavedPath(webClient, "tenant-jwt-not-used")); assertEquals("Log in to quarkus", page.getTitleText()); HtmlForm loginForm = page.getForms().get(0); loginForm.getInputByName("username").setValueAttribute("alice"); loginForm.getInputByName("password").setValueAttribute("alice"); try { loginForm.getInputByName("login").click(); fail("401 status error is expected"); } catch (FailingHttpStatusCodeException ex) { assertEquals(401, ex.getStatusCode()); } webClient.getCookieManager().clearCookies(); } }
Example #7
Source File: CsrfIT.java From krazo with Apache License 2.0 | 6 votes |
/** * Retrieves a form, removes CSRF hidden field and attempts to submit. Should * result in a 403 error. * * @throws Exception an error occurs or validation fails. */ @Test public void testFormFail() throws Exception { HtmlPage page1 = webClient.getPage(webUrl + "resources/csrf"); HtmlForm form = (HtmlForm) page1.getDocumentElement().getElementsByTagName("form").get(0); // Remove hidden input field to cause a CSRF validation failure HtmlElement input = form.getElementsByTagName("input").get(1); form.removeChild(input); // Submit form - should fail HtmlSubmitInput button = (HtmlSubmitInput) form.getElementsByTagName("input").get(0); try { button.click(); fail("CSRF validation should have failed!"); } catch (FailingHttpStatusCodeException e) { // falls through } }
Example #8
Source File: CsrfIT.java From ozark with Apache License 2.0 | 6 votes |
/** * Retrieves a form, removes CSRF hidden field and attempts to submit. Should * result in a 403 error. * * @throws Exception an error occurs or validation fails. */ @Test public void testFormFail() throws Exception { HtmlPage page1 = webClient.getPage(webUrl + "resources/csrf"); HtmlForm form = (HtmlForm) page1.getDocumentElement().getHtmlElementsByTagName("form").get(0); // Remove hidden input field to cause a CSRF validation failure HtmlElement input = form.getHtmlElementsByTagName("input").get(1); form.removeChild(input); // Submit form - should fail HtmlSubmitInput button = (HtmlSubmitInput) form.getHtmlElementsByTagName("input").get(0); try { button.click(); fail("CSRF validation should have failed!"); } catch (FailingHttpStatusCodeException e) { // falls through } }
Example #9
Source File: ValidationIT.java From krazo with Apache License 2.0 | 6 votes |
@Test public void testFormControllerFail() throws Exception { final HtmlPage page = webClient.getPage(webUrl); final HtmlForm form = page.getFormByName("form"); final HtmlTextInput name = form.getInputByName("name"); final HtmlTextInput age = form.getInputByName("age"); final HtmlSubmitInput button = form.getInputByName("button"); name.setValueAttribute("john"); age.setValueAttribute("2"); // Not old enough! try { button.click(); fail("Validation error expected in form submission"); } catch (FailingHttpStatusCodeException e) { assertTrue(e.getStatusCode() == 400); assertTrue(e.getResponse().getContentAsString().contains("<h1>Form Error</h1>")); assertTrue(e.getResponse().getContentAsString().contains("<p>Param: age</p>")); } }
Example #10
Source File: DoubleEquivalenceSubmissionTest.java From CodeDefenders with GNU Lesser General Public License v3.0 | 6 votes |
public void acceptEquivalence(int gameId) throws FailingHttpStatusCodeException, MalformedURLException, IOException { // http://localhost:8080/multiplayer/ HtmlPage playPage = browser.getPage("http://localhost:8080" + Paths.BATTLEGROUND_GAME + "?gameId=" + gameId); HtmlAnchor acceptEquivalenceLink = null; for (HtmlAnchor a : playPage.getAnchors()) { if (a.getHrefAttribute().contains(Paths.BATTLEGROUND_GAME + "?acceptEquivalent=")) { acceptEquivalenceLink = a; break; } } if (!acceptEquivalenceLink.getHrefAttribute().startsWith("http://localhost:8080/")) { acceptEquivalenceLink.setAttribute("href", "http://localhost:8080/" + acceptEquivalenceLink.getHrefAttribute()); } System.out.println( "DoubleEquivalenceSubmissionTest.HelperUser.acceptEquivalence() Accepting equivalence on game " + gameId); acceptEquivalenceLink.click(); }
Example #11
Source File: DoubleEquivalenceSubmissionTest.java From CodeDefenders with GNU Lesser General Public License v3.0 | 6 votes |
public void claimEquivalenceOnLine(int gameId, int line) throws FailingHttpStatusCodeException, MalformedURLException, IOException { HtmlPage playPage = browser.getPage("http://localhost:8080" + Paths.BATTLEGROUND_GAME + "?gameId=" + gameId); HtmlAnchor claimEquivalenceLink = null; for (HtmlAnchor a : playPage.getAnchors()) { if (a.getHrefAttribute().contains(Paths.BATTLEGROUND_GAME + "?equivLines=" + line)) { claimEquivalenceLink = a; break; } } if (!claimEquivalenceLink.getHrefAttribute().startsWith("http://localhost:8080/")) { claimEquivalenceLink.setAttribute("href", "http://localhost:8080/" + claimEquivalenceLink.getHrefAttribute()); } claimEquivalenceLink.click(); }
Example #12
Source File: DoubleEquivalenceSubmissionTest.java From CodeDefenders with GNU Lesser General Public License v3.0 | 6 votes |
public void attack(int gameId, String mutant) throws FailingHttpStatusCodeException, IOException { WebRequest attackRequest = new WebRequest(new URL("http://localhost:8080" + Paths.BATTLEGROUND_GAME), HttpMethod.POST); // // Then we set the request parameters attackRequest.setRequestParameters(Arrays.asList(new NameValuePair[] { new NameValuePair("formType", "createMutant"), new NameValuePair("gameId", "" + gameId), // TODO Encoded somehow ? new NameValuePair("mutant", "" + mutant) })); // curl -X POST \ // --data "formType=createMutant&gameId=${gameId}" \ // --data-urlencode mutant@${mutant} \ // --cookie "${cookie}" --cookie-jar "${cookie}" \ // -w @curl-format.txt \ // -s ${CODE_DEFENDER_URL}/multiplayergame browser.getPage(attackRequest); }
Example #13
Source File: DoubleEquivalenceSubmissionTest.java From CodeDefenders with GNU Lesser General Public License v3.0 | 6 votes |
public void joinOpenGame(int gameID, boolean isAttacker) throws FailingHttpStatusCodeException, IOException { HtmlPage openGames = browser.getPage("http://localhost:8080" + Paths.GAMES_OVERVIEW); // Really we can simply click on that link once we know the gameID, // no need to go to openGame page HtmlAnchor joinLink = null; for (HtmlAnchor a : openGames.getAnchors()) { if (a.getHrefAttribute().contains( Paths.BATTLEGROUND_GAME + "?" + ((isAttacker) ? "attacker" : "defender") + "=1&gameId=" + gameID)) { joinLink = a; break; } } if (!joinLink.getHrefAttribute().startsWith("http://localhost:8080/")) { joinLink.setAttribute("href", "http://localhost:8080/" + joinLink.getHrefAttribute()); } HtmlPage page = joinLink.click(); }
Example #14
Source File: HelperUser.java From CodeDefenders with GNU Lesser General Public License v3.0 | 6 votes |
/** * Returns the landing HtmlPage after joining the game * * @param gameID * @param isAttacker * @return * @throws FailingHttpStatusCodeException * @throws IOException */ public HtmlPage joinOpenGame(int gameID, boolean isAttacker) throws FailingHttpStatusCodeException, IOException { HtmlPage openGames = browser.getPage(codedefendersHome + Paths.GAMES_OVERVIEW); // Really we can simply click on that link once we know the gameID, // no need to go to openGame page HtmlAnchor joinLink = null; for (HtmlAnchor a : openGames.getAnchors()) { if (a.getHrefAttribute() .contains(Paths.BATTLEGROUND_GAME + "?" + ((isAttacker) ? "attacker" : "defender") + "=1&gameId=" + gameID)) { joinLink = a; break; } } if (!joinLink.getHrefAttribute().startsWith(codedefendersHome + "/")) { joinLink.setAttribute("href", codedefendersHome + "/" + joinLink.getHrefAttribute()); } return joinLink.click(); }
Example #15
Source File: QuestionnairResourceInServletTest.java From gazpachoquest with GNU General Public License v3.0 | 6 votes |
@Test public void listTest() throws FailingHttpStatusCodeException, MalformedURLException, IOException { final WebClient webClient = new WebClient(); webClient.addRequestHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP // 1.1. webClient.addRequestHeader("Pragma", "no-cache"); // HTTP 1.0. webClient.addRequestHeader("Expires", "0"); // final HtmlPage page = webClient.getPage(contextPath.toExternalForm() + "/testServlet"); final String pageAsText = page.asText(); System.out.println(pageAsText); webClient.closeAllWindows(); }
Example #16
Source File: HelperUser.java From CodeDefenders with GNU Lesser General Public License v3.0 | 6 votes |
public void attack(int gameId, String mutant) throws FailingHttpStatusCodeException, IOException { WebRequest attackRequest = new WebRequest(new URL(codedefendersHome + Paths.BATTLEGROUND_GAME), HttpMethod.POST); // // Then we set the request parameters attackRequest.setRequestParameters(Arrays.asList(new NameValuePair[] { new NameValuePair("formType", "createMutant"), new NameValuePair("gameId", "" + gameId), // TODO Encoded somehow ? new NameValuePair("mutant", "" + mutant) })); // curl -X POST \ // --data "formType=createMutant&gameId=${gameId}" \ // --data-urlencode mutant@${mutant} \ // --cookie "${cookie}" --cookie-jar "${cookie}" \ // -w @curl-format.txt \ // -s ${CODE_DEFENDER_URL}/multiplayergame browser.getPage(attackRequest); }
Example #17
Source File: ValidationIT.java From ozark with Apache License 2.0 | 6 votes |
@Test public void testFormControllerPropertyFail() throws Exception { final HtmlPage page = webClient.getPage(webUrl + "indexprop.html"); final HtmlForm form = page.getFormByName("form"); final HtmlTextInput name = form.getInputByName("name"); final HtmlTextInput age = form.getInputByName("age"); final HtmlSubmitInput button = form.getInputByName("button"); name.setValueAttribute("john"); age.setValueAttribute("2"); // Not old enough! try { button.click(); fail("Validation error expected in form submission"); } catch (FailingHttpStatusCodeException e) { assertTrue(e.getStatusCode() == 400); assertTrue(e.getResponse().getContentAsString().contains("<h1>Form Error</h1>")); assertTrue(e.getResponse().getContentAsString().contains("<p>Param: age</p>")); } }
Example #18
Source File: BaseFrameElement.java From htmlunit with Apache License 2.0 | 6 votes |
private void init() { FrameWindow enclosedWindow = null; try { final HtmlPage htmlPage = getHtmlPageOrNull(); if (null != htmlPage) { // if loaded as part of XHR.responseXML, don't load content enclosedWindow = new FrameWindow(this); // put about:blank in the window to allow JS to run on this frame before the // real content is loaded final WebClient webClient = htmlPage.getWebClient(); final HtmlPage temporaryPage = webClient.getPage(enclosedWindow, WebRequest.newAboutBlankRequest()); temporaryPage.setReadyState(READY_STATE_LOADING); } } catch (final FailingHttpStatusCodeException | IOException e) { // should never occur } enclosedWindow_ = enclosedWindow; }
Example #19
Source File: HelperUser.java From CodeDefenders with GNU Lesser General Public License v3.0 | 6 votes |
public void acceptEquivalence(int gameId) throws FailingHttpStatusCodeException, MalformedURLException, IOException { // codedefendersHome+"/multiplayer/ HtmlPage playPage = browser.getPage(codedefendersHome + "" + Paths.BATTLEGROUND_GAME + "?gameId=" + gameId); HtmlAnchor acceptEquivalenceLink = null; for (HtmlAnchor a : playPage.getAnchors()) { if (a.getHrefAttribute().contains(Paths.BATTLEGROUND_GAME + "?acceptEquivalent=")) { acceptEquivalenceLink = a; break; } } if (!acceptEquivalenceLink.getHrefAttribute().startsWith(codedefendersHome + "/")) { acceptEquivalenceLink.setAttribute("href", codedefendersHome + "/" + acceptEquivalenceLink.getHrefAttribute()); } System.out .println("DoubleEquivalenceSubmissionTest.HelperUser.acceptEquivalence() Accepting equivalence on game " + gameId); acceptEquivalenceLink.click(); }
Example #20
Source File: DoubleEquivalenceSubmissionTest.java From CodeDefenders with GNU Lesser General Public License v3.0 | 5 votes |
public void assertNoMoreEquivalenceDuels(int gameId) throws FailingHttpStatusCodeException, MalformedURLException, IOException { HtmlPage playPage = browser.getPage("http://localhost:8080" + Paths.BATTLEGROUND_GAME + "?gameId=" + gameId); for (HtmlAnchor a : playPage.getAnchors()) { if (a.getHrefAttribute().contains(Paths.BATTLEGROUND_GAME + "?acceptEquivalent=")) { Assert.fail("On game " + gameId + " there is still an equivalence duel open"); } } }
Example #21
Source File: IdpTest.java From cxf-fediz with Apache License 2.0 | 5 votes |
@org.junit.Test public void testMissingRelayState() throws Exception { OpenSAMLUtil.initSamlEngine(); // Create SAML AuthnRequest String consumerURL = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet"; AuthnRequest authnRequest = new DefaultAuthnRequestBuilder().createAuthnRequest( null, "urn:org:apache:cxf:fediz:fedizhelloworld", consumerURL ); authnRequest.setDestination("https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml"); signAuthnRequest(authnRequest); String authnRequestEncoded = encodeAuthnRequest(authnRequest); String url = "https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml?" + SSOConstants.SAML_REQUEST + "=" + URLEncoder.encode(authnRequestEncoded, UTF_8.name()); final WebClient webClient = new WebClient(); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(USER, PWD)); webClient.getOptions().setJavaScriptEnabled(false); try { webClient.getPage(url); Assert.fail("Failure expected on not sending the RelayState"); } catch (FailingHttpStatusCodeException ex) { Assert.assertEquals(ex.getStatusCode(), 400); } webClient.close(); }
Example #22
Source File: IdpTest.java From cxf-fediz with Apache License 2.0 | 5 votes |
@org.junit.Test public void testBadWReply() throws Exception { String url = "https://localhost:" + getIdpHttpsPort() + "/fediz-idp/federation?"; url += "wa=wsignin1.0"; url += "&whr=urn:org:apache:cxf:fediz:idp:realm-A"; url += "&wtrealm=urn:org:apache:cxf:fediz:fedizhelloworld"; String wreply = "https://www.apache.org:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet"; url += "&wreply=" + wreply; String user = "alice"; String password = "ecila"; final WebClient webClient = new WebClient(); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); try { webClient.getPage(url); Assert.fail("Failure expected on a bad wreply value"); } catch (FailingHttpStatusCodeException ex) { Assert.assertEquals(ex.getStatusCode(), 400); } webClient.close(); }
Example #23
Source File: IdpTest.java From cxf-fediz with Apache License 2.0 | 5 votes |
@org.junit.Test public void testWReplyExactMatchingFailure() throws Exception { String url = "https://localhost:" + getIdpHttpsPort() + "/fediz-idp/federation?"; url += "wa=wsignin1.0"; url += "&whr=urn:org:apache:cxf:fediz:idp:realm-A"; url += "&wtrealm=urn:org:apache:cxf:fediz:fedizhelloworld3"; String wreply = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet/blah"; url += "&wreply=" + wreply; String user = "alice"; String password = "ecila"; final WebClient webClient = new WebClient(); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); try { webClient.getPage(url); Assert.fail("Failure expected on a bad wreply value"); } catch (FailingHttpStatusCodeException ex) { Assert.assertEquals(ex.getStatusCode(), 400); } webClient.close(); }
Example #24
Source File: AbstractOIDCTest.java From cxf-fediz with Apache License 2.0 | 5 votes |
@org.junit.Test public void testIncorrectRedirectURI() throws Exception { final UriBuilder authorizationUrl = oidcEndpointBuilder("/idp/authorize") .queryParam("client_id", confidentialClientId) .queryParam("response_type", "code") .queryParam("scope", "openid") .queryParam("redirect_uri", "https://127.0.0.5"); // Login to the OIDC token endpoint + get the authorization code try { loginAndGetAuthorizationCode(authorizationUrl, "alice", "ecila"); } catch (FailingHttpStatusCodeException e) { assertEquals(Status.BAD_REQUEST.getStatusCode(), e.getStatusCode()); } }
Example #25
Source File: DoubleEquivalenceSubmissionTest.java From CodeDefenders with GNU Lesser General Public License v3.0 | 5 votes |
public void assertThereIsAnEquivalenceDuel(int gameId) throws FailingHttpStatusCodeException, MalformedURLException, IOException { HtmlPage playPage = browser.getPage("http://localhost:8080" + Paths.BATTLEGROUND_GAME + "?gameId=" + gameId); for (HtmlAnchor a : playPage.getAnchors()) { if (a.getHrefAttribute().contains(Paths.BATTLEGROUND_GAME + "?acceptEquivalent=")) { return; } } Assert.fail("On game " + gameId + " there is no equivalence duels open"); }
Example #26
Source File: IdpTest.java From cxf-fediz with Apache License 2.0 | 5 votes |
@org.junit.Test public void testEntityExpansionWReq() throws Exception { String url = "https://localhost:" + getIdpHttpsPort() + "/fediz-idp/federation?"; url += "wa=wsignin1.0"; url += "&whr=urn:org:apache:cxf:fediz:idp:realm-A"; url += "&wtrealm=urn:org:apache:cxf:fediz:fedizhelloworld"; String wreply = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet"; url += "&wreply=" + wreply; String currentDir = new File(".").getCanonicalPath(); File f = new File(currentDir + "/src/test/resources/entity_wreq.xml"); String entity = new String(Files.readAllBytes(f.toPath()), "UTF-8"); String validWreq = "<RequestSecurityToken xmlns=\"http://docs.oasis-open.org/ws-sx/ws-trust/200512\">" + "<TokenType>&m;http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0</TokenType>" + "</RequestSecurityToken>"; url += "&wreq=" + URLEncoder.encode(entity + validWreq, "UTF-8"); String user = "alice"; String password = "ecila"; final WebClient webClient = new WebClient(); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); try { webClient.getPage(url); Assert.fail("Failure expected on a bad wreq value"); } catch (FailingHttpStatusCodeException ex) { Assert.assertEquals(ex.getStatusCode(), 400); } webClient.close(); }
Example #27
Source File: AbstractTests.java From cxf-fediz with Apache License 2.0 | 5 votes |
@Test public void testAliceManagerNoAccess() throws Exception { String url = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/manager/fedservlet"; String user = "alice"; String password = "ecila"; try { HTTPTestUtils.login(url, user, password, getIdpHttpsPort(), getLoginFormName()); Assert.fail("Exception expected"); } catch (FailingHttpStatusCodeException ex) { Assert.assertEquals(ex.getStatusCode(), 403); } }
Example #28
Source File: DoubleEquivalenceSubmissionTest.java From CodeDefenders with GNU Lesser General Public License v3.0 | 5 votes |
public void startGame(int gameID) throws FailingHttpStatusCodeException, IOException { WebRequest startGameRequest = new WebRequest(new URL("http://localhost:8080" + Paths.BATTLEGROUND_GAME), HttpMethod.POST); // // Then we set the request parameters startGameRequest.setRequestParameters(Arrays.asList(new NameValuePair[] { new NameValuePair("formType", "startGame"), new NameValuePair("gameId", "" + gameID) })); // Finally, we can get the page // Not sure why this returns TextPage and not HtmlPage browser.getPage(startGameRequest); }
Example #29
Source File: DoubleEquivalenceSubmissionTest.java From CodeDefenders with GNU Lesser General Public License v3.0 | 5 votes |
public void doLogin() throws FailingHttpStatusCodeException, IOException { WebRequest loginRequest = new WebRequest(new URL("http://localhost:8080"+ Paths.LOGIN), HttpMethod.POST); // // Then we set the request parameters loginRequest.setRequestParameters(Arrays.asList(new NameValuePair[] { new NameValuePair("formType", "login"), new NameValuePair("username", user.getUsername()), new NameValuePair("password", password), })); // Finally, we can get the page HtmlPage retunToGamePage = browser.getPage(loginRequest); }
Example #30
Source File: HelperUser.java From CodeDefenders with GNU Lesser General Public License v3.0 | 5 votes |
public void assertThereIsAnEquivalenceDuel(int gameId) throws FailingHttpStatusCodeException, MalformedURLException, IOException { HtmlPage playPage = browser.getPage(codedefendersHome + "" + Paths.BATTLEGROUND_GAME + "?gameId=" + gameId); for (HtmlAnchor a : playPage.getAnchors()) { if (a.getHrefAttribute().contains(Paths.BATTLEGROUND_GAME + "?acceptEquivalent=")) { return; } } Assert.fail("On game " + gameId + " there is no equivalence duels open"); }