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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations