From a9ea98592494b026a0048279df84ca058b068358 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 4 May 2017 12:30:10 -0400 Subject: [PATCH 1/2] Make path-help request forward Fixes #2676 --- http/forwarding_test.go | 33 +++++++++++++++++++++++++++++++++ http/help.go | 12 ++++++++---- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/http/forwarding_test.go b/http/forwarding_test.go index fdc3b76fc120..cb11797f253c 100644 --- a/http/forwarding_test.go +++ b/http/forwarding_test.go @@ -595,3 +595,36 @@ func TestHTTP_Forwarding_ClientTLS(t *testing.T) { } } } + +func TestHTTP_Forwarding_HelpOperation(t *testing.T) { + handler1 := http.NewServeMux() + handler2 := http.NewServeMux() + handler3 := http.NewServeMux() + + coreConfig := &vault.CoreConfig{} + + cores := vault.TestCluster(t, []http.Handler{handler1, handler2, handler3}, coreConfig, true) + for _, core := range cores { + defer core.CloseListeners() + } + handler1.Handle("/", Handler(cores[0].Core)) + handler2.Handle("/", Handler(cores[1].Core)) + handler3.Handle("/", Handler(cores[2].Core)) + + // make it easy to get access to the active + core := cores[0].Core + vault.TestWaitActive(t, core) + + testHelp := func(client *api.Client) { + help, err := client.Help("auth/token") + if err != nil { + t.Fatal(err) + } + if help == nil { + t.Fatal("help was nil") + } + } + + testHelp(cores[0].Client) + testHelp(cores[1].Client) +} diff --git a/http/help.go b/http/help.go index f0ca8b170741..1c3a9560f040 100644 --- a/http/help.go +++ b/http/help.go @@ -8,14 +8,18 @@ import ( ) func wrapHelpHandler(h http.Handler, core *vault.Core) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - // If the help parameter is not blank, then show the help + return http.HandlerFunc(func(writer http.ResponseWriter, req *http.Request) { + // If the help parameter is not blank, then show the help. We request + // forward because standby nodes do not have mounts and other state. if v := req.URL.Query().Get("help"); v != "" || req.Method == "HELP" { - handleHelp(core, w, req) + handleRequestForwarding(core, + http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + handleHelp(core, w, r) + })).ServeHTTP(writer, req) return } - h.ServeHTTP(w, req) + h.ServeHTTP(writer, req) return }) } From a8add85b4ce0aec377f1e1a2c71de55fac744df0 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 4 May 2017 13:22:57 -0400 Subject: [PATCH 2/2] Minor test cleanup --- http/forwarding_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/http/forwarding_test.go b/http/forwarding_test.go index cb11797f253c..e7d285e2424a 100644 --- a/http/forwarding_test.go +++ b/http/forwarding_test.go @@ -601,19 +601,16 @@ func TestHTTP_Forwarding_HelpOperation(t *testing.T) { handler2 := http.NewServeMux() handler3 := http.NewServeMux() - coreConfig := &vault.CoreConfig{} - - cores := vault.TestCluster(t, []http.Handler{handler1, handler2, handler3}, coreConfig, true) + cores := vault.TestCluster(t, []http.Handler{handler1, handler2, handler3}, &vault.CoreConfig{}, true) for _, core := range cores { defer core.CloseListeners() } + handler1.Handle("/", Handler(cores[0].Core)) handler2.Handle("/", Handler(cores[1].Core)) handler3.Handle("/", Handler(cores[2].Core)) - // make it easy to get access to the active - core := cores[0].Core - vault.TestWaitActive(t, core) + vault.TestWaitActive(t, cores[0].Core) testHelp := func(client *api.Client) { help, err := client.Help("auth/token")