@@ -418,10 +418,18 @@ func TestFirewallDBMigration(t *testing.T) {
418418 name : "session specific kv entries" ,
419419 populateDB : sessionSpecificEntries ,
420420 },
421+ {
422+ name : "session specific kv entries deleted session" ,
423+ populateDB : sessionSpecificEntriesDeletedSession ,
424+ },
421425 {
422426 name : "feature specific kv entries" ,
423427 populateDB : featureSpecificEntries ,
424428 },
429+ {
430+ name : "feature specific kv entries deleted session" ,
431+ populateDB : featureSpecificEntriesDeletedSession ,
432+ },
425433 {
426434 name : "all kv entry combinations" ,
427435 populateDB : allEntryCombinations ,
@@ -585,6 +593,34 @@ func sessionSpecificEntries(t *testing.T, ctx context.Context, boltDB *BoltDB,
585593 )
586594}
587595
596+ // sessionSpecificEntriesDeletedSession populates the kv store with one session
597+ // specific entry for the local temp store, and one session specific entry for
598+ // the perm local store. Once populated, the session that the entries are linked
599+ // to is deleted. When migrating, we therefore expect that the kv entries linked
600+ // to the deleted session are not migrated.
601+ func sessionSpecificEntriesDeletedSession (t * testing.T , ctx context.Context ,
602+ boltDB * BoltDB , sessionStore session.Store , _ accounts.Store ,
603+ _ * rootKeyMockStore ) * expectedResult {
604+
605+ groupAlias := getNewSessionAlias (t , ctx , sessionStore )
606+
607+ _ = insertTempAndPermEntry (
608+ t , ctx , boltDB , testRuleName , groupAlias , fn .None [string ](),
609+ testEntryKey , testEntryValue ,
610+ )
611+
612+ err := sessionStore .DeleteReservedSessions (ctx )
613+ require .NoError (t , err )
614+
615+ return & expectedResult {
616+ // Since the session the kx entries were linked to has been
617+ // deleted, we expect no kv entries to be migrated.
618+ kvEntries : []* kvEntry {},
619+ privPairs : make (privacyPairs ),
620+ actions : []* Action {},
621+ }
622+ }
623+
588624// featureSpecificEntries populates the kv store with one feature specific
589625// entry for the local temp store, and one feature specific entry for the perm
590626// local store.
@@ -600,6 +636,34 @@ func featureSpecificEntries(t *testing.T, ctx context.Context, boltDB *BoltDB,
600636 )
601637}
602638
639+ // featureSpecificEntriesDeletedSession populates the kv store with one feature
640+ // specific entry for the local temp store, and one feature specific entry for
641+ // the perm local store. Once populated, the session that the entries are linked
642+ // to is deleted. When migrating, we therefore expect that the kv entries linked
643+ // to the deleted session are not migrated.
644+ func featureSpecificEntriesDeletedSession (t * testing.T , ctx context.Context ,
645+ boltDB * BoltDB , sessionStore session.Store , _ accounts.Store ,
646+ _ * rootKeyMockStore ) * expectedResult {
647+
648+ groupAlias := getNewSessionAlias (t , ctx , sessionStore )
649+
650+ _ = insertTempAndPermEntry (
651+ t , ctx , boltDB , testRuleName , groupAlias ,
652+ fn .Some (testFeatureName ), testEntryKey , testEntryValue ,
653+ )
654+
655+ err := sessionStore .DeleteReservedSessions (ctx )
656+ require .NoError (t , err )
657+
658+ return & expectedResult {
659+ // Since the session the kv entries were linked to has been
660+ // deleted, we expect no kv entries to be migrated.
661+ kvEntries : []* kvEntry {},
662+ privPairs : make (privacyPairs ),
663+ actions : []* Action {},
664+ }
665+ }
666+
603667// allEntryCombinations adds all types of different entries at all possible
604668// levels of the kvstores, including multple entries with the same
605669// ruleName, groupAlias and featureName. The test aims to cover all possible
0 commit comments