Skip to content

Commit

Permalink
Revert "fix: Orphaned encrypted_value records left after `Credentia…
Browse files Browse the repository at this point in the history
…l` entity deletion"

This reverts commit 6eae79c.
  • Loading branch information
hsinn0 committed Apr 16, 2024
1 parent 50ccd68 commit 7ec7d1e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void beforeEach() throws Exception {
@Test
public void deleteCertificateVersion_whenThereAreOtherVersionsOfTheCertificate_deletesTheSpecifiedVersion() throws Exception {
UUID aUuid = UUID.randomUUID();
var nEncryptedValuesPre = encryptedValueDataService.countAllByCanaryUuid(aUuid);
var nEncrypredValuesPre = encryptedValueDataService.countAllByCanaryUuid(aUuid);

final String credentialName = "/test-certificate";

Expand All @@ -91,7 +91,7 @@ public void deleteCertificateVersion_whenThereAreOtherVersionsOfTheCertificate_d

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(nEncryptedValuesPre + 2));
encryptedValueDataService.countAllByCanaryUuid(aUuid), equalTo(nEncrypredValuesPre + 2));

final String versionUuid = JsonPath.parse(version).read("$.id");
final String versionValue = JsonPath.parse(version).read("$.value.certificate");
Expand All @@ -114,7 +114,7 @@ public void deleteCertificateVersion_whenThereAreOtherVersionsOfTheCertificate_d
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(nEncryptedValuesPre + 1));
encryptedValueDataService.countAllByCanaryUuid(aUuid), equalTo(nEncrypredValuesPre + 1));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import org.cloudfoundry.credhub.audit.AuditableCredential
import org.cloudfoundry.credhub.constants.UuidConstants.Companion.UUID_BYTES
import org.hibernate.annotations.GenericGenerator
import java.util.UUID
import javax.persistence.CascadeType
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.FetchType
import javax.persistence.GeneratedValue
import javax.persistence.Id
import javax.persistence.OneToMany
import javax.persistence.Table

@Entity
Expand All @@ -24,11 +21,6 @@ class Credential : AuditableCredential {
@GenericGenerator(name = "uuid2", strategy = "uuid2")
override var uuid: UUID? = null

@OneToMany(cascade = [CascadeType.REMOVE],
mappedBy = "credential", fetch = FetchType.EAGER)
var credentialVersions: MutableList<CredentialVersionData<*>> =
mutableListOf();

@Column(nullable = false)
override var name: String? = null
set(name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -282,7 +281,6 @@ public void delete_onAnExistingCredential_returnsTrue() {
}

@Test
@Transactional(propagation = Propagation.NEVER)
public void delete_onACredentialName_deletesAllCredentialsWithTheName() {
long nEncryptedValuesPre = encryptedValueRepository.count();
final Credential credential = credentialDataService
Expand Down Expand Up @@ -319,7 +317,6 @@ public void delete_onACredentialName_deletesAllCredentialsWithTheName() {
}

@Test
@Transactional(propagation = Propagation.NEVER)
public void delete_givenACredentialNameCasedDifferentlyFromTheActual_shouldBeCaseInsensitive() {
long nEncryptedValuesPre = encryptedValueRepository.count();
final Credential credentialName = credentialDataService
Expand Down Expand Up @@ -356,7 +353,6 @@ public void delete_givenACredentialNameCasedDifferentlyFromTheActual_shouldBeCas
}

@Test
@Transactional(propagation = Propagation.NEVER)
public void delete_UserTypeCredential() {
long nEncryptedValuesPre = encryptedValueRepository.count();
final Credential credentialName = credentialDataService.save(
Expand Down

0 comments on commit 7ec7d1e

Please sign in to comment.