Skip to content

Commit

Permalink
validation for registry-creds config test
Browse files Browse the repository at this point in the history
  • Loading branch information
panyam committed Jan 13, 2025
1 parent a819dbf commit 1f355fa
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cmd/minikube/cmd/config/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func processRegistryCredsConfig(profile string, configFileData map[string]any) {
}
}
} else if gcrAction == "enable" {
out.Ln("Loading GCR configs from: ", AddonConfigFile)
out.Ln("Loading GCR configs from: %s", AddonConfigFile)
// Then read the configs
gcrPath = getNestedJSONString(configFileData, "gcrConfigs", "gcrPath")
gcrURL = getNestedJSONString(configFileData, "gcrConfigs", "gcrURL")
Expand Down Expand Up @@ -380,6 +380,7 @@ func processRegistryCredsConfig(profile string, configFileData map[string]any) {
dockerPass = AskForPasswordValue("-- Enter docker registry password: ")
}
} else if dockerRegistryAction == "enable" {
out.Ln("Loading Docker Registry configs from: %s", AddonConfigFile)
dockerServer = getNestedJSONString(configFileData, "dockerConfigs", "dockerServer")
dockerUser = getNestedJSONString(configFileData, "dockerConfigs", "dockerUser")
dockerPass = getNestedJSONString(configFileData, "dockerConfigs", "dockerPass")
Expand Down
39 changes: 39 additions & 0 deletions test/integration/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ package integration

import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -123,4 +126,40 @@ func validateRegistryCredsAddon(ctx context.Context, t *testing.T, profile strin
if err != nil {
t.Errorf("failed to configure addon. args %q : %v", rr.Command(), err)
}

// Check a few secrets exists that match our test data
// In our test aws and gcp are set, docker and acr are disabled - so they will be set to "changeme"
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "-n", "kube-system", "get", "secret", "-o", "yaml"))
if err != nil {
t.Errorf("failed to get secrets. args %q : %v", rr.Command(), err)
}

expected := []string{
"DOCKER_PRIVATE_REGISTRY_PASSWORD: Y2hhbmdlbWU=",
"DOCKER_PRIVATE_REGISTRY_SERVER: Y2hhbmdlbWU=",
"DOCKER_PRIVATE_REGISTRY_USER: Y2hhbmdlbWU=",

"ACR_CLIENT_ID: Y2hhbmdlbWU=",
"ACR_PASSWORD: Y2hhbmdlbWU=",
"ACR_URL: Y2hhbmdlbWU=",

"AWS_ACCESS_KEY_ID: dGVzdF9hd3NfYWNjZXNzaWQ=",
"AWS_SECRET_ACCESS_KEY: dGVzdF9hd3NfYWNjZXNza2V5",
"AWS_SESSION_TOKEN: dGVzdF9hd3Nfc2Vzc2lvbl90b2tlbg==",
"aws-account: dGVzdF9hd3NfYWNjb3VudA==",
"aws-assume-role: dGVzdF9hd3Nfcm9sZQ==",
"aws-region: dGVzdF9hd3NfcmVnaW9u",

"application_default_credentials.json: ewogICJjbGllbnRfaWQiOiAiaGFoYSIsCiAgImNsaWVudF9zZWNyZXQiOiAibmljZV90cnkiLAogICJxdW90YV9wcm9qZWN0X2lkIjogInRoaXNfaXNfZmFrZSIsCiAgInJlZnJlc2hfdG9rZW4iOiAibWF5YmVfbmV4dF90aW1lIiwKICAidHlwZSI6ICJhdXRob3JpemVkX3VzZXIiCn0K",
"gcrurl: aHR0cHM6Ly9nY3IuaW8=",
}

rrout := strings.TrimSpace(rr.Stdout.String())
for _, exp := range expected {
re := regexp.MustCompile(fmt.Sprintf(".*%s.*", exp))
secret := re.FindString(rrout)
if secret == "" {
t.Errorf("Did not find expected secret: '%s'", secret)
}
}
}
2 changes: 1 addition & 1 deletion test/integration/testdata/addons_testconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"gcrPath": "./testdata/gcp-creds.json",
"gcrURL": "https://gcr.io"
},
"enableDockerRegistry": "enable",
"enableDockerRegistry": "disable",
"dockerConfigs": {
"dockerServer": "test_docker_server",
"dockerUser": "test_docker_user",
Expand Down

0 comments on commit 1f355fa

Please sign in to comment.