-
Notifications
You must be signed in to change notification settings - Fork 12
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
fix: Commit log special key bug #2115
Conversation
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.
Thanks @murali-shris
- Noticed another bug while I was reviewing that we should also fix via this PR
- All of this code could really do with some explanation of what's going on and why - especially what is the purpose of
_acceptKey
?
@@ -220,7 +220,7 @@ class CommitLogKeyStore extends BaseCommitLogKeyStore { | |||
|
|||
bool _isSpecialKey(String atKey) { | |||
return atKey.contains(AtConstants.atEncryptionSharedKey) || |
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.
this contains AtConstants.atEncryptionSharedKey
check is also a bug. Why are we treating keys that contain "shared_key" as special?
And if we are treating them as special for good reason, we should specifically only match shared_key\..*@this_atservers_at_sign
or @some_other_atsign:shared_key@this_servers_at_sign
(precise regexes are in at_commons in Regexes._reservedKeysWithAtsignSuffix
) ... currently this code would also match keys like
"@bob:key1.shared_keys.buzz@alice"
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.
@murali-shris I don't see a good explanation for why we are not treating the two reserved shared_key variants as 'special' which (as I understand it) would result in those keys not being synced?
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.
Oh - ignore that last comment. I understand it now. This ensures that those keys are synced, regardless of whether they match the enrollment namespace or not.
These are my findings on _acceptKey.
|
…n-foundation/at_server into commit_log_special_key_bug
…n-foundation/at_server into commit_log_special_key_bug
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.
@murali-shris thanks for adding comments explaining the purpose of this code which is to ensure that we are syncing none of the stuff that should not be synced (i.e. anything in namespaces the client does not have access to) and all of the stuff that should be synced (i.e. anything in namespaces the client does have access to, plus other things that all clients should have access to)
As I understand it now, therefore, shouldn't we also, in _isSpecialKey, match everything which (a) is public (b) has no namespace? This would explain why the code had a startsWith 'public:' match, although that was incorrect since it should be 'starts with public:' and 'does not contain a period'
Scenario 2) and 4) are the ones you meant. correct ?
There are currently no tests to check whether public: keys without namespace are returned. I will add them |
@murali-shris yes that's correct. Please can you also come up with better names for these functions - i.e. names which are more reflective of their purpose? Future maintainers will thank you! |
I have renamed the methods. Please review whether the methods names are self explanatory. |
@@ -217,16 +218,17 @@ class CommitLogKeyStore extends BaseCommitLogKeyStore { | |||
return false; | |||
} | |||
|
|||
bool _isRegexMatches(String atKey, String regex) { | |||
bool _doesKeyMatchRegex(String atKey, String regex) { |
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.
I'd suggest _keyMatchesRegex
bool _isSpecialKey(String atKey) { | ||
/// match only reserved keys and public keys without namespace which have to be synced from server to client, if regex doesn't match | ||
/// e.g @bob:shared_key@alice, shared_key.bob@alice, public:publickey@alice, public:phone@alice | ||
bool _shouldKeyBeIncludedInSyncIfNoRegexMatch(String atKey) { |
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.
I'd suggest _alwaysIncludeInSync
expect(commitEntriesMap.containsKey('@bob:shared_key@alice'), true); | ||
expect(commitEntriesMap.containsKey('shared_key.bob@alice'), true); | ||
expect( | ||
commitEntriesMap.containsKey('bob:test_shared_key@alice'), false); |
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.
👍
This reads so much better, thank you. I've suggested two changes |
…n-foundation/at_server into commit_log_special_key_bug
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. Thank you @murali-shris
Fixes #2114
- What I did
- How I did it
@bob:shared_key@alice
,shared_key.bob@alice
) in _specialKey- How to verify it
fix: test persistence at_client_sdk#1414
Dependent at_commons PR:
atsign-foundation/at_libraries#694