Browse Source

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.
pull/10396/head
Daniel Nephin 3 years ago
parent
commit
a77575e93e
  1. 24
      agent/consul/acl_test.go

24
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) { func testPolicyForID(policyID string) (bool, *structs.ACLPolicy, error) {
switch policyID { switch policyID {
case "acl-ro": case "acl-ro":
return true, &structs.ACLPolicy{ p := &structs.ACLPolicy{
ID: "acl-ro", ID: "acl-ro",
Name: "acl-ro", Name: "acl-ro",
Description: "acl-ro", Description: "acl-ro",
Rules: `acl = "read"`, Rules: `acl = "read"`,
Syntax: acl.SyntaxCurrent, Syntax: acl.SyntaxCurrent,
RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2}, RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2},
}, nil }
p.SetHash(false)
return true, p, nil
case "acl-wr": case "acl-wr":
p := &structs.ACLPolicy{ p := &structs.ACLPolicy{
ID: "acl-wr", ID: "acl-wr",
@ -330,23 +332,27 @@ func testPolicyForID(policyID string) (bool, *structs.ACLPolicy, error) {
p.SetHash(false) p.SetHash(false)
return true, p, nil return true, p, nil
case "service-ro": case "service-ro":
return true, &structs.ACLPolicy{ p := &structs.ACLPolicy{
ID: "service-ro", ID: "service-ro",
Name: "service-ro", Name: "service-ro",
Description: "service-ro", Description: "service-ro",
Rules: `service_prefix "" { policy = "read" }`, Rules: `service_prefix "" { policy = "read" }`,
Syntax: acl.SyntaxCurrent, Syntax: acl.SyntaxCurrent,
RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2}, RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2},
}, nil }
p.SetHash(false)
return true, p, nil
case "service-wr": case "service-wr":
return true, &structs.ACLPolicy{ p := &structs.ACLPolicy{
ID: "service-wr", ID: "service-wr",
Name: "service-wr", Name: "service-wr",
Description: "service-wr", Description: "service-wr",
Rules: `service_prefix "" { policy = "write" }`, Rules: `service_prefix "" { policy = "write" }`,
Syntax: acl.SyntaxCurrent, Syntax: acl.SyntaxCurrent,
RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2}, RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2},
}, nil }
p.SetHash(false)
return true, p, nil
case "node-wr": case "node-wr":
p := &structs.ACLPolicy{ p := &structs.ACLPolicy{
ID: "node-wr", ID: "node-wr",
@ -360,7 +366,7 @@ func testPolicyForID(policyID string) (bool, *structs.ACLPolicy, error) {
p.SetHash(false) p.SetHash(false)
return true, p, nil return true, p, nil
case "dc2-key-wr": case "dc2-key-wr":
return true, &structs.ACLPolicy{ p := &structs.ACLPolicy{
ID: "dc2-key-wr", ID: "dc2-key-wr",
Name: "dc2-key-wr", Name: "dc2-key-wr",
Description: "dc2-key-wr", Description: "dc2-key-wr",
@ -368,7 +374,9 @@ func testPolicyForID(policyID string) (bool, *structs.ACLPolicy, error) {
Syntax: acl.SyntaxCurrent, Syntax: acl.SyntaxCurrent,
Datacenters: []string{"dc2"}, Datacenters: []string{"dc2"},
RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2}, RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2},
}, nil }
p.SetHash(false)
return true, p, nil
default: default:
return testPolicyForIDEnterprise(policyID) return testPolicyForIDEnterprise(policyID)
} }

Loading…
Cancel
Save