aboutsummaryrefslogtreecommitdiff
path: root/pkg/ext/auth_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/ext/auth_test.go')
-rw-r--r--pkg/ext/auth_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/pkg/ext/auth_test.go b/pkg/ext/auth_test.go
new file mode 100644
index 0000000..dc72a0c
--- /dev/null
+++ b/pkg/ext/auth_test.go
@@ -0,0 +1,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)
+ })
+ }
+}