use of org.cloudfoundry.credhub.auth.UserContext in project credhub by cloudfoundry-incubator.
the class InterpolationHandlerTest method beforeEach.
@Before
public void beforeEach() {
credentialService = mock(PermissionedCredentialService.class);
userContext = mock(UserContext.class);
subject = new InterpolationHandler(credentialService);
eventAuditRecordParameters = new ArrayList<>();
}
use of org.cloudfoundry.credhub.auth.UserContext in project credhub by cloudfoundry-incubator.
the class PermissionCheckingServiceTest method beforeEach.
@Before
public void beforeEach() {
userContext = mock(UserContext.class);
when(userContext.getActor()).thenReturn("test-actor");
permissionDataService = mock(PermissionDataService.class);
UserContextHolder userContextHolder = new UserContextHolder();
userContextHolder.setUserContext(userContext);
subject = new PermissionCheckingService(permissionDataService, userContextHolder);
}
use of org.cloudfoundry.credhub.auth.UserContext in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateServiceTest method getAllByName_returnsCertificateWithMatchingNameIfCurrentUserHasAccess.
@Test
public void getAllByName_returnsCertificateWithMatchingNameIfCurrentUserHasAccess() throws Exception {
Credential myCredential = mock(Credential.class);
when(myCredential.getName()).thenReturn("my-credential");
Credential otherCredential = mock(Credential.class);
when(otherCredential.getName()).thenReturn("other-credential");
UserContext userContext = mock(UserContext.class);
when(userContextHolder.getUserContext()).thenReturn(userContext);
String user = "my-user";
when(userContext.getActor()).thenReturn(user);
when(permissionCheckingService.hasPermission(user, "my-credential", PermissionOperation.READ)).thenReturn(true);
when(permissionCheckingService.hasPermission(user, "other-credential", PermissionOperation.READ)).thenReturn(true);
when(certificateDataService.findByName("my-credential")).thenReturn(myCredential);
final List<Credential> certificates = subject.getByName("my-credential", newArrayList());
assertThat(certificates, equalTo(newArrayList(myCredential)));
}
use of org.cloudfoundry.credhub.auth.UserContext in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateServiceTest method deleteVersion_whenTheProvidedCredentialDoesNotExist_returnsAnError.
@Test(expected = EntryNotFoundException.class)
public void deleteVersion_whenTheProvidedCredentialDoesNotExist_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);
when(certificateDataService.findByUuid(certificateUuid)).thenReturn(null);
CertificateCredentialVersion versionToDelete = mock(CertificateCredentialVersion.class);
when(certificateVersionDataService.findVersion(versionUuid)).thenReturn(versionToDelete);
subject.deleteVersion(certificateUuid, versionUuid, newArrayList());
}
use of org.cloudfoundry.credhub.auth.UserContext in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateServiceTest method updateTransitionalVersion_whenTheCertificateIsNotFound_returnsAnError.
@Test(expected = EntryNotFoundException.class)
public void updateTransitionalVersion_whenTheCertificateIsNotFound_returnsAnError() {
UUID certificateUuid = UUID.randomUUID();
UUID transitionalVersionUuid = UUID.randomUUID();
UserContext userContext = mock(UserContext.class);
when(userContextHolder.getUserContext()).thenReturn(userContext);
when(certificateDataService.findByUuid(certificateUuid)).thenReturn(null);
subject.updateTransitionalVersion(certificateUuid, transitionalVersionUuid, newArrayList());
}
Aggregations