-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport of Fix policy lookup to allow for slashes into release/1.15.x (
#18371) * backport of commit 1a9cded * backport of commit cfec746 * backport of commit 8a9db4c * backport of commit ac13bf1 --------- Co-authored-by: Jeremy Jacobson <[email protected]>
- Loading branch information
1 parent
78f6df4
commit fae6844
Showing
3 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package acl | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"testing" | ||
|
||
"github.com/hashicorp/consul/agent" | ||
"github.com/hashicorp/consul/agent/structs" | ||
"github.com/hashicorp/consul/testrpc" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_GetPolicyIDByName_Builtins(t *testing.T) { | ||
t.Parallel() | ||
|
||
a := agent.StartTestAgent(t, | ||
agent.TestAgent{ | ||
LogOutput: io.Discard, | ||
HCL: ` | ||
primary_datacenter = "dc1" | ||
acl { | ||
enabled = true | ||
tokens { | ||
initial_management = "root" | ||
} | ||
} | ||
`, | ||
}, | ||
) | ||
|
||
defer a.Shutdown() | ||
testrpc.WaitForTestAgent(t, a.RPC, "dc1", testrpc.WithToken("root")) | ||
|
||
client := a.Client() | ||
client.AddHeader("X-Consul-Token", "root") | ||
|
||
for _, policy := range structs.ACLBuiltinPolicies { | ||
name := fmt.Sprintf("%s policy", policy.Name) | ||
t.Run(name, func(t *testing.T) { | ||
id, err := GetPolicyIDByName(client, policy.Name) | ||
require.NoError(t, err) | ||
require.Equal(t, policy.ID, id) | ||
}) | ||
} | ||
} | ||
|
||
func Test_GetPolicyIDFromPartial_Builtins(t *testing.T) { | ||
t.Parallel() | ||
|
||
a := agent.StartTestAgent(t, | ||
agent.TestAgent{ | ||
LogOutput: io.Discard, | ||
HCL: ` | ||
primary_datacenter = "dc1" | ||
acl { | ||
enabled = true | ||
tokens { | ||
initial_management = "root" | ||
} | ||
} | ||
`, | ||
}, | ||
) | ||
|
||
defer a.Shutdown() | ||
testrpc.WaitForTestAgent(t, a.RPC, "dc1", testrpc.WithToken("root")) | ||
|
||
client := a.Client() | ||
client.AddHeader("X-Consul-Token", "root") | ||
|
||
for _, policy := range structs.ACLBuiltinPolicies { | ||
name := fmt.Sprintf("%s policy", policy.Name) | ||
t.Run(name, func(t *testing.T) { | ||
id, err := GetPolicyIDFromPartial(client, policy.Name) | ||
require.NoError(t, err) | ||
require.Equal(t, policy.ID, id) | ||
}) | ||
} | ||
} |