From 15b06780ab8c65614d2e21a0bec60d1ffda19766 Mon Sep 17 00:00:00 2001 From: Chris Capurso Date: Tue, 23 Nov 2021 13:57:22 -0500 Subject: [PATCH] remove nil response to 404 translation for PatchOperation (#13167) * remove nil response to 404 translation for PatchOperation * go get vault-plugin-secrets-kv@master --- go.mod | 2 +- go.sum | 2 ++ http/handler_test.go | 48 ------------------------------------ sdk/logical/response_util.go | 2 +- 4 files changed, 4 insertions(+), 50 deletions(-) diff --git a/go.mod b/go.mod index 883acaa2e..8347ce007 100644 --- a/go.mod +++ b/go.mod @@ -108,7 +108,7 @@ require ( github.com/hashicorp/vault-plugin-secrets-azure v0.11.1 github.com/hashicorp/vault-plugin-secrets-gcp v0.11.0 github.com/hashicorp/vault-plugin-secrets-gcpkms v0.10.0 - github.com/hashicorp/vault-plugin-secrets-kv v0.10.1 + github.com/hashicorp/vault-plugin-secrets-kv v0.5.7-0.20211123171606-16933c88368a github.com/hashicorp/vault-plugin-secrets-mongodbatlas v0.5.1 github.com/hashicorp/vault-plugin-secrets-openldap v0.6.0 github.com/hashicorp/vault-plugin-secrets-terraform v0.3.0 diff --git a/go.sum b/go.sum index ad0cf3cd6..6a7e25731 100644 --- a/go.sum +++ b/go.sum @@ -966,6 +966,8 @@ github.com/hashicorp/vault-plugin-secrets-gcp v0.11.0 h1:3i2uXY/n4jJv71baXeS1q19 github.com/hashicorp/vault-plugin-secrets-gcp v0.11.0/go.mod h1:ndpmRkIPHW5UYqv2nn2AJNVZsucJ8lY2bp5i5Ngvhuc= github.com/hashicorp/vault-plugin-secrets-gcpkms v0.10.0 h1:0Vi5WEIpZctk/ZoRClodV9WCnM/lCzw9XekMhRZdo8k= github.com/hashicorp/vault-plugin-secrets-gcpkms v0.10.0/go.mod h1:6DPwGu8oGR1sZRpjwkcAnrQZWQuAJ/Ph+rQHfUo1Yf4= +github.com/hashicorp/vault-plugin-secrets-kv v0.5.7-0.20211123171606-16933c88368a h1:GVA3sY+FRhQrMexWGMCsIfVVMgcdru36WMKvDtKed5I= +github.com/hashicorp/vault-plugin-secrets-kv v0.5.7-0.20211123171606-16933c88368a/go.mod h1:TNPRoB53Twd9tYvlhqqEhMsQPiVN604kZw9jr2zUzDk= github.com/hashicorp/vault-plugin-secrets-kv v0.10.1 h1:88a6YkbU0FCboZoFdB5uv6ukBf3gc3zDLKM4z64dWxo= github.com/hashicorp/vault-plugin-secrets-kv v0.10.1/go.mod h1:TNPRoB53Twd9tYvlhqqEhMsQPiVN604kZw9jr2zUzDk= github.com/hashicorp/vault-plugin-secrets-mongodbatlas v0.5.1 h1:Maewon4nu0KL1ALBOvL6Rsj+Qyr9hdULWflyMz7+9nk= diff --git a/http/handler_test.go b/http/handler_test.go index c937e7e7b..c97d272f9 100644 --- a/http/handler_test.go +++ b/http/handler_test.go @@ -914,54 +914,6 @@ func kvRequestWithRetry(t *testing.T, req func() (*api.Secret, error)) (*api.Sec } } -func TestHandler_Patch_NotFound(t *testing.T) { - coreConfig := &vault.CoreConfig{ - LogicalBackends: map[string]logical.Factory{ - "kv": kv.VersionedKVFactory, - }, - } - - cluster := vault.NewTestCluster(t, coreConfig, &vault.TestClusterOptions{ - HandlerFunc: Handler, - }) - - cluster.Start() - defer cluster.Cleanup() - - cores := cluster.Cores - - core := cores[0].Core - c := cluster.Cores[0].Client - vault.TestWaitActive(t, core) - - // Mount a KVv2 backend - err := c.Sys().Mount("kv", &api.MountInput{ - Type: "kv-v2", - }) - if err != nil { - t.Fatal(err) - } - - kvData := map[string]interface{}{ - "data": map[string]interface{}{ - "bar": "a", - }, - } - - resp, err := kvRequestWithRetry(t, func() (*api.Secret, error) { - return c.Logical().JSONMergePatch(context.Background(), "kv/data/foo", kvData) - }) - - if err == nil { - t.Fatalf("expected PATCH request to fail, resp: %#v\n", resp) - } - - responseError := err.(*api.ResponseError) - if responseError.StatusCode != http.StatusNotFound { - t.Fatalf("expected PATCH request to fail with %d status code - err: %#v, resp: %#v\n", http.StatusNotFound, responseError, resp) - } -} - func TestHandler_Patch_Audit(t *testing.T) { coreConfig := &vault.CoreConfig{ LogicalBackends: map[string]logical.Factory{ diff --git a/sdk/logical/response_util.go b/sdk/logical/response_util.go index 353ef569a..92e3483d8 100644 --- a/sdk/logical/response_util.go +++ b/sdk/logical/response_util.go @@ -17,7 +17,7 @@ import ( func RespondErrorCommon(req *Request, resp *Response, err error) (int, error) { if err == nil && (resp == nil || !resp.IsError()) { switch { - case req.Operation == ReadOperation, req.Operation == PatchOperation: + case req.Operation == ReadOperation: if resp == nil { return http.StatusNotFound, nil }