@@ -76,6 +76,11 @@ func TestSessionsStoreMigration(t *testing.T) {
76
76
// kvSession has such a recipe stored.
77
77
overrideMacaroonRecipe (kvSession , sqlSession )
78
78
79
+ // We also need to override the account ID if the
80
+ // kvSession has an account ID set, while the SQL
81
+ // session doesn't.
82
+ overrideRemovedAccount (kvSession , sqlSession )
83
+
79
84
assertEqualSessions (t , kvSession , sqlSession )
80
85
}
81
86
@@ -314,6 +319,51 @@ func TestSessionsStoreMigration(t *testing.T) {
314
319
return getBoltStoreSessions (t , store )
315
320
},
316
321
},
322
+ {
323
+ name : "one session with a deleted linked account" ,
324
+ populateDB : func (t * testing.T , store * BoltStore ,
325
+ acctStore accounts.Store ) []* Session {
326
+
327
+ // Create an account with balance
328
+ acct , err := acctStore .NewAccount (
329
+ ctx , 1234 , time .Now ().Add (time .Hour ),
330
+ "" ,
331
+ )
332
+ require .NoError (t , err )
333
+ require .False (t , acct .HasExpired ())
334
+
335
+ // For now, we manually add the account caveat
336
+ // for bbolt compatibility.
337
+ accountCaveat := checkers .Condition (
338
+ macaroons .CondLndCustom ,
339
+ fmt .Sprintf ("%s %x" ,
340
+ accounts .CondAccount ,
341
+ acct .ID [:],
342
+ ),
343
+ )
344
+
345
+ sessCaveats := []macaroon.Caveat {
346
+ {
347
+ Id : []byte (accountCaveat ),
348
+ },
349
+ }
350
+
351
+ _ , err = store .NewSession (
352
+ ctx , "test" , TypeMacaroonAccount ,
353
+ time .Unix (1000 , 0 ), "" ,
354
+ WithAccount (acct .ID ),
355
+ WithMacaroonRecipe (sessCaveats , nil ),
356
+ )
357
+ require .NoError (t , err )
358
+
359
+ // Now delete the account, which represents
360
+ // that the user ran "litcli accounts remove".
361
+ err = acctStore .RemoveAccount (ctx , acct .ID )
362
+ require .NoError (t , err )
363
+
364
+ return getBoltStoreSessions (t , store )
365
+ },
366
+ },
317
367
{
318
368
name : "linked session" ,
319
369
populateDB : func (t * testing.T , store * BoltStore ,
@@ -664,6 +714,16 @@ func randomizedSessions(t *testing.T, kvStore *BoltStore,
664
714
}
665
715
}
666
716
717
+ // When an account is set, we also remove the account in 50% of
718
+ // the cases. This simulates that the user ran "litcli accounts
719
+ // remove" after creating the session.
720
+ activeSess .AccountID .WhenSome (func (id accounts.AccountID ) {
721
+ if rand .Intn (2 ) == 0 {
722
+ err = accountsStore .RemoveAccount (ctx , id )
723
+ }
724
+ })
725
+ require .NoError (t , err )
726
+
667
727
// Finally, we shift the active session to a random state.
668
728
// As the state we set may be a state that's no longer set
669
729
// through the current code base, or be an illegal state
0 commit comments