Skip to content
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: make namespace for local keys NOT mandatory #1135

Merged
merged 9 commits into from
Oct 26, 2023
1 change: 1 addition & 0 deletions packages/at_client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## 3.0.66
- feat: make namespace NOT mandatory for local keys
- feat: deprecate useAtChops experimental flag and remove fallback code using private key from preferences/EncryptionUtil methods
- updated at_commons to `'3.0.57'`, at_chops to `'1.0.5`, at_persistence_secondary_server to `'3.0.59'`
## 3.0.65
Expand Down
1 change: 1 addition & 0 deletions packages/at_client/lib/src/util/at_client_validation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class AtClientValidation {
}
// If namespace is not set on key and in preferences, throw exception
if ((atKey.namespace == null || atKey.namespace!.isEmpty) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this condition to
if (((atKey.namespace == null || atKey.namespace!.isEmpty &&) !atKey.isLocal) &&
(atClientPreference.namespace == null ||
atClientPreference.namespace!.isEmpty)
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change made as part of 27600db

!atKey.isLocal &&
(atClientPreference.namespace == null ||
atClientPreference.namespace!.isEmpty)) {
throw AtKeyException('namespace is mandatory');
Expand Down
45 changes: 45 additions & 0 deletions packages/at_client/test/at_key_validation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,49 @@ void main() {
.setCurrentAtSign(atSign, namespace, preference),
throwsA(predicate((dynamic e) => e is InvalidAtSignException)));
});

test('Verify namespace is mandatory for public key', () {
AtKey atKey = AtKey.public('key_no_namespace', sharedBy: '@noname').build();
AtClientPreference preference = AtClientPreference()..namespace = null;

expect(
() => AtClientValidation.validatePutRequest(
atKey, 'dummyvalue', preference),
throwsA(predicate((dynamic e) =>
e is AtKeyException && e.message == 'namespace is mandatory')));
});

test('Verify namespace is mandatory for private key', () {
AtKey atKey = AtKey.private('key_no_namespace1').build()
..sharedBy = '@noname1';
AtClientPreference preference = AtClientPreference()..namespace = null;

expect(
() => AtClientValidation.validatePutRequest(
atKey, 'dummyvalue', preference),
throwsA(predicate((dynamic e) =>
e is AtKeyException && e.message == 'namespace is mandatory')));
});

test('Verify namespace is mandatory for shared key', () {
AtKey atKey =
(AtKey.shared('key_no_namespace2', namespace: null, sharedBy: '@sharer')
..sharedWith('@sharee'))
.build();
AtClientPreference preference = AtClientPreference()..namespace = null;

expect(
() => AtClientValidation.validatePutRequest(
atKey, 'dummyvalue', preference),
throwsA(predicate((dynamic e) =>
e is AtKeyException && e.message == 'namespace is mandatory')));
});

test('Verify namespace is NOT mandatory for local key', () {
AtKey atKey = AtKey.local('key_no_namespace3', '@sharer').build();
AtClientPreference preference = AtClientPreference()..namespace = null;
// validatePutRequest() has a return type of void
// error-less execution of this method should be considered as test passing
AtClientValidation.validatePutRequest(atKey, 'dummyvalue', preference);
});
}