@@ -4,7 +4,6 @@ import (
4 "crypto/rand"
4 "crypto/rand"
@@ -257,78 +256,6 @@ func TestEncodeAndDecodeSessionState(t *testing.T) {
260−// TestLegacyV5DecodeSessionState confirms V5 JSON sessions decode
262−// TODO: Remove when this is deprecated (likely V7)
263−func TestLegacyV5DecodeSessionState(t *testing.T) {
264− testCases, cipher, legacyCipher := CreateLegacyV5TestCases(t)
266− for testName, tc := range testCases {
267− t.Run(testName, func(t *testing.T) {
268− // Legacy sessions fail in DecodeSessionState which results in
269− // the fallback to LegacyV5DecodeSessionState
270− _, err := DecodeSessionState([]byte(tc.Input), cipher, false)
271− assert.Error(t, err)
272− _, err = DecodeSessionState([]byte(tc.Input), cipher, true)
273− assert.Error(t, err)
275− ss, err := LegacyV5DecodeSessionState(tc.Input, legacyCipher)
277− assert.Error(t, err)
281− assert.NoError(t, err)
282− compareSessionStates(t, tc.Output, ss)
287−// Test_into tests the into helper function used in LegacyV5DecodeSessionState
289−// TODO: Remove when this is deprecated (likely V7)
290−func Test_into(t *testing.T) {
291− const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
293− // Test all 3 valid AES sizes
294− for _, secretSize := range []int{16, 24, 32} {
295− t.Run(fmt.Sprintf("%d", secretSize), func(t *testing.T) {
296− secret := make([]byte, secretSize)
297− _, err := io.ReadFull(rand.Reader, secret)
298− assert.Equal(t, nil, err)
300− cfb, err := encryption.NewCFBCipher(secret)
301− assert.NoError(t, err)
302− c := encryption.NewBase64Cipher(cfb)
304− // Check no errors with empty or nil strings
306− assert.Equal(t, nil, into(&empty, c.Encrypt))
307− assert.Equal(t, nil, into(&empty, c.Decrypt))
308− assert.Equal(t, nil, into(nil, c.Encrypt))
309− assert.Equal(t, nil, into(nil, c.Decrypt))
311− // Test various sizes tokens might be
312− for _, dataSize := range []int{10, 100, 1000, 5000, 10000} {
313− t.Run(fmt.Sprintf("%d", dataSize), func(t *testing.T) {
314− b := make([]byte, dataSize)
316− b[i] = charset[mathrand.Intn(len(charset))]
319− originalData := data
321− assert.Equal(t, nil, into(&data, c.Encrypt))
322− assert.NotEqual(t, originalData, data)
324− assert.Equal(t, nil, into(&data, c.Decrypt))
325− assert.Equal(t, originalData, data)
332func compareSessionStates(t *testing.T, expected *SessionState, actual *SessionState) {
259func compareSessionStates(t *testing.T, expected *SessionState, actual *SessionState) {
333 if expected.CreatedAt != nil {
260 if expected.CreatedAt != nil {
334 assert.NotNil(t, actual.CreatedAt)
261 assert.NotNil(t, actual.CreatedAt)