vault/sdk/helper/pluginutil/identity_token_test.go
Austin Gebauer d90c7e8ab5
systemview: adds method for plugins to generate identity tokens (#24929)
* systemview: adds method for plugins to generate identity tokens

* change test name and godoc

* adds changelog

* make proto to include comment
2024-01-18 11:01:14 -08:00

30 lines
838 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package pluginutil
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
// TestIdentityToken_Stringer ensures that plugin identity tokens that
// are printed in formatted strings or errors are redacted and getters
// return expected values.
func TestIdentityToken_Stringer(t *testing.T) {
contents := "header.payload.signature"
tk := IdentityToken(contents)
// token getters
assert.Equal(t, contents, tk.Token())
assert.Equal(t, redactedTokenString, tk.String())
// formatted strings and errors
assert.NotContains(t, fmt.Sprintf("%v", tk), tk.Token())
assert.NotContains(t, fmt.Sprintf("%s", tk), tk.Token())
assert.NotContains(t, fmt.Errorf("%v", tk).Error(), tk.Token())
assert.NotContains(t, fmt.Errorf("%s", tk).Error(), tk.Token())
}