Skip to content

Commit

Permalink
backport of commit f452948 (#24659)
Browse files Browse the repository at this point in the history
Co-authored-by: Phil Renaud <phil.renaud@hashicorp.com>
  • Loading branch information
hc-github-team-nomad-core and philrenaud authored Dec 13, 2024
1 parent 08cbe82 commit 107b81f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/24642.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
actions: Nomad Actions names now accept a wider range of names
```
4 changes: 2 additions & 2 deletions nomad/structs/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"github.com/hashicorp/go-multierror"
)

// validJobActionName is used to validate a job action name.
var validJobActionName = regexp.MustCompile("^[a-zA-Z0-9-]{1,128}$")
// validJobActionName is used to validate a action name.
var validJobActionName = regexp.MustCompile(`^[^\x00\s]{1,128}$`)

type Action struct {
Name string
Expand Down
22 changes: 19 additions & 3 deletions nomad/structs/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,28 @@ func TestAction_Validate(t *testing.T) {
expectedError: errors.New(`invalid name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'`),
},
{
name: "invalid character name",
name: "invalid character name with spaces",
inputAction: &Action{
Name: `\//?|?|?%&%@$&£@$)`,
Name: "invalid name with spaces",
Command: "env",
},
expectedError: errors.New(`invalid name '\//?|?|?%&%@$&£@$)'`),
expectedError: errors.New(`invalid name 'invalid name with spaces'`),
},
{
name: "invalid character name with nulls",
inputAction: &Action{
Name: "invalid\x00name",
Command: "env",
},
expectedError: fmt.Errorf("1 error occurred:\n\t* invalid name 'invalid\x00name'\n\n"), // had to use fmt.Errorf to show the null character
},
{
name: "Emoji characters are valid",
inputAction: &Action{
Name: "🇳🇴🇲🇦🇩",
Command: "env",
},
expectedError: nil,
},
{
name: "valid",
Expand Down

0 comments on commit 107b81f

Please sign in to comment.