use of org.alfresco.service.cmr.remotecredentials.BaseCredentialsInfo in project alfresco-remote-api by Alfresco.
the class RemoteAlfrescoTicketServiceTest method testGetStoreGetCredentials.
/**
* Getting, storing and fetching credentials
*/
public void testGetStoreGetCredentials() throws Exception {
// Run this test initially as the first user
AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
// First, try an invalid system
try {
remoteAlfrescoTicketService.getRemoteCredentials(INVALID_REMOTE_SYSTEM_ID);
fail("Shouldn't work for an invalid system");
} catch (NoSuchSystemException e) {
}
try {
remoteAlfrescoTicketService.storeRemoteCredentials(INVALID_REMOTE_SYSTEM_ID, null, null);
fail("Shouldn't work for an invalid system");
} catch (NoSuchSystemException e) {
}
// Our user starts out without credentials
BaseCredentialsInfo credentials = remoteAlfrescoTicketService.getRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertEquals(null, credentials);
// Try to store some invalid credentials (real user, but password wrong)
try {
remoteAlfrescoTicketService.storeRemoteCredentials(TEST_REMOTE_SYSTEM_ID, USER_ONE, "invalid");
fail("Credentials invalid, shouldn't be allowed");
} catch (AuthenticationException e) {
}
// And an invalid user
try {
remoteAlfrescoTicketService.storeRemoteCredentials(TEST_REMOTE_SYSTEM_ID, "thisUSERdoesNOTexist", "invalid");
fail("Credentials invalid, shouldn't be allowed");
} catch (AuthenticationException e) {
}
// Still none there
credentials = remoteAlfrescoTicketService.getRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertEquals(null, credentials);
// Store some valid ones
credentials = remoteAlfrescoTicketService.storeRemoteCredentials(TEST_REMOTE_SYSTEM_ID, USER_ONE, PASSWORD);
assertNotNull(credentials);
assertEquals(TEST_REMOTE_SYSTEM_ID, credentials.getRemoteSystemName());
assertEquals(USER_ONE, credentials.getRemoteUsername());
// Check we can find them
credentials = remoteAlfrescoTicketService.getRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertNotNull(credentials);
assertEquals(TEST_REMOTE_SYSTEM_ID, credentials.getRemoteSystemName());
assertEquals(USER_ONE, credentials.getRemoteUsername());
// Store some different, valid credentials for the user
credentials = remoteAlfrescoTicketService.storeRemoteCredentials(TEST_REMOTE_SYSTEM_ID, USER_TWO, PASSWORD);
assertNotNull(credentials);
assertEquals(TEST_REMOTE_SYSTEM_ID, credentials.getRemoteSystemName());
assertEquals(USER_TWO, credentials.getRemoteUsername());
// Check we see the change
credentials = remoteAlfrescoTicketService.getRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertNotNull(credentials);
assertEquals(TEST_REMOTE_SYSTEM_ID, credentials.getRemoteSystemName());
assertEquals(USER_TWO, credentials.getRemoteUsername());
// Switch to the other user, no credentials there
AuthenticationUtil.setFullyAuthenticatedUser(USER_TWO);
credentials = remoteAlfrescoTicketService.getRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertEquals(null, credentials);
// Switch back, and delete
AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
credentials = remoteAlfrescoTicketService.getRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertNotNull(credentials);
boolean deleted = remoteAlfrescoTicketService.deleteRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertEquals(true, deleted);
// Will have gone
credentials = remoteAlfrescoTicketService.getRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertEquals(null, credentials);
// Double delete is reported
deleted = remoteAlfrescoTicketService.deleteRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertEquals(false, deleted);
}
Aggregations