-
Notifications
You must be signed in to change notification settings - Fork 103
[sql-28] firewall+sessions: clean up in preparation for SQL backend #1029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
GetGroupID is given a session ID as a param and so should return ErrSessionNotFound if that session is not found. GetSessionIDs is given a groupID as a param and so should return ErrUnknownGroup if that group does not exist. This commit updates the kvstore and sql implementations to return the correct error values and also ensures that this is properly tested now.
In preparation for it clashing with a transaction tx variable in an upcoming commit.
Convert some helpers to be methods on `kvStoreTx` in preparation for some of these helpers needing access to other variables within `kvStoreTx`.
If the is writing to a kvstore that is namespaced by a session's ID, we first assert that the session exists in the session store. We add a test for this accordingly. We do this in preparation for adding a sql backend which will error out if we try to link a kvstore to a session that does not yet exist.
|
||
// Get a kvstore namespaced by a session ID for a session that does | ||
// not exist. | ||
store := db.GetKVStores("AutoFees", [4]byte{1, 1, 1, 1}, "auto-fees") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it make sense to already error here in case the session is not found, or does this prevent some functionality?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just cause of how this works under the hood on db types, it makes more sense to have this check at DB access time. THis call doesnt currently make a DB call. Also i think we want Get/Delete to not necessarily error out if the session does not exist yet - those should just return nil, nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Niiiice uTACK LGTM 🔥!
@@ -376,6 +392,81 @@ func TestKVStoreNameSpaces(t *testing.T) { | |||
require.True(t, bytes.Equal(v, []byte("thing 3"))) | |||
} | |||
|
|||
// TestKVStoreSessionCoupling tests if we attempt to write to a kvstore that | |||
// is namespaced by a session that does not exist, then we should get an error. | |||
func TestKVStoreSessionCoupling(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ⚡
In this PR, we do the last bit of clean up of the bbolt kvstores impl along with the tests of the kvstores.
The main thing this PR does is to assert strong coupling between kvstores and the session it is referencing. We do this in the bbolt implementation so that our unit tests can assert the correct errors. After this, we should be able to just plug in the SQL impl without making any further changes to the kvstore unit tests.
See commit messages for more details.
Part of #917