Refactor test helper (#11689)
Allow custom ACL root tokens to be passed
This commit is contained in:
parent
0ec67cc2d1
commit
e9c661db7f
|
@ -263,10 +263,10 @@ node "foo" {
|
|||
|
||||
func createToken(t *testing.T, cc rpc.ClientCodec, policyRules string) string {
|
||||
t.Helper()
|
||||
return createTokenWithPolicyName(t, "the-policy", cc, policyRules)
|
||||
return createTokenWithPolicyName(t, cc, "the-policy", policyRules, "root")
|
||||
}
|
||||
|
||||
func createTokenWithPolicyName(t *testing.T, policyName string, cc rpc.ClientCodec, policyRules string) string {
|
||||
func createTokenWithPolicyName(t *testing.T, cc rpc.ClientCodec, policyName string, policyRules string, token string) string {
|
||||
t.Helper()
|
||||
|
||||
reqPolicy := structs.ACLPolicySetRequest{
|
||||
|
@ -275,25 +275,25 @@ func createTokenWithPolicyName(t *testing.T, policyName string, cc rpc.ClientCod
|
|||
Name: policyName,
|
||||
Rules: policyRules,
|
||||
},
|
||||
WriteRequest: structs.WriteRequest{Token: "root"},
|
||||
WriteRequest: structs.WriteRequest{Token: token},
|
||||
}
|
||||
err := msgpackrpc.CallWithCodec(cc, "ACL.PolicySet", &reqPolicy, &structs.ACLPolicy{})
|
||||
require.NoError(t, err)
|
||||
|
||||
token, err := uuid.GenerateUUID()
|
||||
secretId, err := uuid.GenerateUUID()
|
||||
require.NoError(t, err)
|
||||
|
||||
reqToken := structs.ACLTokenSetRequest{
|
||||
Datacenter: "dc1",
|
||||
ACLToken: structs.ACLToken{
|
||||
SecretID: token,
|
||||
SecretID: secretId,
|
||||
Policies: []structs.ACLTokenPolicyLink{{Name: policyName}},
|
||||
},
|
||||
WriteRequest: structs.WriteRequest{Token: "root"},
|
||||
WriteRequest: structs.WriteRequest{Token: token},
|
||||
}
|
||||
err = msgpackrpc.CallWithCodec(cc, "ACL.TokenSet", &reqToken, &structs.ACLToken{})
|
||||
require.NoError(t, err)
|
||||
return token
|
||||
return secretId
|
||||
}
|
||||
|
||||
func TestCatalog_Register_ForwardLeader(t *testing.T) {
|
||||
|
|
|
@ -1430,13 +1430,13 @@ func TestPreparedQuery_Execute(t *testing.T) {
|
|||
testrpc.WaitForLeader(t, s1.RPC, "dc1", testrpc.WithToken("root"))
|
||||
testrpc.WaitForLeader(t, s1.RPC, "dc2", testrpc.WithToken("root"))
|
||||
|
||||
execNoNodesToken := createTokenWithPolicyName(t, "no-nodes", codec1, `service_prefix "foo" { policy = "read" }`)
|
||||
execNoNodesToken := createTokenWithPolicyName(t, codec1, "no-nodes", `service_prefix "foo" { policy = "read" }`, "root")
|
||||
rules := `
|
||||
service_prefix "foo" { policy = "read" }
|
||||
node_prefix "" { policy = "read" }
|
||||
`
|
||||
execToken := createTokenWithPolicyName(t, "with-read", codec1, rules)
|
||||
denyToken := createTokenWithPolicyName(t, "with-deny", codec1, `service_prefix "foo" { policy = "deny" }`)
|
||||
execToken := createTokenWithPolicyName(t, codec1, "with-read", rules, "root")
|
||||
denyToken := createTokenWithPolicyName(t, codec1, "with-deny", `service_prefix "foo" { policy = "deny" }`, "root")
|
||||
|
||||
newSessionDC1 := func(t *testing.T) string {
|
||||
t.Helper()
|
||||
|
|
Loading…
Reference in New Issue