@@ -4,7 +4,6 @@ import (
44 "crypto/rand"
55 "fmt"
66 "io"
7− mathrand "math/rand"
87 "testing"
98 "time"
109
@@ -257,78 +256,6 @@ func TestEncodeAndDecodeSessionState(t *testing.T) {
257256 }
258257}
259258
260−// TestLegacyV5DecodeSessionState confirms V5 JSON sessions decode
261−//
262−// TODO: Remove when this is deprecated (likely V7)
263−func TestLegacyV5DecodeSessionState(t *testing.T) {
264− testCases, cipher, legacyCipher := CreateLegacyV5TestCases(t)
265−
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)
274−
275− ss, err := LegacyV5DecodeSessionState(tc.Input, legacyCipher)
276− if tc.Error {
277− assert.Error(t, err)
278− assert.Nil(t, ss)
279− return
280− }
281− assert.NoError(t, err)
282− compareSessionStates(t, tc.Output, ss)
283− })
284− }
285−}
286−
287−// Test_into tests the into helper function used in LegacyV5DecodeSessionState
288−//
289−// TODO: Remove when this is deprecated (likely V7)
290−func Test_into(t *testing.T) {
291− const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
292−
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)
299−
300− cfb, err := encryption.NewCFBCipher(secret)
301− assert.NoError(t, err)
302− c := encryption.NewBase64Cipher(cfb)
303−
304− // Check no errors with empty or nil strings
305− empty := ""
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))
310−
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)
315− for i := range b {
316− b[i] = charset[mathrand.Intn(len(charset))]
317− }
318− data := string(b)
319− originalData := data
320−
321− assert.Equal(t, nil, into(&data, c.Encrypt))
322− assert.NotEqual(t, originalData, data)
323−
324− assert.Equal(t, nil, into(&data, c.Decrypt))
325− assert.Equal(t, originalData, data)
326− })
327− }
328− })
329− }
330−}
331−
332259func compareSessionStates(t *testing.T, expected *SessionState, actual *SessionState) {
333260 if expected.CreatedAt != nil {
334261 assert.NotNil(t, actual.CreatedAt)