@@ -450,6 +450,14 @@ func TestFirewallDBMigration(t *testing.T) {
450450 name : "multiple sessions and privacy pairs" ,
451451 populateDB : multipleSessionsAndPrivacyPairs ,
452452 },
453+ {
454+ name : "deleted session with privacy pair" ,
455+ populateDB : deletedSessionWithPrivPair ,
456+ },
457+ {
458+ name : "deleted and existing sessions with privacy pairs" ,
459+ populateDB : deletedAndExistingSessionsWithPrivPairs ,
460+ },
453461 {
454462 name : "random privacy pairs" ,
455463 populateDB : randomPrivacyPairs ,
@@ -997,6 +1005,53 @@ func oneSessionAndPrivPair(t *testing.T, ctx context.Context,
9971005 return createPrivacyPairs (t , ctx , boltDB , sessionStore , 1 , 1 )
9981006}
9991007
1008+ // deletedSessionWithPrivPair inserts 1 session with a linked 1 privacy pair
1009+ // into the boltDB, and then deletes the session from the sessions store, to
1010+ // simulate the case where a session has been deleted, but the privacy pairs
1011+ // still exist. This can happen if the user deletes their session db but not
1012+ // their firewall db.
1013+ func deletedSessionWithPrivPair (t * testing.T , ctx context.Context ,
1014+ boltDB * BoltDB , sessionStore session.Store , _ accounts.Store ,
1015+ _ * rootKeyMockStore ) * expectedResult {
1016+
1017+ _ = createPrivacyPairs (t , ctx , boltDB , sessionStore , 1 , 1 )
1018+
1019+ // Now we delete the session that the privacy pair was linked to.
1020+ err := sessionStore .DeleteReservedSessions (ctx )
1021+ require .NoError (t , err )
1022+
1023+ return & expectedResult {
1024+ kvEntries : []* kvEntry {},
1025+ // Since the session the privacy pair was linked to has been
1026+ // deleted, we expect no privacy pairs to be migrated.
1027+ privPairs : make (privacyPairs ),
1028+ actions : []* Action {},
1029+ }
1030+ }
1031+
1032+ // deletedAndExistingSessionsWithPrivPairs generates 2 different privacy pairs,
1033+ // each linked to a different sessions. However, one of the sessions is deleted
1034+ // prior to the migration, to test that only one of the privacy pairs should be
1035+ // migrated, while the other one should be ignored since its session has been
1036+ // deleted.
1037+ func deletedAndExistingSessionsWithPrivPairs (t * testing.T , ctx context.Context ,
1038+ boltDB * BoltDB , sessionStore session.Store , _ accounts.Store ,
1039+ _ * rootKeyMockStore ) * expectedResult {
1040+
1041+ // First generate one privacy pair linked to a session that will be
1042+ // deleted.
1043+ _ = createPrivacyPairs (t , ctx , boltDB , sessionStore , 1 , 1 )
1044+
1045+ // Delete the linked session.
1046+ err := sessionStore .DeleteReservedSessions (ctx )
1047+ require .NoError (t , err )
1048+
1049+ // Now generate another privacy pair linked to a session that won't be
1050+ // deleted prior to the migration. Therefore, this privacy pair should
1051+ // be migrated.
1052+ return createPrivacyPairs (t , ctx , boltDB , sessionStore , 1 , 1 )
1053+ }
1054+
10001055// oneSessionsMultiplePrivPairs inserts 1 session with 10 privacy pairs into the
10011056// boltDB.
10021057func oneSessionsMultiplePrivPairs (t * testing.T , ctx context.Context ,
0 commit comments