Skip to content

Commit 6f33893

Browse files
committed
firewalldb: fetch correct bucket for session level temp KV store
In this commit, we fix a bug which would result in the "perm" store being used for the LocalTemp KV DB _if and only if_ the KV store being requested was a session level one (as opposed to a session feature level one). It is ok for us to just change this here since as of this commit, the session level KV store is not used at all and so nothing will be in that store yet.
1 parent ba81aaf commit 6f33893

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

firewalldb/kvstores.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func (tx *kvStoreTx) GlobalTemp() KVStore {
268268
//
269269
// NOTE: this is part of the KVStoreTx interface.
270270
func (tx *kvStoreTx) LocalTemp() KVStore {
271-
fn := getSessionRuleBucket(true, tx.ruleName, tx.groupID)
271+
fn := getSessionRuleBucket(false, tx.ruleName, tx.groupID)
272272
if tx.featureName != "" {
273273
fn = getSessionFeatureRuleBucket(
274274
false, tx.ruleName, tx.groupID, tx.featureName,

firewalldb/kvstores_test.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,39 @@ func TestKVStoreTxs(t *testing.T) {
6060

6161
// TestTempAndPermStores tests that the kv stores stored under the `temp` bucket
6262
// are properly deleted and re-initialised upon restart but that anything under
63-
// the `perm` bucket is retained.
63+
// the `perm` bucket is retained. We repeat the test for both the session level
64+
// KV stores and the session feature level stores.
6465
func TestTempAndPermStores(t *testing.T) {
66+
t.Run("session level kv store", func(t *testing.T) {
67+
testTempAndPermStores(t, false)
68+
})
69+
70+
t.Run("session feature level kv store", func(t *testing.T) {
71+
testTempAndPermStores(t, true)
72+
})
73+
}
74+
75+
// testTempAndPermStores tests that the kv stores stored under the `temp` bucket
76+
// are properly deleted and re-initialised upon restart but that anything under
77+
// the `perm` bucket is retained. If featureSpecificStore is true, then this
78+
// will test the session feature level KV stores. Otherwise, it will test the
79+
// session level KV stores.
80+
func testTempAndPermStores(t *testing.T, featureSpecificStore bool) {
6581
ctx := context.Background()
6682
tmpDir := t.TempDir()
6783

84+
var featureName string
85+
if featureSpecificStore {
86+
featureName = "auto-fees"
87+
}
88+
6889
db, err := NewDB(tmpDir, "test.db", nil)
6990
require.NoError(t, err)
7091
t.Cleanup(func() {
7192
_ = db.Close()
7293
})
7394

74-
store := db.GetKVStores("test-rule", [4]byte{1, 1, 1, 1}, "auto-fees")
95+
store := db.GetKVStores("test-rule", [4]byte{1, 1, 1, 1}, featureName)
7596

7697
err = store.Update(func(tx KVStoreTx) error {
7798
// Set an item in the temp store.
@@ -119,7 +140,7 @@ func TestTempAndPermStores(t *testing.T) {
119140
_ = db.Close()
120141
_ = os.RemoveAll(tmpDir)
121142
})
122-
store = db.GetKVStores("test-rule", [4]byte{1, 1, 1, 1}, "auto-fees")
143+
store = db.GetKVStores("test-rule", [4]byte{1, 1, 1, 1}, featureName)
123144

124145
// The temp store should no longer have the stored value but the perm
125146
// store should .

0 commit comments

Comments
 (0)