use of io.gravitee.am.common.event.EventManager in project gravitee-access-management by gravitee-io.
the class SocialAuthenticationProviderTest method shouldAuthenticateUser.
@Test
public void shouldAuthenticateUser() throws Exception {
JsonObject credentials = new JsonObject();
credentials.put("username", "my-user-id");
credentials.put("password", "my-user-password");
credentials.put("provider", "idp");
credentials.put("additionalParameters", Collections.emptyMap());
io.gravitee.am.identityprovider.api.User user = new io.gravitee.am.identityprovider.api.DefaultUser("username");
Client client = new Client();
when(userAuthenticationManager.connect(any())).thenReturn(Single.just(new User()));
when(authenticationProvider.loadUserByUsername(any(EndUserAuthentication.class))).thenReturn(Maybe.just(user));
when(routingContext.get("client")).thenReturn(client);
when(routingContext.get("provider")).thenReturn(authenticationProvider);
when(routingContext.get("providerId")).thenReturn("idp");
when(routingContext.request()).thenReturn(httpServerRequest);
final io.vertx.core.http.HttpServerRequest delegateRequest = mock(io.vertx.core.http.HttpServerRequest.class);
when(httpServerRequest.getDelegate()).thenReturn(delegateRequest);
when(delegateRequest.method()).thenReturn(HttpMethod.POST);
CountDownLatch latch = new CountDownLatch(1);
authProvider.authenticate(routingContext, credentials, userAsyncResult -> {
latch.countDown();
Assert.assertNotNull(userAsyncResult);
Assert.assertNotNull(userAsyncResult.result());
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
verify(userAuthenticationManager, times(1)).connect(any());
verify(eventManager).publishEvent(argThat(evt -> evt == AuthenticationEvent.SUCCESS), any());
}
Aggregations