@@ -16,17 +16,18 @@ var testTime = time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
16
16
// store.
17
17
func TestBasicSessionStore (t * testing.T ) {
18
18
// Set up a new DB.
19
- db , err := NewDB (t .TempDir (), "test.db" , clock .NewTestClock (testTime ))
19
+ clock := clock .NewTestClock (testTime )
20
+ db , err := NewDB (t .TempDir (), "test.db" , clock )
20
21
require .NoError (t , err )
21
22
t .Cleanup (func () {
22
23
_ = db .Close ()
23
24
})
24
25
25
26
// Create a few sessions.
26
- s1 := newSession (t , db , "session 1" , nil )
27
- s2 := newSession (t , db , "session 2" , nil )
28
- s3 := newSession (t , db , "session 3" , nil )
29
- s4 := newSession (t , db , "session 4" , nil )
27
+ s1 := newSession (t , db , clock , "session 1" , nil )
28
+ s2 := newSession (t , db , clock , "session 2" , nil )
29
+ s3 := newSession (t , db , clock , "session 3" , nil )
30
+ s4 := newSession (t , db , clock , "session 4" , nil )
30
31
31
32
// Persist session 1. This should now succeed.
32
33
require .NoError (t , db .CreateSession (s1 ))
@@ -92,17 +93,18 @@ func TestBasicSessionStore(t *testing.T) {
92
93
// TestLinkingSessions tests that session linking works as expected.
93
94
func TestLinkingSessions (t * testing.T ) {
94
95
// Set up a new DB.
95
- db , err := NewDB (t .TempDir (), "test.db" , clock .NewTestClock (testTime ))
96
+ clock := clock .NewTestClock (testTime )
97
+ db , err := NewDB (t .TempDir (), "test.db" , clock )
96
98
require .NoError (t , err )
97
99
t .Cleanup (func () {
98
100
_ = db .Close ()
99
101
})
100
102
101
103
// Create a new session with no previous link.
102
- s1 := newSession (t , db , "session 1" , nil )
104
+ s1 := newSession (t , db , clock , "session 1" , nil )
103
105
104
106
// Create another session and link it to the first.
105
- s2 := newSession (t , db , "session 2" , & s1 .GroupID )
107
+ s2 := newSession (t , db , clock , "session 2" , & s1 .GroupID )
106
108
107
109
// Try to persist the second session and assert that it fails due to the
108
110
// linked session not existing in the DB yet.
@@ -128,7 +130,8 @@ func TestLinkingSessions(t *testing.T) {
128
130
// of the GetGroupID and GetSessionIDs methods.
129
131
func TestLinkedSessions (t * testing.T ) {
130
132
// Set up a new DB.
131
- db , err := NewDB (t .TempDir (), "test.db" , clock .NewTestClock (testTime ))
133
+ clock := clock .NewTestClock (testTime )
134
+ db , err := NewDB (t .TempDir (), "test.db" , clock )
132
135
require .NoError (t , err )
133
136
t .Cleanup (func () {
134
137
_ = db .Close ()
@@ -138,9 +141,9 @@ func TestLinkedSessions(t *testing.T) {
138
141
// after are all linked to the prior one. All these sessions belong to
139
142
// the same group. The group ID is equivalent to the session ID of the
140
143
// first session.
141
- s1 := newSession (t , db , "session 1" , nil )
142
- s2 := newSession (t , db , "session 2" , & s1 .GroupID )
143
- s3 := newSession (t , db , "session 3" , & s2 .GroupID )
144
+ s1 := newSession (t , db , clock , "session 1" , nil )
145
+ s2 := newSession (t , db , clock , "session 2" , & s1 .GroupID )
146
+ s3 := newSession (t , db , clock , "session 3" , & s2 .GroupID )
144
147
145
148
// Persist the sessions.
146
149
require .NoError (t , db .CreateSession (s1 ))
@@ -166,8 +169,8 @@ func TestLinkedSessions(t *testing.T) {
166
169
167
170
// To ensure that different groups don't interfere with each other,
168
171
// let's add another set of linked sessions not linked to the first.
169
- s4 := newSession (t , db , "session 4" , nil )
170
- s5 := newSession (t , db , "session 5" , & s4 .GroupID )
172
+ s4 := newSession (t , db , clock , "session 4" , nil )
173
+ s5 := newSession (t , db , clock , "session 5" , & s4 .GroupID )
171
174
172
175
require .NotEqual (t , s4 .GroupID , s1 .GroupID )
173
176
@@ -195,7 +198,8 @@ func TestLinkedSessions(t *testing.T) {
195
198
// method correctly checks if each session in a group passes a predicate.
196
199
func TestCheckSessionGroupPredicate (t * testing.T ) {
197
200
// Set up a new DB.
198
- db , err := NewDB (t .TempDir (), "test.db" , clock .NewTestClock (testTime ))
201
+ clock := clock .NewTestClock (testTime )
202
+ db , err := NewDB (t .TempDir (), "test.db" , clock )
199
203
require .NoError (t , err )
200
204
t .Cleanup (func () {
201
205
_ = db .Close ()
@@ -205,7 +209,7 @@ func TestCheckSessionGroupPredicate(t *testing.T) {
205
209
// function is checked correctly.
206
210
207
211
// Add a new session to the DB.
208
- s1 := newSession (t , db , "label 1" , nil )
212
+ s1 := newSession (t , db , clock , "label 1" , nil )
209
213
require .NoError (t , db .CreateSession (s1 ))
210
214
211
215
// Check that the group passes against an appropriate predicate.
@@ -230,7 +234,7 @@ func TestCheckSessionGroupPredicate(t *testing.T) {
230
234
require .NoError (t , db .RevokeSession (s1 .LocalPublicKey ))
231
235
232
236
// Add a new session to the same group as the first one.
233
- s2 := newSession (t , db , "label 2" , & s1 .GroupID )
237
+ s2 := newSession (t , db , clock , "label 2" , & s1 .GroupID )
234
238
require .NoError (t , db .CreateSession (s2 ))
235
239
236
240
// Check that the group passes against an appropriate predicate.
@@ -252,7 +256,7 @@ func TestCheckSessionGroupPredicate(t *testing.T) {
252
256
require .False (t , ok )
253
257
254
258
// Add a new session that is not linked to the first one.
255
- s3 := newSession (t , db , "completely different" , nil )
259
+ s3 := newSession (t , db , clock , "completely different" , nil )
256
260
require .NoError (t , db .CreateSession (s3 ))
257
261
258
262
// Ensure that the first group is unaffected.
@@ -282,15 +286,15 @@ func TestCheckSessionGroupPredicate(t *testing.T) {
282
286
require .True (t , ok )
283
287
}
284
288
285
- func newSession (t * testing.T , db Store , label string ,
289
+ func newSession (t * testing.T , db Store , clock clock. Clock , label string ,
286
290
linkedGroupID * ID ) * Session {
287
291
288
292
id , priv , err := db .GetUnusedIDAndKeyPair ()
289
293
require .NoError (t , err )
290
294
291
295
session , err := buildSession (
292
296
id , priv , label , TypeMacaroonAdmin ,
293
- time .Now (),
297
+ clock .Now (),
294
298
time .Date (99999 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
295
299
"foo.bar.baz:1234" , true , nil , nil , nil , true , linkedGroupID ,
296
300
[]PrivacyFlag {ClearPubkeys },
0 commit comments