Search in sources :

Example 21 with Client

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

the class ClientsControllerTest method addClientTest.

@Test
public void addClientTest() {
    List<Client> clients = controller.getClients();
    int clientsSoFar = clients.size();
    assertTrue(clientsSoFar > 0);
    Client client = new Client();
    client.setAllowAutoDeprecate(Checkbox.valueOf(true));
    client.setClientId(Text.valueOf("XXXXXX"));
    client.setDisplayName(Text.valueOf("My client name"));
    client.setMemberId(Text.valueOf("0000-0000-0000-0000"));
    client.setMemberName(Text.valueOf("My member name"));
    client.setPersistentTokenEnabled(Checkbox.valueOf(true));
    List<RedirectUri> redirectUris = new ArrayList<RedirectUri>();
    RedirectUri r1 = new RedirectUri();
    r1.setValue(Text.valueOf("http://orcid.org"));
    r1.setType(Text.valueOf(RedirectUriType.DEFAULT.value()));
    redirectUris.add(r1);
    client.setRedirectUris(redirectUris);
    client.setShortDescription(Text.valueOf("My short description"));
    client.setWebsite(Text.valueOf("http://orcid.org"));
    client = controller.createClient(client);
    assertTrue(client.getErrors().isEmpty());
    assertNotNull(client);
    assertNotNull(client.getClientId());
    assertTrue(client.getClientId().getValue().startsWith("APP-"));
    assertFalse(PojoUtil.isEmpty(client.getClientSecret()));
    clients = controller.getClients();
    assertTrue(clients.size() > clientsSoFar);
    boolean found = false;
    for (Client c : clients) {
        if (client.getClientId().getValue().equals(c.getClientId().getValue())) {
            found = true;
            break;
        }
    }
    assertTrue(found);
}
Also used : ArrayList(java.util.ArrayList) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Client(org.orcid.pojo.ajaxForm.Client) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Example 22 with Client

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

the class ClientsControllerTest method testInvalidDescription.

@Test
public void testInvalidDescription() {
    Client client = controller.getEmptyClient();
    client.setRedirectUris(new ArrayList<RedirectUri>());
    client.setDisplayName(Text.valueOf("This is a valid name"));
    client.setShortDescription(Text.valueOf("This is a <a>invalid</a> description"));
    client.setWebsite(Text.valueOf("http://www.orcid.org"));
    client = controller.createClient(client);
    assertNotNull(client);
    assertEquals(1, client.getErrors().size());
    assertEquals(controller.getMessage("manage.developer_tools.group.error.short_description.html"), client.getErrors().get(0));
}
Also used : RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Client(org.orcid.pojo.ajaxForm.Client) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Example 23 with Client

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

the class DeveloperToolsControllerTest method testCrossSiteScriptingOnClientName.

@Test
public void testCrossSiteScriptingOnClientName() throws Exception {
    Client client = new Client();
    client.setDisplayName(Text.valueOf("<script>alert('name')</script>"));
    client.setShortDescription(Text.valueOf("This is a short 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);
    assertEquals(1, result.getErrors().size());
    assertEquals(developerToolsController.getMessage("manage.developer_tools.name.html"), result.getErrors().get(0));
}
Also used : ArrayList(java.util.ArrayList) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Client(org.orcid.pojo.ajaxForm.Client) Test(org.junit.Test)

Example 24 with Client

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

the class DeveloperToolsControllerTest method createClientTest.

@Test
public void createClientTest() throws Exception {
    Client client = new Client();
    client.setDisplayName(Text.valueOf("Client Name"));
    client.setShortDescription(Text.valueOf("This is a test"));
    client.setType(Text.valueOf(ClientType.PUBLIC_CLIENT.value()));
    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);
    verify(mockClientManager, times(1)).createPublicClient(Matchers.any(org.orcid.jaxb.model.v3.dev1.client.Client.class));
    assertEquals(CLIENT_1, result.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 25 with Client

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

the class DeveloperToolsControllerTest method testCrossSiteScriptingOnClientDescription.

@Test
public void testCrossSiteScriptingOnClientDescription() throws Exception {
    Client client = new Client();
    client.setDisplayName(Text.valueOf("Client Name"));
    client.setShortDescription(Text.valueOf("This is a test to show that html is <script>alert('name')</script> throws an error"));
    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);
    assertEquals(1, result.getErrors().size());
    assertEquals(developerToolsController.getMessage("manage.developer_tools.description.html"), result.getErrors().get(0));
}
Also used : ArrayList(java.util.ArrayList) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Client(org.orcid.pojo.ajaxForm.Client) Test(org.junit.Test)

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