Skip to content

Commit

Permalink
Revert "test: encrypted_value data clean up"
Browse files Browse the repository at this point in the history
This reverts commit 9ca4e03.
  • Loading branch information
hsinn0 committed Apr 16, 2024
1 parent 7ec7d1e commit a26ebb2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.cloudfoundry.credhub.integration;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
Expand All @@ -15,7 +13,6 @@

import com.jayway.jsonpath.JsonPath;
import org.cloudfoundry.credhub.CredhubTestApp;
import org.cloudfoundry.credhub.data.EncryptedValueDataService;
import org.cloudfoundry.credhub.helpers.RequestHelper;
import org.cloudfoundry.credhub.utils.BouncyCastleFipsConfigurer;
import org.cloudfoundry.credhub.utils.DatabaseProfileResolver;
Expand Down Expand Up @@ -54,9 +51,6 @@ public class CertificateVersionDeleteTest {
@Autowired
private WebApplicationContext webApplicationContext;

@Autowired
EncryptedValueDataService encryptedValueDataService;

private MockMvc mockMvc;

@Rule
Expand All @@ -77,9 +71,6 @@ public void beforeEach() throws Exception {

@Test
public void deleteCertificateVersion_whenThereAreOtherVersionsOfTheCertificate_deletesTheSpecifiedVersion() throws Exception {
UUID aUuid = UUID.randomUUID();
var nEncrypredValuesPre = encryptedValueDataService.countAllByCanaryUuid(aUuid);

final String credentialName = "/test-certificate";

String response = generateCertificateCredential(mockMvc, credentialName, true, "test", null, ALL_PERMISSIONS_TOKEN);
Expand All @@ -90,14 +81,13 @@ public void deleteCertificateVersion_whenThereAreOtherVersionsOfTheCertificate_d
.read("$.certificates[0].id");

final String version = RequestHelper.regenerateCertificate(mockMvc, uuid, false, ALL_PERMISSIONS_TOKEN);
assertThat("One associated encrypted value exist for each certificate vesion",
encryptedValueDataService.countAllByCanaryUuid(aUuid), equalTo(nEncrypredValuesPre + 2));

final String versionUuid = JsonPath.parse(version).read("$.id");
final String versionValue = JsonPath.parse(version).read("$.value.certificate");

final MockHttpServletRequestBuilder request = delete("/api/v1/certificates/" + uuid + "/versions/" + versionUuid)
.header("Authorization", "Bearer " + ALL_PERMISSIONS_TOKEN)
.accept(APPLICATION_JSON);

response = mockMvc.perform(request)
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
Expand All @@ -113,8 +103,6 @@ public void deleteCertificateVersion_whenThereAreOtherVersionsOfTheCertificate_d
final JSONArray jsonArray = new JSONArray(response);
assertThat(jsonArray.length(), equalTo(1));
assertThat(JsonPath.parse(jsonArray.get(0).toString()).read("$.value.certificate"), equalTo(nonDeletedVersion));
assertThat("Associated encrypted value is deleted when the certificate version is deleted",
encryptedValueDataService.countAllByCanaryUuid(aUuid), equalTo(nEncrypredValuesPre + 1));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.function.Consumer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ActiveProfiles;
Expand All @@ -32,13 +31,11 @@
import org.cloudfoundry.credhub.entity.CredentialVersionData;
import org.cloudfoundry.credhub.entity.PasswordCredentialVersionData;
import org.cloudfoundry.credhub.entity.SshCredentialVersionData;
import org.cloudfoundry.credhub.entity.UserCredentialVersionData;
import org.cloudfoundry.credhub.entity.ValueCredentialVersionData;
import org.cloudfoundry.credhub.exceptions.MaximumSizeException;
import org.cloudfoundry.credhub.exceptions.ParameterizedValidationException;
import org.cloudfoundry.credhub.repositories.CredentialRepository;
import org.cloudfoundry.credhub.repositories.CredentialVersionRepository;
import org.cloudfoundry.credhub.repositories.EncryptedValueRepository;
import org.cloudfoundry.credhub.util.CurrentTimeProvider;
import org.cloudfoundry.credhub.utils.DatabaseProfileResolver;
import org.cloudfoundry.credhub.utils.DatabaseUtilities;
Expand All @@ -63,7 +60,6 @@
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.core.IsCollectionContaining.hasItem;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
Expand All @@ -74,18 +70,12 @@
@Transactional
public class DefaultCredentialVersionDataServiceTest {

@Value("${spring.profiles.active}")
private String activeSpringProfile;

@Autowired
private CredentialVersionRepository credentialVersionRepository;

@Autowired
private CredentialRepository credentialRepository;

@Autowired
private EncryptedValueRepository encryptedValueRepository;

@Autowired
private EncryptionKeyCanaryDataService encryptionKeyCanaryDataService;

Expand Down Expand Up @@ -282,7 +272,6 @@ public void delete_onAnExistingCredential_returnsTrue() {

@Test
public void delete_onACredentialName_deletesAllCredentialsWithTheName() {
long nEncryptedValuesPre = encryptedValueRepository.count();
final Credential credential = credentialDataService
.save(new Credential("/my-credential"));

Expand Down Expand Up @@ -312,13 +301,10 @@ public void delete_onACredentialName_deletesAllCredentialsWithTheName() {

assertThat(subject.findAllByName("/my-credential"), hasSize(0));
assertNull(credentialDataService.find("/my-credential"));
assertEquals("Associated encryptedValues are deleted when password credential is deleted",
nEncryptedValuesPre, encryptedValueRepository.count());
}

@Test
public void delete_givenACredentialNameCasedDifferentlyFromTheActual_shouldBeCaseInsensitive() {
long nEncryptedValuesPre = encryptedValueRepository.count();
final Credential credentialName = credentialDataService
.save(new Credential("/my-credential"));

Expand Down Expand Up @@ -348,46 +334,6 @@ public void delete_givenACredentialNameCasedDifferentlyFromTheActual_shouldBeCas
subject.delete("/MY-CREDENTIAL");

assertThat(subject.findAllByName("/my-credential"), empty());
assertEquals("Associated encryptedValues are deleted when password credential is deleted",
nEncryptedValuesPre, encryptedValueRepository.count());
}

@Test
public void delete_UserTypeCredential() {
long nEncryptedValuesPre = encryptedValueRepository.count();
final Credential credentialName = credentialDataService.save(
new Credential("/my-credential"));

final EncryptedValue encryptedValueA = new EncryptedValue();
encryptedValueA.setEncryptionKeyUuid(activeCanaryUuid);
encryptedValueA.setEncryptedValue("credential-password".getBytes(UTF_8));
encryptedValueA.setNonce(new byte[]{});

final UserCredentialVersionData credentialDataA =
new UserCredentialVersionData("test-user");
credentialDataA.setCredential(credentialName);
credentialDataA.setEncryptedValueData(encryptedValueA);
credentialDataA.setSalt("salt");
subject.save(credentialDataA);

final EncryptedValue encryptedValueB = new EncryptedValue();
encryptedValueB.setEncryptionKeyUuid(activeCanaryUuid);
encryptedValueB.setEncryptedValue("another password".getBytes(UTF_8));
encryptedValueB.setNonce(new byte[]{});

final UserCredentialVersionData credentialDataB = new UserCredentialVersionData(
"/my-credential");
credentialDataB.setCredential(credentialName);
credentialDataB.setEncryptedValueData(encryptedValueB);
credentialDataB.setSalt("salt");
subject.save(credentialDataB);

assertThat(subject.findAllByName("/my-credential"), hasSize(2));

subject.delete("/my-credential");
assertThat(subject.findAllByName("/my-credential"), empty());
assertEquals("Associated encryptedValues are deleted when user credential is deleted",
nEncryptedValuesPre, encryptedValueRepository.count());
}

@Test
Expand Down

0 comments on commit a26ebb2

Please sign in to comment.