Skip to content

Commit

Permalink
added testEmptyUsername to FormMechTestBase
Browse files Browse the repository at this point in the history
  • Loading branch information
spriadka committed Mar 6, 2019
1 parent 1fd929c commit f614959
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
Expand Up @@ -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"));
Expand Down
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -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()));
}
}
}

}

0 comments on commit f614959

Please sign in to comment.