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