Search in sources :

Example 1 with ValueCredentialVersion

use of org.cloudfoundry.credhub.domain.ValueCredentialVersion in project credhub by cloudfoundry-incubator.

the class LegacyCredentialTest method setup.

@Before
public void setup() throws Exception {
    CREDENTIAL_NAME = "/bob";
    ValueCredentialVersionData valueCredentialData = new ValueCredentialVersionData(CREDENTIAL_NAME);
    ValueCredentialVersion noAclsSecret = new ValueCredentialVersion(valueCredentialData);
    noAclsSecret.setEncryptor(encryptor);
    noAclsSecret.setValue("bob's value");
    credentialVersionDataService.save(noAclsSecret);
    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
}
Also used : ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) ValueCredentialVersionData(org.cloudfoundry.credhub.entity.ValueCredentialVersionData) Before(org.junit.Before)

Example 2 with ValueCredentialVersion

use of org.cloudfoundry.credhub.domain.ValueCredentialVersion in project credhub by cloudfoundry-incubator.

the class CredentialsControllerGetTest method gettingACredential_byName_withCurrentSetToFalse_returnsAllTheCredentialVersions.

@Test
public void gettingACredential_byName_withCurrentSetToFalse_returnsAllTheCredentialVersions() throws Exception {
    UUID uuid = UUID.randomUUID();
    ValueCredentialVersion valueCredential1 = new ValueCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setUuid(uuid).setVersionCreatedAt(FROZEN_TIME);
    ValueCredentialVersion valueCredential2 = new ValueCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setUuid(uuid).setVersionCreatedAt(FROZEN_TIME);
    doReturn(CREDENTIAL_VALUE).when(encryptor).decrypt(any());
    doReturn(newArrayList(valueCredential1, valueCredential2)).when(credentialVersionDataService).findAllByName(CREDENTIAL_NAME);
    mockMvc.perform(get("/api/v1/data?current=false&name=" + CREDENTIAL_NAME).header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)).andExpect(jsonPath("$.data", hasSize(equalTo(2))));
}
Also used : ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) UUID(java.util.UUID) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with ValueCredentialVersion

use of org.cloudfoundry.credhub.domain.ValueCredentialVersion in project credhub by cloudfoundry-incubator.

the class CredentialsControllerGetTest method gettingACredential_byName_withCurrentSetToTrue_returnsTheLatestCredential.

@Test
public void gettingACredential_byName_withCurrentSetToTrue_returnsTheLatestCredential() throws Exception {
    UUID uuid = UUID.randomUUID();
    ValueCredentialVersion credential = new ValueCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setUuid(uuid).setVersionCreatedAt(FROZEN_TIME);
    doReturn(CREDENTIAL_VALUE).when(encryptor).decrypt(any());
    doReturn(Arrays.asList(credential)).when(credentialVersionDataService).findActiveByName(CREDENTIAL_NAME);
    mockMvc.perform(get("/api/v1/data?current=true&name=" + CREDENTIAL_NAME).header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)).andExpect(jsonPath("$.data", hasSize(1)));
    verify(credentialVersionDataService).findActiveByName(CREDENTIAL_NAME);
}
Also used : ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) UUID(java.util.UUID) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 4 with ValueCredentialVersion

use of org.cloudfoundry.credhub.domain.ValueCredentialVersion in project credhub by cloudfoundry-incubator.

the class CredentialsControllerGetTest method gettingACredential_byName_thatExists_withoutLeadingSlash_returnsTheCredential.

@Test
public void gettingACredential_byName_thatExists_withoutLeadingSlash_returnsTheCredential() throws Exception {
    doReturn(true).when(permissionCheckingService).hasPermission(any(String.class), any(String.class), eq(PermissionOperation.READ));
    UUID uuid = UUID.randomUUID();
    ValueCredentialVersion credential = new ValueCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setUuid(uuid).setVersionCreatedAt(FROZEN_TIME);
    doReturn(CREDENTIAL_VALUE).when(encryptor).decrypt(any());
    doReturn(newArrayList(credential)).when(credentialVersionDataService).findAllByName(CREDENTIAL_NAME);
    final MockHttpServletRequestBuilder request = get("/api/v1/data?name=" + CREDENTIAL_NAME).header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON);
    mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)).andExpect(jsonPath("$.data[0]" + ".value").value(CREDENTIAL_VALUE));
    auditingHelper.verifyAuditing(AuditingOperationCode.CREDENTIAL_ACCESS, CREDENTIAL_NAME, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "/api/v1/data", 200);
}
Also used : ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) UUID(java.util.UUID) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 5 with ValueCredentialVersion

use of org.cloudfoundry.credhub.domain.ValueCredentialVersion in project credhub by cloudfoundry-incubator.

the class CredentialsControllerGetTest method gettingACredential_thatIsEncryptedWithAnUnknownKey_throwsAnException.

@Test
public void gettingACredential_thatIsEncryptedWithAnUnknownKey_throwsAnException() throws Exception {
    UUID uuid = UUID.randomUUID();
    ValueCredentialVersion valueCredential = new ValueCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setUuid(uuid).setVersionCreatedAt(FROZEN_TIME);
    doThrow(new KeyNotFoundException("error.missing_encryption_key")).when(encryptor).decrypt(any());
    doReturn(Arrays.asList(valueCredential)).when(credentialVersionDataService).findAllByName(CREDENTIAL_NAME);
    final MockHttpServletRequestBuilder get = get("/api/v1/data?name=" + CREDENTIAL_NAME).header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON);
    String expectedError = "The credential could not be accessed with the provided encryption keys. You must update your deployment configuration to continue.";
    mockMvc.perform(get).andExpect(status().isInternalServerError()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)).andExpect(jsonPath("$.error").value(expectedError));
}
Also used : ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) UUID(java.util.UUID) KeyNotFoundException(org.cloudfoundry.credhub.exceptions.KeyNotFoundException) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

ValueCredentialVersion (org.cloudfoundry.credhub.domain.ValueCredentialVersion)18 Test (org.junit.Test)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)14 UUID (java.util.UUID)9 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)7 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)6 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)4 ValueCredentialVersionData (org.cloudfoundry.credhub.entity.ValueCredentialVersionData)4 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)3 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)3 PasswordCredentialVersionData (org.cloudfoundry.credhub.entity.PasswordCredentialVersionData)3 Encryptor (org.cloudfoundry.credhub.domain.Encryptor)2 CertificateCredentialVersionData (org.cloudfoundry.credhub.entity.CertificateCredentialVersionData)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Before (org.junit.Before)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JSONObject (net.minidev.json.JSONObject)1