use of bio.terra.externalcreds.models.GA4GHPassport in project terra-external-credentials-manager by DataBiosphere.
the class AuthorizationCodeExchangeTest method runTest.
private void runTest(LinkedAccount expectedLinkedAccount, GA4GHPassport expectedPassport, List<GA4GHVisa> expectedVisas) throws URISyntaxException {
var state = new OAuth2State.Builder().provider(expectedLinkedAccount.getProviderName()).random(OAuth2State.generateRandomState(new SecureRandom())).build();
String encodedState = state.encode(objectMapper);
setupMocks(expectedLinkedAccount, expectedPassport, authorizationCode, redirectUri, scopes, encodedState);
linkedAccountService.upsertOAuth2State(expectedLinkedAccount.getUserId(), state);
var linkedAccountWithPassportAndVisas = providerService.createLink(expectedLinkedAccount.getProviderName(), expectedLinkedAccount.getUserId(), authorizationCode, redirectUri, scopes, encodedState);
assertPresent(linkedAccountWithPassportAndVisas);
assertEquals(expectedLinkedAccount, linkedAccountWithPassportAndVisas.get().getLinkedAccount().withExpires(passportExpiresTime).withId(Optional.empty()));
var stablePassport = linkedAccountWithPassportAndVisas.get().getPassport().map(p -> p.withId(Optional.empty()).withLinkedAccountId(Optional.empty()));
assertEquals(Optional.ofNullable(expectedPassport), stablePassport);
var stableVisas = linkedAccountWithPassportAndVisas.get().getVisas().stream().map(visa -> visa.withLastValidated(Optional.empty()).withId(Optional.empty()).withPassportId(Optional.empty())).collect(Collectors.toList());
assertEquals(expectedVisas, stableVisas);
// state should have been removed from the db
assertThrows(BadRequestException.class, () -> linkedAccountService.validateAndDeleteOAuth2State(expectedLinkedAccount.getUserId(), state));
}
Aggregations