-
Notifications
You must be signed in to change notification settings - Fork 0
/
csrf_store_test.go
executable file
·75 lines (58 loc) · 1.83 KB
/
csrf_store_test.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package campid
import (
"context"
"testing"
"time"
"github.com/influx6/npkg/nstorage/nmap"
"github.com/stretchr/testify/require"
)
func TestCSRFStore(t *testing.T) {
var sessionId = "1"
var ctx = context.Background()
var store = nmap.NewExprByteStore(100)
var csrfStore = NewCSRFStore(store, 1*time.Minute)
t.Run("Create", func(t *testing.T) {
store.Clear()
var token, err = csrfStore.GetOrCreate(ctx, sessionId)
require.NoError(t, err)
require.NotEmpty(t, token)
var retreivedToken, err2 = csrfStore.Get(ctx, sessionId)
require.NoError(t, err2)
require.NotEmpty(t, retreivedToken)
require.Equal(t, retreivedToken, token)
})
t.Run("GetOrCreateWithDur", func(t *testing.T) {
store.Clear()
var token, err = csrfStore.GetOrCreateWithDur(ctx, sessionId, time.Minute*2)
require.NoError(t, err)
require.NotEmpty(t, token)
var retreivedToken, err2 = csrfStore.Get(ctx, sessionId)
require.NoError(t, err2)
require.NotEmpty(t, retreivedToken)
require.Equal(t, retreivedToken, token)
})
t.Run("GetAll", func(t *testing.T) {
store.Clear()
var token, err = csrfStore.GetOrCreate(ctx, sessionId)
require.NoError(t, err)
require.NotEmpty(t, token)
var tokenList, err2 = csrfStore.GetAll(ctx)
require.NoError(t, err2)
require.NotEmpty(t, tokenList)
})
t.Run("Delete", func(t *testing.T) {
store.Clear()
var token, err = csrfStore.GetOrCreate(ctx, sessionId)
require.NoError(t, err)
require.NotEmpty(t, token)
var retreivedToken, err2 = csrfStore.Get(ctx, sessionId)
require.NoError(t, err2)
require.NotEmpty(t, retreivedToken)
require.Equal(t, retreivedToken, token)
var deletedToken, deleteErr = csrfStore.Delete(ctx, sessionId)
require.NoError(t, deleteErr)
require.Equal(t, retreivedToken, deletedToken)
var _, getErr = csrfStore.Get(ctx, sessionId)
require.Error(t, getErr)
})
}