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();
}
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))));
}
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);
}
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);
}
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));
}
Aggregations