use of org.cloudfoundry.credhub.domain.SshCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialsHandlerTest method beforeEach.
@Before
public void beforeEach() {
Encryptor encryptor = mock(Encryptor.class);
permissionedCredentialService = mock(PermissionedCredentialService.class);
permissionCheckingService = mock(PermissionCheckingService.class);
subject = new CredentialsHandler(permissionedCredentialService);
userContext = mock(UserContext.class);
when(userContext.getActor()).thenReturn(USER);
version1 = new SshCredentialVersion(CREDENTIAL_NAME);
version1.setVersionCreatedAt(VERSION1_CREATED_AT);
version1.setEncryptor(encryptor);
version2 = new SshCredentialVersion(CREDENTIAL_NAME);
version2.setVersionCreatedAt(VERSION2_CREATED_AT);
version2.setEncryptor(encryptor);
}
use of org.cloudfoundry.credhub.domain.SshCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialRegenerateTest method regeneratingAnSshKey_regeneratesTheSshKey_andPersistsAnAuditEntry.
@Test
public void regeneratingAnSshKey_regeneratesTheSshKey_andPersistsAnAuditEntry() throws Exception {
SshCredentialVersion originalCredential = new SshCredentialVersion("/my-ssh");
originalCredential.setEncryptor(encryptor);
originalCredential.setPrivateKey("original value");
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-ssh\"}");
mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)).andExpect(jsonPath("$.type").value("ssh")).andExpect(jsonPath("$.version_created_at").value(FROZEN_TIME.plusSeconds(10).toString()));
final SshCredentialVersion newSsh = (SshCredentialVersion) credentialVersionDataService.findMostRecent("/my-ssh");
assertThat(newSsh.getPrivateKey(), containsString("-----BEGIN RSA PRIVATE KEY-----"));
assertThat(newSsh.getPublicKey(), containsString("ssh-rsa "));
assertThat(newSsh.getPrivateKey(), not(equalTo(originalCredential.getPrivateKey())));
assertThat(newSsh.getPublicKey(), not(equalTo(originalCredential.getPublicKey())));
auditingHelper.verifyAuditing(CREDENTIAL_UPDATE, "/my-ssh", AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "/api/v1/data", 200);
}
use of org.cloudfoundry.credhub.domain.SshCredentialVersion in project credhub by cloudfoundry-incubator.
the class SshCredentialRegeneratable method createGenerateRequest.
@Override
public BaseCredentialGenerateRequest createGenerateRequest(CredentialVersion credentialVersion, List<EventAuditRecordParameters> auditRecordParameters) {
SshCredentialVersion sshCredential = (SshCredentialVersion) credentialVersion;
SshGenerateRequest generateRequest = new SshGenerateRequest();
generateRequest.setName(sshCredential.getName());
generateRequest.setType(sshCredential.getCredentialType());
SshGenerationParameters generationParameters = new SshGenerationParameters();
generationParameters.setSshComment(sshCredential.getComment());
generateRequest.setGenerationParameters(generationParameters);
generateRequest.setOverwrite(true);
return generateRequest;
}
use of org.cloudfoundry.credhub.domain.SshCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method save_givenANewCredential_generatesTheUuid.
@Test
public void save_givenANewCredential_generatesTheUuid() {
SshCredentialVersion credential = new SshCredentialVersion("/my-credential-2").setEncryptor(encryptor).setPrivateKey("privatekey").setPublicKey("fake-public-key");
SshCredentialVersion savedCredential = subject.save(credential);
UUID generatedUuid = savedCredential.getUuid();
assertNotNull(generatedUuid);
savedCredential.setPublicKey("updated-fake-public-key");
savedCredential = subject.save(savedCredential);
assertThat(savedCredential.getUuid(), equalTo(generatedUuid));
}
use of org.cloudfoundry.credhub.domain.SshCredentialVersion in project credhub by cloudfoundry-incubator.
the class SshViewTest method beforeEach.
@Before
public void beforeEach() {
Encryptor encryptor = mock(Encryptor.class);
final EncryptedValue encryption = new EncryptedValue(UUID.randomUUID(), "encrypted".getBytes(), "nonce".getBytes());
when(encryptor.encrypt(TestConstants.PRIVATE_KEY_4096)).thenReturn(encryption);
when(encryptor.decrypt(encryption)).thenReturn(TestConstants.PRIVATE_KEY_4096);
entity = new SshCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setPublicKey(TestConstants.SSH_PUBLIC_KEY_4096_WITH_COMMENT).setPrivateKey(TestConstants.PRIVATE_KEY_4096);
entity.setUuid(CREDENTIAL_UUID);
}
Aggregations