github.com/blend/go-sdk@v1.20220411.3/oauth/state_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package oauth 9 10 import ( 11 "testing" 12 13 "github.com/blend/go-sdk/assert" 14 "github.com/blend/go-sdk/stringutil" 15 ) 16 17 func TestSerializeState(t *testing.T) { 18 assert := assert.New(t) 19 20 state := State{ 21 RedirectURI: "https://foo.com/bar", 22 Token: stringutil.Random(stringutil.Letters, 32), 23 SecureToken: stringutil.Random(stringutil.Letters, 64), 24 } 25 26 contents, err := SerializeState(state) 27 assert.Nil(err) 28 assert.NotEmpty(contents) 29 30 deserialized, err := DeserializeState(contents) 31 assert.Nil(err) 32 assert.NotNil(deserialized) 33 assert.Equal(state.RedirectURI, deserialized.RedirectURI) 34 assert.Equal(state.Token, deserialized.Token) 35 assert.Equal(state.SecureToken, deserialized.SecureToken) 36 }