use of org.cloudfoundry.credhub.domain.ValueCredentialVersion in project credhub by cloudfoundry-incubator.
the class ValueViewTest method beforeEach.
@Before
public void beforeEach() {
uuid = UUID.randomUUID();
encryptor = mock(Encryptor.class);
when(encryptor.decrypt(any())).thenReturn("fake-plaintext-value");
entity = new ValueCredentialVersion("/foo").setEncryptor(encryptor).setUuid(uuid);
}
use of org.cloudfoundry.credhub.domain.ValueCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialsControllerConcurrencySetTest method whenAnotherThreadsWinsARaceToUpdateACredential_retriesAndReturnsTheValueWrittenByTheOtherThread.
@Test
public void whenAnotherThreadsWinsARaceToUpdateACredential_retriesAndReturnsTheValueWrittenByTheOtherThread() throws Exception {
UUID uuid = UUID.randomUUID();
ValueCredentialVersion valueCredential = new ValueCredentialVersion(credentialName);
valueCredential.setEncryptor(encryptor);
valueCredential.setValue(credentialValue);
valueCredential.setUuid(uuid);
doReturn(null).doReturn(valueCredential).when(credentialVersionDataService).findMostRecent(anyString());
doThrow(new DataIntegrityViolationException("we already have one of those")).when(credentialVersionDataService).save(any(CredentialVersion.class));
final MockHttpServletRequestBuilder put = put("/api/v1/data").header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{" + "\"type\":\"value\"," + "\"name\":\"" + credentialName + "\"," + "\"value\":\"" + credentialValue + "\"}");
mockMvc.perform(put).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)).andExpect(jsonPath("$.type").value("value")).andExpect(jsonPath("$.value").value(credentialValue)).andExpect(jsonPath("$.id").value(uuid.toString()));
verify(credentialVersionDataService).save(any(CredentialVersion.class));
}
use of org.cloudfoundry.credhub.domain.ValueCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialsControllerGetTest method gettingACredential_byId_returnsTheCredentialAndPersistAnAuditEntry.
@Test
public void gettingACredential_byId_returnsTheCredentialAndPersistAnAuditEntry() 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(credential).when(credentialVersionDataService).findByUuid(uuid.toString());
final MockHttpServletRequestBuilder request = get("/api/v1/data/" + uuid).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("$.type").value("value")).andExpect(jsonPath("$.value").value(CREDENTIAL_VALUE)).andExpect(jsonPath("$.id").value(uuid.toString())).andExpect(jsonPath("$.version_created_at").value(FROZEN_TIME.toString()));
auditingHelper.verifyAuditing(AuditingOperationCode.CREDENTIAL_ACCESS, CREDENTIAL_NAME, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "/api/v1/data/" + uuid.toString(), 200);
}
use of org.cloudfoundry.credhub.domain.ValueCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialsControllerGetTest method gettingACredential_byName_thatExists_returnsTheCredential.
@Test
public void gettingACredential_byName_thatExists_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]" + ".type").value("value")).andExpect(jsonPath("$.data[0]" + ".value").value(CREDENTIAL_VALUE)).andExpect(jsonPath("$.data[0]" + ".id").value(uuid.toString())).andExpect(jsonPath("$.data[0]" + ".version_created_at").value(FROZEN_TIME.toString()));
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_byName_withCurrentSetToFalse_andNumberOfVersions_returnsTheSpecifiedNumberOfVersions.
@Test
public void gettingACredential_byName_withCurrentSetToFalse_andNumberOfVersions_returnsTheSpecifiedNumberOfVersions() throws Exception {
UUID uuid = UUID.randomUUID();
Instant credential1Instant = Instant.ofEpochSecond(1400000001L);
Instant credential2Instant = Instant.ofEpochSecond(1400000002L);
Instant credential3Instant = Instant.ofEpochSecond(1400000003L);
ValueCredentialVersion valueCredential1 = new ValueCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setUuid(uuid).setVersionCreatedAt(credential1Instant);
ValueCredentialVersion valueCredential2 = new ValueCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setUuid(uuid).setVersionCreatedAt(credential2Instant);
ValueCredentialVersion valueCredential3 = new ValueCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setUuid(uuid).setVersionCreatedAt(credential3Instant);
doReturn(CREDENTIAL_VALUE).when(encryptor).decrypt(any());
doReturn(newArrayList(valueCredential1, valueCredential2)).when(credentialVersionDataService).findNByName(CREDENTIAL_NAME, 2);
mockMvc.perform(get("/api/v1/data?current=false&name=" + CREDENTIAL_NAME + "&versions=2").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)))).andExpect(jsonPath("$.data[0].version_created_at", equalTo(credential1Instant.toString()))).andExpect(jsonPath("$.data[1].version_created_at", equalTo(credential2Instant.toString())));
}
Aggregations