Search in sources :

Example 26 with RedirectUri

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

the class ClientsControllerTest method editInvalidClientTest.

@Test
public void editInvalidClientTest() {
    // Test invalid fields
    Client client = controller.getEmptyClient();
    String _151chars = RandomStringUtils.randomAlphanumeric(151);
    client.setDisplayName(Text.valueOf(_151chars));
    client.setShortDescription(Text.valueOf("description"));
    client.setWebsite(Text.valueOf("http://site.com"));
    List<RedirectUri> redirectUris = new ArrayList<RedirectUri>();
    RedirectUri one = new RedirectUri();
    one.setType(Text.valueOf("default"));
    one.setValue(Text.valueOf(""));
    redirectUris.add(one);
    client.setRedirectUris(redirectUris);
    client = controller.editClient(client);
    List<String> errors = client.getErrors();
    assertEquals(2, errors.size());
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.group.error.display_name.150")));
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.empty_redirect_uri")));
    // Test invalid redirect uris
    client = controller.getEmptyClient();
    client.setDisplayName(Text.valueOf("Name"));
    client.setShortDescription(Text.valueOf("Description"));
    client.setWebsite(Text.valueOf("http://mysite.com"));
    redirectUris = new ArrayList<RedirectUri>();
    one = new RedirectUri();
    one.setType(Text.valueOf("default"));
    one.setValue(new Text());
    redirectUris.add(one);
    client.setRedirectUris(redirectUris);
    client = controller.editClient(client);
    errors = client.getErrors();
    assertEquals(1, errors.size());
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.empty_redirect_uri")));
    RedirectUri two = new RedirectUri();
    two.setType(Text.valueOf("grant-read-wizard"));
    two.setValue(new Text());
    redirectUris = new ArrayList<RedirectUri>();
    redirectUris.add(two);
    client.setRedirectUris(redirectUris);
    client = controller.editClient(client);
    errors = client.getErrors();
    assertEquals(2, errors.size());
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.empty_redirect_uri")));
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.group.error.empty_scopes")));
}
Also used : ArrayList(java.util.ArrayList) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Text(org.orcid.pojo.ajaxForm.Text) Client(org.orcid.pojo.ajaxForm.Client) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Example 27 with RedirectUri

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

the class ClientsControllerTest method editClientTest.

@Test
public void editClientTest() {
    List<Client> clients = controller.getClients();
    int clientsSoFar = clients.size();
    assertNotNull(clients);
    assertEquals(2, clients.size());
    Client client = clients.get(0);
    assertEquals("APP-5555555555555555", client.getClientId().getValue());
    String random = RandomStringUtils.randomAlphanumeric(20);
    client.getDisplayName().setValue("Source Client 1 Updated");
    client.getShortDescription().setValue("Updated client description");
    client.getWebsite().setValue("http://orcid.org/" + random);
    RedirectUri newRedirectUri = new RedirectUri();
    newRedirectUri.setValue(Text.valueOf("http://orcid.org/" + random));
    newRedirectUri.setType(Text.valueOf(RedirectUriType.DEFAULT.value()));
    client.getRedirectUris().add(newRedirectUri);
    client = controller.editClient(client);
    assertTrue(client.getErrors().isEmpty());
    clients = controller.getClients();
    assertTrue(clients.size() == clientsSoFar);
    boolean found = false;
    for (Client c : clients) {
        if (client.getClientId().getValue().equals(c.getClientId().getValue())) {
            assertEquals("Source Client 1 Updated", client.getDisplayName().getValue());
            assertEquals("Updated client description", client.getShortDescription().getValue());
            assertEquals("http://orcid.org/" + random, client.getWebsite().getValue());
            boolean rUriFound = false;
            for (RedirectUri rUri : client.getRedirectUris()) {
                if (rUri.getValue().getValue().equals("http://orcid.org/" + random)) {
                    assertEquals(RedirectUriType.DEFAULT.value(), rUri.getType().getValue());
                    rUriFound = true;
                }
            }
            assertTrue(rUriFound);
            found = true;
            break;
        }
    }
    assertTrue(found);
}
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 28 with RedirectUri

use of org.orcid.pojo.ajaxForm.RedirectUri 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 29 with RedirectUri

use of org.orcid.pojo.ajaxForm.RedirectUri 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 30 with RedirectUri

use of org.orcid.pojo.ajaxForm.RedirectUri 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)

Aggregations

RedirectUri (org.orcid.pojo.ajaxForm.RedirectUri)38 Test (org.junit.Test)22 Client (org.orcid.pojo.ajaxForm.Client)21 ArrayList (java.util.ArrayList)15 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)15 Text (org.orcid.pojo.ajaxForm.Text)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 HashSet (java.util.HashSet)7 SSOCredentials (org.orcid.pojo.ajaxForm.SSOCredentials)5 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)4 Transactional (org.springframework.transaction.annotation.Transactional)4 OrcidClient (org.orcid.jaxb.model.clientgroup.OrcidClient)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 Produces (javax.ws.rs.Produces)2 OrcidClientGroupManagementException (org.orcid.core.exception.OrcidClientGroupManagementException)2 ErrorDesc (org.orcid.jaxb.model.message.ErrorDesc)2 DBUnitTest (org.orcid.test.DBUnitTest)2 UrlValidator (org.apache.commons.validator.routines.UrlValidator)1 ClientSecretEntity (org.orcid.persistence.jpa.entities.ClientSecretEntity)1