Search in sources :

Example 11 with PasswordCredentialVersion

use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.

the class CredentialVersionDataServiceTest method save_givenAnExistingCredential_throwsExceptionIfTypeMismatch.

@Test(expected = ParameterizedValidationException.class)
public void save_givenAnExistingCredential_throwsExceptionIfTypeMismatch() {
    PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData("/my-credential-3");
    passwordCredentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue(new byte[] {}).setNonce(new byte[] {}));
    PasswordCredentialVersion credential = new PasswordCredentialVersion(passwordCredentialData);
    subject.save(credential);
    ValueCredentialVersionData newCredentialData = new ValueCredentialVersionData();
    newCredentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("some value".getBytes()));
    newCredentialData.setCredential(passwordCredentialData.getCredential());
    ValueCredentialVersion newCredential = new ValueCredentialVersion(newCredentialData);
    subject.save(newCredential);
}
Also used : ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) ValueCredentialVersionData(org.cloudfoundry.credhub.entity.ValueCredentialVersionData) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 12 with PasswordCredentialVersion

use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.

the class CredentialVersionDataServiceTest method findAllPaths_returnsCompleteDirectoryStructure.

@Test
public void findAllPaths_returnsCompleteDirectoryStructure() {
    String valueOther = "/fubario";
    String valueName = "/value/Credential";
    String passwordName = "/password/Credential";
    String certificateName = "/certif/ic/ateCredential";
    ValueCredentialVersionData valueCredentialData = new ValueCredentialVersionData(valueOther);
    ValueCredentialVersion valueCredential = new ValueCredentialVersion(valueCredentialData);
    subject.save(valueCredential);
    valueCredentialData = new ValueCredentialVersionData(valueName);
    valueCredential = new ValueCredentialVersion(valueCredentialData);
    subject.save(valueCredential);
    PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData(passwordName);
    PasswordCredentialVersion passwordCredential = new PasswordCredentialVersion(passwordCredentialData);
    subject.save(passwordCredential);
    CertificateCredentialVersionData certificateCredentialData = new CertificateCredentialVersionData(certificateName);
    CertificateCredentialVersion certificateCredential = new CertificateCredentialVersion(certificateCredentialData);
    subject.save(certificateCredential);
    assertThat(subject.findAllPaths(), equalTo(newArrayList("/", "/certif/", "/certif/ic/", "/password/", "/value/")));
}
Also used : ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) CertificateCredentialVersionData(org.cloudfoundry.credhub.entity.CertificateCredentialVersionData) PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) ValueCredentialVersionData(org.cloudfoundry.credhub.entity.ValueCredentialVersionData) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 13 with PasswordCredentialVersion

use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.

the class AuthConfigurationTest method setupDataEndpointMocks.

private void setupDataEndpointMocks() {
    when(credentialVersionDataService.save(any(CredentialVersion.class))).thenAnswer(invocation -> {
        PasswordCredentialVersion passwordCredential = invocation.getArgumentAt(0, PasswordCredentialVersion.class);
        passwordCredential.setUuid(UUID.randomUUID());
        passwordCredential.setVersionCreatedAt(Instant.now());
        return passwordCredential;
    });
}
Also used : PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion)

Example 14 with PasswordCredentialVersion

use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.

the class CredentialsControllerAuditLogTest method gettingACredential_byId_makesACredentialAccessAuditLogEntry.

@Test
public void gettingACredential_byId_makesACredentialAccessAuditLogEntry() throws Exception {
    doReturn(new PasswordCredentialVersion("/foo").setEncryptor(encryptor)).when(credentialVersionDataService).findByUuid(eq("foo-id"));
    mockMvc.perform(get(CredentialsController.API_V1_DATA + "/foo-id").accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).header("X-Forwarded-For", "1.1.1.1,2.2.2.2"));
    ArgumentCaptor<List> recordCaptor = ArgumentCaptor.forClass(List.class);
    verify(eventAuditRecordDataService, times(1)).save(recordCaptor.capture());
    EventAuditRecord auditRecord = (EventAuditRecord) recordCaptor.getValue().get(0);
    assertThat(auditRecord.getCredentialName(), equalTo("/foo"));
    assertThat(auditRecord.getOperation(), equalTo(CREDENTIAL_ACCESS.toString()));
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) List(java.util.List) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 15 with PasswordCredentialVersion

use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.

the class CredentialsControllerAuditLogTest method gettingACredential_byName_makesACredentialAccessLogEntry.

@Test
public void gettingACredential_byName_makesACredentialAccessLogEntry() throws Exception {
    doReturn(Arrays.asList(new PasswordCredentialVersion("/foo").setEncryptor(encryptor))).when(credentialVersionDataService).findAllByName(eq("foo"));
    mockMvc.perform(get(CredentialsController.API_V1_DATA + "?name=foo").accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).header("X-Forwarded-For", "1.1.1.1,2.2.2.2"));
    ArgumentCaptor<List> recordCaptor = ArgumentCaptor.forClass(List.class);
    verify(eventAuditRecordDataService, times(1)).save(recordCaptor.capture());
    EventAuditRecord auditRecord = (EventAuditRecord) recordCaptor.getValue().get(0);
    assertThat(auditRecord.getCredentialName(), equalTo("/foo"));
    assertThat(auditRecord.getOperation(), equalTo(CREDENTIAL_ACCESS.toString()));
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) List(java.util.List) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)34 Test (org.junit.Test)25 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)20 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)15 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)11 ValueCredentialVersion (org.cloudfoundry.credhub.domain.ValueCredentialVersion)11 PasswordCredentialVersionData (org.cloudfoundry.credhub.entity.PasswordCredentialVersionData)10 SshCredentialVersion (org.cloudfoundry.credhub.domain.SshCredentialVersion)9 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)7 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)6 CertificateCredentialVersionData (org.cloudfoundry.credhub.entity.CertificateCredentialVersionData)5 ValueCredentialVersionData (org.cloudfoundry.credhub.entity.ValueCredentialVersionData)5 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)4 UUID (java.util.UUID)3 Encryptor (org.cloudfoundry.credhub.domain.Encryptor)3 CredentialVersionData (org.cloudfoundry.credhub.entity.CredentialVersionData)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Before (org.junit.Before)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 ArrayList (java.util.ArrayList)2