Search in sources :

Example 16 with UserContext

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

the class CredentialsControllerGenerateTest method beforeEach.

@Before
public void beforeEach() {
    Consumer<Long> fakeTimeSetter = mockOutCurrentTimeProvider(mockCurrentTimeProvider);
    userContext = mock(UserContext.class);
    fakeTimeSetter.accept(FROZEN_TIME.toEpochMilli());
    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
    when(credentialGenerator.generateCredential(any(StringGenerationParameters.class))).thenReturn(new StringCredentialValue(FAKE_PASSWORD_NAME));
    when(sshGenerator.generateCredential(any(SshGenerationParameters.class))).thenReturn(new SshCredentialValue(PUBLIC_KEY, PRIVATE_KEY, null));
    when(rsaGenerator.generateCredential(any(RsaGenerationParameters.class))).thenReturn(new RsaCredentialValue(PUBLIC_KEY, PRIVATE_KEY));
    when(certificateGenerator.generateCredential(any(CertificateGenerationParameters.class))).thenReturn(new CertificateCredentialValue("ca_cert", CERT, PRIVATE_KEY, null));
}
Also used : RsaGenerationParameters(org.cloudfoundry.credhub.request.RsaGenerationParameters) CertificateGenerationParameters(org.cloudfoundry.credhub.domain.CertificateGenerationParameters) UserContext(org.cloudfoundry.credhub.auth.UserContext) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) RsaCredentialValue(org.cloudfoundry.credhub.credential.RsaCredentialValue) SshGenerationParameters(org.cloudfoundry.credhub.request.SshGenerationParameters) SshCredentialValue(org.cloudfoundry.credhub.credential.SshCredentialValue) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Before(org.junit.Before)

Example 17 with UserContext

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

the class AuditLogFactoryTest method createEventAuditRecord_whenParametersAreNull_createsEventAuditRecord.

@Test
public void createEventAuditRecord_whenParametersAreNull_createsEventAuditRecord() {
    final UserContext userContext = mock(UserContext.class);
    final UUID requestUuid = UUID.randomUUID();
    when(userContext.getActor()).thenReturn("test-actor");
    EventAuditRecord eventAuditRecord = AuditLogFactory.createEventAuditRecord(null, userContext, requestUuid, true);
    assertNotNull(eventAuditRecord);
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) Test(org.junit.Test)

Example 18 with UserContext

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

the class AuditLogFactoryTest method createEventAuditRecord_whenCredentialNameIsMissingLeadingSlash_prependsLeadingSlash.

@Test
public void createEventAuditRecord_whenCredentialNameIsMissingLeadingSlash_prependsLeadingSlash() {
    final UserContext userContext = mock(UserContext.class);
    final UUID requestUuid = UUID.randomUUID();
    final EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters();
    eventAuditRecordParameters.setCredentialName("test-credential");
    EventAuditRecord eventAuditRecord = AuditLogFactory.createEventAuditRecord(eventAuditRecordParameters, userContext, requestUuid, true);
    assertThat(eventAuditRecord.getCredentialName(), equalTo("/test-credential"));
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) Test(org.junit.Test)

Example 19 with UserContext

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

the class AuditLogFactoryTest method createEventAuditRecord_whenCredentialNameIsNull_createsEventAuditRecord.

@Test
public void createEventAuditRecord_whenCredentialNameIsNull_createsEventAuditRecord() {
    final UserContext userContext = mock(UserContext.class);
    final UUID requestUuid = UUID.randomUUID();
    final EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters();
    eventAuditRecordParameters.setAuditingOperationCode(CREDENTIAL_UPDATE);
    when(userContext.getActor()).thenReturn("test-actor");
    EventAuditRecord eventAuditRecord = AuditLogFactory.createEventAuditRecord(eventAuditRecordParameters, userContext, requestUuid, true);
    assertNotNull(eventAuditRecord);
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) Test(org.junit.Test)

Example 20 with UserContext

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

the class EventAuditLogServiceTest method mockUserContext.

private UserContext mockUserContext(boolean valid) {
    UserContext context = mock(UserContext.class);
    when(context.getValidFrom()).thenReturn(now.getEpochSecond());
    when(context.getValidUntil()).thenReturn(then.getEpochSecond());
    when(context.getClientId()).thenReturn("test-client-id");
    when(context.getActor()).thenReturn("test-actor");
    if (valid) {
        when(context.getAuthMethod()).thenReturn(UserContext.AUTH_METHOD_UAA);
    }
    return context;
}
Also used : UserContext(org.cloudfoundry.credhub.auth.UserContext)

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