use of com.nexblocks.authguard.dal.model.ApiKeyDO in project AuthGuard by AuthGuard.
the class ApiKeysServiceImplTest method getByAppId.
@Test
void getByAppId() {
final String appId = "app";
final String key = "key";
final ApiKeyBO apiKeyBO = ApiKeyBO.builder().appId(appId).key(key).build();
final ApiKeyDO apiKeyDO = serviceMapper.toDO(apiKeyBO);
Mockito.when(apiKeysRepository.getByAppId(appId)).thenReturn(CompletableFuture.completedFuture(Collections.singletonList(apiKeyDO)));
final List<ApiKeyBO> actual = apiKeysService.getByAppId(appId);
assertThat(actual).isEqualTo(Collections.singletonList(apiKeyBO));
}
use of com.nexblocks.authguard.dal.model.ApiKeyDO in project AuthGuard by AuthGuard.
the class DefaultApiKeyExchangeTest method verifyAndGetAppId.
@Test
void verifyAndGetAppId() {
final String key = "key";
final String hashedKey = apiKeyHashProvider.getHash().hash(key);
final String appId = "app";
final ApiKeyDO apiKeyDO = ApiKeyDO.builder().key(hashedKey).appId(appId).build();
Mockito.when(repository.getByKey(hashedKey)).thenReturn(CompletableFuture.completedFuture(Optional.of(apiKeyDO)));
final Optional<String> retrieved = exchange.verifyAndGetAppId(key).join();
assertThat(retrieved).contains(appId);
}
use of com.nexblocks.authguard.dal.model.ApiKeyDO in project AuthGuard by AuthGuard.
the class ApiKeysServiceImplTest method getById.
@Test
void getById() {
final String id = "api_key";
final ApiKeyBO apiKeyBO = ApiKeyBO.builder().id(id).build();
final ApiKeyDO apiKeyDO = ApiKeyDO.builder().id(id).build();
Mockito.when(apiKeysRepository.getById(id)).thenReturn(CompletableFuture.completedFuture(Optional.of(apiKeyDO)));
final Optional<ApiKeyBO> actual = apiKeysService.getById(id);
assertThat(actual).contains(apiKeyBO);
}
use of com.nexblocks.authguard.dal.model.ApiKeyDO in project AuthGuard by AuthGuard.
the class ApiKeysServiceImplTest method generateApiKey.
@Test
void generateApiKey() {
final String appId = "app";
final String key = "key";
final AppBO app = AppBO.builder().id(appId).build();
Mockito.when(applicationsService.getById(appId)).thenReturn(Optional.of(app));
Mockito.when(apiKeysRepository.save(Mockito.any())).thenAnswer(invocation -> CompletableFuture.completedFuture(invocation.getArgument(0, ApiKeyDO.class)));
Mockito.when(apiKeyExchange.generateKey(app)).thenReturn(AuthResponseBO.builder().token(key).build());
final ApiKeyBO actual = apiKeysService.generateApiKey(appId);
assertThat(actual.getAppId()).isEqualTo(appId);
assertThat(actual.getKey()).isEqualTo(key);
// verify that we persisted the hashed key and not the clear key
final ArgumentCaptor<ApiKeyDO> argumentCaptor = ArgumentCaptor.forClass(ApiKeyDO.class);
Mockito.verify(apiKeysRepository).save(argumentCaptor.capture());
final ApiKeyDO persisted = argumentCaptor.getValue();
assertThat(persisted.getKey()).isEqualTo(apiKeyHash.hash(key));
}
use of com.nexblocks.authguard.dal.model.ApiKeyDO in project AuthGuard by AuthGuard.
the class ApiKeysServiceImplTest method delete.
@Test
void delete() {
final String id = "api_key";
final ApiKeyBO apiKeyBO = ApiKeyBO.builder().id(id).build();
final ApiKeyDO apiKeyDO = ApiKeyDO.builder().id(id).build();
Mockito.when(apiKeysRepository.delete(id)).thenReturn(CompletableFuture.completedFuture(Optional.of(apiKeyDO)));
final Optional<ApiKeyBO> actual = apiKeysService.delete(id);
assertThat(actual).contains(apiKeyBO);
}