2023-03-15 12:00:52 -04:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-10 21:14:03 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-15 12:00:52 -04:00
|
|
|
|
2017-09-04 23:50:59 -04:00
|
|
|
package token
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"sync"
|
2024-03-04 13:29:20 -05:00
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/api/tokenhelper"
|
2017-09-04 23:50:59 -04:00
|
|
|
)
|
|
|
|
|
|
2024-03-04 13:29:20 -05:00
|
|
|
var _ tokenhelper.TokenHelper = (*TestingTokenHelper)(nil)
|
2017-09-04 23:50:59 -04:00
|
|
|
|
|
|
|
|
// TestingTokenHelper implements token.TokenHelper which runs entirely
|
|
|
|
|
// in-memory. This should not be used outside of testing.
|
|
|
|
|
type TestingTokenHelper struct {
|
|
|
|
|
lock sync.RWMutex
|
|
|
|
|
token string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewTestingTokenHelper() *TestingTokenHelper {
|
|
|
|
|
return &TestingTokenHelper{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *TestingTokenHelper) Erase() error {
|
|
|
|
|
t.lock.Lock()
|
|
|
|
|
defer t.lock.Unlock()
|
|
|
|
|
t.token = ""
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *TestingTokenHelper) Get() (string, error) {
|
|
|
|
|
t.lock.RLock()
|
|
|
|
|
defer t.lock.RUnlock()
|
|
|
|
|
return t.token, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *TestingTokenHelper) Path() string {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *TestingTokenHelper) Store(token string) error {
|
|
|
|
|
t.lock.Lock()
|
|
|
|
|
defer t.lock.Unlock()
|
|
|
|
|
t.token = token
|
|
|
|
|
return nil
|
|
|
|
|
}
|