private Optional<String> resolveUserEmail(final FundDto fund) { return Optional.ofNullable(fund.getFunderUserId()) .map(userId -> keycloakRepository.getUser(fund.getFunderUserId())) .map(UserRepresentation::getEmail); }
@Test public void getUserProfileReturnsEmailVerifiedSignature() throws Exception { UserRepresentation userRepresentation = new UserRepresentation(); userRepresentation.setEmail("davy.van.roy@gmail.com"); when(keycloakRepository.getUser("davy")).thenReturn(userRepresentation); when(keycloakRepository.getUserIdentities("davy")).thenReturn(Stream.empty()); UserProfile userProfile = profileService.getUserProfile(() -> "davy"); assertThat(userProfile.getEmailSignedVerification()).isEqualTo("424a4f5feb0d4adeec05c717f6260c734a0ca036a133c7d29e911ac3c4fbb775"); }
@Test public void getUserProfileReturnsCreationDate() { UserRepresentation userRepresentation = new UserRepresentation(); Date creationDate = DateUtil.parse("2018-01-31"); userRepresentation.setCreatedTimestamp(creationDate.getTime()); userRepresentation.setEmail("davy.van.roy@gmail.com"); when(keycloakRepository.getUser("davy")).thenReturn(userRepresentation); when(keycloakRepository.getUserIdentities("davy")).thenReturn(Stream.empty()); UserProfile userProfile = profileService.getUserProfile(() -> "davy"); assertThat(userProfile.getCreatedAt()).isEqualTo(creationDate.getTime()); }
private ReferralDto createReferralDto(Referral r) { UserRepresentation ur = keycloakRepository.getUser(r.getReferee()); return ReferralDto.builder().status(r.getStatus()) .name(ur.getFirstName() + " " + ur.getLastName()) .email(ur.getEmail()) .picture(keycloakRepository.getAttribute(ur, "picture")) .createdAt(r.getCreationDate()).build(); }
.username(x.getUsername()) .build())); final UserRepresentation user = keycloakRepository.getUser(principal.getName()); List<Wallet> wallets = providers.containsKey(Provider.ARKANE) ? getWallets(principal, providers, getArkaneAccessTokenWithoutCheck((KeycloakAuthenticationToken) principal))
@Test void getProfileWithWallets() { KeycloakAuthenticationToken principal = new KeycloakAuthenticationToken(new KeycloakAccount() { @Override public Principal getPrincipal() { return () -> "davy"; } @Override public Set<String> getRoles() { return null; } }, true); UserRepresentation userRepresentation = new UserRepresentation(); when(keycloakRepository.getUser("davy")).thenReturn(userRepresentation); when(keycloakRepository.getAccessToken(principal, Provider.ARKANE)).thenReturn("token"); Wallet expectedWallet = WalletMother.aWallet(); when(keycloakRepository.getUserIdentities("davy")).thenReturn(Stream.of(UserIdentity.builder().provider(Provider.ARKANE).build())); WalletsResult walletsResult = new WalletsResult(); walletsResult.setResult(Collections.singletonList(expectedWallet)); when(arkaneRepository.getWallets("Bearer token")).thenReturn(walletsResult); UserProfile profile = profileService.getUserProfile(principal); assertThat(profile.getWallets()).containsExactly(expectedWallet); } }