Search in sources :

Example 26 with Client

use of org.orcid.pojo.ajaxForm.Client in project ORCID-Source by ORCID.

the class DeveloperToolsControllerTest method updateClientTest.

@Test
public void updateClientTest() throws Exception {
    Client client = new Client();
    client.setDisplayName(Text.valueOf("Updated client name"));
    client.setShortDescription(Text.valueOf("Updated client description"));
    client.setWebsite(Text.valueOf("http://updated.com"));
    client.setType(Text.valueOf(ClientType.PUBLIC_CLIENT.value()));
    List<RedirectUri> redirectUris = new ArrayList<RedirectUri>();
    RedirectUri rUri = new RedirectUri();
    rUri.setType(Text.valueOf(RedirectUriType.SSO_AUTHENTICATION.value()));
    rUri.setValue(Text.valueOf("http://test.com"));
    redirectUris.add(rUri);
    RedirectUri rUri2 = new RedirectUri();
    rUri2.setType(Text.valueOf(RedirectUriType.SSO_AUTHENTICATION.value()));
    rUri2.setValue(Text.valueOf("http://test2.com"));
    redirectUris.add(rUri2);
    client.setRedirectUris(redirectUris);
    Client updatedClient = developerToolsController.updateClient(client);
    verify(mockClientManager, times(1)).edit(Matchers.any(org.orcid.jaxb.model.v3.dev1.client.Client.class), Matchers.eq(false));
    assertEquals(CLIENT_2, updatedClient.getClientId().getValue());
}
Also used : ArrayList(java.util.ArrayList) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Client(org.orcid.pojo.ajaxForm.Client) Test(org.junit.Test)

Example 27 with Client

use of org.orcid.pojo.ajaxForm.Client in project ORCID-Source by ORCID.

the class DeveloperToolsControllerTest method testClientValidation.

@Test
public void testClientValidation() throws Exception {
    // Test empty title
    Client client = new Client();
    client.setShortDescription(Text.valueOf("This is a description"));
    client.setWebsite(Text.valueOf("http://client.com"));
    List<RedirectUri> redirectUris = new ArrayList<RedirectUri>();
    RedirectUri rUri = new RedirectUri();
    rUri.setType(Text.valueOf(RedirectUriType.SSO_AUTHENTICATION.value()));
    rUri.setValue(Text.valueOf("http://test.com"));
    redirectUris.add(rUri);
    client.setRedirectUris(redirectUris);
    Client result = developerToolsController.createClient(client);
    assertNotNull(result.getErrors());
    assertEquals(result.getErrors().size(), 1);
    assertEquals(result.getErrors().get(0), developerToolsController.getMessage("manage.developer_tools.name_not_empty"));
    // Test empty description
    client = new Client();
    client.setDisplayName(Text.valueOf("Client Name"));
    client.setWebsite(Text.valueOf("http://client.com"));
    redirectUris = new ArrayList<RedirectUri>();
    rUri = new RedirectUri();
    rUri.setType(Text.valueOf(RedirectUriType.SSO_AUTHENTICATION.value()));
    rUri.setValue(Text.valueOf("http://test.com"));
    redirectUris.add(rUri);
    client.setRedirectUris(redirectUris);
    result = developerToolsController.createClient(client);
    assertNotNull(result.getErrors());
    assertEquals(result.getErrors().size(), 1);
    assertEquals(result.getErrors().get(0), developerToolsController.getMessage("manage.developer_tools.description_not_empty"));
    // Test empty website
    client = new Client();
    client.setDisplayName(Text.valueOf("Client Name"));
    client.setShortDescription(Text.valueOf("This is a description"));
    redirectUris = new ArrayList<RedirectUri>();
    rUri = new RedirectUri();
    rUri.setType(Text.valueOf(RedirectUriType.SSO_AUTHENTICATION.value()));
    rUri.setValue(Text.valueOf("http://test.com"));
    redirectUris.add(rUri);
    client.setRedirectUris(redirectUris);
    result = developerToolsController.createClient(client);
    assertNotNull(result.getErrors());
    assertEquals(result.getErrors().size(), 1);
    assertEquals(result.getErrors().get(0), developerToolsController.getMessage("manage.developer_tools.website_not_empty"));
    // Test empty redirect uris
    client = new Client();
    client.setDisplayName(Text.valueOf("Client Name"));
    client.setShortDescription(Text.valueOf("This is a description"));
    client.setWebsite(Text.valueOf("http://client.com"));
    result = developerToolsController.createClient(client);
    assertNotNull(result.getErrors());
    assertEquals(result.getErrors().size(), 1);
    assertEquals(result.getErrors().get(0), developerToolsController.getMessage("manage.developer_tools.at_least_one"));
}
Also used : ArrayList(java.util.ArrayList) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Client(org.orcid.pojo.ajaxForm.Client) Test(org.junit.Test)

Example 28 with Client

use of org.orcid.pojo.ajaxForm.Client in project ORCID-Source by ORCID.

the class DeveloperToolsControllerTest method before.

@SuppressWarnings("deprecation")
@Before
public void before() {
    MockitoAnnotations.initMocks(this);
    TargetProxyHelper.injectIntoProxy(developerToolsController, "emailManagerReadOnly", mockEmailManagerReadOnly);
    TargetProxyHelper.injectIntoProxy(developerToolsController, "profileEntityCacheManager", mockProfileEntityCacheManager);
    TargetProxyHelper.injectIntoProxy(developerToolsController, "clientManager", mockClientManager);
    TargetProxyHelper.injectIntoProxy(developerToolsController, "clientManagerReadOnly", mockClientManagerReadOnly);
    TargetProxyHelper.injectIntoProxy(developerToolsController, "sourceManager", mockSourceManager);
    when(mockClientManager.createPublicClient(Matchers.any(org.orcid.jaxb.model.v3.dev1.client.Client.class))).thenAnswer(new Answer<org.orcid.jaxb.model.v3.dev1.client.Client>() {

        @Override
        public org.orcid.jaxb.model.v3.dev1.client.Client answer(InvocationOnMock invocation) throws Throwable {
            org.orcid.jaxb.model.v3.dev1.client.Client c = (org.orcid.jaxb.model.v3.dev1.client.Client) invocation.getArguments()[0];
            c.setId(CLIENT_1);
            c.setClientType(ClientType.PUBLIC_CLIENT);
            return c;
        }
    });
    when(mockClientManager.edit(Matchers.any(org.orcid.jaxb.model.v3.dev1.client.Client.class), Matchers.eq(false))).thenAnswer(new Answer<org.orcid.jaxb.model.v3.dev1.client.Client>() {

        @Override
        public org.orcid.jaxb.model.v3.dev1.client.Client answer(InvocationOnMock invocation) throws Throwable {
            org.orcid.jaxb.model.v3.dev1.client.Client c = (org.orcid.jaxb.model.v3.dev1.client.Client) invocation.getArguments()[0];
            c.setId(CLIENT_2);
            c.setClientType(ClientType.PUBLIC_CLIENT);
            return c;
        }
    });
    when(mockProfileEntityCacheManager.retrieve(USER_ORCID)).thenReturn(new ProfileEntity(USER_ORCID));
    Set<org.orcid.jaxb.model.v3.dev1.client.Client> clients = new HashSet<>();
    org.orcid.jaxb.model.v3.dev1.client.Client c = new org.orcid.jaxb.model.v3.dev1.client.Client();
    c.setId(CLIENT_3);
    c.setGroupProfileId(USER_ORCID);
    Set<org.orcid.jaxb.model.v3.dev1.client.ClientRedirectUri> rUris = new HashSet<>();
    org.orcid.jaxb.model.v3.dev1.client.ClientRedirectUri rUri1 = new org.orcid.jaxb.model.v3.dev1.client.ClientRedirectUri();
    rUri1.setRedirectUri("http://ruri1.com");
    rUri1.setRedirectUriType(RedirectUriType.SSO_AUTHENTICATION.value());
    rUris.add(rUri1);
    c.setClientType(ClientType.PUBLIC_CLIENT);
    c.setClientRedirectUris(rUris);
    c.setDescription("Client description");
    c.setName("Client name");
    c.setWebsite("http://ruri1.com");
    c.setDecryptedSecret("client-secret");
    clients.add(c);
    when(mockClientManagerReadOnly.getClients(Matchers.anyString())).thenReturn(clients);
    when(mockClientManagerReadOnly.get(Matchers.anyString())).thenAnswer(new Answer<org.orcid.jaxb.model.v3.dev1.client.Client>() {

        @Override
        public org.orcid.jaxb.model.v3.dev1.client.Client answer(InvocationOnMock invocation) throws Throwable {
            String clientId = (String) invocation.getArguments()[0];
            org.orcid.jaxb.model.v3.dev1.client.Client c = new org.orcid.jaxb.model.v3.dev1.client.Client();
            c.setId(clientId);
            c.setGroupProfileId(USER_ORCID);
            return c;
        }
    });
    when(mockSourceManager.isInDelegationMode()).thenReturn(false);
    when(mockClientManager.resetClientSecret(CLIENT_3)).thenReturn(true);
}
Also used : ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Client(org.orcid.pojo.ajaxForm.Client) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 29 with Client

use of org.orcid.pojo.ajaxForm.Client in project ORCID-Source by ORCID.

the class ManageMembersControllerTest method findClientTest.

@Test
public void findClientTest() throws Exception {
    // Client with all redirect uris default
    Client client_0002 = manageMembers.findClient("APP-0000000000000002");
    assertNotNull(client_0002);
    assertNotNull(client_0002.getDisplayName());
    assertEquals("Client # 2", client_0002.getDisplayName().getValue());
    assertNotNull(client_0002.getRedirectUris());
    assertEquals(1, client_0002.getRedirectUris().size());
    assertEquals("http://www.google.com/APP-0000000000000002/redirect/oauth", client_0002.getRedirectUris().get(0).getValue().getValue());
    // Client with redirect uri not default
    Client client_0003 = manageMembers.findClient("APP-0000000000000003");
    assertNotNull(client_0003);
    assertNotNull(client_0003.getDisplayName());
    assertEquals("Client # 3", client_0003.getDisplayName().getValue());
    assertNotNull(client_0003.getRedirectUris());
    assertEquals(2, client_0003.getRedirectUris().size());
    RedirectUri rUri1 = client_0003.getRedirectUris().get(0);
    if ("http://www.google.com/APP-0000000000000003/redirect/oauth".equals(rUri1.getValue().getValue())) {
        assertNotNull(rUri1.getType());
        assertEquals("default", rUri1.getType().getValue());
        assertNotNull(rUri1.getScopes());
        assertEquals(0, rUri1.getScopes().size());
    } else if ("http://www.google.com/APP-0000000000000003/redirect/oauth/grant_read_wizard".equals(rUri1.getValue().getValue())) {
        assertNotNull(rUri1.getType());
        assertEquals("grant-read-wizard", rUri1.getType().getValue());
        assertNotNull(rUri1.getScopes());
        assertEquals(1, rUri1.getScopes().size());
        assertEquals("/funding/read-limited", rUri1.getScopes().get(0));
    } else {
        fail("Invalid redirect uri: " + rUri1.getValue().getValue());
    }
    RedirectUri rUri2 = client_0003.getRedirectUris().get(1);
    if ("http://www.google.com/APP-0000000000000003/redirect/oauth".equals(rUri2.getValue().getValue())) {
        assertNotNull(rUri2.getType());
        assertEquals("default", rUri2.getType().getValue());
        assertNotNull(rUri2.getScopes());
        assertEquals(0, rUri2.getScopes().size());
    } else if ("http://www.google.com/APP-0000000000000003/redirect/oauth/grant_read_wizard".equals(rUri2.getValue().getValue())) {
        assertNotNull(rUri2.getType());
        assertEquals("grant-read-wizard", rUri2.getType().getValue());
        assertNotNull(rUri2.getScopes());
        assertEquals(1, rUri2.getScopes().size());
        assertEquals("/funding/read-limited", rUri2.getScopes().get(0));
    } else {
        fail("Invalid redirect uri: " + rUri2.getValue().getValue());
    }
}
Also used : RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Client(org.orcid.pojo.ajaxForm.Client) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 30 with Client

use of org.orcid.pojo.ajaxForm.Client in project ORCID-Source by ORCID.

the class ClientsController method getEmptyClient.

@RequestMapping(value = "/client.json", method = RequestMethod.GET)
@ResponseBody
public Client getEmptyClient() {
    Client emptyClient = new Client();
    emptyClient.setDisplayName(new Text());
    emptyClient.setWebsite(new Text());
    emptyClient.setShortDescription(new Text());
    emptyClient.setClientId(new Text());
    emptyClient.setClientSecret(new Text());
    emptyClient.setType(new Text());
    emptyClient.setAllowAutoDeprecate(Checkbox.valueOf(false));
    ArrayList<RedirectUri> redirectUris = new ArrayList<RedirectUri>();
    RedirectUri emptyRedirectUri = new RedirectUri();
    emptyRedirectUri.setValue(new Text());
    emptyRedirectUri.setType(Text.valueOf(RedirectUriType.DEFAULT.value()));
    emptyRedirectUri.setActType(Text.valueOf(""));
    emptyRedirectUri.setGeoArea(Text.valueOf(""));
    redirectUris.add(emptyRedirectUri);
    emptyClient.setRedirectUris(redirectUris);
    return emptyClient;
}
Also used : ArrayList(java.util.ArrayList) Text(org.orcid.pojo.ajaxForm.Text) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Client(org.orcid.pojo.ajaxForm.Client) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Client (org.orcid.pojo.ajaxForm.Client)31 Test (org.junit.Test)23 RedirectUri (org.orcid.pojo.ajaxForm.RedirectUri)21 ArrayList (java.util.ArrayList)14 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)14 Text (org.orcid.pojo.ajaxForm.Text)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 OrcidClient (org.orcid.jaxb.model.clientgroup.OrcidClient)3 DBUnitTest (org.orcid.test.DBUnitTest)3 Rollback (org.springframework.test.annotation.Rollback)2 Transactional (org.springframework.transaction.annotation.Transactional)2 HashSet (java.util.HashSet)1 Produces (javax.ws.rs.Produces)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 OrcidClientGroupManagementException (org.orcid.core.exception.OrcidClientGroupManagementException)1 OrcidClientGroup (org.orcid.jaxb.model.clientgroup.OrcidClientGroup)1 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)1 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)1