Search in sources :

Example 21 with RedirectUri

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

the class DeveloperToolsControllerTest method testResetClientSecret.

@Test
public void testResetClientSecret() throws Exception {
    SSOCredentials ssoCredentials = new SSOCredentials();
    ssoCredentials.setClientName(Text.valueOf("Client Name"));
    ssoCredentials.setClientDescription(Text.valueOf("This is a test"));
    ssoCredentials.setClientWebsite(Text.valueOf("http://client.com"));
    Set<RedirectUri> redirectUris = new HashSet<RedirectUri>();
    RedirectUri rUri = new RedirectUri();
    rUri.setType(Text.valueOf("default"));
    rUri.setValue(Text.valueOf("http://test.com"));
    redirectUris.add(rUri);
    ssoCredentials.setRedirectUris(redirectUris);
    SSOCredentials result = developerToolsController.generateSSOCredentialsJson(ssoCredentials);
    assertNotNull(result);
    assertNotNull(result.getErrors());
    assertEquals(result.getErrors().size(), 0);
    Text clientSecret = result.getClientSecret();
    assertTrue(developerToolsController.resetClientSecret(result.getClientOrcid().getValue()));
    ClientDetailsEntity clientDetails = clientDetailsDao.findByClientId(result.getClientOrcid().getValue(), System.currentTimeMillis());
    assertEquals(result.getClientName().getValue(), clientDetails.getClientName());
    assertEquals(result.getClientDescription().getValue(), clientDetails.getClientDescription());
    assertEquals(result.getClientOrcid().getValue(), clientDetails.getClientId());
    assertEquals(result.getClientWebsite().getValue(), clientDetails.getClientWebsite());
    Set<ClientSecretEntity> clientSecrets = clientDetails.getClientSecrets();
    assertNotNull(clientSecrets);
    assertEquals(2, clientSecrets.size());
    for (ClientSecretEntity clientSecretEntity : clientSecrets) {
        String secret = encryptionManager.decryptForInternalUse(clientSecretEntity.getClientSecret());
        if (!clientSecretEntity.isPrimary())
            assertEquals(clientSecret.getValue(), secret);
        else
            assertFalse(clientSecret.getValue().equals(secret));
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SSOCredentials(org.orcid.pojo.ajaxForm.SSOCredentials) ClientSecretEntity(org.orcid.persistence.jpa.entities.ClientSecretEntity) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Text(org.orcid.pojo.ajaxForm.Text) HashSet(java.util.HashSet) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Example 22 with RedirectUri

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

the class DeveloperToolsControllerTest method testGenerateSSOCredentials.

@Test
@Transactional("transactionManager")
public void testGenerateSSOCredentials() throws Exception {
    SSOCredentials ssoCredentials = new SSOCredentials();
    ssoCredentials.setClientName(Text.valueOf("Client Name"));
    ssoCredentials.setClientDescription(Text.valueOf("This is a test"));
    ssoCredentials.setClientWebsite(Text.valueOf("http://client.com"));
    Set<RedirectUri> redirectUris = new HashSet<RedirectUri>();
    RedirectUri rUri = new RedirectUri();
    rUri.setType(Text.valueOf("default"));
    rUri.setValue(Text.valueOf("http://test.com"));
    redirectUris.add(rUri);
    ssoCredentials.setRedirectUris(redirectUris);
    SSOCredentials result = developerToolsController.generateSSOCredentialsJson(ssoCredentials);
    assertNotNull(result);
    assertNotNull(result.getErrors());
    assertEquals(result.getErrors().size(), 0);
    assertNotNull(result.getClientSecret());
    assertFalse(PojoUtil.isEmpty(result.getClientSecret()));
    assertFalse(PojoUtil.isEmpty(result.getClientOrcid()));
}
Also used : SSOCredentials(org.orcid.pojo.ajaxForm.SSOCredentials) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) HashSet(java.util.HashSet) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with RedirectUri

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

the class DeveloperToolsControllerTest method testCrossSiteScriptingOnClientDescription.

@Test
@Transactional("transactionManager")
public void testCrossSiteScriptingOnClientDescription() throws Exception {
    SSOCredentials ssoCredentials = new SSOCredentials();
    ssoCredentials.setClientName(Text.valueOf("Client Name"));
    ssoCredentials.setClientDescription(Text.valueOf("This is a test to show that html is <script>alert('name')</script> throws an error"));
    ssoCredentials.setClientWebsite(Text.valueOf("http://client.com"));
    Set<RedirectUri> redirectUris = new HashSet<RedirectUri>();
    RedirectUri rUri = new RedirectUri();
    rUri.setType(Text.valueOf("default"));
    rUri.setValue(Text.valueOf("http://test.com"));
    redirectUris.add(rUri);
    ssoCredentials.setRedirectUris(redirectUris);
    SSOCredentials result = developerToolsController.generateSSOCredentialsJson(ssoCredentials);
    assertNotNull(result);
    assertEquals(1, result.getErrors().size());
    assertEquals(developerToolsController.getMessage("manage.developer_tools.description.html"), result.getErrors().get(0));
}
Also used : SSOCredentials(org.orcid.pojo.ajaxForm.SSOCredentials) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) HashSet(java.util.HashSet) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with RedirectUri

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

the class DeveloperToolsControllerTest method testCrossSiteScriptingOnClientName.

@Test
@Transactional("transactionManager")
public void testCrossSiteScriptingOnClientName() throws Exception {
    SSOCredentials ssoCredentials = new SSOCredentials();
    ssoCredentials.setClientName(Text.valueOf("<script>alert('name')</script>"));
    ssoCredentials.setClientDescription(Text.valueOf("This is a short description"));
    ssoCredentials.setClientWebsite(Text.valueOf("http://client.com"));
    Set<RedirectUri> redirectUris = new HashSet<RedirectUri>();
    RedirectUri rUri = new RedirectUri();
    rUri.setType(Text.valueOf("default"));
    rUri.setValue(Text.valueOf("http://test.com"));
    redirectUris.add(rUri);
    ssoCredentials.setRedirectUris(redirectUris);
    SSOCredentials result = developerToolsController.generateSSOCredentialsJson(ssoCredentials);
    assertNotNull(result);
    assertEquals(1, result.getErrors().size());
    assertEquals(developerToolsController.getMessage("manage.developer_tools.name.html"), result.getErrors().get(0));
}
Also used : SSOCredentials(org.orcid.pojo.ajaxForm.SSOCredentials) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) HashSet(java.util.HashSet) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RedirectUri (org.orcid.pojo.ajaxForm.RedirectUri)24 Test (org.junit.Test)12 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)10 HashSet (java.util.HashSet)9 Text (org.orcid.pojo.ajaxForm.Text)8 Client (org.orcid.pojo.ajaxForm.Client)7 SSOCredentials (org.orcid.pojo.ajaxForm.SSOCredentials)7 Transactional (org.springframework.transaction.annotation.Transactional)6 ArrayList (java.util.ArrayList)5 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)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