@@ -458,6 +458,14 @@ func TestFirewallDBMigration(t *testing.T) {
458458 name : "multiple sessions and privacy pairs" ,
459459 populateDB : multipleSessionsAndPrivacyPairs ,
460460 },
461+ {
462+ name : "deleted session with privacy pair" ,
463+ populateDB : deletedSessionWithPrivPair ,
464+ },
465+ {
466+ name : "deleted and existing sessions with privacy pairs" ,
467+ populateDB : deletedAndExistingSessionsWithPrivPairs ,
468+ },
461469 {
462470 name : "random privacy pairs" ,
463471 populateDB : randomPrivacyPairs ,
@@ -1059,6 +1067,53 @@ func oneSessionAndPrivPair(t *testing.T, ctx context.Context,
10591067 return createPrivacyPairs (t , ctx , boltDB , sessionStore , 1 , 1 )
10601068}
10611069
1070+ // deletedSessionWithPrivPair inserts 1 session with a linked 1 privacy pair
1071+ // into the boltDB, and then deletes the session from the sessions store, to
1072+ // simulate the case where a session has been deleted, but the privacy pairs
1073+ // still exist. This can happen if the user deletes their session db but not
1074+ // their firewall db.
1075+ func deletedSessionWithPrivPair (t * testing.T , ctx context.Context ,
1076+ boltDB * BoltDB , sessionStore session.Store , _ accounts.Store ,
1077+ _ * rootKeyMockStore ) * expectedResult {
1078+
1079+ _ = createPrivacyPairs (t , ctx , boltDB , sessionStore , 1 , 1 )
1080+
1081+ // Now we delete the session that the privacy pair was linked to.
1082+ err := sessionStore .DeleteReservedSessions (ctx )
1083+ require .NoError (t , err )
1084+
1085+ return & expectedResult {
1086+ kvEntries : []* kvEntry {},
1087+ // Since the session the privacy pair was linked to has been
1088+ // deleted, we expect no privacy pairs to be migrated.
1089+ privPairs : make (privacyPairs ),
1090+ actions : []* Action {},
1091+ }
1092+ }
1093+
1094+ // deletedAndExistingSessionsWithPrivPairs generates 2 different privacy pairs,
1095+ // each linked to a different sessions. However, one of the sessions is deleted
1096+ // prior to the migration, to test that only one of the privacy pairs should be
1097+ // migrated, while the other one should be ignored since its session has been
1098+ // deleted.
1099+ func deletedAndExistingSessionsWithPrivPairs (t * testing.T , ctx context.Context ,
1100+ boltDB * BoltDB , sessionStore session.Store , _ accounts.Store ,
1101+ _ * rootKeyMockStore ) * expectedResult {
1102+
1103+ // First generate one privacy pair linked to a session that will be
1104+ // deleted.
1105+ _ = createPrivacyPairs (t , ctx , boltDB , sessionStore , 1 , 1 )
1106+
1107+ // Delete the linked session.
1108+ err := sessionStore .DeleteReservedSessions (ctx )
1109+ require .NoError (t , err )
1110+
1111+ // Now generate another privacy pair linked to a session that won't be
1112+ // deleted prior to the migration. Therefore, this privacy pair should
1113+ // be migrated.
1114+ return createPrivacyPairs (t , ctx , boltDB , sessionStore , 1 , 1 )
1115+ }
1116+
10621117// oneSessionsMultiplePrivPairs inserts 1 session with 10 privacy pairs into the
10631118// boltDB.
10641119func oneSessionsMultiplePrivPairs (t * testing.T , ctx context.Context ,
0 commit comments