use of com.nexblocks.authguard.service.SessionsService in project AuthGuard by AuthGuard.
the class SessionProviderTest method generateForAccount.
@Test
void generateForAccount() {
final SessionsService sessionsService = Mockito.mock(SessionsService.class);
Mockito.when(sessionsService.create(any())).thenAnswer(invocation -> invocation.getArgument(0, SessionBO.class).withSessionToken("token"));
final SessionProvider sessionProvider = new SessionProvider(sessionsService, sessionsConfig());
final AccountBO account = AccountBO.builder().id("account-id").build();
final AuthResponseBO expected = AuthResponseBO.builder().type("session_token").entityType(EntityType.ACCOUNT).entityId(account.getId()).validFor(Duration.ofMinutes(20).getSeconds()).build();
final AuthResponseBO actual = sessionProvider.generateToken(account);
assertThat(actual).isEqualToIgnoringGivenFields(expected, "token");
assertThat(actual.getToken()).isNotNull().isInstanceOf(String.class);
}
use of com.nexblocks.authguard.service.SessionsService in project AuthGuard by AuthGuard.
the class SessionProviderTest method delete.
@Test
void delete() {
final SessionsService sessionsService = Mockito.mock(SessionsService.class);
final SessionProvider sessionProvider = new SessionProvider(sessionsService, sessionsConfig());
final String sessionToken = "session-token";
final String accountId = "account";
Mockito.when(sessionsService.deleteByToken(sessionToken)).thenReturn(Optional.of(SessionBO.builder().accountId(accountId).sessionToken(sessionToken).build()));
final AuthResponseBO expected = AuthResponseBO.builder().type("session_token").entityType(EntityType.ACCOUNT).entityId(accountId).token(sessionToken).build();
final AuthResponseBO actual = sessionProvider.delete(AuthRequestBO.builder().token(sessionToken).build());
assertThat(actual).isEqualTo(expected);
}
use of com.nexblocks.authguard.service.SessionsService in project AuthGuard by AuthGuard.
the class SessionProviderTest method generateForInactiveAccount.
@Test
void generateForInactiveAccount() {
final SessionsService sessionsService = Mockito.mock(SessionsService.class);
Mockito.when(sessionsService.create(any())).thenAnswer(invocation -> invocation.getArgument(0, SessionBO.class).withSessionToken("token"));
final SessionProvider sessionProvider = new SessionProvider(sessionsService, sessionsConfig());
final AccountBO account = AccountBO.builder().id("account-id").active(false).build();
assertThatThrownBy(() -> sessionProvider.generateToken(account)).isInstanceOf(ServiceAuthorizationException.class);
}
use of com.nexblocks.authguard.service.SessionsService in project AuthGuard by AuthGuard.
the class SessionVerifierTest method verifyNonExistingSession.
@Test
void verifyNonExistingSession() {
final SessionsService sessionsService = Mockito.mock(SessionsService.class);
final SessionVerifier sessionVerifier = new SessionVerifier(sessionsService);
Mockito.when(sessionsService.getByToken(any())).thenReturn(Optional.empty());
final Either<Exception, String> result = sessionVerifier.verifyAccountToken("invalid");
assertThat(result.isLeft());
assertThat(result.getLeft()).isInstanceOf(ServiceAuthorizationException.class);
}
use of com.nexblocks.authguard.service.SessionsService in project AuthGuard by AuthGuard.
the class OAuthServiceTest method setup.
@BeforeAll
void setup() {
testIdentityServer = new TestIdentityServer();
testIdentityServer.start();
clientConfiguration = ImmutableOAuthClientConfiguration.builder().provider("test").authUrl("http://localhost:" + testIdentityServer.getPort() + "/auth").tokenUrl("http://localhost:" + testIdentityServer.getPort() + "/token").authRedirectUrl("http://localhost/redirect").tokenRedirectUrl("http://localhost/redirect").clientId("unit-tests").clientSecret("secret").addDefaultScopes("openid", "profile").build();
accountProviderClientConfiguration = ImmutableOAuthClientConfiguration.builder().provider("account_test").authUrl("http://localhost:" + testIdentityServer.getPort() + "/auth").tokenUrl("http://localhost:" + testIdentityServer.getPort() + "/token").authRedirectUrl("http://localhost/redirect").tokenRedirectUrl("http://localhost/redirect").clientId("unit-tests").clientSecret("secret").addDefaultScopes("openid", "profile").accountProvider(true).emailField("email").build();
final ImmutableOAuthConfiguration oAuthConfiguration = ImmutableOAuthConfiguration.builder().addClients(clientConfiguration).addClients(accountProviderClientConfiguration).build();
sessionsService = Mockito.mock(SessionsService.class);
accountsService = Mockito.mock(AccountsService.class);
oAuthService = new OAuthService(oAuthConfiguration, sessionsService, accountsService);
}
Aggregations