From 86196daf439d8acc30cd7087523bdf25efcc3d40 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Wed, 11 Oct 2023 19:31:24 +0530 Subject: [PATCH 1/6] fix: namespace not mandatory for local keys --- packages/at_client/lib/src/util/at_client_validation.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/at_client/lib/src/util/at_client_validation.dart b/packages/at_client/lib/src/util/at_client_validation.dart index 1183b426b..52d5cbb20 100644 --- a/packages/at_client/lib/src/util/at_client_validation.dart +++ b/packages/at_client/lib/src/util/at_client_validation.dart @@ -104,7 +104,7 @@ class AtClientValidation { // If namespace is not set on key and in preferences, throw exception if ((atKey.namespace == null || atKey.namespace!.isEmpty) && (atClientPreference.namespace == null || - atClientPreference.namespace!.isEmpty)) { + atClientPreference.namespace!.isEmpty) && !atKey.isLocal) { throw AtKeyException('namespace is mandatory'); } // validate metadata From 37e6c5359897d09747a32e0b259f205d0fac064e Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Wed, 11 Oct 2023 19:31:41 +0530 Subject: [PATCH 2/6] test: unit tests for 'namespace not mandatory for local keys' --- .../test/at_key_validation_test.dart | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/packages/at_client/test/at_key_validation_test.dart b/packages/at_client/test/at_key_validation_test.dart index 6cf4eb0f6..b60af8f74 100644 --- a/packages/at_client/test/at_key_validation_test.dart +++ b/packages/at_client/test/at_key_validation_test.dart @@ -37,4 +37,47 @@ 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: 'namespace', 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); + }); } From 82b280065830d2ee17352465fad2b7ca52caadbf Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Thu, 12 Oct 2023 11:00:23 +0530 Subject: [PATCH 3/6] test: fix failing unit test --- packages/at_client/test/at_key_validation_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/at_client/test/at_key_validation_test.dart b/packages/at_client/test/at_key_validation_test.dart index b60af8f74..e6f8b7542 100644 --- a/packages/at_client/test/at_key_validation_test.dart +++ b/packages/at_client/test/at_key_validation_test.dart @@ -62,7 +62,7 @@ void main() { }); test('Verify namespace is mandatory for shared key', () { - AtKey atKey = (AtKey.shared('key_no_namespace2', namespace: 'namespace', sharedBy: '@sharer') + AtKey atKey = (AtKey.shared('key_no_namespace2', namespace: null, sharedBy: '@sharer') ..sharedWith('@sharee')).build(); AtClientPreference preference = AtClientPreference()..namespace = null; From 254c076b881ec43affaa1a1b5d7956894d21d7c3 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Thu, 12 Oct 2023 11:08:32 +0530 Subject: [PATCH 4/6] reformat: run dart format on the required files --- packages/at_client/lib/src/util/at_client_validation.dart | 5 +++-- packages/at_client/test/at_key_validation_test.dart | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/at_client/lib/src/util/at_client_validation.dart b/packages/at_client/lib/src/util/at_client_validation.dart index 52d5cbb20..93ea1b097 100644 --- a/packages/at_client/lib/src/util/at_client_validation.dart +++ b/packages/at_client/lib/src/util/at_client_validation.dart @@ -97,14 +97,15 @@ class AtClientValidation { } // If key starts with 'cached:' (or) if the metadata of key has isCached set to true; it represent // a cached key. Prevent client updating the cached key. Hence throw exception. - if (atKey.key!.startsWith('$CACHED:') || + if (atKey.key!.startsWith('${AtConstants.cached}:') || (atKey.metadata != null && atKey.metadata!.isCached)) { throw AtKeyException('Cannot create/update a cached key'); } // If namespace is not set on key and in preferences, throw exception if ((atKey.namespace == null || atKey.namespace!.isEmpty) && (atClientPreference.namespace == null || - atClientPreference.namespace!.isEmpty) && !atKey.isLocal) { + atClientPreference.namespace!.isEmpty) && + !atKey.isLocal) { throw AtKeyException('namespace is mandatory'); } // validate metadata diff --git a/packages/at_client/test/at_key_validation_test.dart b/packages/at_client/test/at_key_validation_test.dart index e6f8b7542..0d0b30841 100644 --- a/packages/at_client/test/at_key_validation_test.dart +++ b/packages/at_client/test/at_key_validation_test.dart @@ -62,8 +62,10 @@ void main() { }); test('Verify namespace is mandatory for shared key', () { - AtKey atKey = (AtKey.shared('key_no_namespace2', namespace: null, sharedBy: '@sharer') - ..sharedWith('@sharee')).build(); + AtKey atKey = + (AtKey.shared('key_no_namespace2', namespace: null, sharedBy: '@sharer') + ..sharedWith('@sharee')) + .build(); AtClientPreference preference = AtClientPreference()..namespace = null; expect( From ed4b6453f5b0360d4eafcd3d8fe99dd12b766a5d Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Thu, 12 Oct 2023 11:25:03 +0530 Subject: [PATCH 5/6] docs: update CHANGELOG.md --- packages/at_client/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/at_client/CHANGELOG.md b/packages/at_client/CHANGELOG.md index b6a616ebc..60ebd95db 100644 --- a/packages/at_client/CHANGELOG.md +++ b/packages/at_client/CHANGELOG.md @@ -1,3 +1,5 @@ +## 3.0.66 +- feat: make namespace NOT mandatory for local keys ## 3.0.65 - feat: apkam changes for at_onboarding_cli - build: updated at_commons to `'3.0.55'`, at_chops to `'1.0.4`, at_lookup to `'3.0.40'` From 27600dbb07a1f422a7e254200b1007e97f54567d Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Fri, 13 Oct 2023 16:05:08 +0530 Subject: [PATCH 6/6] reformat: re-order if-conditions in AtClientValidation.validatePutRequest() --- packages/at_client/lib/src/preference/at_client_config.dart | 2 +- packages/at_client/lib/src/util/at_client_validation.dart | 4 ++-- packages/at_client/pubspec.yaml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/at_client/lib/src/preference/at_client_config.dart b/packages/at_client/lib/src/preference/at_client_config.dart index 84309ef0f..3d77b5b4f 100644 --- a/packages/at_client/lib/src/preference/at_client_config.dart +++ b/packages/at_client/lib/src/preference/at_client_config.dart @@ -10,7 +10,7 @@ class AtClientConfig { /// Represents the at_client version. /// Must always be the same as the actual version in pubspec.yaml - final String atClientVersion = '3.0.65'; + final String atClientVersion = '3.0.66'; /// Represents the client commit log compaction time interval /// diff --git a/packages/at_client/lib/src/util/at_client_validation.dart b/packages/at_client/lib/src/util/at_client_validation.dart index 93ea1b097..9f814b3e1 100644 --- a/packages/at_client/lib/src/util/at_client_validation.dart +++ b/packages/at_client/lib/src/util/at_client_validation.dart @@ -103,9 +103,9 @@ 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) && - !atKey.isLocal) { + atClientPreference.namespace!.isEmpty)) { throw AtKeyException('namespace is mandatory'); } // validate metadata diff --git a/packages/at_client/pubspec.yaml b/packages/at_client/pubspec.yaml index 613fef7ac..d7b6957ca 100644 --- a/packages/at_client/pubspec.yaml +++ b/packages/at_client/pubspec.yaml @@ -4,7 +4,7 @@ description: The at_client library is the non-platform specific Client SDK which ## ## ## NB: When incrementing the version, please also increment the version in AtClientConfig file -version: 3.0.65 +version: 3.0.66 ## NB: When incrementing the version, please also increment the version in AtClientConfig file ##