From a77575e93efb0f70fd62d7f16dca6ef63300c988 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 16 Jul 2021 17:59:56 -0400 Subject: [PATCH] acl: use SetHash consistently in testPolicyForID A previous commit used SetHash on two of the cases to fix a data race. This commit applies that change to all cases. Using SetHash in this test helper should ensure that the test helper behaves closer to production. --- agent/consul/acl_test.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/agent/consul/acl_test.go b/agent/consul/acl_test.go index 2646989b9a..c85e5c2a09 100644 --- a/agent/consul/acl_test.go +++ b/agent/consul/acl_test.go @@ -310,14 +310,16 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { func testPolicyForID(policyID string) (bool, *structs.ACLPolicy, error) { switch policyID { case "acl-ro": - return true, &structs.ACLPolicy{ + p := &structs.ACLPolicy{ ID: "acl-ro", Name: "acl-ro", Description: "acl-ro", Rules: `acl = "read"`, Syntax: acl.SyntaxCurrent, RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2}, - }, nil + } + p.SetHash(false) + return true, p, nil case "acl-wr": p := &structs.ACLPolicy{ ID: "acl-wr", @@ -330,23 +332,27 @@ func testPolicyForID(policyID string) (bool, *structs.ACLPolicy, error) { p.SetHash(false) return true, p, nil case "service-ro": - return true, &structs.ACLPolicy{ + p := &structs.ACLPolicy{ ID: "service-ro", Name: "service-ro", Description: "service-ro", Rules: `service_prefix "" { policy = "read" }`, Syntax: acl.SyntaxCurrent, RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2}, - }, nil + } + p.SetHash(false) + return true, p, nil case "service-wr": - return true, &structs.ACLPolicy{ + p := &structs.ACLPolicy{ ID: "service-wr", Name: "service-wr", Description: "service-wr", Rules: `service_prefix "" { policy = "write" }`, Syntax: acl.SyntaxCurrent, RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2}, - }, nil + } + p.SetHash(false) + return true, p, nil case "node-wr": p := &structs.ACLPolicy{ ID: "node-wr", @@ -360,7 +366,7 @@ func testPolicyForID(policyID string) (bool, *structs.ACLPolicy, error) { p.SetHash(false) return true, p, nil case "dc2-key-wr": - return true, &structs.ACLPolicy{ + p := &structs.ACLPolicy{ ID: "dc2-key-wr", Name: "dc2-key-wr", Description: "dc2-key-wr", @@ -368,7 +374,9 @@ func testPolicyForID(policyID string) (bool, *structs.ACLPolicy, error) { Syntax: acl.SyntaxCurrent, Datacenters: []string{"dc2"}, RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2}, - }, nil + } + p.SetHash(false) + return true, p, nil default: return testPolicyForIDEnterprise(policyID) }