Search in sources :

Example 1 with UserContext

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<>();
}
Also used : UserContext(org.cloudfoundry.credhub.auth.UserContext) InterpolationHandler(org.cloudfoundry.credhub.handler.InterpolationHandler) Before(org.junit.Before)

Example 2 with UserContext

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);
}
Also used : UserContext(org.cloudfoundry.credhub.auth.UserContext) UserContextHolder(org.cloudfoundry.credhub.auth.UserContextHolder) PermissionDataService(org.cloudfoundry.credhub.data.PermissionDataService) Before(org.junit.Before)

Example 3 with UserContext

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)));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) UserContext(org.cloudfoundry.credhub.auth.UserContext) Test(org.junit.Test)

Example 4 with UserContext

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());
}
Also used : UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) Test(org.junit.Test)

Example 5 with UserContext

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());
}
Also used : UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) 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