Skip to content

Commit

Permalink
Merge pull request #1135 from atsign-foundation/namespace_localkey_no…
Browse files Browse the repository at this point in the history
…t_mandatory

fix: make namespace for local keys NOT mandatory
  • Loading branch information
sitaram-kalluri authored Oct 26, 2023
2 parents 916a8a8 + dbc536d commit 5680849
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
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) &&
!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);
});
}

0 comments on commit 5680849

Please sign in to comment.