mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
Make path-help request forward (#2677)
This commit is contained in:
@@ -595,3 +595,33 @@ func TestHTTP_Forwarding_ClientTLS(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTP_Forwarding_HelpOperation(t *testing.T) {
|
||||
handler1 := http.NewServeMux()
|
||||
handler2 := http.NewServeMux()
|
||||
handler3 := http.NewServeMux()
|
||||
|
||||
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))
|
||||
|
||||
vault.TestWaitActive(t, cores[0].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)
|
||||
}
|
||||
|
||||
12
http/help.go
12
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
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user