Skip to content

Commit

Permalink
acl: fix validation of ACL plugin policy entries. (hashicorp#23274)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasell authored Jun 10, 2024
1 parent fa70267 commit d2a03de
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/23274.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
acl: Fix plugin policy validation when checking write permissions
```
2 changes: 1 addition & 1 deletion acl/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func isPolicyValid(policy string) bool {

func (p *PluginPolicy) isValid() bool {
switch p.Policy {
case PolicyDeny, PolicyRead, PolicyList:
case PolicyDeny, PolicyRead, PolicyList, PolicyWrite:
return true
default:
return false
Expand Down
44 changes: 44 additions & 0 deletions acl/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/hashicorp/nomad/ci"
"github.com/shoenig/test/must"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -898,3 +899,46 @@ func TestParse_BadInput(t *testing.T) {
})
}
}

func TestPluginPolicy_isValid(t *testing.T) {
ci.Parallel(t)

testCases := []struct {
name string
inputPluginPolicy *PluginPolicy
expectedOutput bool
}{
{
name: "policy deny",
inputPluginPolicy: &PluginPolicy{Policy: "deny"},
expectedOutput: true,
},
{
name: "policy read",
inputPluginPolicy: &PluginPolicy{Policy: "read"},
expectedOutput: true,
},
{
name: "policy list",
inputPluginPolicy: &PluginPolicy{Policy: "list"},
expectedOutput: true,
},
{
name: "policy write",
inputPluginPolicy: &PluginPolicy{Policy: "write"},
expectedOutput: true,
},
{
name: "policy invalid",
inputPluginPolicy: &PluginPolicy{Policy: "invalid"},
expectedOutput: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
actualOutput := tc.inputPluginPolicy.isValid()
must.Eq(t, tc.expectedOutput, actualOutput)
})
}
}

0 comments on commit d2a03de

Please sign in to comment.