Skip to content

Commit 80a4d4b

Browse files
bosouzadrivera258
authored andcommitted
fix panic in HCL dup warning (#30780)
1 parent 5135c68 commit 80a4d4b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

vault/logical_system.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3682,6 +3682,9 @@ func (b *SystemBackend) handlePoliciesSet(policyType PolicyType) framework.Opera
36823682
}
36833683

36843684
if duplicate {
3685+
if resp == nil {
3686+
resp = &logical.Response{}
3687+
}
36853688
// TODO (HCL_DUP_KEYS_DEPRECATION): remove log and API Warning once the deprecation is done
36863689
b.logger.Warn("newly created HCL policy contains duplicate attributes, which will no longer be supported in a future version", "policy", policy.Name, "namespace", ns.Path)
36873690
resp.AddWarning("policy contains duplicate attributes, which will no longer be supported in a future version")

vault/logical_system_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,8 +2817,8 @@ func TestSystemBackend_writeHCLDuplicateAttributes(t *testing.T) {
28172817

28182818
// policy with duplicate attribute
28192819
rules := `path "foo/" { policy = "read" policy = "read" }`
2820-
req := logical.TestRequest(t, logical.UpdateOperation, "policy/Foo")
2821-
req.Data["rules"] = rules
2820+
req := logical.TestRequest(t, logical.UpdateOperation, "policy/foo")
2821+
req.Data["policy"] = rules
28222822
resp, err := b.HandleRequest(namespace.RootContext(nil), req)
28232823
// TODO (HCL_DUP_KEYS_DEPRECATION): change this test to expect an error when creating a policy with duplicate attributes
28242824
if err != nil {

0 commit comments

Comments
 (0)