use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialRegenerateTest method regeneratingAPassword_regeneratesThePassword_andPersistsAnAuditEntry.
@Test
public void regeneratingAPassword_regeneratesThePassword_andPersistsAnAuditEntry() throws Exception {
PasswordCredentialVersion originalCredential = new PasswordCredentialVersion("/my-password");
originalCredential.setEncryptor(encryptor);
StringGenerationParameters generationParameters = new StringGenerationParameters();
generationParameters.setExcludeNumber(true);
originalCredential.setPasswordAndGenerationParameters("original-password", generationParameters);
originalCredential.setVersionCreatedAt(FROZEN_TIME.plusSeconds(1));
credentialVersionDataService.save(originalCredential);
fakeTimeSetter.accept(FROZEN_TIME.plusSeconds(10).toEpochMilli());
MockHttpServletRequestBuilder request = post("/api/v1/data").header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{\"regenerate\":true,\"name\":\"my-password\"}");
mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)).andExpect(jsonPath("$.type").value("password")).andExpect(jsonPath("$.version_created_at").value(FROZEN_TIME.plusSeconds(10).toString()));
final PasswordCredentialVersion newPassword = (PasswordCredentialVersion) credentialVersionDataService.findMostRecent("/my-password");
assertThat(newPassword.getPassword(), not(equalTo("original-credential")));
assertThat(newPassword.getGenerationParameters().isExcludeNumber(), equalTo(true));
auditingHelper.verifyAuditing(CREDENTIAL_UPDATE, "/my-password", AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "/api/v1/data", 200);
}
use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialRegenerateTest method regeneratingANonGeneratedPassword_returnsAnError_andPersistsAnAuditEntry.
@Test
public void regeneratingANonGeneratedPassword_returnsAnError_andPersistsAnAuditEntry() throws Exception {
PasswordCredentialVersion originalCredential = new PasswordCredentialVersion("/my-password");
originalCredential.setEncryptor(encryptor);
originalCredential.setPasswordAndGenerationParameters("abcde", null);
credentialVersionDataService.save(originalCredential);
String cannotRegenerateJson = "{" + " \"error\": \"The password could not be regenerated because the value was " + "statically set. Only generated passwords may be regenerated.\"" + "}";
MockHttpServletRequestBuilder request = post("/api/v1/data").header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{\"regenerate\":true,\"name\":\"my-password\"}");
mockMvc.perform(request).andExpect(content().json(cannotRegenerateJson));
auditingHelper.verifyAuditing(CREDENTIAL_UPDATE, "/my-password", AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "/api/v1/data", 400);
}
use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findMostRecent_givenACredentialName_returnsMostRecentCredentialWithoutCaseSensitivity.
@Test
public void findMostRecent_givenACredentialName_returnsMostRecentCredentialWithoutCaseSensitivity() {
setupTestFixtureForFindMostRecent();
PasswordCredentialVersion passwordCredential = (PasswordCredentialVersion) subject.findMostRecent("/my-credential");
assertThat(passwordCredential.getName(), equalTo("/my-CREDENTIAL"));
assertThat(passwordCredential2.getEncryptedValueData().getEncryptedValue(), equalTo("/my-new-password".getBytes()));
}
use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findByUuid_givenAUuid_findsTheCredential.
@Test
public void findByUuid_givenAUuid_findsTheCredential() {
PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData("/my-credential");
passwordCredentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("credential-password".getBytes()).setNonce("nonce".getBytes()));
PasswordCredentialVersion credential = new PasswordCredentialVersion(passwordCredentialData);
PasswordCredentialVersion savedCredential = subject.save(credential);
assertNotNull(savedCredential.getUuid());
PasswordCredentialVersion oneByUuid = (PasswordCredentialVersion) subject.findByUuid(savedCredential.getUuid().toString());
assertThat(oneByUuid.getName(), equalTo("/my-credential"));
assertThat(passwordCredentialData.getEncryptedValueData().getEncryptedValue(), equalTo("credential-password".getBytes()));
}
use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method save_givenAnExistingCredential_updatesTheCredential.
@Test
public void save_givenAnExistingCredential_updatesTheCredential() {
PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData("/my-credential-2");
passwordCredentialData.setEncryptedValueData(new EncryptedValue(activeCanaryUuid, "credential-password", "nonce"));
PasswordCredentialVersion credential = new PasswordCredentialVersion(passwordCredentialData);
subject.save(credential);
passwordCredentialData.getEncryptedValueData().setEncryptedValue("irynas-ninja-skills".getBytes());
subject.save(credential);
PasswordCredentialVersion savedPasswordCredential = (PasswordCredentialVersion) subject.findMostRecent("/my-credential-2");
CredentialVersionData credentialVersionData = credentialVersionRepository.findOneByUuid(savedPasswordCredential.getUuid());
assertThat(credentialVersionData.getCredential().getName(), equalTo("/my-credential-2"));
assertThat(credentialVersionData.getEncryptedValueData().getEncryptedValue(), equalTo("irynas-ninja-skills".getBytes()));
assertThat(credentialVersionData.getUuid(), equalTo(credential.getUuid()));
}
Aggregations