use of io.helidon.security.AuthenticationResponse in project helidon by oracle.
the class HttpAuthProviderBuilderTest method sendInvalidDigestTest.
@Test
public void sendInvalidDigestTest() {
setHeader(context, HttpBasicAuthProvider.HEADER_AUTHENTICATION, "digest wrong_header_value");
AuthenticationResponse response = context.atnClientBuilder().explicitProvider("digest").buildAndGet();
assertThat(response.status(), is(SecurityResponse.SecurityStatus.FAILURE));
assertThat(response.statusCode().orElse(200), is(401));
}
use of io.helidon.security.AuthenticationResponse in project helidon by oracle.
the class HttpAuthProviderBuilderTest method digestTestInvalidUser.
@Test
public void digestTestInvalidUser() {
setHeader(context, HttpBasicAuthProvider.HEADER_AUTHENTICATION, buildDigest(HttpDigest.Qop.AUTH, "wrong", "user"));
AuthenticationResponse response = context.atnClientBuilder().explicitProvider("digest").buildAndGet();
assertThat(response.description().orElse(""), is("Invalid username or password"));
assertThat(response.status().isSuccess(), is(false));
assertThat(response.statusCode().orElse(200), is(401));
String authHeader = response.responseHeaders().get(HttpBasicAuthProvider.HEADER_AUTHENTICATION_REQUIRED).get(0);
assertThat(authHeader, notNullValue());
assertThat(authHeader.toLowerCase(), startsWith("digest realm=\"mic\""));
setHeader(context, HttpBasicAuthProvider.HEADER_AUTHENTICATION, buildDigest(HttpDigest.Qop.AUTH, "jack", "wrong password"));
response = context.atnClientBuilder().explicitProvider("digest").buildAndGet();
assertThat(response.description().orElse(""), is("Invalid username or password"));
assertThat(response.status().isSuccess(), is(false));
assertThat(response.statusCode().orElse(200), is(401));
}
use of io.helidon.security.AuthenticationResponse in project helidon by oracle.
the class HttpAuthProviderBuilderTest method basicTestJack.
@Test
public void basicTestJack() {
setHeader(context, HttpBasicAuthProvider.HEADER_AUTHENTICATION, buildBasic("jack", "jackIsGreat"));
AuthenticationResponse response = context.authenticate();
assertThat(response.status(), is(SecurityResponse.SecurityStatus.SUCCESS));
assertThat(response.statusCode().orElse(200), is(200));
assertThat(context.user().map(sub -> sub.principal().getName()).orElse(null), is("jack"));
assertThat(context.isUserInRole("admin"), is(true));
assertThat(context.isUserInRole("user"), is(true));
}
use of io.helidon.security.AuthenticationResponse in project helidon by oracle.
the class HttpAuthProviderBuilderTest method digestTestOptional.
@Test
public void digestTestOptional() {
AuthenticationResponse response = context.atnClientBuilder().explicitProvider("digest_optional").buildAndGet();
assertThat(response.status().isSuccess(), is(false));
assertThat(response.status().name(), is(SecurityResponse.SecurityStatus.ABSTAIN.name()));
assertThat(response.statusCode().orElse(200), is(200));
assertThat(response.description().orElse(""), is("No authorization header"));
setHeader(context, HttpBasicAuthProvider.HEADER_AUTHENTICATION, buildDigest(HttpDigest.Qop.AUTH, "wrong", "user"));
response = context.atnClientBuilder().explicitProvider("digest_optional").buildAndGet();
assertThat(response.status().isSuccess(), is(false));
assertThat(response.status().name(), is(SecurityResponse.SecurityStatus.ABSTAIN.name()));
assertThat(response.statusCode().orElse(200), is(200));
assertThat(response.description().orElse(""), is("Invalid username or password"));
}
use of io.helidon.security.AuthenticationResponse in project helidon by oracle.
the class HttpAuthProviderBuilderTest method digestTestNonceTimeout.
@Test
public void digestTestNonceTimeout() {
Instant in = Instant.now().minus(100, ChronoUnit.DAYS);
setHeader(context, HttpBasicAuthProvider.HEADER_AUTHENTICATION, buildDigest(HttpDigest.Qop.AUTH, "jack", "jackIsGreat", HttpDigestAuthProvider.nonce(in.toEpochMilli(), random, "pwd".toCharArray()), "mic"));
AuthenticationResponse response = context.atnClientBuilder().explicitProvider("digest").buildAndGet();
assertThat(response.description().orElse(""), is("Nonce timeout"));
assertThat(response.status(), is(SecurityResponse.SecurityStatus.FAILURE));
assertThat(response.statusCode().orElse(200), is(401));
}
Aggregations