use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialsControllerTypeSpecificGenerateTest method parameters.
@Parameterized.Parameters(name = "{0}")
public static Collection<Object> parameters() {
credentialUuid = UUID.randomUUID();
Collection<Object> params = new ArrayList<>();
TestParameterizer passwordParameters = new TestParameterizer("password", "{\"exclude_number\": true}") {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value", FAKE_PASSWORD);
}
void credentialAssertions(CredentialVersion credential) {
PasswordCredentialVersion passwordCredential = (PasswordCredentialVersion) credential;
assertThat(passwordCredential.getGenerationParameters().isExcludeNumber(), equalTo(true));
assertThat(passwordCredential.getPassword(), equalTo(FAKE_PASSWORD));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new PasswordCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setPasswordAndGenerationParameters(FAKE_PASSWORD, new StringGenerationParameters().setExcludeNumber(true)).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
TestParameterizer userParameterizer = new TestParameterizer("user", "null") {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value.username", USERNAME, "$.value.password", FAKE_PASSWORD);
}
void credentialAssertions(CredentialVersion credential) {
UserCredentialVersion userCredential = (UserCredentialVersion) credential;
assertThat(userCredential.getUsername(), equalTo(USERNAME));
assertThat(userCredential.getPassword(), equalTo(FAKE_PASSWORD));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new UserCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setPassword(FAKE_PASSWORD).setUsername(USERNAME).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
TestParameterizer certificateParameterizer = new TestParameterizer("certificate", "{\"common_name\":\"my-common-name\",\"self_sign\":true}") {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value.certificate", "certificate", "$.value.private_key", "private_key", "$.value.ca", "ca");
}
void credentialAssertions(CredentialVersion credential) {
CertificateCredentialVersion certificateCredential = (CertificateCredentialVersion) credential;
assertThat(certificateCredential.getCa(), equalTo(CA));
assertThat(certificateCredential.getCertificate(), equalTo(CERTIFICATE));
assertThat(certificateCredential.getPrivateKey(), equalTo(PRIVATE_KEY));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new CertificateCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setCa(CA).setCertificate(CERTIFICATE).setPrivateKey(PRIVATE_KEY).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
TestParameterizer sshParameterizer = new TestParameterizer("ssh", "null") {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value.public_key", "public_key", "$.value.private_key", "private_key", "$.value.public_key_fingerprint", null);
}
void credentialAssertions(CredentialVersion credential) {
SshCredentialVersion sshCredential = (SshCredentialVersion) credential;
assertThat(sshCredential.getPublicKey(), equalTo(PUBLIC_KEY));
assertThat(sshCredential.getPrivateKey(), equalTo(PRIVATE_KEY));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new SshCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setPrivateKey(PRIVATE_KEY).setPublicKey(PUBLIC_KEY).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
TestParameterizer rsaParameterizer = new TestParameterizer("rsa", "null") {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value.public_key", "public_key", "$.value.private_key", "private_key");
}
void credentialAssertions(CredentialVersion credential) {
RsaCredentialVersion rsaCredential = (RsaCredentialVersion) credential;
assertThat(rsaCredential.getPublicKey(), equalTo(PUBLIC_KEY));
assertThat(rsaCredential.getPrivateKey(), equalTo(PRIVATE_KEY));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new RsaCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setPrivateKey(PRIVATE_KEY).setPublicKey(PUBLIC_KEY).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
params.add(passwordParameters);
params.add(userParameterizer);
params.add(certificateParameterizer);
params.add(sshParameterizer);
params.add(rsaParameterizer);
return params;
}
use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialsControllerTypeSpecificSetTest method parameters.
@Parameterized.Parameters(name = "{0}")
public static Collection<Object> parameters() {
UUID credentialUuid = UUID.randomUUID();
Collection<Object> params = new ArrayList<>();
TestParametizer valueParameters = new TestParametizer("value", "\"" + VALUE_VALUE + "\"") {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value", VALUE_VALUE);
}
void credentialAssertions(CredentialVersion credential) {
assertThat(((ValueCredentialVersion) credential).getValue(), equalTo(VALUE_VALUE));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new ValueCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setValue(VALUE_VALUE).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
TestParametizer passwordParameters = new TestParametizer("password", "\"" + PASSWORD_VALUE + "\"") {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value", PASSWORD_VALUE);
}
void credentialAssertions(CredentialVersion credential) {
assertThat(((PasswordCredentialVersion) credential).getPassword(), equalTo(PASSWORD_VALUE));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new PasswordCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setPasswordAndGenerationParameters(PASSWORD_VALUE, null).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
TestParametizer certificateParameters = new TestParametizer("certificate", CERTIFICATE_VALUE_JSON_STRING) {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value.certificate", TestConstants.TEST_CERTIFICATE, "$.value.private_key", TestConstants.TEST_PRIVATE_KEY, "$.value.ca", TestConstants.TEST_CA);
}
void credentialAssertions(CredentialVersion credential) {
CertificateCredentialVersion certificateCredential = (CertificateCredentialVersion) credential;
assertThat(certificateCredential.getCa(), equalTo(TestConstants.TEST_CA));
assertThat(certificateCredential.getCertificate(), equalTo(TestConstants.TEST_CERTIFICATE));
assertThat(certificateCredential.getPrivateKey(), equalTo(TestConstants.TEST_PRIVATE_KEY));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new CertificateCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setCa(TestConstants.TEST_CA).setCertificate(TestConstants.TEST_CERTIFICATE).setPrivateKey(TestConstants.TEST_PRIVATE_KEY).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
TestParametizer sshParameters = new TestParametizer("ssh", SSH_VALUE_JSON_STRING) {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value.public_key", TestConstants.SSH_PUBLIC_KEY_4096_WITH_COMMENT, "$.value.private_key", TestConstants.PRIVATE_KEY_4096, "$.value.public_key_fingerprint", "UmqxK9UJJR4Jrcw0DcwqJlCgkeQoKp8a+HY+0p0nOgc");
}
void credentialAssertions(CredentialVersion credential) {
SshCredentialVersion sshCredential = (SshCredentialVersion) credential;
assertThat(sshCredential.getPublicKey(), equalTo(TestConstants.SSH_PUBLIC_KEY_4096_WITH_COMMENT));
assertThat(sshCredential.getPrivateKey(), equalTo(TestConstants.PRIVATE_KEY_4096));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new SshCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setPrivateKey(TestConstants.PRIVATE_KEY_4096).setPublicKey(TestConstants.SSH_PUBLIC_KEY_4096_WITH_COMMENT).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
TestParametizer rsaParameters = new TestParametizer("rsa", RSA_VALUE_JSON_STRING) {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value.public_key", TestConstants.RSA_PUBLIC_KEY_4096, "$.value.private_key", TestConstants.PRIVATE_KEY_4096);
}
void credentialAssertions(CredentialVersion credential) {
RsaCredentialVersion rsaCredential = (RsaCredentialVersion) credential;
assertThat(rsaCredential.getPublicKey(), equalTo(TestConstants.RSA_PUBLIC_KEY_4096));
assertThat(rsaCredential.getPrivateKey(), equalTo(TestConstants.PRIVATE_KEY_4096));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new RsaCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setPrivateKey(TestConstants.PRIVATE_KEY_4096).setPublicKey(TestConstants.RSA_PUBLIC_KEY_4096).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
TestParametizer jsonParameters = new TestParametizer("json", JSON_VALUE_JSON_STRING) {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value", jsonValueMap);
}
void credentialAssertions(CredentialVersion credential) {
JsonCredentialVersion jsonCredential = (JsonCredentialVersion) credential;
assertThat(jsonCredential.getValue(), equalTo(jsonValueMap));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new JsonCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setValue(jsonValueMap).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
TestParametizer userParameters = new TestParametizer("user", USER_VALUE_JSON_STRING) {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value.username", USERNAME_VALUE, "$.value.password", PASSWORD_VALUE);
}
void credentialAssertions(CredentialVersion credential) {
UserCredentialVersion userCredential = (UserCredentialVersion) credential;
assertThat(userCredential.getUsername(), equalTo(USERNAME_VALUE));
assertThat(userCredential.getPassword(), equalTo(PASSWORD_VALUE));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new UserCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setUsername(USERNAME_VALUE).setPassword(PASSWORD_VALUE).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
params.add(valueParameters);
params.add(passwordParameters);
params.add(certificateParameters);
params.add(sshParameters);
params.add(rsaParameters);
params.add(jsonParameters);
params.add(userParameters);
return params;
}
use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findAllCertificateCredentialsByCaName_returnsCertificatesSignedByTheCa.
@Test
public void findAllCertificateCredentialsByCaName_returnsCertificatesSignedByTheCa() {
CertificateCredentialVersion caCert = saveCertificate(2000000000123L, "/ca-cert");
CertificateCredentialVersion cert1 = saveCertificateByCa(2000000000125L, "/cert1", "/ca-cert");
CertificateCredentialVersion cert2 = saveCertificateByCa(2000000000126L, "/cert2", "/ca-cert");
CertificateCredentialVersion caCert2 = saveCertificate(2000000000124L, "/ca-cert2");
CertificateCredentialVersion cert3 = saveCertificateByCa(2000000000127L, "/cert3", "/ca-cert2");
List<String> certificates = subject.findAllCertificateCredentialsByCaName("/ca-cert");
assertThat(certificates, containsInAnyOrder(equalTo("/cert1"), equalTo("/cert2")));
assertThat(certificates, not(hasItem("/cert3")));
certificates = subject.findAllCertificateCredentialsByCaName("/ca-cert2");
assertThat(certificates, hasItem("/cert3"));
assertThat(certificates, not(hasItem("/cert1")));
assertThat(certificates, not(hasItem("/cert2")));
}
use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findActiveByName_whenAskedForCertificate_returnsTransitionalValueInAddition.
@Test
public void findActiveByName_whenAskedForCertificate_returnsTransitionalValueInAddition() throws Exception {
CertificateCredentialVersion certificate = saveCertificate(2000000000123L, "/some-certificate");
CertificateCredentialVersion version2 = saveTransitionalCertificate(2000000000123L, "/some-certificate");
CertificateCredentialVersion version3 = saveCertificate(2000000000229L, "/some-certificate");
List<CredentialVersion> credentialVersions = subject.findActiveByName("/some-certificate");
assertThat(credentialVersions.size(), equalTo(2));
assertThat(credentialVersions, containsInAnyOrder(hasProperty("uuid", equalTo(version2.getUuid())), hasProperty("uuid", equalTo(version3.getUuid()))));
}
use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method setupTestFixturesForFindContainingName.
private void setupTestFixturesForFindContainingName(String valueName, String passwordName, String certificateName) {
fakeTimeSetter.accept(2000000000123L);
valueCredentialData = new ValueCredentialVersionData(valueName);
valueCredentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("value".getBytes()).setNonce(new byte[] {}));
ValueCredentialVersion namedValueCredential = new ValueCredentialVersion(valueCredentialData);
namedValueCredential.setEncryptor(encryptor);
subject.save(namedValueCredential);
PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData("/mySe.cret");
passwordCredentialData.setEncryptedValueData(new EncryptedValue(activeCanaryUuid, "", ""));
new PasswordCredentialVersion(passwordCredentialData);
PasswordCredentialVersion namedPasswordCredential;
subject.save(namedValueCredential);
fakeTimeSetter.accept(1000000000123L);
passwordCredentialData = new PasswordCredentialVersionData(passwordName);
passwordCredentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("password".getBytes()).setNonce(new byte[] {}));
namedPasswordCredential = new PasswordCredentialVersion(passwordCredentialData);
subject.save(namedPasswordCredential);
CertificateCredentialVersionData certificateCredentialData = new CertificateCredentialVersionData("/myseecret");
CertificateCredentialVersion certificateCredential = new CertificateCredentialVersion(certificateCredentialData);
subject.save(certificateCredential);
fakeTimeSetter.accept(3000000000123L);
certificateCredentialData = new CertificateCredentialVersionData(certificateName);
certificateCredential = new CertificateCredentialVersion(certificateCredentialData);
subject.save(certificateCredential);
}
Aggregations