Search in sources :

Example 21 with CredentialVersion

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

the class CredentialsControllerTypeSpecificSetTest method updatingACredential_withTheOverwriteFlagSetToTrue_returnsTheExistingCredentialVersion.

@Test
public void updatingACredential_withTheOverwriteFlagSetToTrue_returnsTheExistingCredentialVersion() throws Exception {
    doReturn(parametizer.createCredential(encryptor)).when(credentialVersionDataService).findMostRecent(CREDENTIAL_NAME);
    final MockHttpServletRequestBuilder put = put("/api/v1/data").header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{" + "  \"type\":\"" + parametizer.credentialType + "\"," + "  \"name\":\"" + CREDENTIAL_NAME + "\"," + "  \"value\":" + parametizer.credentialValue + "," + "  \"overwrite\":true" + "}");
    ResultActions response = mockMvc.perform(put);
    ArgumentCaptor<CredentialVersion> argumentCaptor = ArgumentCaptor.forClass(CredentialVersion.class);
    verify(credentialVersionDataService, times(1)).save(argumentCaptor.capture());
    response.andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)).andExpect(parametizer.jsonAssertions()).andExpect(multiJsonPath("$.type", parametizer.credentialType, "$.id", argumentCaptor.getValue().getUuid().toString(), "$.version_created_at", FROZEN_TIME.toString()));
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ResultActions(org.springframework.test.web.servlet.ResultActions) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) RsaCredentialVersion(org.cloudfoundry.credhub.domain.RsaCredentialVersion) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) JsonCredentialVersion(org.cloudfoundry.credhub.domain.JsonCredentialVersion) ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) UserCredentialVersion(org.cloudfoundry.credhub.domain.UserCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 22 with CredentialVersion

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

the class CredentialsControllerTypeSpecificSetTest method updatingACredential_withOverwriteSetToFalse_returnsThePreviousVersion.

@Test
public void updatingACredential_withOverwriteSetToFalse_returnsThePreviousVersion() throws Exception {
    CredentialVersion expectedCredentialVersion = parametizer.createCredential(encryptor);
    doReturn(expectedCredentialVersion).when(credentialVersionDataService).findMostRecent(CREDENTIAL_NAME);
    final MockHttpServletRequestBuilder request = put("/api/v1/data").header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{" + "\"type\":\"" + parametizer.credentialType + "\"," + "\"name\":\"" + CREDENTIAL_NAME + "\"," + "\"value\":" + parametizer.credentialValue + "}");
    mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)).andExpect(parametizer.jsonAssertions()).andExpect(multiJsonPath("$.id", expectedCredentialVersion.getUuid().toString(), "$.version_created_at", FROZEN_TIME.minusSeconds(1).toString()));
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) RsaCredentialVersion(org.cloudfoundry.credhub.domain.RsaCredentialVersion) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) JsonCredentialVersion(org.cloudfoundry.credhub.domain.JsonCredentialVersion) ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) UserCredentialVersion(org.cloudfoundry.credhub.domain.UserCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 23 with CredentialVersion

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

the class CredentialVersionDataServiceTest method findAllByName_whenProvidedAName_findsAllMatchingCredentials.

@Test
public void findAllByName_whenProvidedAName_findsAllMatchingCredentials() {
    PasswordCredentialVersion credential1 = savePassword(2000000000123L, "/secret1");
    PasswordCredentialVersion credential2 = savePassword(4000000000123L, "/seCret1");
    savePassword(3000000000123L, "/Secret2");
    List<CredentialVersion> credentialVersions = subject.findAllByName("/Secret1");
    assertThat(credentialVersions, containsInAnyOrder(hasProperty("uuid", equalTo(credential1.getUuid())), hasProperty("uuid", equalTo(credential2.getUuid()))));
    assertThat("returns empty list when no credential matches", subject.findAllByName("does/NOT/exist"), empty());
}
Also used : PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 24 with CredentialVersion

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

the class CredentialVersionDataServiceTest method findActiveByName_whenAskedNonCertificateType_returnsOneCredentialValue.

@Test
public void findActiveByName_whenAskedNonCertificateType_returnsOneCredentialValue() throws Exception {
    PasswordCredentialVersion password1 = savePassword(2000000000123L, "/test/password");
    PasswordCredentialVersion password2 = savePassword(3000000000123L, "/test/password");
    PasswordCredentialVersion password3 = savePassword(4000000000123L, "/test/password");
    List<CredentialVersion> credentialVersions = subject.findActiveByName("/test/password");
    assertThat(credentialVersions.size(), equalTo(1));
    assertThat(credentialVersions, contains(hasProperty("uuid", equalTo(password3.getUuid()))));
}
Also used : PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 25 with CredentialVersion

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

the class CredentialVersionDataServiceTest method save_givenACredentialWithALeadingSlash_savesWithTheLeadingSlash.

@Test
public void save_givenACredentialWithALeadingSlash_savesWithTheLeadingSlash() {
    PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData("/my/credential");
    PasswordCredentialVersion credentialWithLeadingSlash = new PasswordCredentialVersion(passwordCredentialData);
    subject.save(credentialWithLeadingSlash);
    CredentialVersion savedCredentialVersion = subject.findMostRecent("/my/credential");
    assertThat(savedCredentialVersion.getCredential().getName(), equalTo("/my/credential"));
}
Also used : PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)50 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)35 Test (org.junit.Test)33 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)27 SshCredentialVersion (org.cloudfoundry.credhub.domain.SshCredentialVersion)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)19 ValueCredentialVersion (org.cloudfoundry.credhub.domain.ValueCredentialVersion)17 RsaCredentialVersion (org.cloudfoundry.credhub.domain.RsaCredentialVersion)14 UserCredentialVersion (org.cloudfoundry.credhub.domain.UserCredentialVersion)13 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)11 JsonCredentialVersion (org.cloudfoundry.credhub.domain.JsonCredentialVersion)10 Credential (org.cloudfoundry.credhub.entity.Credential)8 EntryNotFoundException (org.cloudfoundry.credhub.exceptions.EntryNotFoundException)7 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)6 ArrayList (java.util.ArrayList)5 UUID (java.util.UUID)5 CredentialVersionData (org.cloudfoundry.credhub.entity.CredentialVersionData)5 ResultActions (org.springframework.test.web.servlet.ResultActions)5 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)4 UserContext (org.cloudfoundry.credhub.auth.UserContext)3