Character restrictions in action names were unduly oppressive (#24642)

* Character restrictions in action names were unduly oppressive

* OK but what about SOME oppression

* Test updates for our new action name rules
This commit is contained in:
Phil Renaud
2024-12-12 15:58:26 -06:00
committed by GitHub
parent dcb0259fe3
commit f452948556
3 changed files with 24 additions and 5 deletions

3
.changelog/24642.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:improvement
actions: Nomad Actions names now accept a wider range of names
```

View File

@@ -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

View File

@@ -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",