use of com.aliyun.ons20190214.Client in project ORCID-Source by ORCID.
the class ClientManagerTest method editWithoutUpdatingConfigValues.
@Test
public void editWithoutUpdatingConfigValues() {
String seed = RandomStringUtils.randomAlphanumeric(15);
Client originalClient = getClient(seed, MEMBER_ID);
assertFalse(originalClient.getId().startsWith("APP-"));
// Create the client
Client client = clientManager.create(originalClient);
String initialClientSecret = client.getDecryptedSecret();
// Update some fields
client.setAllowAutoDeprecate(false);
client.setAuthenticationProviderId("updated-authentication-provider-id");
client.setDescription("updated-desciption");
client.setEmailAccessReason("updated-email-access-reason");
client.setName("updated-client-name");
client.setPersistentTokensEnabled(false);
client.setWebsite("updated-website");
// Change group id, which should not be persisted
client.setGroupProfileId("0000-0000-0000-0000");
// Change client type, which should not be persisted
client.setClientType(ClientType.UPDATER);
// Add a new redirect uri
ClientRedirectUri rUri = new ClientRedirectUri();
Set<ScopePathType> scopes = new HashSet<ScopePathType>();
scopes.add(ScopePathType.READ_LIMITED);
scopes.add(ScopePathType.ACTIVITIES_UPDATE);
rUri.setPredefinedClientScopes(scopes);
rUri.setRedirectUri("new-redirect-uri");
rUri.setRedirectUriType(RedirectUriType.IMPORT_WORKS_WIZARD.value());
rUri.setUriActType("updated-uri-act-type");
rUri.setUriGeoArea("updated-geo-area");
client.getClientRedirectUris().add(rUri);
// Edit the client
Date editTime = new Date();
clientManager.edit(client, false);
// Verify new data is there
ClientDetailsEntity entityClient = clientDetailsDao.find(client.getId());
assertEquals(MEMBER_ID, entityClient.getGroupProfileId());
assertEquals("updated-desciption", entityClient.getClientDescription());
assertEquals("updated-client-name", entityClient.getClientName());
assertEquals("updated-website", entityClient.getClientWebsite());
assertEquals(initialClientSecret, encryptionManager.decryptForInternalUse(entityClient.getClientSecretForJpa()));
assertFalse(entityClient.isAllowAutoDeprecate());
// Verify authentication provider id doesn't changed
assertNotEquals(originalClient.getAuthenticationProviderId(), client.getAuthenticationProviderId());
assertEquals(originalClient.getAuthenticationProviderId(), entityClient.getAuthenticationProviderId());
// Verify enable persistent tokens doesn't changed
assertNotEquals(originalClient.isPersistentTokensEnabled(), client.isPersistentTokensEnabled());
assertEquals(originalClient.isPersistentTokensEnabled(), entityClient.isPersistentTokensEnabled());
// Verify config data doesn't changed
validateClientConfigSettings(entityClient, editTime);
}
use of com.aliyun.ons20190214.Client in project ORCID-Source by ORCID.
the class ClientManagerTest method editWithInvalidClientId.
@Test(expected = IllegalArgumentException.class)
public void editWithInvalidClientId() {
Client client = new Client();
client.setId("APP-0");
clientManager.edit(client, false);
fail();
}
use of com.aliyun.ons20190214.Client in project ORCID-Source by ORCID.
the class ClientManagerTest method createClientTest.
@Test
public void createClientTest() {
String seed = RandomStringUtils.randomAlphanumeric(15);
Client client = getClient(seed, MEMBER_ID);
assertFalse(client.getId().startsWith("APP-"));
client = clientManager.create(client);
assertTrue(client.getId().startsWith("APP-"));
ClientDetailsEntity newEntity = clientDetailsDao.find(client.getId());
assertNotNull(newEntity);
assertNotNull(newEntity.getDateCreated());
assertNotNull(newEntity.getLastModified());
assertEquals(client.getId(), newEntity.getId());
assertEquals(MEMBER_ID, newEntity.getGroupProfileId());
assertNotNull(newEntity.getAccessTokenValiditySeconds());
assertTrue(newEntity.isAllowAutoDeprecate());
assertEquals("description " + seed, newEntity.getClientDescription());
assertEquals("client-name " + seed, newEntity.getClientName());
assertEquals(ClientType.PREMIUM_CREATOR, newEntity.getClientType());
assertEquals("client-website " + seed, newEntity.getClientWebsite());
assertNotNull(newEntity.getClientRegisteredRedirectUris());
assertEquals(3, newEntity.getClientRegisteredRedirectUris().size());
boolean found1 = false, found2 = false, found3 = false;
for (ClientRedirectUriEntity rUri : newEntity.getClientRegisteredRedirectUris()) {
assertNotNull(rUri.getRedirectUri());
assertNotNull(rUri.getDateCreated());
assertNotNull(rUri.getLastModified());
if (rUri.getRedirectUri().equals("redirect-uri-1 " + seed)) {
assertEquals(ScopePathType.ACTIVITIES_READ_LIMITED.value(), rUri.getPredefinedClientScope());
assertEquals("type-1 " + seed, rUri.getRedirectUriType());
assertEquals("uri-act-type-1 " + seed, rUri.getUriActType());
assertEquals("uri-geo-area-1 " + seed, rUri.getUriGeoArea());
found1 = true;
} else if (rUri.getRedirectUri().equals("redirect-uri-2 " + seed)) {
assertEquals(ScopePathType.ACTIVITIES_UPDATE.value(), rUri.getPredefinedClientScope());
assertEquals("type-2 " + seed, rUri.getRedirectUriType());
assertEquals("uri-act-type-2 " + seed, rUri.getUriActType());
assertEquals("uri-geo-area-2 " + seed, rUri.getUriGeoArea());
found2 = true;
} else if (rUri.getRedirectUri().equals("redirect-uri-3 " + seed)) {
assertEquals(ScopePathType.AFFILIATIONS_CREATE.value(), rUri.getPredefinedClientScope());
assertEquals("type-3 " + seed, rUri.getRedirectUriType());
assertEquals("uri-act-type-3 " + seed, rUri.getUriActType());
assertEquals("uri-geo-area-3 " + seed, rUri.getUriGeoArea());
found3 = true;
} else {
fail("Invalid redirect uri: " + rUri.getRedirectUri());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
validateClientConfigSettings(newEntity, null);
}
use of com.aliyun.ons20190214.Client in project ORCID-Source by ORCID.
the class ClientManagerTest method editUpdatingConfigValues.
@Test
public void editUpdatingConfigValues() {
String seed = RandomStringUtils.randomAlphanumeric(15);
Client originalClient = getClient(seed, MEMBER_ID);
assertFalse(originalClient.getId().startsWith("APP-"));
// Create the client
Client client = clientManager.create(originalClient);
String initialClientSecret = client.getDecryptedSecret();
// Update some fields
client.setAllowAutoDeprecate(false);
client.setAuthenticationProviderId("updated-authentication-provider-id");
client.setDescription("updated-desciption");
client.setEmailAccessReason("updated-email-access-reason");
client.setName("updated-client-name");
client.setPersistentTokensEnabled(false);
client.setWebsite("updated-website");
// Change group id, which should not be persisted
client.setGroupProfileId("0000-0000-0000-0000");
// Change client type, which should not be persisted
client.setClientType(ClientType.UPDATER);
// Add a new redirect uri
ClientRedirectUri rUri = new ClientRedirectUri();
Set<ScopePathType> scopes = new HashSet<ScopePathType>();
scopes.add(ScopePathType.READ_LIMITED);
scopes.add(ScopePathType.ACTIVITIES_UPDATE);
rUri.setPredefinedClientScopes(scopes);
rUri.setRedirectUri("new-redirect-uri");
rUri.setRedirectUriType(RedirectUriType.IMPORT_WORKS_WIZARD.value());
rUri.setUriActType("updated-uri-act-type");
rUri.setUriGeoArea("updated-geo-area");
client.getClientRedirectUris().add(rUri);
// Edit the client
Date editTime = new Date();
clientManager.edit(client, true);
// Verify new data is there
ClientDetailsEntity entityClient = clientDetailsDao.find(client.getId());
assertEquals(MEMBER_ID, entityClient.getGroupProfileId());
assertEquals("updated-desciption", entityClient.getClientDescription());
assertEquals("updated-client-name", entityClient.getClientName());
assertEquals("updated-website", entityClient.getClientWebsite());
assertEquals(initialClientSecret, encryptionManager.decryptForInternalUse(entityClient.getClientSecretForJpa()));
assertFalse(entityClient.isAllowAutoDeprecate());
// Verify authentication provider id changed
assertNotEquals(originalClient.getAuthenticationProviderId(), client.getAuthenticationProviderId());
assertEquals(client.getAuthenticationProviderId(), entityClient.getAuthenticationProviderId());
// Verify enable persistent tokens changed
assertNotEquals(originalClient.isPersistentTokensEnabled(), client.isPersistentTokensEnabled());
assertEquals(client.isPersistentTokensEnabled(), entityClient.isPersistentTokensEnabled());
// Verify config data doesn't changed
validateClientConfigSettings(entityClient, editTime);
}
use of com.aliyun.ons20190214.Client in project ORCID-Source by ORCID.
the class ClientManagerTest method editClientDontOverwriteConfigValuesTest.
@Test
@Transactional
public void editClientDontOverwriteConfigValuesTest() {
// Create a new client
String seed = RandomStringUtils.randomAlphanumeric(15);
Client client = getClient(seed, MEMBER_ID);
assertFalse(client.getId().startsWith("APP-"));
client = clientManager.create(client);
assertTrue(client.getId().startsWith("APP-"));
assertEquals(ClientType.PREMIUM_CREATOR, client.getClientType());
ClientDetailsEntity newEntity = clientDetailsDao.find(client.getId());
assertEquals("authentication-provider-id " + seed, newEntity.getAuthenticationProviderId());
assertNull(newEntity.getEmailAccessReason());
newEntity.setAuthenticationProviderId("my-authentication-provider-id");
newEntity.setEmailAccessReason("my-email-access-reason");
newEntity.setPersistentTokensEnabled(true);
newEntity.setAllowAutoDeprecate(true);
clientDetailsDao.merge(newEntity);
client.setName("Updated name");
// Try to disable the persistent tokens
client.setPersistentTokensEnabled(false);
client.setAuthenticationProviderId("another-authentication-provider-id");
client.setClientType(ClientType.PUBLIC_CLIENT);
client.setDescription("Updated description");
client.setEmailAccessReason("another-email-access-reason");
client.setWebsite("http://updated.com");
clientManager.edit(client, false);
ClientDetailsEntity updatedEntity = clientDetailsDao.find(client.getId());
// Check config options where not overwritten
assertEquals(client.getId(), updatedEntity.getId());
assertEquals("my-authentication-provider-id", updatedEntity.getAuthenticationProviderId());
assertEquals("my-email-access-reason", updatedEntity.getEmailAccessReason());
assertTrue(updatedEntity.isPersistentTokensEnabled());
assertEquals(ClientType.PREMIUM_CREATOR, updatedEntity.getClientType());
// Check updated fields where persisted
assertEquals("Updated name", updatedEntity.getClientName());
assertEquals("Updated description", updatedEntity.getClientDescription());
assertEquals("http://updated.com", updatedEntity.getClientWebsite());
}
Aggregations