Search in sources :

Example 26 with UserContext

use of org.cloudfoundry.credhub.auth.UserContext in project credhub by cloudfoundry-incubator.

the class PermissionedCertificateServiceTest method deleteVersion_whenTheProvidedVersionDoesNotExist_returnsAnError.

@Test(expected = EntryNotFoundException.class)
public void deleteVersion_whenTheProvidedVersionDoesNotExist_returnsAnError() throws Exception {
    UUID versionUuid = UUID.randomUUID();
    UUID certificateUuid = UUID.randomUUID();
    UserContext userContext = mock(UserContext.class);
    when(userContextHolder.getUserContext()).thenReturn(userContext);
    String user = "my-user";
    String credentialName = "my-credential";
    when(userContext.getActor()).thenReturn(user);
    when(permissionCheckingService.hasPermission(user, credentialName, PermissionOperation.DELETE)).thenReturn(true);
    Credential certificate = mock(Credential.class);
    when(certificate.getName()).thenReturn(credentialName);
    when(certificate.getUuid()).thenReturn(certificateUuid);
    when(certificateDataService.findByUuid(certificateUuid)).thenReturn(certificate);
    when(certificate.getUuid()).thenReturn(UUID.randomUUID());
    when(certificateVersionDataService.findVersion(versionUuid)).thenReturn(null);
    subject.deleteVersion(certificateUuid, versionUuid, newArrayList());
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) Test(org.junit.Test)

Example 27 with UserContext

use of org.cloudfoundry.credhub.auth.UserContext in project credhub by cloudfoundry-incubator.

the class PermissionedCertificateServiceTest method updateTransitionalVersion_whenVersionDoesNotExist_returnsAnError.

@Test(expected = ParameterizedValidationException.class)
public void updateTransitionalVersion_whenVersionDoesNotExist_returnsAnError() {
    UUID certificateUuid = UUID.randomUUID();
    UUID transitionalVersionUuid = UUID.randomUUID();
    String credentialName = "my-credential";
    Credential certificate = mock(Credential.class);
    when(certificate.getName()).thenReturn(credentialName);
    when(certificate.getUuid()).thenReturn(certificateUuid);
    String user = "my-user";
    UserContext userContext = mock(UserContext.class);
    when(userContextHolder.getUserContext()).thenReturn(userContext);
    when(userContext.getActor()).thenReturn(user);
    when(certificateDataService.findByUuid(certificateUuid)).thenReturn(certificate);
    when(permissionCheckingService.hasPermission(user, credentialName, PermissionOperation.WRITE)).thenReturn(true);
    when(certificateVersionDataService.findVersion(transitionalVersionUuid)).thenReturn(null);
    subject.updateTransitionalVersion(certificateUuid, transitionalVersionUuid, newArrayList());
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) Test(org.junit.Test)

Example 28 with UserContext

use of org.cloudfoundry.credhub.auth.UserContext in project credhub by cloudfoundry-incubator.

the class PermissionedCertificateServiceTest method updateTransitionalVersion_whenVersionDoesNotBelongToCertificate_returnsAnError.

@Test(expected = ParameterizedValidationException.class)
public void updateTransitionalVersion_whenVersionDoesNotBelongToCertificate_returnsAnError() {
    UUID certificateUuid = UUID.randomUUID();
    UUID transitionalVersionUuid = UUID.randomUUID();
    String credentialName = "my-credential";
    Credential certificate = mock(Credential.class);
    when(certificate.getName()).thenReturn(credentialName);
    when(certificate.getUuid()).thenReturn(certificateUuid);
    Credential otherCertificate = mock(Credential.class);
    when(otherCertificate.getUuid()).thenReturn(UUID.randomUUID());
    CertificateCredentialVersion version = mock(CertificateCredentialVersion.class);
    String user = "my-user";
    UserContext userContext = mock(UserContext.class);
    when(userContextHolder.getUserContext()).thenReturn(userContext);
    when(userContext.getActor()).thenReturn(user);
    when(certificateDataService.findByUuid(certificateUuid)).thenReturn(certificate);
    when(permissionCheckingService.hasPermission(user, credentialName, PermissionOperation.WRITE)).thenReturn(true);
    when(certificateVersionDataService.findVersion(transitionalVersionUuid)).thenReturn(version);
    when(version.getCredential()).thenReturn(otherCertificate);
    subject.updateTransitionalVersion(certificateUuid, transitionalVersionUuid, newArrayList());
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) Test(org.junit.Test)

Example 29 with UserContext

use of org.cloudfoundry.credhub.auth.UserContext in project credhub by cloudfoundry-incubator.

the class PermissionedCertificateServiceTest method updateTransitionalVersion_whenTheUserDoesNotHavePermissions_returnsAnError.

@Test(expected = EntryNotFoundException.class)
public void updateTransitionalVersion_whenTheUserDoesNotHavePermissions_returnsAnError() {
    UUID certificateUuid = UUID.randomUUID();
    UUID transitionalVersionUuid = UUID.randomUUID();
    String credentialName = "my-credential";
    Credential certificate = mock(Credential.class);
    when(certificate.getName()).thenReturn(credentialName);
    UserContext userContext = mock(UserContext.class);
    when(userContextHolder.getUserContext()).thenReturn(userContext);
    String user = "my-user";
    when(certificateDataService.findByUuid(certificateUuid)).thenReturn(certificate);
    when(permissionCheckingService.hasPermission(user, credentialName, PermissionOperation.WRITE)).thenReturn(false);
    subject.updateTransitionalVersion(certificateUuid, transitionalVersionUuid, newArrayList());
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) Test(org.junit.Test)

Example 30 with UserContext

use of org.cloudfoundry.credhub.auth.UserContext in project credhub by cloudfoundry-incubator.

the class PermissionedCertificateServiceTest method deleteVersion_whenTheProvidedVersionDoesNotExistForTheSpecifiedCredential_returnsAnError.

@Test(expected = EntryNotFoundException.class)
public void deleteVersion_whenTheProvidedVersionDoesNotExistForTheSpecifiedCredential_returnsAnError() throws Exception {
    UUID versionUuid = UUID.randomUUID();
    UUID certificateUuid = UUID.randomUUID();
    UserContext userContext = mock(UserContext.class);
    when(userContextHolder.getUserContext()).thenReturn(userContext);
    String user = "my-user";
    String credentialName = "my-credential";
    when(userContext.getActor()).thenReturn(user);
    when(permissionCheckingService.hasPermission(user, credentialName, PermissionOperation.DELETE)).thenReturn(true);
    Credential certificate = mock(Credential.class);
    when(certificate.getName()).thenReturn(credentialName);
    when(certificate.getUuid()).thenReturn(certificateUuid);
    when(certificateDataService.findByUuid(certificateUuid)).thenReturn(certificate);
    CertificateCredentialVersion versionToDelete = mock(CertificateCredentialVersion.class);
    Credential someOtherCredential = mock(Credential.class);
    when(certificate.getUuid()).thenReturn(UUID.randomUUID());
    when(certificateVersionDataService.findVersion(versionUuid)).thenReturn(versionToDelete);
    when(versionToDelete.getCredential()).thenReturn(someOtherCredential);
    subject.deleteVersion(certificateUuid, versionUuid, newArrayList());
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) Test(org.junit.Test)

Aggregations

UserContext (org.cloudfoundry.credhub.auth.UserContext)37 Test (org.junit.Test)21 UUID (java.util.UUID)16 Before (org.junit.Before)14 Credential (org.cloudfoundry.credhub.entity.Credential)13 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)9 UserContextHolder (org.cloudfoundry.credhub.auth.UserContextHolder)7 EventAuditRecord (org.cloudfoundry.credhub.entity.EventAuditRecord)6 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)4 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)4 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)4 PermissionCheckingService (org.cloudfoundry.credhub.service.PermissionCheckingService)4 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)3 PermissionedCredentialService (org.cloudfoundry.credhub.service.PermissionedCredentialService)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 UserContextFactory (org.cloudfoundry.credhub.auth.UserContextFactory)2 CertificateAuthorityService (org.cloudfoundry.credhub.data.CertificateAuthorityService)2 PermissionDataService (org.cloudfoundry.credhub.data.PermissionDataService)2 CertificateGenerationParameters (org.cloudfoundry.credhub.domain.CertificateGenerationParameters)2 Encryptor (org.cloudfoundry.credhub.domain.Encryptor)2