Skip to content

Commit

Permalink
Character restrictions in action names were unduly oppressive (#24642)
Browse files Browse the repository at this point in the history
* Character restrictions in action names were unduly oppressive

* OK but what about SOME oppression

* Test updates for our new action name rules
  • Loading branch information
philrenaud authored Dec 12, 2024
1 parent dcb0259 commit f452948
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 f452948

Please sign in to comment.