use of org.sagebionetworks.bridge.models.apps.OAuthProvider in project BridgeServer2 by Sage-Bionetworks.
the class DynamoAppTest method appFullySerializesForCaching.
@Test
public void appFullySerializesForCaching() throws Exception {
final DynamoApp app = TestUtils.getValidApp(DynamoAppTest.class);
OAuthProvider oauthProvider = new OAuthProvider("clientId", "secret", "endpoint", OAuthProviderTest.CALLBACK_URL, null);
app.getOAuthProviders().put("myProvider", oauthProvider);
app.setAutomaticCustomEvents(ImmutableMap.of("3-days-after-enrollment", "P3D"));
app.setVersion(2L);
app.setMinSupportedAppVersions(ImmutableMap.<String, Integer>builder().put(OperatingSystem.IOS, 2).build());
app.setUploadMetadataFieldDefinitions(ImmutableList.of(new UploadFieldDefinition.Builder().withName("test-metadata-field").withType(UploadFieldType.INT).build()));
app.setAndroidAppLinks(ANDROID_APP_LINKS);
app.setAppleAppLinks(APPLE_APP_LINKS);
final JsonNode node = BridgeObjectMapper.get().valueToTree(app);
assertTrue(node.get("autoVerificationEmailSuppressed").booleanValue());
assertEqualsAndNotNull(app.getConsentNotificationEmail(), node.get("consentNotificationEmail").asText());
assertEqualsAndNotNull(app.getExporter3Configuration(), JsonUtils.asEntity(node, "exporter3Configuration", Exporter3Configuration.class));
assertFalse(node.get("participantIpLockingEnabled").booleanValue());
assertTrue(node.get("appIdExcludedInExport").booleanValue());
assertEqualsAndNotNull(app.getSupportEmail(), node.get("supportEmail").asText());
assertEqualsAndNotNull(app.getSynapseDataAccessTeamId(), node.get("synapseDataAccessTeamId").longValue());
assertEqualsAndNotNull(app.getSynapseProjectId(), node.get("synapseProjectId").textValue());
assertEqualsAndNotNull(app.getTechnicalEmail(), node.get("technicalEmail").asText());
assertEqualsAndNotNull(app.getUploadValidationStrictness().toString().toLowerCase(), node.get("uploadValidationStrictness").textValue());
assertTrue(node.get("usesCustomExportSchedule").asBoolean());
assertEqualsAndNotNull(app.getSponsorName(), node.get("sponsorName").asText());
assertEqualsAndNotNull(app.getName(), node.get("name").asText());
assertEqualsAndNotNull(app.getShortName(), node.get("shortName").textValue());
assertEqualsAndNotNull(app.isActive(), node.get("active").asBoolean());
assertEqualsAndNotNull(app.getIdentifier(), node.get("identifier").asText());
assertEqualsAndNotNull(app.getMinAgeOfConsent(), node.get("minAgeOfConsent").asInt());
assertEqualsAndNotNull(app.getPasswordPolicy(), JsonUtils.asEntity(node, "passwordPolicy", PasswordPolicy.class));
assertEqualsAndNotNull(app.getUserProfileAttributes(), JsonUtils.asStringSet(node, "userProfileAttributes"));
assertEqualsAndNotNull(app.getTaskIdentifiers(), JsonUtils.asStringSet(node, "taskIdentifiers"));
assertEqualsAndNotNull(app.getActivityEventKeys(), JsonUtils.asStringSet(node, "activityEventKeys"));
assertEqualsAndNotNull(app.getDataGroups(), JsonUtils.asStringSet(node, "dataGroups"));
assertEqualsAndNotNull(app.getVersion(), node.get("version").longValue());
assertTrue(node.get("strictUploadValidationEnabled").asBoolean());
assertTrue(node.get("healthCodeExportEnabled").asBoolean());
assertTrue(node.get("emailVerificationEnabled").asBoolean());
assertTrue(node.get("externalIdRequiredOnSignup").asBoolean());
assertTrue(node.get("emailSignInEnabled").asBoolean());
assertTrue(node.get("reauthenticationEnabled").booleanValue());
assertTrue(node.get("autoVerificationPhoneSuppressed").booleanValue());
assertTrue(node.get("verifyChannelOnSignInEnabled").booleanValue());
assertEquals(node.get("accountLimit").asInt(), 0);
assertFalse(node.get("disableExport").asBoolean());
assertEqualsAndNotNull("App", node.get("type").asText());
assertEqualsAndNotNull(app.getPushNotificationARNs().get(OperatingSystem.IOS), node.get("pushNotificationARNs").get(OperatingSystem.IOS).asText());
assertEqualsAndNotNull(app.getPushNotificationARNs().get(OperatingSystem.ANDROID), node.get("pushNotificationARNs").get(OperatingSystem.ANDROID).asText());
JsonNode automaticCustomEventsNode = node.get("automaticCustomEvents");
assertEquals(automaticCustomEventsNode.size(), 1);
assertEquals(automaticCustomEventsNode.get("3-days-after-enrollment").textValue(), "P3D");
JsonNode appleLink = node.get("appleAppLinks").get(0);
assertEquals(appleLink.get("appID").textValue(), "appId");
assertEquals(appleLink.get("paths").get(0).textValue(), "/appId/");
assertEquals(appleLink.get("paths").get(1).textValue(), "/appId/*");
JsonNode androidLink = node.get("androidAppLinks").get(0);
assertEquals(androidLink.get("namespace").textValue(), "namespace");
assertEquals(androidLink.get("package_name").textValue(), "package_name");
assertEquals(androidLink.get("sha256_cert_fingerprints").get(0).textValue(), "sha256_cert_fingerprints");
// validate minAppVersion
JsonNode supportedVersionsNode = JsonUtils.asJsonNode(node, "minSupportedAppVersions");
assertNotNull(supportedVersionsNode);
assertEqualsAndNotNull(app.getMinSupportedAppVersions().get(OperatingSystem.IOS), supportedVersionsNode.get(OperatingSystem.IOS).intValue());
// validate metadata field defs
JsonNode metadataFieldDefListNode = node.get("uploadMetadataFieldDefinitions");
assertEquals(metadataFieldDefListNode.size(), 1);
JsonNode oneMetadataFieldDefNode = metadataFieldDefListNode.get(0);
assertEquals(oneMetadataFieldDefNode.get("name").textValue(), "test-metadata-field");
assertEquals(oneMetadataFieldDefNode.get("type").textValue(), "int");
JsonNode providerNode = node.get("oAuthProviders").get("myProvider");
assertEquals(providerNode.get("clientId").textValue(), "clientId");
assertEquals(providerNode.get("secret").textValue(), "secret");
assertEquals(providerNode.get("endpoint").textValue(), "endpoint");
assertEquals(providerNode.get("callbackUrl").textValue(), OAuthProviderTest.CALLBACK_URL);
assertEquals(providerNode.get("type").textValue(), "OAuthProvider");
JsonNode defaultTemplates = node.get("defaultTemplates");
assertEquals(defaultTemplates.get("email_account_exists").textValue(), "ABC-DEF");
// Deserialize back to a POJO and verify.
final App deserApp = BridgeObjectMapper.get().readValue(node.toString(), App.class);
assertEquals(deserApp, app);
}
use of org.sagebionetworks.bridge.models.apps.OAuthProvider in project BridgeServer2 by Sage-Bionetworks.
the class CacheProviderTest method getObjectWithTypeReference.
@Test
public void getObjectWithTypeReference() throws Exception {
OAuthProvider provider1 = new OAuthProvider("clientId1", "secret1", "endpoint1", "callbackUrl1", null);
OAuthProvider provider2 = new OAuthProvider("clientId2", "secret2", "endpoint2", "callbackUrl2", null);
List<OAuthProvider> providers = Lists.newArrayList(provider1, provider2);
String ser = BridgeObjectMapper.get().writeValueAsString(providers);
when(jedisOps.get(CACHE_KEY.toString())).thenReturn(ser);
TypeReference<List<OAuthProvider>> typeRef = new TypeReference<List<OAuthProvider>>() {
};
List<OAuthProvider> returned = cacheProvider.getObject(CACHE_KEY, typeRef);
assertEquals(returned.get(0), provider1);
assertEquals(returned.get(1), provider2);
assertEquals(returned.size(), 2);
}
use of org.sagebionetworks.bridge.models.apps.OAuthProvider in project BridgeServer2 by Sage-Bionetworks.
the class CacheProviderTest method getObject.
@Test
public void getObject() throws Exception {
OAuthProvider provider = new OAuthProvider("clientId", "secret", "endpoint", "callbackUrl", null);
String ser = BridgeObjectMapper.get().writeValueAsString(provider);
when(jedisOps.get(CACHE_KEY.toString())).thenReturn(ser);
OAuthProvider returned = cacheProvider.getObject(CACHE_KEY, OAuthProvider.class);
assertEquals(returned, provider);
verify(jedisOps).get(CACHE_KEY.toString());
}
use of org.sagebionetworks.bridge.models.apps.OAuthProvider in project BridgeServer2 by Sage-Bionetworks.
the class CacheProviderTest method setObjectWithExpire.
@Test
public void setObjectWithExpire() throws Exception {
OAuthProvider provider = new OAuthProvider("clientId", "secret", "endpoint", "callbackUrl", null);
String ser = BridgeObjectMapper.get().writeValueAsString(provider);
when(jedisOps.setex(CACHE_KEY.toString(), 100, ser)).thenReturn("OK");
cacheProvider.setObject(CACHE_KEY, provider, 100);
verify(jedisOps).setex(CACHE_KEY.toString(), 100, ser);
}
use of org.sagebionetworks.bridge.models.apps.OAuthProvider in project BridgeServer2 by Sage-Bionetworks.
the class CacheProviderTest method getObjectWithReexpire.
@Test
public void getObjectWithReexpire() throws Exception {
OAuthProvider provider = new OAuthProvider("clientId", "secret", "endpoint", "callbackUrl", null);
String ser = BridgeObjectMapper.get().writeValueAsString(provider);
when(jedisOps.get(CACHE_KEY.toString())).thenReturn(ser);
OAuthProvider returned = cacheProvider.getObject(CACHE_KEY, OAuthProvider.class, 100);
assertEquals(returned, provider);
verify(jedisOps).get(CACHE_KEY.toString());
verify(jedisOps).expire(CACHE_KEY.toString(), 100);
}
Aggregations