From f6149597fb8ae4d3475f5c2f33ab1ffbe3345f34 Mon Sep 17 00:00:00 2001 From: spriadka Date: Wed, 6 Mar 2019 14:11:13 +0100 Subject: [PATCH] added testEmptyUsername to FormMechTestBase --- .../elytron/http/FormMechTestBase.java | 20 +++++++++++++ .../elytron/http/FormMechTestCase.java | 29 ------------------- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/testsuite/integration/elytron/src/test/java/org/wildfly/test/integration/elytron/http/FormMechTestBase.java b/testsuite/integration/elytron/src/test/java/org/wildfly/test/integration/elytron/http/FormMechTestBase.java index 709b3de5f7a7..e9d69ade8c90 100644 --- a/testsuite/integration/elytron/src/test/java/org/wildfly/test/integration/elytron/http/FormMechTestBase.java +++ b/testsuite/integration/elytron/src/test/java/org/wildfly/test/integration/elytron/http/FormMechTestBase.java @@ -167,6 +167,26 @@ public void testInvalidCredential() throws Exception { } } + @Test + public void testEmptyUsername() throws Exception { + try (CloseableHttpClient httpClient = HttpClientBuilder.create().disableRedirectHandling().build()) { + HttpPost emptyUsernameRequest = createLoginRequest("", "non-empty-password"); + try (CloseableHttpResponse response = httpClient.execute(emptyUsernameRequest)) { + int statusCode = response.getStatusLine().getStatusCode(); + assertEquals("Unexpected status code in HTTP response.", SC_OK, statusCode); + assertEquals("Unexpected content of HTTP response.", ERROR_PAGE_CONTENT, + EntityUtils.toString(response.getEntity())); + } + HttpPost emptyUsernameAndPasswordLoginRequest = createLoginRequest("", ""); + try (CloseableHttpResponse response = httpClient.execute(emptyUsernameAndPasswordLoginRequest)) { + int statusCode = response.getStatusLine().getStatusCode(); + assertEquals("Unexpected status code in HTTP response.", SC_OK, statusCode); + assertEquals("Unexpected content of HTTP response.", ERROR_PAGE_CONTENT, + EntityUtils.toString(response.getEntity())); + } + } + } + protected HttpPost createLoginRequest(String username, String password) throws Exception { HttpPost request = new HttpPost(new URI(url.toExternalForm() + "j_security_check")); diff --git a/testsuite/integration/elytron/src/test/java/org/wildfly/test/integration/elytron/http/FormMechTestCase.java b/testsuite/integration/elytron/src/test/java/org/wildfly/test/integration/elytron/http/FormMechTestCase.java index 0b050910f15b..cfa9583ca1b7 100644 --- a/testsuite/integration/elytron/src/test/java/org/wildfly/test/integration/elytron/http/FormMechTestCase.java +++ b/testsuite/integration/elytron/src/test/java/org/wildfly/test/integration/elytron/http/FormMechTestCase.java @@ -22,11 +22,6 @@ package org.wildfly.test.integration.elytron.http; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.util.EntityUtils; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; @@ -37,13 +32,9 @@ import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.junit.Test; import org.junit.runner.RunWith; import org.wildfly.test.security.common.elytron.MechanismConfiguration; -import static org.apache.http.HttpStatus.SC_OK; -import static org.junit.Assert.assertEquals; - /** * Test of FORM HTTP mechanism. * @@ -73,24 +64,4 @@ public static WebArchive createDeployment() { .addAsWebInfResource(FormMechTestCase.class.getPackage(), NAME + "-web.xml", "web.xml"); } - @Test - public void testEmptyUsername() throws Exception { - try (CloseableHttpClient httpClient = HttpClientBuilder.create().disableRedirectHandling().build()) { - HttpPost emptyUsernameRequest = createLoginRequest("", "non-empty-password"); - try (CloseableHttpResponse response = httpClient.execute(emptyUsernameRequest)) { - int statusCode = response.getStatusLine().getStatusCode(); - assertEquals("Unexpected status code in HTTP response.", SC_OK, statusCode); - assertEquals("Unexpected content of HTTP response.", ERROR_PAGE_CONTENT, - EntityUtils.toString(response.getEntity())); - } - HttpPost emptyUsernameAndPasswordLoginRequest = createLoginRequest("", ""); - try (CloseableHttpResponse response = httpClient.execute(emptyUsernameAndPasswordLoginRequest)) { - int statusCode = response.getStatusLine().getStatusCode(); - assertEquals("Unexpected status code in HTTP response.", SC_OK, statusCode); - assertEquals("Unexpected content of HTTP response.", ERROR_PAGE_CONTENT, - EntityUtils.toString(response.getEntity())); - } - } - } - }