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