@@ -21,14 +21,17 @@ import org.springframework.credhub.support.KeyPairCredential;
|
||||
/**
|
||||
* An SSH credential consists of a public and/or private key. At least one of these key values must be provided.
|
||||
*
|
||||
* @author Scott Frederick
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
public class SshCredential extends KeyPairCredential {
|
||||
private final String publicKeyFingerprint;
|
||||
|
||||
/**
|
||||
* Create an empty {@link SshCredential}. Intended to be used internally for deserialization of responses.
|
||||
*/
|
||||
private SshCredential() {
|
||||
super();
|
||||
publicKeyFingerprint = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,5 +43,16 @@ public class SshCredential extends KeyPairCredential {
|
||||
*/
|
||||
public SshCredential(String publicKey, String privateKey) {
|
||||
super(publicKey, privateKey);
|
||||
publicKeyFingerprint = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fingerprint of the public key associated with the credential. This value can not be provided
|
||||
* when creating an {@code SshCredential}, but may be provided by CredHub when retrieving one.
|
||||
*
|
||||
* @return the public key fingerprint value
|
||||
*/
|
||||
public String getPublicKeyFingerprint() {
|
||||
return publicKeyFingerprint;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,12 +44,12 @@ public class CredHubTemplateDetailSshUnitTests
|
||||
|
||||
@DataPoints("detail-responses")
|
||||
public static List<ResponseEntity<CredentialDetails<SshCredential>>> buildDetailResponses() {
|
||||
return buildDetailResponses(CredentialType.RSA, CREDENTIAL);
|
||||
return buildDetailResponses(CredentialType.SSH, CREDENTIAL);
|
||||
}
|
||||
|
||||
@DataPoints("data-responses")
|
||||
public static List<ResponseEntity<CredentialDetailsData<SshCredential>>> buildDataResponses() {
|
||||
return buildDataResponses(CredentialType.RSA, CREDENTIAL);
|
||||
return buildDataResponses(CredentialType.SSH, CREDENTIAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,14 +31,15 @@ public class SshCredentialDetailsUnitTests extends JsonParsingUnitTestsBase {
|
||||
" \"type\": \"ssh\"," +
|
||||
" \"value\": {" +
|
||||
" \"private_key\": \"private-key\"," +
|
||||
" \"public_key\": \"public-key\"" +
|
||||
" \"public_key\": \"public-key\"," +
|
||||
" \"public_key_fingerprint\": \"fingerprint\"" +
|
||||
" }";
|
||||
|
||||
@Test
|
||||
public void deserializeDetailsWithPublicAndPrivateKeys() throws Exception {
|
||||
CredentialDetails<SshCredential> data = parseDetails(SSH_CREDENTIALS);
|
||||
|
||||
assertDetails(data, "public-key", "private-key");
|
||||
assertDetails(data, "public-key", "private-key", "fingerprint");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -50,7 +51,7 @@ public class SshCredentialDetailsUnitTests extends JsonParsingUnitTestsBase {
|
||||
" }";
|
||||
CredentialDetails<SshCredential> data = parseDetails(credentials);
|
||||
|
||||
assertDetails(data, "public-key", null);
|
||||
assertDetails(data, "public-key", null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,7 +63,7 @@ public class SshCredentialDetailsUnitTests extends JsonParsingUnitTestsBase {
|
||||
" }";
|
||||
CredentialDetails<SshCredential> data = parseDetails(credentials);
|
||||
|
||||
assertDetails(data, null, "private-key");
|
||||
assertDetails(data, null, "private-key", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,14 +74,16 @@ public class SshCredentialDetailsUnitTests extends JsonParsingUnitTestsBase {
|
||||
|
||||
CredentialDetails<SshCredential> data = response.getData().get(0);
|
||||
|
||||
assertDetails(data, "public-key", "private-key");
|
||||
assertDetails(data, "public-key", "private-key", "fingerprint");
|
||||
}
|
||||
|
||||
private void assertDetails(CredentialDetails<SshCredential> data, String publicKey, String privateKey) {
|
||||
private void assertDetails(CredentialDetails<SshCredential> data,
|
||||
String publicKey, String privateKey, String publicKeyFingerprint) {
|
||||
assertCommonDetails(data);
|
||||
|
||||
assertThat(data.getCredentialType(), equalTo(CredentialType.SSH));
|
||||
assertThat(data.getValue().getPublicKey(), equalTo(publicKey));
|
||||
assertThat(data.getValue().getPrivateKey(), equalTo(privateKey));
|
||||
assertThat(data.getValue().getPublicKeyFingerprint(), equalTo(publicKeyFingerprint));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user