Search in sources :

Example 26 with PasswordCredentialVersion

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);
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 27 with PasswordCredentialVersion

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);
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 28 with PasswordCredentialVersion

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()));
}
Also used : PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 29 with PasswordCredentialVersion

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()));
}
Also used : PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 30 with PasswordCredentialVersion

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()));
}
Also used : PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) PasswordCredentialVersionData(org.cloudfoundry.credhub.entity.PasswordCredentialVersionData) CertificateCredentialVersionData(org.cloudfoundry.credhub.entity.CertificateCredentialVersionData) SshCredentialVersionData(org.cloudfoundry.credhub.entity.SshCredentialVersionData) ValueCredentialVersionData(org.cloudfoundry.credhub.entity.ValueCredentialVersionData) CredentialVersionData(org.cloudfoundry.credhub.entity.CredentialVersionData) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) 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