From 7801b7c400042240fcdc78ea4c06afd2fc3202c8 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Mon, 16 Oct 2023 16:16:42 -0500 Subject: [PATCH] chore: fix numbers in package templates (#2076) ## Description Fix issues where the template regex does not match that of constants and variables. ## Related Issue Fixes #2074 ## Type of change - [X] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Other (security config, docs update, etc) ## Checklist before merging - [X] Test, docs, adr added or updated as needed - [X] [Contributor Guide Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow) followed --- .github/workflows/test-external.yml | 3 +++ src/pkg/utils/yaml.go | 2 +- src/test/e2e/24_variables_test.go | 6 ++++-- src/test/packages/24-evil-variables/zarf.yaml | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-external.yml b/.github/workflows/test-external.yml index 961921563a..157b00af15 100644 --- a/.github/workflows/test-external.yml +++ b/.github/workflows/test-external.yml @@ -34,6 +34,9 @@ jobs: - name: Build binary and zarf packages uses: ./.github/actions/packages + with: + init-package: "false" + build-examples: "false" - name: Setup k3d uses: ./.github/actions/k3d diff --git a/src/pkg/utils/yaml.go b/src/pkg/utils/yaml.go index f88a6617eb..fcf81c497c 100644 --- a/src/pkg/utils/yaml.go +++ b/src/pkg/utils/yaml.go @@ -178,7 +178,7 @@ func FindYamlTemplates(config any, prefix string, suffix string) (map[string]str } // Find all strings that are between the given prefix and suffix - r := regexp.MustCompile(fmt.Sprintf("%s([A-Z_]+)%s", prefix, suffix)) + r := regexp.MustCompile(fmt.Sprintf("%s([A-Z0-9_]+)%s", prefix, suffix)) matches := r.FindAllStringSubmatch(string(text), -1) for _, match := range matches { diff --git a/src/test/e2e/24_variables_test.go b/src/test/e2e/24_variables_test.go index 00bc485d8e..b4b6d49712 100644 --- a/src/test/e2e/24_variables_test.go +++ b/src/test/e2e/24_variables_test.go @@ -28,11 +28,13 @@ func TestVariables(t *testing.T) { e2e.CleanFiles(tfPath, evilPath) // Test that specifying an invalid setVariable value results in an error - stdOut, stdErr, err := e2e.Zarf("package", "create", evilSrc, "--confirm") + stdOut, stdErr, err := e2e.Zarf("package", "create", evilSrc, "--set", "NUMB3R5=K1TT3H", "--confirm") require.NoError(t, err, stdOut, stdErr) + expectedOutString := "\"K1TT3H\"" + require.Contains(t, stdErr, "", expectedOutString) stdOut, stdErr, err = e2e.Zarf("package", "deploy", evilPath, "--confirm") require.Error(t, err, stdOut, stdErr) - expectedOutString := "variable \"HELLO_KITTEH\" does not match pattern " + expectedOutString = "variable \"HELLO_KITTEH\" does not match pattern " require.Contains(t, stdErr, "", expectedOutString) // Test that specifying an invalid constant value results in an error diff --git a/src/test/packages/24-evil-variables/zarf.yaml b/src/test/packages/24-evil-variables/zarf.yaml index 70b0576bd3..906bced7c5 100644 --- a/src/test/packages/24-evil-variables/zarf.yaml +++ b/src/test/packages/24-evil-variables/zarf.yaml @@ -5,6 +5,7 @@ metadata: components: - name: bad-set-variables-pattern + description: "###ZARF_PKG_TMPL_NUMB3R5###" required: true actions: onDeploy: