use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialsControllerTypeSpecificGenerateTest method generatingANewCredentialVersion_withOverwrite_shouldGenerateANewCredential.
@Test
public void generatingANewCredentialVersion_withOverwrite_shouldGenerateANewCredential() throws Exception {
beforeEachExistingCredential();
MockHttpServletRequestBuilder request = beforeEachOverwriteSetToTrue();
ResultActions response = mockMvc.perform(request);
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 CredentialsControllerTypeSpecificGenerateTest method generatingANewCredentialVersion_withOverwrite_shouldPersistTheNewCredential.
@Test
public void generatingANewCredentialVersion_withOverwrite_shouldPersistTheNewCredential() throws Exception {
beforeEachExistingCredential();
MockHttpServletRequestBuilder request = beforeEachOverwriteSetToTrue();
mockMvc.perform(request);
CredentialVersion credentialVersion = credentialVersionDataService.findMostRecent(CREDENTIAL_NAME);
parametizer.credentialAssertions(credentialVersion);
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialsControllerTypeSpecificGenerateTest method generatingANewCredential_shouldReturnGeneratedCredentialAndAskDataServiceToPersistTheCredential.
@Test
public void generatingANewCredential_shouldReturnGeneratedCredentialAndAskDataServiceToPersistTheCredential() throws Exception {
MockHttpServletRequestBuilder request = createGenerateNewCredentialRequest();
ResultActions response = mockMvc.perform(request);
ArgumentCaptor<CredentialVersion> argumentCaptor = ArgumentCaptor.forClass(CredentialVersion.class);
verify(credentialVersionDataService, times(1)).save(argumentCaptor.capture());
response.andExpect(parametizer.jsonAssertions()).andExpect(multiJsonPath("$.type", parametizer.credentialType, "$.id", argumentCaptor.getValue().getUuid().toString(), "$.version_created_at", FROZEN_TIME.toString())).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON));
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialsControllerTypeSpecificSetTest method updatingACredential_withTheOverwriteFlagSetToTrue_persistsTheCredential.
@Test
public void updatingACredential_withTheOverwriteFlagSetToTrue_persistsTheCredential() 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" + "}");
mockMvc.perform(put);
CredentialVersion credentialVersion = credentialVersionDataService.findMostRecent(CREDENTIAL_NAME);
parametizer.credentialAssertions(credentialVersion);
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialsControllerTypeSpecificSetTest method updatingACredential_withOverwriteSetToFalse_doesNotPersistTheCredential.
@Test
public void updatingACredential_withOverwriteSetToFalse_doesNotPersistTheCredential() 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);
verify(credentialVersionDataService, times(0)).save(any(CredentialVersion.class));
}
Aggregations