Skip to content

Commit

Permalink
Adding failure tests to client-statefulset when only one of global.en…
Browse files Browse the repository at this point in the history
…terpriseLicense.secretKey or secretName is supplied.
  • Loading branch information
jmurret committed Feb 18, 2022
1 parent 0d43d9b commit d8562cb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
8 changes: 2 additions & 6 deletions acceptance/tests/vault/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/rand"
"encoding/base64"
"fmt"
"os"
"testing"

"github.com/hashicorp/consul-k8s/acceptance/framework/config"
Expand Down Expand Up @@ -101,15 +100,12 @@ func configureGossipVaultSecret(t *testing.T, vaultClient *vapi.Client) string {
}

// configureEnterpriseLicenseVaultSecret stores it in vault as a secret and configures a policy to access it.
func configureEnterpriseLicenseVaultSecret(t *testing.T, vaultClient *vapi.Client) {
// Retrieve the license.
enterpriseLicense := os.Getenv("CONSUL_ENT_LICENSE")

func configureEnterpriseLicenseVaultSecret(t *testing.T, vaultClient *vapi.Client, cfg *config.TestConfig) {
// Create the enterprise license secret.
logger.Log(t, "Creating the Enterprise License secret")
params := map[string]interface{}{
"data": map[string]interface{}{
"enterpriselicense": enterpriseLicense,
"enterpriselicense": cfg.EnterpriseLicense,
},
}
_, err := vaultClient.Logical().Write("consul/data/secret/enterpriselicense", params)
Expand Down
2 changes: 1 addition & 1 deletion acceptance/tests/vault/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestVault(t *testing.T) {

createConnectCAPolicy(t, vaultClient, "dc1")
if cfg.EnableEnterprise {
configureEnterpriseLicenseVaultSecret(t, vaultClient)
configureEnterpriseLicenseVaultSecret(t, vaultClient, cfg)
}

configureKubernetesAuthRoles(t, vaultClient, consulReleaseName, ns, "kubernetes", "dc1", cfg)
Expand Down
21 changes: 21 additions & 0 deletions charts/consul/test/unit/client-daemonset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,27 @@ rollingUpdate:
[ "${actual}" = "" ]
}

@test "client/DaemonSet: when global.enterpriseLicense.secretKey!=null and global.enterpriseLicense.secretName=null, fail" {
cd `chart_dir`
run helm template \
-s templates/client-daemonset.yaml \
--set 'global.enterpriseLicense.secretName=' \
--set 'global.enterpriseLicense.secretKey=enterpriselicense' \
.
[ "$status" -eq 1 ]
[[ "$output" =~ "enterpriseLicense.secretKey and secretName must both be specified." ]]
}

@test "client/DaemonSet: when global.enterpriseLicense.secretName!=null and global.enterpriseLicense.secretKey=null, fail" {
cd `chart_dir`
run helm template \
-s templates/client-daemonset.yaml \
--set 'global.enterpriseLicense.secretName=foo' \
--set 'global.enterpriseLicense.secretKey=' \
.
[ "$status" -eq 1 ]
[[ "$output" =~ "enterpriseLicense.secretKey and secretName must both be specified." ]]
}
#--------------------------------------------------------------------
# recursors

Expand Down

0 comments on commit d8562cb

Please sign in to comment.