use of org.cloudfoundry.credhub.auth.UserContext in project credhub by cloudfoundry-incubator.
the class CertificateGeneratorTest method beforeEach.
@Before
public void beforeEach() throws Exception {
TestHelper.getBouncyCastleProvider();
keyGenerator = mock(LibcryptoRsaKeyPairGenerator.class);
signedCertificateGenerator = mock(SignedCertificateGenerator.class);
certificateAuthorityService = mock(CertificateAuthorityService.class);
permissionCheckingService = mock(PermissionCheckingService.class);
userContext = mock(UserContext.class);
subject = new CertificateGenerator(keyGenerator, signedCertificateGenerator, certificateAuthorityService);
when(permissionCheckingService.hasPermission(anyString(), anyString(), any())).thenReturn(true);
fakeKeyPairGenerator = new FakeKeyPairGenerator();
rootCaDn = new X500Name("O=foo,ST=bar,C=root");
signeeDn = new X500Name("O=foo,ST=bar,C=mars");
rootCaKeyPair = fakeKeyPairGenerator.generate();
X509CertificateHolder caX509CertHolder = makeCert(rootCaKeyPair, rootCaKeyPair.getPrivate(), rootCaDn, rootCaDn, true);
rootCaX509Certificate = new JcaX509CertificateConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME).getCertificate(caX509CertHolder);
rootCa = new CertificateCredentialValue(null, CertificateFormatter.pemOf(rootCaX509Certificate), CertificateFormatter.pemOf(rootCaKeyPair.getPrivate()), null);
generationParameters = new CertificateGenerationRequestParameters();
generationParameters.setOrganization("foo");
generationParameters.setState("bar");
generationParameters.setCaName("my-ca-name");
generationParameters.setCountry("mars");
generationParameters.setDuration(365);
inputParameters = new CertificateGenerationParameters(generationParameters);
}
use of org.cloudfoundry.credhub.auth.UserContext in project credhub by cloudfoundry-incubator.
the class AuditLogFactoryTest method createEventAuditRecord_whenParameterAceOperationIsNull_createsEventAuditRecord.
@Test
public void createEventAuditRecord_whenParameterAceOperationIsNull_createsEventAuditRecord() {
final UserContext userContext = mock(UserContext.class);
final UUID requestUuid = UUID.randomUUID();
final EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters();
eventAuditRecordParameters.setCredentialName("/test-credential");
when(userContext.getActor()).thenReturn("test-actor");
EventAuditRecord eventAuditRecord = AuditLogFactory.createEventAuditRecord(eventAuditRecordParameters, userContext, requestUuid, true);
assertThat(eventAuditRecord.getAceOperation(), equalTo(null));
}
use of org.cloudfoundry.credhub.auth.UserContext in project credhub by cloudfoundry-incubator.
the class AuditLogFactoryTest method createEventAuditRecord_whenAllFieldsAreComplete_createsEventAuditRecord.
@Test
public void createEventAuditRecord_whenAllFieldsAreComplete_createsEventAuditRecord() {
final UserContext userContext = mock(UserContext.class);
final UUID requestUuid = UUID.randomUUID();
final EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters();
eventAuditRecordParameters.setAuditingOperationCode(CREDENTIAL_ACCESS);
eventAuditRecordParameters.setCredentialName("/test-credential");
eventAuditRecordParameters.setAceOperation(WRITE_ACL);
eventAuditRecordParameters.setAceActor("ace-actor");
when(userContext.getActor()).thenReturn("test-actor");
EventAuditRecord eventAuditRecord = AuditLogFactory.createEventAuditRecord(eventAuditRecordParameters, userContext, requestUuid, true);
assertThat(eventAuditRecord.getOperation(), equalTo("credential_access"));
assertThat(eventAuditRecord.getCredentialName(), equalTo("/test-credential"));
assertThat(eventAuditRecord.getActor(), equalTo("test-actor"));
assertThat(eventAuditRecord.getRequestUuid(), equalTo(requestUuid));
assertThat(eventAuditRecord.isSuccess(), equalTo(true));
assertThat(eventAuditRecord.getAceOperation(), equalTo("write_acl"));
assertThat(eventAuditRecord.getAceActor(), equalTo("ace-actor"));
}
use of org.cloudfoundry.credhub.auth.UserContext in project credhub by cloudfoundry-incubator.
the class AuditLogFactoryTest method createEventAuditRecord_whenOperationIsNull_fallsBackToUnknownOperation.
@Test
public void createEventAuditRecord_whenOperationIsNull_fallsBackToUnknownOperation() {
final UserContext userContext = mock(UserContext.class);
final UUID requestUuid = UUID.randomUUID();
final EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters();
eventAuditRecordParameters.setCredentialName("/test-credential");
when(userContext.getActor()).thenReturn("test-actor");
EventAuditRecord eventAuditRecord = AuditLogFactory.createEventAuditRecord(eventAuditRecordParameters, userContext, requestUuid, true);
assertThat(eventAuditRecord.getOperation(), equalTo("unknown_operation"));
}
use of org.cloudfoundry.credhub.auth.UserContext in project credhub by cloudfoundry-incubator.
the class PermissionServiceTest method beforeEach.
@Before
public void beforeEach() {
userContext = mock(UserContext.class);
when(userContext.getActor()).thenReturn(USER_NAME);
expectedCredential = new Credential(CREDENTIAL_NAME);
expectedCredentialVersion = new PasswordCredentialVersion(CREDENTIAL_NAME);
permissionDataService = mock(PermissionDataService.class);
permissionCheckingService = mock(PermissionCheckingService.class);
when(permissionCheckingService.hasPermission(anyString(), anyString(), any(PermissionOperation.class))).thenReturn(true);
auditRecordParameters = newArrayList();
UserContextHolder userContextHolder = new UserContextHolder();
userContextHolder.setUserContext(userContext);
subject = new PermissionService(permissionDataService, permissionCheckingService, userContextHolder);
}
Aggregations