github.com/hashicorp/vault/sdk@v0.11.0/helper/pluginutil/identity_token_test.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package pluginutil 5 6 import ( 7 "fmt" 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 // TestIdentityToken_Stringer ensures that plugin identity tokens that 14 // are printed in formatted strings or errors are redacted and getters 15 // return expected values. 16 func TestIdentityToken_Stringer(t *testing.T) { 17 contents := "header.payload.signature" 18 tk := IdentityToken(contents) 19 20 // token getters 21 assert.Equal(t, contents, tk.Token()) 22 assert.Equal(t, redactedTokenString, tk.String()) 23 24 // formatted strings and errors 25 assert.NotContains(t, fmt.Sprintf("%v", tk), tk.Token()) 26 assert.NotContains(t, fmt.Sprintf("%s", tk), tk.Token()) 27 assert.NotContains(t, fmt.Errorf("%v", tk).Error(), tk.Token()) 28 assert.NotContains(t, fmt.Errorf("%s", tk).Error(), tk.Token()) 29 }