Search in sources :

Example 16 with Client

use of com.aliyun.dysmsapi20170525.Client in project ORCID-Source by ORCID.

the class ClientManagerReadOnlyTest method getClientTest.

@Test
public void getClientTest() {
    String seed = RandomStringUtils.randomAlphanumeric(30);
    when(daoMock.findByClientId(anyString(), anyLong())).thenReturn(getClientDetailsEntity(seed));
    Client client = clientManagerReadOnly.get(seed);
    assertEquals(getClient(seed), client);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Client(org.orcid.jaxb.model.client_v2.Client) Test(org.junit.Test)

Example 17 with Client

use of com.aliyun.dysmsapi20170525.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);
}
Also used : ClientRedirectUri(org.orcid.jaxb.model.client_v2.ClientRedirectUri) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) Client(org.orcid.jaxb.model.client_v2.Client) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 18 with Client

use of com.aliyun.dysmsapi20170525.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();
}
Also used : Client(org.orcid.jaxb.model.client_v2.Client) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 19 with Client

use of com.aliyun.dysmsapi20170525.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);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Client(org.orcid.jaxb.model.client_v2.Client) ClientRedirectUriEntity(org.orcid.persistence.jpa.entities.ClientRedirectUriEntity) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 20 with Client

use of com.aliyun.dysmsapi20170525.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);
}
Also used : ClientRedirectUri(org.orcid.jaxb.model.client_v2.ClientRedirectUri) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) Client(org.orcid.jaxb.model.client_v2.Client) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Aggregations

Client (org.orcid.jaxb.model.client_v2.Client)18 Test (org.junit.Test)13 Client (com.aliyun.dysmsapi20170525.Client)12 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)10 Client (com.predic8.membrane.core.interceptor.oauth2.Client)9 Config (com.aliyun.teaopenapi.models.Config)7 HashSet (java.util.HashSet)6 ClientRedirectUri (org.orcid.jaxb.model.client_v2.ClientRedirectUri)6 SessionManager (com.predic8.membrane.core.interceptor.authentication.session.SessionManager)5 BaseTest (org.orcid.core.BaseTest)5 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)5 SendSmsRequest (com.aliyun.dysmsapi20170525.models.SendSmsRequest)3 NoResponse (com.predic8.membrane.core.interceptor.oauth2.request.NoResponse)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 SendSmsResponse (com.aliyun.dysmsapi20170525.models.SendSmsResponse)2 Client (com.aliyun.ons20190214.Client)2 OnsTopicListRequest (com.aliyun.ons20190214.models.OnsTopicListRequest)2 OnsTopicListResponse (com.aliyun.ons20190214.models.OnsTopicListResponse)2