@@ -418,10 +418,26 @@ 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+ },
425+ {
426+ name : "session specific kv entries deleted and existing sessions" ,
427+ populateDB : sessionSpecificEntriesDeletedAndExistingSessions ,
428+ },
421429 {
422430 name : "feature specific kv entries" ,
423431 populateDB : featureSpecificEntries ,
424432 },
433+ {
434+ name : "feature specific kv entries deleted session" ,
435+ populateDB : featureSpecificEntriesDeletedSession ,
436+ },
437+ {
438+ name : "feature specific kv entries deleted and existing sessions" ,
439+ populateDB : featureSpecificEntriesDeletedAndExistingSessions ,
440+ },
425441 {
426442 name : "all kv entry combinations" ,
427443 populateDB : allEntryCombinations ,
@@ -585,6 +601,61 @@ func sessionSpecificEntries(t *testing.T, ctx context.Context, boltDB *BoltDB,
585601 )
586602}
587603
604+ // sessionSpecificEntriesDeletedSession populates the kv store with one session
605+ // specific entry for the local temp store, and one session specific entry for
606+ // the perm local store. Once populated, the session that the entries are linked
607+ // to is deleted. When migrating, we therefore expect that the kv entries linked
608+ // to the deleted session are not migrated.
609+ func sessionSpecificEntriesDeletedSession (t * testing.T , ctx context.Context ,
610+ boltDB * BoltDB , sessionStore session.Store , _ accounts.Store ,
611+ _ * rootKeyMockStore ) * expectedResult {
612+
613+ groupAlias := getNewSessionAlias (t , ctx , sessionStore )
614+
615+ _ = insertTempAndPermEntry (
616+ t , ctx , boltDB , testRuleName , groupAlias , fn .None [string ](),
617+ testEntryKey , testEntryValue ,
618+ )
619+
620+ err := sessionStore .DeleteReservedSessions (ctx )
621+ require .NoError (t , err )
622+
623+ return & expectedResult {
624+ // Since the session the kx entries were linked to has been
625+ // deleted, we expect no kv entries to be migrated.
626+ kvEntries : []* kvEntry {},
627+ privPairs : make (privacyPairs ),
628+ actions : []* Action {},
629+ }
630+ }
631+
632+ // sessionSpecificEntriesDeletedAndExistingSessions populates the kv store with
633+ // two sessions and their corresponding kv entries.
634+ // One of the sessions is deleted prior to the migration though, and therefore
635+ // the migration should only migrate the kv entries linked to the still existing
636+ // session.
637+ func sessionSpecificEntriesDeletedAndExistingSessions (t * testing.T ,
638+ ctx context.Context , boltDB * BoltDB , sessionStore session.Store ,
639+ _ accounts.Store , _ * rootKeyMockStore ) * expectedResult {
640+
641+ groupAlias1 := getNewSessionAlias (t , ctx , sessionStore )
642+
643+ _ = insertTempAndPermEntry (
644+ t , ctx , boltDB , testRuleName , groupAlias1 , fn .None [string ](),
645+ testEntryKey , testEntryValue ,
646+ )
647+
648+ err := sessionStore .DeleteReservedSessions (ctx )
649+ require .NoError (t , err )
650+
651+ groupAlias2 := getNewSessionAlias (t , ctx , sessionStore )
652+
653+ return insertTempAndPermEntry (
654+ t , ctx , boltDB , testRuleName2 , groupAlias2 , fn .None [string ](),
655+ testEntryKey2 , testEntryValue ,
656+ )
657+ }
658+
588659// featureSpecificEntries populates the kv store with one feature specific
589660// entry for the local temp store, and one feature specific entry for the perm
590661// local store.
@@ -600,6 +671,61 @@ func featureSpecificEntries(t *testing.T, ctx context.Context, boltDB *BoltDB,
600671 )
601672}
602673
674+ // featureSpecificEntriesDeletedSession populates the kv store with one feature
675+ // specific entry for the local temp store, and one feature specific entry for
676+ // the perm local store. Once populated, the session that the entries are linked
677+ // to is deleted. When migrating, we therefore expect that the kv entries linked
678+ // to the deleted session are not migrated.
679+ func featureSpecificEntriesDeletedSession (t * testing.T , ctx context.Context ,
680+ boltDB * BoltDB , sessionStore session.Store , _ accounts.Store ,
681+ _ * rootKeyMockStore ) * expectedResult {
682+
683+ groupAlias := getNewSessionAlias (t , ctx , sessionStore )
684+
685+ _ = insertTempAndPermEntry (
686+ t , ctx , boltDB , testRuleName , groupAlias ,
687+ fn .Some (testFeatureName ), testEntryKey , testEntryValue ,
688+ )
689+
690+ err := sessionStore .DeleteReservedSessions (ctx )
691+ require .NoError (t , err )
692+
693+ return & expectedResult {
694+ // Since the session the kv entries were linked to has been
695+ // deleted, we expect no kv entries to be migrated.
696+ kvEntries : []* kvEntry {},
697+ privPairs : make (privacyPairs ),
698+ actions : []* Action {},
699+ }
700+ }
701+
702+ // featureSpecificEntriesDeletedAndExistingSessions populates the kv store with
703+ // two sessions and their corresponding feature specific kv entries.
704+ // One of the sessions is deleted prior to the migration though, and therefore
705+ // the migration should only migrate the kv entries linked to the still existing
706+ // session.
707+ func featureSpecificEntriesDeletedAndExistingSessions (t * testing.T ,
708+ ctx context.Context , boltDB * BoltDB , sessionStore session.Store ,
709+ _ accounts.Store , _ * rootKeyMockStore ) * expectedResult {
710+
711+ groupAlias1 := getNewSessionAlias (t , ctx , sessionStore )
712+
713+ _ = insertTempAndPermEntry (
714+ t , ctx , boltDB , testRuleName , groupAlias1 ,
715+ fn .Some (testFeatureName ), testEntryKey , testEntryValue ,
716+ )
717+
718+ err := sessionStore .DeleteReservedSessions (ctx )
719+ require .NoError (t , err )
720+
721+ groupAlias2 := getNewSessionAlias (t , ctx , sessionStore )
722+
723+ return insertTempAndPermEntry (
724+ t , ctx , boltDB , testRuleName2 , groupAlias2 ,
725+ fn .Some (testFeatureName2 ), testEntryKey2 , testEntryValue ,
726+ )
727+ }
728+
603729// allEntryCombinations adds all types of different entries at all possible
604730// levels of the kvstores, including multple entries with the same
605731// ruleName, groupAlias and featureName. The test aims to cover all possible
0 commit comments