Search in sources :

Example 1 with SshCredentialVersion

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);
}
Also used : PermissionCheckingService(org.cloudfoundry.credhub.service.PermissionCheckingService) PermissionedCredentialService(org.cloudfoundry.credhub.service.PermissionedCredentialService) UserContext(org.cloudfoundry.credhub.auth.UserContext) Encryptor(org.cloudfoundry.credhub.domain.Encryptor) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) Before(org.junit.Before)

Example 2 with SshCredentialVersion

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

Example 3 with SshCredentialVersion

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;
}
Also used : SshGenerateRequest(org.cloudfoundry.credhub.request.SshGenerateRequest) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) SshGenerationParameters(org.cloudfoundry.credhub.request.SshGenerationParameters)

Example 4 with SshCredentialVersion

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

Example 5 with SshCredentialVersion

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);
}
Also used : Encryptor(org.cloudfoundry.credhub.domain.Encryptor) EncryptedValue(org.cloudfoundry.credhub.entity.EncryptedValue) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) Before(org.junit.Before)

Aggregations

SshCredentialVersion (org.cloudfoundry.credhub.domain.SshCredentialVersion)9 Encryptor (org.cloudfoundry.credhub.domain.Encryptor)4 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)2 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)2 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)2 RsaCredentialVersion (org.cloudfoundry.credhub.domain.RsaCredentialVersion)2 UserCredentialVersion (org.cloudfoundry.credhub.domain.UserCredentialVersion)2 SshCredentialVersionData (org.cloudfoundry.credhub.entity.SshCredentialVersionData)2 Before (org.junit.Before)2 JSONObject (net.minidev.json.JSONObject)1 UserContext (org.cloudfoundry.credhub.auth.UserContext)1 JsonCredentialVersion (org.cloudfoundry.credhub.domain.JsonCredentialVersion)1 ValueCredentialVersion (org.cloudfoundry.credhub.domain.ValueCredentialVersion)1 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)1 SshGenerateRequest (org.cloudfoundry.credhub.request.SshGenerateRequest)1