aboutsummaryrefslogtreecommitdiff
path: root/pkg/ext/auth_test.go
blob: dc72a0cd66d92a1a07de9ee36a08120d954f6e60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//go:build unit

package ext

import (
	"testing"

	"git.sr.ht/~gabrielgio/img/pkg/testkit"
)

func TestReadWriteToken(t *testing.T) {
	t.Parallel()

	testCases := []struct {
		name  string
		key   []byte
		token *Token
	}{
		{
			name: "Normal write",
			key:  []byte("AES256Key-32Characters1234567890"),
			token: &Token{
				UserID:   3,
				Username: "username",
			},
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			data, err := WriteToken(tc.token, tc.key)
			testkit.TestFatalError(t, "WriteToken", err)

			token, err := ReadToken(data, tc.key)
			testkit.TestFatalError(t, "ReadToken", err)

			testkit.TestValue(t, "ReadWriteToken", token, tc.token)
		})
	}
}