use constant where x-vault-token was still hardcoded (#5392)

This commit is contained in:
Martin 2018-09-25 18:34:40 +02:00 committed by Brian Kassouf
parent d509588cd2
commit 79ab601cdb
4 changed files with 10 additions and 6 deletions

View File

@ -8,6 +8,8 @@ import (
"net/http"
"net/url"
"github.com/hashicorp/vault/helper/consts"
retryablehttp "github.com/hashicorp/go-retryablehttp"
)
@ -124,7 +126,7 @@ func (r *Request) toRetryableHTTP() (*retryablehttp.Request, error) {
}
if len(r.ClientToken) != 0 {
req.Header.Set("X-Vault-Token", r.ClientToken)
req.Header.Set(consts.AuthHeaderName, r.ClientToken)
}
if len(r.WrapTTL) != 0 {

View File

@ -12,6 +12,7 @@ import (
"time"
"github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/vault/helper/consts"
"github.com/hashicorp/vault/helper/jsonutil"
)
@ -68,7 +69,7 @@ func testHttpData(t *testing.T, method string, token string, addr string, body i
req.Header.Set("Content-Type", "application/json")
if len(token) != 0 {
req.Header.Set("X-Vault-Token", token)
req.Header.Set(consts.AuthHeaderName, token)
}
client := cleanhttp.DefaultClient()
@ -89,8 +90,8 @@ func testHttpData(t *testing.T, method string, token string, addr string, body i
return nil
}
// mutate the subsequent redirect requests with the first Header
if token := via[0].Header.Get("X-Vault-Token"); len(token) != 0 {
req.Header.Set("X-Vault-Token", token)
if token := via[0].Header.Get(consts.AuthHeaderName); len(token) != 0 {
req.Header.Set(consts.AuthHeaderName, token)
}
return nil
}

View File

@ -345,7 +345,7 @@ func testCluster_ForwardRequests(t *testing.T, c *TestClusterCore, rootToken, re
if err != nil {
t.Fatal(err)
}
req.Header.Add("X-Vault-Token", rootToken)
req.Header.Add(consts.AuthHeaderName, rootToken)
req = req.WithContext(context.WithValue(req.Context(), "original_request_path", req.URL.Path))
statusCode, header, respBytes, err := c.ForwardRequest(req)

View File

@ -7,6 +7,7 @@ import (
"sync/atomic"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/vault/helper/consts"
"github.com/hashicorp/vault/helper/strutil"
"github.com/hashicorp/vault/logical"
)
@ -22,10 +23,10 @@ var StdAllowedHeaders = []string{
"X-Vault-AWS-IAM-Server-ID",
"X-Vault-MFA",
"X-Vault-No-Request-Forwarding",
"X-Vault-Token",
"X-Vault-Wrap-Format",
"X-Vault-Wrap-TTL",
"X-Vault-Policy-Override",
consts.AuthHeaderName,
}
// CORSConfig stores the state of the CORS configuration.