vault/command/token/helper_testing.go
Vault Automation 58e59e67b2
Backport license: update headers to IBM Corp. into release/1.21.x+ent (#10234) (#10252)
* license: update headers to IBM Corp.
* `make proto`
* update offset because source file changed
* update licenses in files that were not included in backport

Signed-off-by: Ryan Cragun <me@ryan.ec>
Co-authored-by: Ryan Cragun <me@ryan.ec>
2025-10-21 15:20:35 -06:00

48 lines
911 B
Go

// Copyright IBM Corp. 2016, 2025
// SPDX-License-Identifier: BUSL-1.1
package token
import (
"sync"
"github.com/hashicorp/vault/api/tokenhelper"
)
var _ tokenhelper.TokenHelper = (*TestingTokenHelper)(nil)
// 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
}