mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 11:38:02 +00:00
api: re-use proper token constant
This commit is contained in:
@@ -5,12 +5,8 @@ import (
|
||||
"net/http/cookiejar"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
// TokenCookieName is the name of the cookie that contains the
|
||||
// access token after logging in.
|
||||
TokenCookieName = "token"
|
||||
vaultHttp "github.com/hashicorp/vault/http"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the client.
|
||||
@@ -79,7 +75,7 @@ func NewClient(c Config) (*Client, error) {
|
||||
func (c *Client) Token() string {
|
||||
r := c.NewRequest("GET", "/")
|
||||
for _, cookie := range c.config.HttpClient.Jar.Cookies(r.URL) {
|
||||
if cookie.Name == TokenCookieName {
|
||||
if cookie.Name == vaultHttp.AuthCookieName {
|
||||
return cookie.Value
|
||||
}
|
||||
}
|
||||
@@ -92,7 +88,7 @@ func (c *Client) ClearToken() {
|
||||
r := c.NewRequest("GET", "/")
|
||||
c.config.HttpClient.Jar.SetCookies(r.URL, []*http.Cookie{
|
||||
&http.Cookie{
|
||||
Name: TokenCookieName,
|
||||
Name: vaultHttp.AuthCookieName,
|
||||
Value: "",
|
||||
Expires: time.Now().Add(-1 * time.Hour),
|
||||
},
|
||||
|
||||
@@ -4,13 +4,15 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
vaultHttp "github.com/hashicorp/vault/http"
|
||||
)
|
||||
|
||||
func TestClientToken(t *testing.T) {
|
||||
tokenValue := "foo"
|
||||
handler := func(w http.ResponseWriter, req *http.Request) {
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: TokenCookieName,
|
||||
Name: vaultHttp.AuthCookieName,
|
||||
Value: tokenValue,
|
||||
Expires: time.Now().Add(time.Hour),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user