-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession_test.go
More file actions
49 lines (42 loc) · 1.1 KB
/
session_test.go
File metadata and controls
49 lines (42 loc) · 1.1 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
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"net/http"
"testing"
"time"
)
var testCookie = "testCookie"
var testKeySession = "testKey"
var testAddress = "testAddress"
var testMaxAge = 10
func addSessionTest(t *testing.T) {
cookie := &http.Cookie{
Name: testCookie,
Value: testKeySession,
MaxAge: testMaxAge, // seconds
}
data := loginData{
Address: testAddress,
}
addSession(*cookie, data, testMaxAge)
login := getSession(testKeySession)
if login == nil {
t.Errorf("TEST 7: session FAILED; getSession returned nil.\n")
} else if login.Address != testAddress {
t.Errorf("TEST 7: encrypting FAILED; getSession returned wrong value\n")
}
}
func TestSessions(t *testing.T) {
newSessions()
addSessionTest(t)
resetSession(testKeySession)
login := getSession(testKeySession)
if login != nil {
t.Errorf("TEST 7: session FAILED; getSession should return nil after resetSession.\n")
}
addSessionTest(t)
time.Sleep(time.Duration(testMaxAge) * time.Second)
login = getSession(testKeySession)
if login != nil {
t.Errorf("TEST 7: session FAILED; getSession should return nil after max expiration time.\n")
}
}