From 19d219aeb65d08b18251c8afb1e87a0e4d197631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Wenzel?= Date: Mon, 19 Oct 2020 14:57:24 +0200 Subject: [PATCH] fix owner reference tests --- src/test/java/de/koudingspawn/vault/CertChainTest.java | 8 +++++--- src/test/java/de/koudingspawn/vault/CertTest.java | 8 +++++--- src/test/java/de/koudingspawn/vault/DockerCfgTest.java | 9 +++++---- src/test/java/de/koudingspawn/vault/KeyValueTest.java | 10 ++++++---- .../java/de/koudingspawn/vault/KeyValueV2Test.java | 10 ++++++---- src/test/java/de/koudingspawn/vault/PKIChainTest.java | 7 ++----- src/test/java/de/koudingspawn/vault/PKITest.java | 3 ++- .../java/de/koudingspawn/vault/PropertiesTest.java | 3 ++- .../vault/kubernetes/KubernetesServiceTest.java | 2 ++ 9 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/test/java/de/koudingspawn/vault/CertChainTest.java b/src/test/java/de/koudingspawn/vault/CertChainTest.java index dfe0149..a9742d9 100644 --- a/src/test/java/de/koudingspawn/vault/CertChainTest.java +++ b/src/test/java/de/koudingspawn/vault/CertChainTest.java @@ -20,6 +20,8 @@ import org.springframework.context.annotation.Primary; import org.springframework.test.context.junit4.SpringRunner; +import java.util.UUID; + import static com.github.tomakehurst.wiremock.client.WireMock.*; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED; @@ -79,7 +81,7 @@ public void before() { public void shouldGenerateCertFromVaultResource() { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("certificate").withNamespace("default").build() + new ObjectMetaBuilder().withName("certificate").withNamespace("default").withUid(UUID.randomUUID().toString()).build() ); VaultSpec spec = new VaultSpec(); spec.setType(VaultType.CERT); @@ -131,7 +133,7 @@ public void shouldGenerateCertFromVaultResource() { public void shouldCheckIfCertificateHasChangedAndReturnFalse() throws SecretNotAccessibleException { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("certificate").withNamespace("default").build() + new ObjectMetaBuilder().withName("certificate").withNamespace("default").withUid(UUID.randomUUID().toString()).build() ); VaultSpec spec = new VaultSpec(); spec.setType(VaultType.CERT); @@ -169,7 +171,7 @@ public void shouldCheckIfCertificateHasChangedAndReturnFalse() throws SecretNotA public void shouldCheckIfCertificateHasChangedAndReturnTrue() throws SecretNotAccessibleException { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("certificate").withNamespace("default").build() + new ObjectMetaBuilder().withName("certificate").withNamespace("default").withUid(UUID.randomUUID().toString()).build() ); VaultSpec spec = new VaultSpec(); spec.setType(VaultType.CERT); diff --git a/src/test/java/de/koudingspawn/vault/CertTest.java b/src/test/java/de/koudingspawn/vault/CertTest.java index 7dcad2c..0476778 100644 --- a/src/test/java/de/koudingspawn/vault/CertTest.java +++ b/src/test/java/de/koudingspawn/vault/CertTest.java @@ -20,6 +20,8 @@ import org.springframework.context.annotation.Primary; import org.springframework.test.context.junit4.SpringRunner; +import java.util.UUID; + import static com.github.tomakehurst.wiremock.client.WireMock.*; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED; @@ -79,7 +81,7 @@ public void before() { public void shouldGenerateCertFromVaultResource() { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("certificate").withNamespace("default").build() + new ObjectMetaBuilder().withName("certificate").withNamespace("default").withUid(UUID.randomUUID().toString()).build() ); VaultSpec spec = new VaultSpec(); spec.setType(VaultType.CERT); @@ -130,7 +132,7 @@ public void shouldGenerateCertFromVaultResource() { public void shouldCheckIfCertificateHasChangedAndReturnFalse() throws SecretNotAccessibleException { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("certificate").withNamespace("default").build() + new ObjectMetaBuilder().withName("certificate").withNamespace("default").withUid(UUID.randomUUID().toString()).build() ); VaultSpec spec = new VaultSpec(); spec.setType(VaultType.CERT); @@ -167,7 +169,7 @@ public void shouldCheckIfCertificateHasChangedAndReturnFalse() throws SecretNotA public void shouldCheckIfCertificateHasChangedAndReturnTrue() throws SecretNotAccessibleException { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("certificate").withNamespace("default").build() + new ObjectMetaBuilder().withName("certificate").withNamespace("default").withUid(UUID.randomUUID().toString()).build() ); VaultSpec spec = new VaultSpec(); spec.setType(VaultType.CERT); diff --git a/src/test/java/de/koudingspawn/vault/DockerCfgTest.java b/src/test/java/de/koudingspawn/vault/DockerCfgTest.java index 36d005b..1947704 100644 --- a/src/test/java/de/koudingspawn/vault/DockerCfgTest.java +++ b/src/test/java/de/koudingspawn/vault/DockerCfgTest.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.util.Base64; +import java.util.UUID; import static com.github.tomakehurst.wiremock.client.WireMock.*; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; @@ -86,7 +87,7 @@ public void before() { public void shouldGenerateDockerCfgFromVaultResource() throws IOException { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("dockercfg").withNamespace("default").build() + new ObjectMetaBuilder().withName("dockercfg").withNamespace("default").withUid(UUID.randomUUID().toString()).build() ); VaultSpec spec = new VaultSpec(); spec.setType(VaultType.DOCKERCFG); @@ -142,7 +143,7 @@ public void shouldGenerateDockerCfgFromVaultResource() throws IOException { public void shouldCheckIfDockerCfgHasChangedAndReturnTrue() throws SecretNotAccessibleException { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("dockercfg").withNamespace("default").build() + new ObjectMetaBuilder().withName("dockercfg").withNamespace("default").withUid(UUID.randomUUID().toString()).build() ); VaultSpec spec = new VaultSpec(); spec.setType(VaultType.DOCKERCFG); @@ -174,7 +175,7 @@ public void shouldCheckIfDockerCfgHasChangedAndReturnTrue() throws SecretNotAcce public void shouldCheckIfDockerCfgHasChangedAndReturnFalse() throws SecretNotAccessibleException { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("dockercfg").withNamespace("default").build() + new ObjectMetaBuilder().withName("dockercfg").withNamespace("default").withUid(UUID.randomUUID().toString()).build() ); VaultSpec spec = new VaultSpec(); spec.setType(VaultType.DOCKERCFG); @@ -197,7 +198,7 @@ public void shouldCheckIfDockerCfgHasChangedAndReturnFalse() throws SecretNotAcc public void shouldGenerateDockerCfgV2() throws JsonProcessingException { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("dockercfg").withNamespace("default").build() + new ObjectMetaBuilder().withName("dockercfg").withNamespace("default").withUid(UUID.randomUUID().toString()).build() ); VaultSpec spec = new VaultSpec(); spec.setType(VaultType.DOCKERCFG); diff --git a/src/test/java/de/koudingspawn/vault/KeyValueTest.java b/src/test/java/de/koudingspawn/vault/KeyValueTest.java index c146faa..ebae7e9 100644 --- a/src/test/java/de/koudingspawn/vault/KeyValueTest.java +++ b/src/test/java/de/koudingspawn/vault/KeyValueTest.java @@ -20,6 +20,8 @@ import org.springframework.context.annotation.Primary; import org.springframework.test.context.junit4.SpringRunner; +import java.util.UUID; + import static com.github.tomakehurst.wiremock.client.WireMock.*; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED; @@ -77,7 +79,7 @@ public void before() { public void shouldGenerateSimpleSecretFromVaultCustomResource() { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("simple").withNamespace("default").build()); + new ObjectMetaBuilder().withName("simple").withNamespace("default").withUid(UUID.randomUUID().toString()).build()); VaultSpec vaultSpec = new VaultSpec(); vaultSpec.setType(VaultType.KEYVALUE); vaultSpec.setPath("secret/simple"); @@ -104,7 +106,7 @@ public void shouldGenerateSimpleSecretFromVaultCustomResource() { public void shouldCheckIfSimpleSecretHasChangedAndReturnTrue() throws SecretNotAccessibleException { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("simple").withNamespace("default").build()); + new ObjectMetaBuilder().withName("simple").withNamespace("default").withUid(UUID.randomUUID().toString()).build()); VaultSpec vaultSpec = new VaultSpec(); vaultSpec.setType(VaultType.KEYVALUE); vaultSpec.setPath("secret/simple"); @@ -136,7 +138,7 @@ public void shouldCheckIfSimpleSecretHasChangedAndReturnTrue() throws SecretNotA public void shouldCheckIfSimpleSecretHasChangedAndReturnFalse() throws SecretNotAccessibleException { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("simple").withNamespace("default").build()); + new ObjectMetaBuilder().withName("simple").withNamespace("default").withUid(UUID.randomUUID().toString()).build()); VaultSpec vaultSpec = new VaultSpec(); vaultSpec.setType(VaultType.KEYVALUE); vaultSpec.setPath("secret/simple"); @@ -157,7 +159,7 @@ public void shouldCheckIfSimpleSecretHasChangedAndReturnFalse() throws SecretNot public void preventNullPointerExceptionWhenSecretDoesNotExist() { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("simple").withNamespace("default").build()); + new ObjectMetaBuilder().withName("simple").withNamespace("default").withUid(UUID.randomUUID().toString()).build()); VaultSpec vaultSpec = new VaultSpec(); vaultSpec.setType(VaultType.KEYVALUE); vaultSpec.setPath("secret/simple"); diff --git a/src/test/java/de/koudingspawn/vault/KeyValueV2Test.java b/src/test/java/de/koudingspawn/vault/KeyValueV2Test.java index bdee5eb..831b279 100644 --- a/src/test/java/de/koudingspawn/vault/KeyValueV2Test.java +++ b/src/test/java/de/koudingspawn/vault/KeyValueV2Test.java @@ -21,6 +21,8 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import java.util.UUID; + import static com.github.tomakehurst.wiremock.client.WireMock.*; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED; @@ -79,7 +81,7 @@ public void before() { public void shouldGenerateSimpleSecretFromVaultCustomResource() { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("simple").withNamespace("default").build()); + new ObjectMetaBuilder().withName("simple").withNamespace("default").withUid(UUID.randomUUID().toString()).build()); VaultSpec vaultSpec = new VaultSpec(); vaultSpec.setType(VaultType.KEYVALUEV2); vaultSpec.setPath("secret/simple"); @@ -125,7 +127,7 @@ public void shouldGenerateSimpleSecretFromVaultCustomResource() { public void shouldCheckIfSimpleSecretHasChangedAndReturnTrue() throws SecretNotAccessibleException { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("simple").withNamespace("default").build()); + new ObjectMetaBuilder().withName("simple").withNamespace("default").withUid(UUID.randomUUID().toString()).build()); VaultSpec vaultSpec = new VaultSpec(); vaultSpec.setType(VaultType.KEYVALUEV2); vaultSpec.setPath("secret/simple"); @@ -195,7 +197,7 @@ public void shouldCheckIfSimpleSecretHasChangedAndReturnTrue() throws SecretNotA public void shouldCheckIfSimpleSecretHasChangedAndReturnFalse() throws SecretNotAccessibleException { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("simple").withNamespace("default").build()); + new ObjectMetaBuilder().withName("simple").withNamespace("default").withUid(UUID.randomUUID().toString()).build()); VaultSpec vaultSpec = new VaultSpec(); vaultSpec.setType(VaultType.KEYVALUEV2); vaultSpec.setPath("secret/simple"); @@ -235,7 +237,7 @@ public void shouldCheckIfSimpleSecretHasChangedAndReturnFalse() throws SecretNot public void shouldSupportNestedPath() { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("simple").withNamespace("default").build()); + new ObjectMetaBuilder().withName("simple").withNamespace("default").withUid(UUID.randomUUID().toString()).build()); VaultSpec vaultSpec = new VaultSpec(); vaultSpec.setType(VaultType.KEYVALUEV2); vaultSpec.setPath("secret/simple/nested"); diff --git a/src/test/java/de/koudingspawn/vault/PKIChainTest.java b/src/test/java/de/koudingspawn/vault/PKIChainTest.java index 80593ca..53c5920 100644 --- a/src/test/java/de/koudingspawn/vault/PKIChainTest.java +++ b/src/test/java/de/koudingspawn/vault/PKIChainTest.java @@ -26,10 +26,7 @@ import java.time.LocalDateTime; import java.time.ZoneId; import java.time.temporal.ChronoUnit; -import java.util.Base64; -import java.util.Collections; -import java.util.Date; -import java.util.TimeZone; +import java.util.*; import static com.github.tomakehurst.wiremock.client.WireMock.*; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; @@ -252,7 +249,7 @@ private VaultResponseData generateKeyPair() { private Vault generateVaultResource() { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("pki").withNamespace("default").build() + new ObjectMetaBuilder().withName("pki").withNamespace("default").withUid(UUID.randomUUID().toString()).build() ); VaultSpec spec = new VaultSpec(); diff --git a/src/test/java/de/koudingspawn/vault/PKITest.java b/src/test/java/de/koudingspawn/vault/PKITest.java index ca401b3..38d6af6 100644 --- a/src/test/java/de/koudingspawn/vault/PKITest.java +++ b/src/test/java/de/koudingspawn/vault/PKITest.java @@ -32,6 +32,7 @@ import java.util.Base64; import java.util.Date; import java.util.TimeZone; +import java.util.UUID; import static com.github.tomakehurst.wiremock.client.WireMock.*; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; @@ -184,7 +185,7 @@ private VaultResponseData generateKeyPair(Date startDate, long valid) throws Exc private Vault generateVaultResource() { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("pki").withNamespace("default").build() + new ObjectMetaBuilder().withName("pki").withNamespace("default").withUid(UUID.randomUUID().toString()).build() ); VaultSpec spec = new VaultSpec(); diff --git a/src/test/java/de/koudingspawn/vault/PropertiesTest.java b/src/test/java/de/koudingspawn/vault/PropertiesTest.java index 2f71875..72406ff 100644 --- a/src/test/java/de/koudingspawn/vault/PropertiesTest.java +++ b/src/test/java/de/koudingspawn/vault/PropertiesTest.java @@ -27,6 +27,7 @@ import java.nio.file.Files; import java.util.Base64; import java.util.HashMap; +import java.util.UUID; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static de.koudingspawn.vault.Constants.LAST_UPDATE_ANNOTATION; @@ -130,7 +131,7 @@ private Vault generatePropertiesManifest() throws IOException { Vault vault = new Vault(); vault.setMetadata( - new ObjectMetaBuilder().withName("properties").withNamespace("default").build() + new ObjectMetaBuilder().withName("properties").withNamespace("default").withUid(UUID.randomUUID().toString()).build() ); vault.setSpec(vaultSpec); diff --git a/src/test/java/de/koudingspawn/vault/kubernetes/KubernetesServiceTest.java b/src/test/java/de/koudingspawn/vault/kubernetes/KubernetesServiceTest.java index a0af081..76e63cc 100644 --- a/src/test/java/de/koudingspawn/vault/kubernetes/KubernetesServiceTest.java +++ b/src/test/java/de/koudingspawn/vault/kubernetes/KubernetesServiceTest.java @@ -17,6 +17,7 @@ import org.springframework.test.context.junit4.SpringRunner; import java.util.HashMap; +import java.util.UUID; import static de.koudingspawn.vault.Constants.COMPARE_ANNOTATION; import static org.junit.Assert.*; @@ -158,6 +159,7 @@ private Vault generateVault() { ObjectMeta meta = new ObjectMeta(); meta.setNamespace(NAMESPACE); meta.setName(SECRETNAME); + meta.setUid(UUID.randomUUID().toString()); vault.setMetadata(meta); return vault;