use of org.sagebionetworks.bridge.models.accounts.UserSession in project BridgeServer2 by Sage-Bionetworks.
the class CacheProviderTest method testSetUserSessionNullSessionToken.
@Test
public void testSetUserSessionNullSessionToken() throws Exception {
StudyParticipant participant = new StudyParticipant.Builder().withEmail("userEmail").withId(USER_ID).withHealthCode("healthCode").build();
UserSession session = new UserSession(participant);
try {
cacheProvider.setUserSession(session);
} catch (NullPointerException e) {
assertTrue(true, "NPE expected.");
} catch (Throwable e) {
fail(e.getMessage());
}
verify(transaction, never()).setex(eq(TOKEN_TO_USER_ID.toString()), anyInt(), anyString());
verify(transaction, never()).setex(eq(USER_ID_TO_SESSION.toString()), anyInt(), eq(DECRYPTED_SESSION_TOKEN));
verify(transaction, never()).exec();
}
use of org.sagebionetworks.bridge.models.accounts.UserSession in project BridgeServer2 by Sage-Bionetworks.
the class CacheProviderTest method testRemoveSession.
@Test
public void testRemoveSession() {
StudyParticipant participant = new StudyParticipant.Builder().withId(USER_ID).build();
UserSession session = new UserSession(participant);
session.setSessionToken(DECRYPTED_SESSION_TOKEN);
cacheProvider.removeSession(session);
cacheProvider.getUserSession(DECRYPTED_SESSION_TOKEN);
verify(transaction).del(TOKEN_TO_USER_ID.toString());
verify(transaction).del(USER_ID_TO_SESSION.toString());
verify(transaction).exec();
}
use of org.sagebionetworks.bridge.models.accounts.UserSession in project BridgeServer2 by Sage-Bionetworks.
the class CacheProviderTest method getUserSessionSuccessful.
@Test
public void getUserSessionSuccessful() throws Exception {
UserSession session = new UserSession(new StudyParticipant.Builder().build());
session.setSessionToken(DECRYPTED_SESSION_TOKEN);
when(jedisOps.get(USER_ID_TO_SESSION.toString())).thenReturn(BridgeObjectMapper.get().writeValueAsString(session));
UserSession retrieved = cacheProvider.getUserSession(DECRYPTED_SESSION_TOKEN);
assertEquals(retrieved.getSessionToken(), session.getSessionToken());
}
use of org.sagebionetworks.bridge.models.accounts.UserSession in project BridgeServer2 by Sage-Bionetworks.
the class CacheProviderTest method assertSession.
private void assertSession(String json) {
JedisOps jedisOps = mock(JedisOps.class);
when(jedisOps.get(TOKEN_TO_USER_ID.toString())).thenReturn(USER_ID);
when(jedisOps.get(USER_ID_TO_SESSION.toString())).thenReturn(json);
cacheProvider.setJedisOps(jedisOps);
UserSession session = cacheProvider.getUserSession(DECRYPTED_SESSION_TOKEN);
assertTrue(session.isAuthenticated());
assertEquals(session.getEnvironment(), Environment.LOCAL);
assertEquals(session.getSessionToken(), DECRYPTED_SESSION_TOKEN);
assertEquals(session.getInternalSessionToken(), "4f0937a5-6ebf-451b-84bc-fbf649b9e93c");
assertEquals(session.getId(), "6gq4jGXLmAxVbLLmVifKN4");
assertEquals(session.getAppId(), TEST_APP_ID);
StudyParticipant participant = session.getParticipant();
assertEquals(participant.getFirstName(), "Bridge");
assertEquals(participant.getLastName(), "IT");
assertEquals(participant.getEmail(), "bridgeit@sagebase.org");
assertEquals(participant.getSharingScope(), SharingScope.NO_SHARING);
assertEquals(participant.getCreatedOn(), DateTime.parse("2016-04-21T16:48:22.386Z"));
assertEquals(participant.getRoles(), Sets.newHashSet(Roles.ADMIN));
assertEquals(participant.getLanguages(), ImmutableList.of("en", "fr"));
assertEquals(participant.getExternalId(), "ABC");
assertEquals(ENCRYPTOR.decrypt(ENCRYPTED_SESSION_TOKEN), participant.getHealthCode());
SubpopulationGuid apiGuid = SubpopulationGuid.create(TEST_APP_ID);
Map<SubpopulationGuid, ConsentStatus> consentStatuses = session.getConsentStatuses();
ConsentStatus status = consentStatuses.get(apiGuid);
assertEquals(status.getName(), "Default Consent Group");
assertEquals(status.getSubpopulationGuid(), apiGuid.getGuid());
assertTrue(status.getSignedMostRecentConsent());
assertTrue(status.isRequired());
assertFalse(status.isConsented());
}
use of org.sagebionetworks.bridge.models.accounts.UserSession in project BridgeServer2 by Sage-Bionetworks.
the class CacheProviderTest method getUserSessionUserHasNoSession.
@Test
public void getUserSessionUserHasNoSession() {
// When token --> userId mapping is mocked, but there's no session, return null
UserSession retrieved = cacheProvider.getUserSession(DECRYPTED_SESSION_TOKEN);
assertNull(retrieved);
}
Aggregations