Search in sources :

Example 1 with AccountId

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");
}
Also used : AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) Test(org.testng.annotations.Test) AssessmentConfigValidatorTest(org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)

Example 2 with AccountId

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);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) Test(org.testng.annotations.Test)

Example 3 with AccountId

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);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) IntentToParticipate(org.sagebionetworks.bridge.models.itp.IntentToParticipate) Test(org.testng.annotations.Test)

Example 4 with AccountId

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);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) EnrollmentDetail(org.sagebionetworks.bridge.models.studies.EnrollmentDetail) Test(org.testng.annotations.Test)

Example 5 with AccountId

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);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) RequestContext(org.sagebionetworks.bridge.RequestContext) Test(org.testng.annotations.Test)

Aggregations

AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)139 Test (org.testng.annotations.Test)74 Account (org.sagebionetworks.bridge.models.accounts.Account)63 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)37 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)27 App (org.sagebionetworks.bridge.models.apps.App)20 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)18 Enrollment (org.sagebionetworks.bridge.models.studies.Enrollment)18 RequestContext (org.sagebionetworks.bridge.RequestContext)14 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)12 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)9 PostMapping (org.springframework.web.bind.annotation.PostMapping)9 BridgeUtils.parseAccountId (org.sagebionetworks.bridge.BridgeUtils.parseAccountId)7 DateTime (org.joda.time.DateTime)5 CacheKey (org.sagebionetworks.bridge.cache.CacheKey)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 UnauthorizedException (org.sagebionetworks.bridge.exceptions.UnauthorizedException)4 SignIn (org.sagebionetworks.bridge.models.accounts.SignIn)4 ReportData (org.sagebionetworks.bridge.models.reports.ReportData)4