Skip to content

Commit

Permalink
chore: fix numbers in package templates (#2076)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
Racer159 authored Oct 16, 2023
1 parent 785c5a0 commit 7801b7c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test-external.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/utils/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions src/test/e2e/24_variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/test/packages/24-evil-variables/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:

components:
- name: bad-set-variables-pattern
description: "###ZARF_PKG_TMPL_NUMB3R5###"
required: true
actions:
onDeploy:
Expand Down

0 comments on commit 7801b7c

Please sign in to comment.