-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth_session_test.go
More file actions
37 lines (28 loc) · 1.04 KB
/
Copy pathauth_session_test.go
File metadata and controls
37 lines (28 loc) · 1.04 KB
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
package auth
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/yaitoo/sqle/shardid"
)
func TestSession(t *testing.T) {
au := createAuthTest("./tests_session.db")
s, err := au.Login(context.TODO(), "u@session.com", "abc123", LoginOption{CreateIfNotExists: true})
require.NoError(t, err)
uid := shardid.Parse(s.UserID)
err = au.checkRefreshToken(context.Background(), uid, s.RefreshToken)
require.NoError(t, err)
// refresh token should be refreshed
rs, err := au.RefreshSession(context.Background(), s.RefreshToken, ClientInfo{})
require.NoError(t, err)
err = au.checkRefreshToken(context.Background(), uid, rs.RefreshToken)
require.NoError(t, err)
// old token should be deleted
err = au.checkRefreshToken(context.Background(), uid, s.RefreshToken)
require.ErrorIs(t, err, ErrInvalidToken)
// sign out should delete all tokens
err = au.Logout(context.Background(), uid)
require.NoError(t, err)
err = au.checkRefreshToken(context.Background(), uid, rs.RefreshToken)
require.ErrorIs(t, err, ErrInvalidToken)
}