From fbcac585cf626917e2baf1d0065c7b632341ba01 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Wed, 19 Jul 2023 21:01:23 +0200 Subject: ref: Move auth functions to service --- pkg/service/auth_test.go | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'pkg/service/auth_test.go') diff --git a/pkg/service/auth_test.go b/pkg/service/auth_test.go index 35b2475..7083d0c 100644 --- a/pkg/service/auth_test.go +++ b/pkg/service/auth_test.go @@ -64,7 +64,7 @@ func TestInitialRegisterAndLogin(t *testing.T) { auth, err := scene.controller.Login(scene.ctx, []byte(tc.username), tc.password) testkit.TestFatalError(t, "Login", err) - token, err := ext.ReadToken(auth, key) + token, err := ReadToken(auth, key) testkit.TestFatalError(t, "Login", err) testkit.TestValue(t, "Login", tc.username, token.Username) @@ -76,3 +76,34 @@ func TestInitialRegisterAndLogin(t *testing.T) { func remove[T any](slice []T, s int) []T { return append(slice[:s], slice[s+1:]...) } + +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) + }) + } +} -- cgit v1.2.3