use of com.nexblocks.authguard.dal.model.AccountDO in project AuthGuard by AuthGuard.
the class AccountsServiceImplTest method revokePermissions.
@Test
void revokePermissions() {
final AccountDO account = createAccountDO();
final List<PermissionBO> currentPermissions = account.getPermissions().stream().map(permissionDO -> PermissionBO.builder().group(permissionDO.getGroup()).name(permissionDO.getName()).build()).collect(Collectors.toList());
Mockito.when(accountsRepository.getById(account.getId())).thenReturn(CompletableFuture.completedFuture(Optional.of(account)));
final List<PermissionBO> permissionsToRevoke = Arrays.asList(currentPermissions.get(0), currentPermissions.get(1));
final AccountBO updated = accountService.revokePermissions(account.getId(), permissionsToRevoke);
assertThat(updated).isNotEqualTo(account);
assertThat(updated.getPermissions()).doesNotContain(permissionsToRevoke.toArray(new PermissionBO[0]));
}
use of com.nexblocks.authguard.dal.model.AccountDO in project AuthGuard by AuthGuard.
the class AccountsServiceImplTest method getByEmail.
@Test
void getByEmail() {
final AccountBO accountBO = createAccountBO();
final AccountDO accountDO = serviceMapper.toDO(accountBO);
Mockito.when(accountsRepository.getByEmail(accountBO.getEmail().getEmail(), accountBO.getDomain())).thenReturn(CompletableFuture.completedFuture(Optional.of(accountDO)));
final Optional<AccountBO> retrieved = accountService.getByEmail(accountBO.getEmail().getEmail(), accountBO.getDomain());
final List<PermissionBO> expectedPermissions = accountBO.getPermissions().stream().map(permission -> permission.withEntityType(null)).collect(Collectors.toList());
assertThat(retrieved).isPresent();
assertThat(retrieved.get()).isEqualTo(accountBO.withPermissions(expectedPermissions));
}
use of com.nexblocks.authguard.dal.model.AccountDO in project AuthGuard by AuthGuard.
the class AccountsServiceImplTest method grantRolesInvalidRoles.
@Test
void grantRolesInvalidRoles() {
final AccountDO account = createAccountDO();
Mockito.when(accountsRepository.getById(account.getId())).thenReturn(CompletableFuture.completedFuture(Optional.of(account)));
Mockito.when(accountsRepository.update(any())).thenAnswer(invocation -> CompletableFuture.completedFuture(Optional.of(invocation.getArgument(0, AccountDO.class))));
final List<String> roles = Arrays.asList(RANDOM.nextObject(String.class), RANDOM.nextObject(String.class));
final List<String> validRoles = Collections.singletonList(roles.get(0));
Mockito.when(rolesService.verifyRoles(roles, "main")).thenReturn(validRoles);
assertThatThrownBy(() -> accountService.grantRoles(account.getId(), roles)).isInstanceOf(ServiceException.class);
}
use of com.nexblocks.authguard.dal.model.AccountDO in project AuthGuard by AuthGuard.
the class AccountsServiceImplTest method grantRolesFromDifferentDomain.
@Test
void grantRolesFromDifferentDomain() {
final AccountDO account = createAccountDO();
Mockito.when(accountsRepository.getById(account.getId())).thenReturn(CompletableFuture.completedFuture(Optional.of(account)));
Mockito.when(accountsRepository.update(any())).thenAnswer(invocation -> CompletableFuture.completedFuture(Optional.of(invocation.getArgument(0, AccountDO.class))));
final List<String> roles = Arrays.asList(RANDOM.nextObject(String.class), RANDOM.nextObject(String.class));
Mockito.when(rolesService.verifyRoles(roles, "other")).thenReturn(roles);
assertThatThrownBy(() -> accountService.grantRoles(account.getId(), roles)).isInstanceOf(ServiceException.class);
}
Aggregations