KEYCLOAK-5821 Fix basic auth tests with embedded Undertow

This commit is contained in:
Stian Thorgersen 2017-11-13 15:39:10 +01:00 committed by Stian Thorgersen
parent 5d8f449ea0
commit d30bf938ee
2 changed files with 5 additions and 8 deletions

View file

@ -46,14 +46,11 @@ public class BasicAuth extends AbstractPageWithInjectedUrl {
@Override @Override
public UriBuilder createUriBuilder() { public UriBuilder createUriBuilder() {
return super.createUriBuilder() return super.createUriBuilder()
.userInfo("{user}:{password}")
.path("basic-auth") .path("basic-auth")
.queryParam("value", "{value}"); .queryParam("value", "{value}");
} }
public BasicAuth setTemplateValues(String user, String password, String value) { public BasicAuth setTemplateValues(String value) {
setUriParameter("user", user);
setUriParameter("password", password);
setUriParameter("value", value); setUriParameter("value", value);
return this; return this;
} }

View file

@ -576,24 +576,24 @@ public abstract class AbstractDemoServletsAdapterTest extends AbstractServletsAd
@Test @Test
public void testBasicAuth() { public void testBasicAuth() {
String value = "hello"; String value = "hello";
Client client = ClientBuilder.newClient(); Client client = ClientBuilder.newBuilder().newClient();
//pause(1000000); //pause(1000000);
Response response = client.target(basicAuthPage Response response = client.target(basicAuthPage
.setTemplateValues("mposolda", "password", value).buildUri()).request().get(); .setTemplateValues(value).buildUri()).request().header("Authorization", BasicAuthHelper.createHeader("mposolda", "password")).get();
assertThat(response, Matchers.statusCodeIs(Status.OK)); assertThat(response, Matchers.statusCodeIs(Status.OK));
assertEquals(value, response.readEntity(String.class)); assertEquals(value, response.readEntity(String.class));
response.close(); response.close();
response = client.target(basicAuthPage response = client.target(basicAuthPage
.setTemplateValues("invalid-user", "password", value).buildUri()).request().get(); .setTemplateValues(value).buildUri()).request().header("Authorization", BasicAuthHelper.createHeader("invalid-user", "password")).get();
assertThat(response, Matchers.statusCodeIs(Status.UNAUTHORIZED)); assertThat(response, Matchers.statusCodeIs(Status.UNAUTHORIZED));
assertThat(response, Matchers.body(anyOf(containsString("Unauthorized"), containsString("Status 401")))); assertThat(response, Matchers.body(anyOf(containsString("Unauthorized"), containsString("Status 401"))));
response = client.target(basicAuthPage response = client.target(basicAuthPage
.setTemplateValues("admin", "invalid-password", value).buildUri()).request().get(); .setTemplateValues(value).buildUri()).request().header("Authorization", BasicAuthHelper.createHeader("admin", "invalid-password")).get();
assertThat(response, Matchers.statusCodeIs(Status.UNAUTHORIZED)); assertThat(response, Matchers.statusCodeIs(Status.UNAUTHORIZED));
assertThat(response, Matchers.body(anyOf(containsString("Unauthorized"), containsString("Status 401")))); assertThat(response, Matchers.body(anyOf(containsString("Unauthorized"), containsString("Status 401"))));