use of org.wildfly.test.integration.elytron.util.ClientConfigProviderNoBasicAuthorizationHeaderFilter in project wildfly by wildfly.
the class BasicAuthnTestCase method testClientConfigProviderUsernameWithoutPasswordWillBeIgnored.
/**
* Test that access credentials from ClientConfigProvider are used only if both username and password are present.
*/
@Test
public void testClientConfigProviderUsernameWithoutPasswordWillBeIgnored(@ArquillianResource URL url) throws MalformedURLException {
final URL servletUrl = new URL(url.toExternalForm() + "role1");
AuthenticationConfiguration adminConfig = AuthenticationConfiguration.empty().useName("thisNameWillBeIgnoredBecausePasswordIsMissing");
AuthenticationContext context = AuthenticationContext.empty();
context = context.with(MatchRule.ALL, adminConfig);
context.run(() -> {
ClientBuilder builder = ClientBuilder.newBuilder();
Client client = builder.build();
client.register(new ClientConfigProviderNoBasicAuthorizationHeaderFilter(), Priorities.USER);
try {
client.target(servletUrl.toString()).request().get();
} catch (Exception e) {
assertTrue(e.getMessage().contains("The request authorization header is not correct expected:<Bearer myTestToken> but was:<null>"));
client.close();
}
Response response = builder.build().target(servletUrl.toString()).request().get();
Assert.assertEquals(SC_UNAUTHORIZED, response.getStatus());
client.close();
});
}
Aggregations