use of org.sagebionetworks.bridge.models.accounts.AccountId in project BridgeServer2 by Sage-Bionetworks.
the class BridgeUtilsTest method parseAccountId.
@Test
public void parseAccountId() {
// Identifier has upper-case letter to ensure we don't downcase or otherwise change it.
AccountId accountId = BridgeUtils.parseAccountId("test", "IdentifierA9");
assertEquals(accountId.getAppId(), "test");
assertEquals(accountId.getId(), "IdentifierA9");
accountId = BridgeUtils.parseAccountId("test", "externalid:IdentifierA9");
assertEquals(accountId.getAppId(), "test");
assertEquals(accountId.getExternalId(), "IdentifierA9");
accountId = BridgeUtils.parseAccountId("test", "externalId:IdentifierA9");
assertEquals(accountId.getAppId(), "test");
assertEquals(accountId.getExternalId(), "IdentifierA9");
accountId = BridgeUtils.parseAccountId("test", "healthcode:IdentifierA9");
assertEquals(accountId.getAppId(), "test");
assertEquals(accountId.getHealthCode(), "IdentifierA9");
accountId = BridgeUtils.parseAccountId("test", "healthCode:IdentifierA9");
assertEquals(accountId.getAppId(), "test");
assertEquals(accountId.getHealthCode(), "IdentifierA9");
// Unrecognized prefix is just part of the userId
accountId = BridgeUtils.parseAccountId("test", "unk:IdentifierA9");
assertEquals(accountId.getAppId(), "test");
assertEquals(accountId.getId(), "unk:IdentifierA9");
accountId = BridgeUtils.parseAccountId("test", "synapseUserId:IdentifierA10");
assertEquals(accountId.getAppId(), "test");
assertEquals(accountId.getSynapseUserId(), "IdentifierA10");
accountId = BridgeUtils.parseAccountId("test", "synapseuserid:IdentifierA11");
assertEquals(accountId.getAppId(), "test");
assertEquals(accountId.getSynapseUserId(), "IdentifierA11");
accountId = BridgeUtils.parseAccountId("test", "syn:IdentifierA12");
assertEquals(accountId.getAppId(), "test");
assertEquals(accountId.getSynapseUserId(), "IdentifierA12");
accountId = BridgeUtils.parseAccountId("test", "email:bridge-testing@sagebase.org");
assertEquals(accountId.getAppId(), "test");
assertEquals(accountId.getEmail(), "bridge-testing@sagebase.org");
}
use of org.sagebionetworks.bridge.models.accounts.AccountId in project BridgeServer2 by Sage-Bionetworks.
the class OAuthProviderServiceTest method oauthSignIn.
@Test
public void oauthSignIn() throws Exception {
// This is not encrypted, the real token is public/private key encrypted. We mock the parser
// to avoid having to sign the payload.
mockAccessGrantCall(201, "{\"access_token\":\"not used\",\"id_token\":{\"userid\":\"77777\"}}");
when(service.getJwtParser()).thenReturn(mockJwtParser);
when(mockJwtParser.parseClaimsJws(any())).thenReturn(mockJwtClaims);
when(mockJwtClaims.getBody()).thenReturn(mockClaims);
when(mockClaims.get(SYNAPSE_USERID_KEY, String.class)).thenReturn("12345");
AccountId returnedValue = service.oauthSignIn(SIGNIN_TOKEN);
assertEquals(returnedValue, AccountId.forSynapseUserId(TEST_APP_ID, "12345"));
String authHeader = "Basic " + Base64.encodeBase64String((SYNAPSE_OAUTH_CLIENT_ID_VALUE + ":" + SYNAPSE_OAUTH_CLIENT_SECRET_VALUE).getBytes());
String body = "grant_type=authorization_code&code=" + BridgeUtils.encodeURIComponent(AUTH_TOKEN_STRING) + "&redirect_uri=" + BridgeUtils.encodeURIComponent(CALLBACK_VALUE);
HttpPost thePost = grantPostCaptor.getValue();
assertEquals(thePost.getURI().toString(), SYNAPSE_OAUTH_URL_VALUE);
assertEquals(thePost.getFirstHeader(AUTHORIZATION_PROP_NAME).getValue(), authHeader);
assertEquals(EntityUtils.toString(thePost.getEntity()), body);
}
use of org.sagebionetworks.bridge.models.accounts.AccountId in project BridgeServer2 by Sage-Bionetworks.
the class IntentServiceTest method submitIntentToParticipateAccountExists.
@Test
public void submitIntentToParticipateAccountExists() {
IntentToParticipate intent = TestUtils.getIntentToParticipate(TIMESTAMP).build();
AccountId accountId = AccountId.forPhone(TEST_APP_ID, intent.getPhone());
Account account = Account.create();
when(mockAccountService.getAccount(accountId)).thenReturn(Optional.of(account));
service.submitIntentToParticipate(intent);
// None of this happens...
verifyNoMoreInteractions(mockAppService);
verifyNoMoreInteractions(mockSubpopService);
verifyNoMoreInteractions(mockCacheProvider);
verifyNoMoreInteractions(mockSmsService);
}
use of org.sagebionetworks.bridge.models.accounts.AccountId in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentServiceTest method getEnrollmentsForUser_filteringForStudies.
@Test
public void getEnrollmentsForUser_filteringForStudies() {
Set<String> callerStudies = ImmutableSet.of("studyA", "studyB");
RequestContext.set(new RequestContext.Builder().withOrgSponsoredStudies(callerStudies).withCallerRoles(ImmutableSet.of(STUDY_COORDINATOR)).build());
AccountId accountId = AccountId.forExternalId(TEST_APP_ID, "extId");
Account account = Account.create();
account.setId(TEST_USER_ID);
when(mockAccountService.getAccount(accountId)).thenReturn(Optional.of(account));
List<EnrollmentDetail> details = ImmutableList.of();
when(mockEnrollmentDao.getEnrollmentsForUser(TEST_APP_ID, callerStudies, TEST_USER_ID)).thenReturn(details);
List<EnrollmentDetail> retValue = service.getEnrollmentsForUser(TEST_APP_ID, TEST_STUDY_ID, "externalId:extId");
assertSame(retValue, details);
verify(mockEnrollmentDao).getEnrollmentsForUser(TEST_APP_ID, callerStudies, TEST_USER_ID);
}
use of org.sagebionetworks.bridge.models.accounts.AccountId in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentServiceTest method updateEnrollment_verifiesAdministrativeAccessToEdit.
@Test(expectedExceptions = UnauthorizedException.class)
public void updateEnrollment_verifiesAdministrativeAccessToEdit() {
RequestContext.set(new RequestContext.Builder().withCallerRoles(ImmutableSet.of()).build());
Enrollment enrollment = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
AccountId accountId = AccountId.forId(TEST_APP_ID, TEST_USER_ID);
Account account = Account.create();
when(mockAccountService.getAccount(accountId)).thenReturn(Optional.of(account));
service.updateEnrollment(enrollment);
}
Aggregations