From a2176021ea3c53f87ed2cfc9ad485cd4480d28ee Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Wed, 13 Mar 2024 19:20:42 +0530 Subject: [PATCH 01/15] feat: update enroll regex -> enroll:list accepts optional params --- packages/at_commons/lib/src/verb/syntax.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/at_commons/lib/src/verb/syntax.dart b/packages/at_commons/lib/src/verb/syntax.dart index a8954e23..5ac2e5ca 100644 --- a/packages/at_commons/lib/src/verb/syntax.dart +++ b/packages/at_commons/lib/src/verb/syntax.dart @@ -128,7 +128,7 @@ class VerbSyntax { static const notifyRemove = r'notify:remove:(?[\w\d\-\_]+)'; static const enroll = // The non-capturing group (?::)? matches ":" if the operation is request|approve|deny|revoke - r'^enroll:(?(?:list$|(request|approve|deny|revoke|update)))(?::)?(?.+)?$'; + r'^enroll:(?(?:(request|approve|deny|revoke|update|list)))(?::)?((?.+)|(<=list:).?)?$'; static const otp = r'^otp:(?get|put)(:(?(?<=put:)\w{6,}))?(:(?:ttl:(?\d+)))?$'; static const keys = r'^keys:((?put|get|delete):?)' From 512e1de63fae7254f61747fab4a1ea4315bda1ad Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Wed, 13 Mar 2024 19:21:18 +0530 Subject: [PATCH 02/15] feat: add new field in EnrollParams named 'approvalStatusFilter' --- packages/at_commons/lib/src/verb/enroll_params.dart | 1 + packages/at_commons/lib/src/verb/enroll_params.g.dart | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/at_commons/lib/src/verb/enroll_params.dart b/packages/at_commons/lib/src/verb/enroll_params.dart index 3d6f2e93..00e685cf 100644 --- a/packages/at_commons/lib/src/verb/enroll_params.dart +++ b/packages/at_commons/lib/src/verb/enroll_params.dart @@ -12,6 +12,7 @@ class EnrollParams { String? encryptedDefaultSelfEncryptionKey; String? encryptedAPKAMSymmetricKey; String? apkamPublicKey; + String? approvalStatusFilter; EnrollParams(); factory EnrollParams.fromJson(Map json) => _$EnrollParamsFromJson(json); diff --git a/packages/at_commons/lib/src/verb/enroll_params.g.dart b/packages/at_commons/lib/src/verb/enroll_params.g.dart index 855a2f0d..23795ede 100644 --- a/packages/at_commons/lib/src/verb/enroll_params.g.dart +++ b/packages/at_commons/lib/src/verb/enroll_params.g.dart @@ -20,7 +20,8 @@ EnrollParams _$EnrollParamsFromJson(Map json) => EnrollParams() ..encryptedDefaultSelfEncryptionKey = json['encryptedDefaultSelfEncryptionKey'] as String? ..encryptedAPKAMSymmetricKey = json['encryptedAPKAMSymmetricKey'] as String? - ..apkamPublicKey = json['apkamPublicKey'] as String?; + ..apkamPublicKey = json['apkamPublicKey'] as String? + ..approvalStatusFilter = json['approvalStatusFilter'] as String?; Map _$EnrollParamsToJson(EnrollParams instance) => { @@ -35,4 +36,5 @@ Map _$EnrollParamsToJson(EnrollParams instance) => instance.encryptedDefaultSelfEncryptionKey, 'encryptedAPKAMSymmetricKey': instance.encryptedAPKAMSymmetricKey, 'apkamPublicKey': instance.apkamPublicKey, + 'approvalStatusFilter': instance.approvalStatusFilter, }; From 8680867aa26872257b3e14526421ec25dc31d439 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Wed, 13 Mar 2024 19:26:01 +0530 Subject: [PATCH 03/15] build: update pubspec and changelog --- packages/at_commons/CHANGELOG.md | 3 +++ packages/at_commons/pubspec.yaml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/at_commons/CHANGELOG.md b/packages/at_commons/CHANGELOG.md index a8a8cd3b..bc851837 100644 --- a/packages/at_commons/CHANGELOG.md +++ b/packages/at_commons/CHANGELOG.md @@ -1,3 +1,6 @@ +## 4.0.4 +- feat: update enroll regex so that enroll:list accepts optional params +- feat: introduce field in EnrollParams named 'approvalStatusFilter' ## 4.0.3 - fix: "toJson()" invoked on "pubKeyHash" leads to NullPointerException. ## 4.0.2 diff --git a/packages/at_commons/pubspec.yaml b/packages/at_commons/pubspec.yaml index f8622410..e5430c31 100644 --- a/packages/at_commons/pubspec.yaml +++ b/packages/at_commons/pubspec.yaml @@ -1,6 +1,6 @@ name: at_commons description: A library of Dart and Flutter utility classes that are used across other components of the atPlatform. -version: 4.0.3 +version: 4.0.4 repository: https://github.com/atsign-foundation/at_libraries homepage: https://atsign.dev From b424643d1084a6ece18008ef10e4994c076fd56d Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Wed, 13 Mar 2024 19:44:22 +0530 Subject: [PATCH 04/15] test: added unit tests --- .../at_commons/test/enroll_params_test.dart | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/at_commons/test/enroll_params_test.dart b/packages/at_commons/test/enroll_params_test.dart index a80ccfe0..8abe743d 100644 --- a/packages/at_commons/test/enroll_params_test.dart +++ b/packages/at_commons/test/enroll_params_test.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'package:at_commons/at_builders.dart'; import 'package:at_commons/src/verb/enroll_params.dart'; import 'package:test/test.dart'; @@ -52,6 +53,20 @@ void main() { var enrollParams = jsonDecode(command); expect(enrollParams['enrollmentId'], '123'); }); + + test('A test to verify enroll list regex with params', () { + String command = 'enroll:list:{"approvalStatusFilter":"123"}'; + expect(RegExp(VerbSyntax.enroll).hasMatch(command), true); + + command = command.replaceAll('enroll:list:', ''); + var enrollParams = jsonDecode(command); + expect(enrollParams['approvalStatusFilter'], '123'); + }); + + test('A test to verify enroll list regex without params', () { + String command = 'enroll:list'; + expect(RegExp(VerbSyntax.enroll).hasMatch(command), true); + }); }); group('A group of tests to verify toJson and fromJson in EnrollParams', () { @@ -64,7 +79,8 @@ void main() { ..enrollmentId = '1234' ..encryptedAPKAMSymmetricKey = 'dummy_pkam_sym_key' ..encryptedDefaultEncryptionPrivateKey = 'dummy_encrypted_private_key' - ..encryptedDefaultSelfEncryptionKey = 'dummy_self_encryption_key'; + ..encryptedDefaultSelfEncryptionKey = 'dummy_self_encryption_key' + ..approvalStatusFilter = 'pending'; Map enrollParamsMap = enrollParams.toJson(); expect(enrollParamsMap['appName'], 'wavi'); @@ -78,6 +94,7 @@ void main() { 'dummy_encrypted_private_key'); expect(enrollParamsMap['encryptedDefaultSelfEncryptionKey'], 'dummy_self_encryption_key'); + expect(enrollParamsMap['approvalStatusFilter'], 'pending'); }); test('A test to verify fromJson', () { @@ -93,6 +110,7 @@ void main() { enrollParamsMap['encryptedDefaultSelfEncryptionKey'] = 'dummy_self_encryption_key'; enrollParamsMap['otp'] = '123'; + enrollParamsMap['approvalStatusFilter'] = 'pending'; var enrollParams = EnrollParams.fromJson(enrollParamsMap); expect(enrollParams.appName, 'wavi'); @@ -106,6 +124,7 @@ void main() { 'dummy_self_encryption_key'); expect(enrollParams.otp, '123'); expect(enrollParams.namespaces, {'wavi': 'rw', '__manage': 'r'}); + expect(enrollParams.approvalStatusFilter, 'pending'); }); }); } From 6cef3f6af1cf7d9a3bb279918d507dea3b1f72ab Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Thu, 14 Mar 2024 15:16:09 +0530 Subject: [PATCH 05/15] fix: change String? approvalStatusFilter -> List enrollmentStatusFilter --- .../lib/src/verb/enroll_params.dart | 5 ++++- .../lib/src/verb/enroll_params.g.dart | 17 ++++++++++++--- .../at_commons/test/enroll_params_test.dart | 21 ++++++++++++------- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/packages/at_commons/lib/src/verb/enroll_params.dart b/packages/at_commons/lib/src/verb/enroll_params.dart index 00e685cf..0b5977b3 100644 --- a/packages/at_commons/lib/src/verb/enroll_params.dart +++ b/packages/at_commons/lib/src/verb/enroll_params.dart @@ -1,4 +1,6 @@ import 'package:json_annotation/json_annotation.dart'; + +import '../../at_commons.dart'; part 'enroll_params.g.dart'; @JsonSerializable() @@ -12,7 +14,8 @@ class EnrollParams { String? encryptedDefaultSelfEncryptionKey; String? encryptedAPKAMSymmetricKey; String? apkamPublicKey; - String? approvalStatusFilter; + List enrollmentStatusFilter = EnrollmentStatus.values; + // or List enrollmentStatusFilter = [EnrollmentStatus.approved, EnrollmentStatus.pending] EnrollParams(); factory EnrollParams.fromJson(Map json) => _$EnrollParamsFromJson(json); diff --git a/packages/at_commons/lib/src/verb/enroll_params.g.dart b/packages/at_commons/lib/src/verb/enroll_params.g.dart index 23795ede..5537e44f 100644 --- a/packages/at_commons/lib/src/verb/enroll_params.g.dart +++ b/packages/at_commons/lib/src/verb/enroll_params.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// dart run build_runner build to generate this file part of 'enroll_params.dart'; @@ -21,7 +20,9 @@ EnrollParams _$EnrollParamsFromJson(Map json) => EnrollParams() json['encryptedDefaultSelfEncryptionKey'] as String? ..encryptedAPKAMSymmetricKey = json['encryptedAPKAMSymmetricKey'] as String? ..apkamPublicKey = json['apkamPublicKey'] as String? - ..approvalStatusFilter = json['approvalStatusFilter'] as String?; + ..enrollmentStatusFilter = (json['enrollmentStatusFilter'] as List) + .map((e) => $enumDecode(_$EnrollmentStatusEnumMap, e)) + .toList(); Map _$EnrollParamsToJson(EnrollParams instance) => { @@ -36,5 +37,15 @@ Map _$EnrollParamsToJson(EnrollParams instance) => instance.encryptedDefaultSelfEncryptionKey, 'encryptedAPKAMSymmetricKey': instance.encryptedAPKAMSymmetricKey, 'apkamPublicKey': instance.apkamPublicKey, - 'approvalStatusFilter': instance.approvalStatusFilter, + 'enrollmentStatusFilter': instance.enrollmentStatusFilter + .map((e) => _$EnrollmentStatusEnumMap[e]!) + .toList(), }; + +const _$EnrollmentStatusEnumMap = { + EnrollmentStatus.pending: 'pending', + EnrollmentStatus.approved: 'approved', + EnrollmentStatus.denied: 'denied', + EnrollmentStatus.revoked: 'revoked', + EnrollmentStatus.expired: 'expired', +}; diff --git a/packages/at_commons/test/enroll_params_test.dart b/packages/at_commons/test/enroll_params_test.dart index 8abe743d..0e9f1d7e 100644 --- a/packages/at_commons/test/enroll_params_test.dart +++ b/packages/at_commons/test/enroll_params_test.dart @@ -1,6 +1,5 @@ import 'dart:convert'; -import 'package:at_commons/at_builders.dart'; -import 'package:at_commons/src/verb/enroll_params.dart'; +import 'package:at_commons/at_commons.dart'; import 'package:test/test.dart'; void main() { @@ -55,12 +54,13 @@ void main() { }); test('A test to verify enroll list regex with params', () { - String command = 'enroll:list:{"approvalStatusFilter":"123"}'; + String command = + 'enroll:list:{"approvalStatusFilter":"[pending, approved]"}'; expect(RegExp(VerbSyntax.enroll).hasMatch(command), true); command = command.replaceAll('enroll:list:', ''); var enrollParams = jsonDecode(command); - expect(enrollParams['approvalStatusFilter'], '123'); + expect(enrollParams['approvalStatusFilter'], '[pending, approved]'); }); test('A test to verify enroll list regex without params', () { @@ -80,7 +80,10 @@ void main() { ..encryptedAPKAMSymmetricKey = 'dummy_pkam_sym_key' ..encryptedDefaultEncryptionPrivateKey = 'dummy_encrypted_private_key' ..encryptedDefaultSelfEncryptionKey = 'dummy_self_encryption_key' - ..approvalStatusFilter = 'pending'; + ..enrollmentStatusFilter = [ + EnrollmentStatus.approved, + EnrollmentStatus.pending + ]; Map enrollParamsMap = enrollParams.toJson(); expect(enrollParamsMap['appName'], 'wavi'); @@ -94,7 +97,8 @@ void main() { 'dummy_encrypted_private_key'); expect(enrollParamsMap['encryptedDefaultSelfEncryptionKey'], 'dummy_self_encryption_key'); - expect(enrollParamsMap['approvalStatusFilter'], 'pending'); + expect( + enrollParamsMap['enrollmentStatusFilter'], ['approved', 'pending']); }); test('A test to verify fromJson', () { @@ -110,7 +114,7 @@ void main() { enrollParamsMap['encryptedDefaultSelfEncryptionKey'] = 'dummy_self_encryption_key'; enrollParamsMap['otp'] = '123'; - enrollParamsMap['approvalStatusFilter'] = 'pending'; + enrollParamsMap['enrollmentStatusFilter'] = ['approved', 'pending']; var enrollParams = EnrollParams.fromJson(enrollParamsMap); expect(enrollParams.appName, 'wavi'); @@ -124,7 +128,8 @@ void main() { 'dummy_self_encryption_key'); expect(enrollParams.otp, '123'); expect(enrollParams.namespaces, {'wavi': 'rw', '__manage': 'r'}); - expect(enrollParams.approvalStatusFilter, 'pending'); + expect(enrollParams.enrollmentStatusFilter, + [EnrollmentStatus.approved, EnrollmentStatus.pending]); }); }); } From ded52281c2e9aedf909c2466f86efc17af5157a7 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Thu, 14 Mar 2024 15:50:14 +0530 Subject: [PATCH 06/15] tests: update tests to match changes --- packages/at_commons/test/update_verb_builder_test.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/at_commons/test/update_verb_builder_test.dart b/packages/at_commons/test/update_verb_builder_test.dart index b2ab94e2..3fc0367a 100644 --- a/packages/at_commons/test/update_verb_builder_test.dart +++ b/packages/at_commons/test/update_verb_builder_test.dart @@ -39,7 +39,7 @@ void main() { ..atKey.key = 'email.wavi' ..atKey.sharedBy = '@alice' ..atKey.sharedWith = '@bob' - // ignore: deprecated_member_use_from_same_package + // ignore: deprecated_member_use_from_same_package ..atKey.metadata.pubKeyCS = pubKeyCS ..atKey.metadata.sharedKeyEnc = ske ..atKey.metadata.skeEncKeyName = skeEncKeyName @@ -131,7 +131,7 @@ void main() { ..atKey.key = 'cabbages_and_kings.wonderland' ..atKey.sharedBy = '@walrus' ..atKey.sharedWith = '@carpenter' - // ignore: deprecated_member_use_from_same_package + // ignore: deprecated_member_use_from_same_package ..atKey.metadata.pubKeyCS = pubKeyCS ..atKey.metadata.sharedKeyEnc = ske ..atKey.metadata.skeEncKeyName = skeEncKeyName @@ -417,7 +417,7 @@ void main() { ..atKey.metadata.isBinary = isBinary ..atKey.metadata.isEncrypted = isEncrypted ..atKey.metadata.sharedKeyEnc = sharedKeyEncrypted - // ignore: deprecated_member_use_from_same_package + // ignore: deprecated_member_use_from_same_package ..atKey.metadata.pubKeyCS = pubKeyChecksum ..atKey.metadata.encoding = encoding ..atKey.metadata.encKeyName = encKeyName From 492345472b92bc38be9cae9368fd584fcfe48749 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Thu, 14 Mar 2024 15:52:09 +0530 Subject: [PATCH 07/15] tests: update tests to match changes --- packages/at_commons/test/enroll_verb_builder_test.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/at_commons/test/enroll_verb_builder_test.dart b/packages/at_commons/test/enroll_verb_builder_test.dart index 7e1bf8d4..6ab75b2b 100644 --- a/packages/at_commons/test/enroll_verb_builder_test.dart +++ b/packages/at_commons/test/enroll_verb_builder_test.dart @@ -17,7 +17,7 @@ void main() { ..encryptedDefaultSelfEncryptionKey = 'dummy_self_encryption_key'; var command = enrollVerbBuilder.buildCommand(); expect(command, - 'enroll:request:{"enrollmentId":"1234","appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw","__manage":"r"},"encryptedDefaultEncryptionPrivateKey":"dummy_encrypted_private_key","encryptedDefaultSelfEncryptionKey":"dummy_self_encryption_key","encryptedAPKAMSymmetricKey":"dummy_pkam_sym_key","apkamPublicKey":"abcd1234"}\n'); + 'enroll:request:{"enrollmentId":"1234","appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw","__manage":"r"},"encryptedDefaultEncryptionPrivateKey":"dummy_encrypted_private_key","encryptedDefaultSelfEncryptionKey":"dummy_self_encryption_key","encryptedAPKAMSymmetricKey":"dummy_pkam_sym_key","apkamPublicKey":"abcd1234","enrollmentStatusFilter":["pending","approved","denied","revoked","expired"]}\n'); }); test('A test to verify enroll approve operation', () { @@ -33,7 +33,7 @@ void main() { ..encryptedDefaultSelfEncryptionKey = 'dummy_self_encryption_key'; var command = enrollVerbBuilder.buildCommand(); expect(command, - 'enroll:approve:{"enrollmentId":"123","appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw"},"encryptedDefaultEncryptionPrivateKey":"dummy_encrypted_private_key","encryptedDefaultSelfEncryptionKey":"dummy_self_encryption_key","encryptedAPKAMSymmetricKey":"dummy_pkam_sym_key","apkamPublicKey":"abcd1234"}\n'); + 'enroll:approve:{"enrollmentId":"123","appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw"},"encryptedDefaultEncryptionPrivateKey":"dummy_encrypted_private_key","encryptedDefaultSelfEncryptionKey":"dummy_self_encryption_key","encryptedAPKAMSymmetricKey":"dummy_pkam_sym_key","apkamPublicKey":"abcd1234","enrollmentStatusFilter":["pending","approved","denied","revoked","expired"]}\n'); }); test('A test to verify enroll deny operation', () { @@ -41,7 +41,7 @@ void main() { ..operation = EnrollOperationEnum.deny ..enrollmentId = '123'; var command = enrollVerbBuilder.buildCommand(); - expect(command, 'enroll:deny:{"enrollmentId":"123"}\n'); + expect(command, 'enroll:deny:{"enrollmentId":"123","enrollmentStatusFilter":["pending","approved","denied","revoked","expired"]}\n'); }); test('A test to verify enroll revoke operation', () { @@ -49,14 +49,14 @@ void main() { ..operation = EnrollOperationEnum.revoke ..enrollmentId = '123'; var command = enrollVerbBuilder.buildCommand(); - expect(command, 'enroll:revoke:{"enrollmentId":"123"}\n'); + expect(command, 'enroll:revoke:{"enrollmentId":"123","enrollmentStatusFilter":["pending","approved","denied","revoked","expired"]}\n'); }); test('A test to verify enroll list operation', () { var enrollVerbBuilder = EnrollVerbBuilder() ..operation = EnrollOperationEnum.list; var command = enrollVerbBuilder.buildCommand(); - expect(command, 'enroll:list\n'); + expect(command, 'enroll:list:{"enrollmentStatusFilter":["pending","approved","denied","revoked","expired"]}\n'); }); }); } From 25425e4d0b57adf89ec65af59207b03367fb350c Mon Sep 17 00:00:00 2001 From: Sri Teja T Date: Thu, 14 Mar 2024 16:00:15 +0530 Subject: [PATCH 08/15] Update CHANGELOG.md --- packages/at_commons/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/at_commons/CHANGELOG.md b/packages/at_commons/CHANGELOG.md index bc851837..49328859 100644 --- a/packages/at_commons/CHANGELOG.md +++ b/packages/at_commons/CHANGELOG.md @@ -1,6 +1,6 @@ ## 4.0.4 - feat: update enroll regex so that enroll:list accepts optional params -- feat: introduce field in EnrollParams named 'approvalStatusFilter' +- feat: introduce field in EnrollParams named 'enrollmentStatusFilter' ## 4.0.3 - fix: "toJson()" invoked on "pubKeyHash" leads to NullPointerException. ## 4.0.2 From 934d53ad2d488e83837d2c28106a1e790ff53912 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Thu, 14 Mar 2024 16:10:02 +0530 Subject: [PATCH 09/15] fix: removed commented code --- packages/at_commons/lib/src/verb/enroll_params.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/at_commons/lib/src/verb/enroll_params.dart b/packages/at_commons/lib/src/verb/enroll_params.dart index 0b5977b3..0d880dc1 100644 --- a/packages/at_commons/lib/src/verb/enroll_params.dart +++ b/packages/at_commons/lib/src/verb/enroll_params.dart @@ -15,7 +15,6 @@ class EnrollParams { String? encryptedAPKAMSymmetricKey; String? apkamPublicKey; List enrollmentStatusFilter = EnrollmentStatus.values; - // or List enrollmentStatusFilter = [EnrollmentStatus.approved, EnrollmentStatus.pending] EnrollParams(); factory EnrollParams.fromJson(Map json) => _$EnrollParamsFromJson(json); From fb7fc2d70dbbb3b181670253ee4c38ec652d5771 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Thu, 14 Mar 2024 18:09:38 +0530 Subject: [PATCH 10/15] fix: removed commented code --- packages/at_commons/CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/at_commons/CHANGELOG.md b/packages/at_commons/CHANGELOG.md index 49328859..07259736 100644 --- a/packages/at_commons/CHANGELOG.md +++ b/packages/at_commons/CHANGELOG.md @@ -1,6 +1,5 @@ ## 4.0.4 -- feat: update enroll regex so that enroll:list accepts optional params -- feat: introduce field in EnrollParams named 'enrollmentStatusFilter' +- feat: Enhance enroll:list to enable filtering of enrollments based on their status ## 4.0.3 - fix: "toJson()" invoked on "pubKeyHash" leads to NullPointerException. ## 4.0.2 From 1f96f17e5b3f4331da323e22eb1905f5352d2a79 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Thu, 14 Mar 2024 18:11:19 +0530 Subject: [PATCH 11/15] fix: make EnrollParams.enrollmentStatusFilter nullable --- packages/at_commons/lib/src/verb/enroll_params.dart | 2 +- packages/at_commons/lib/src/verb/enroll_params.g.dart | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/at_commons/lib/src/verb/enroll_params.dart b/packages/at_commons/lib/src/verb/enroll_params.dart index 0d880dc1..7c849e37 100644 --- a/packages/at_commons/lib/src/verb/enroll_params.dart +++ b/packages/at_commons/lib/src/verb/enroll_params.dart @@ -14,7 +14,7 @@ class EnrollParams { String? encryptedDefaultSelfEncryptionKey; String? encryptedAPKAMSymmetricKey; String? apkamPublicKey; - List enrollmentStatusFilter = EnrollmentStatus.values; + List? enrollmentStatusFilter = EnrollmentStatus.values; EnrollParams(); factory EnrollParams.fromJson(Map json) => _$EnrollParamsFromJson(json); diff --git a/packages/at_commons/lib/src/verb/enroll_params.g.dart b/packages/at_commons/lib/src/verb/enroll_params.g.dart index 5537e44f..ea341765 100644 --- a/packages/at_commons/lib/src/verb/enroll_params.g.dart +++ b/packages/at_commons/lib/src/verb/enroll_params.g.dart @@ -20,8 +20,8 @@ EnrollParams _$EnrollParamsFromJson(Map json) => EnrollParams() json['encryptedDefaultSelfEncryptionKey'] as String? ..encryptedAPKAMSymmetricKey = json['encryptedAPKAMSymmetricKey'] as String? ..apkamPublicKey = json['apkamPublicKey'] as String? - ..enrollmentStatusFilter = (json['enrollmentStatusFilter'] as List) - .map((e) => $enumDecode(_$EnrollmentStatusEnumMap, e)) + ..enrollmentStatusFilter = (json['enrollmentStatusFilter'] as List?) + ?.map((e) => $enumDecode(_$EnrollmentStatusEnumMap, e)) .toList(); Map _$EnrollParamsToJson(EnrollParams instance) => @@ -38,7 +38,7 @@ Map _$EnrollParamsToJson(EnrollParams instance) => 'encryptedAPKAMSymmetricKey': instance.encryptedAPKAMSymmetricKey, 'apkamPublicKey': instance.apkamPublicKey, 'enrollmentStatusFilter': instance.enrollmentStatusFilter - .map((e) => _$EnrollmentStatusEnumMap[e]!) + ?.map((e) => _$EnrollmentStatusEnumMap[e]!) .toList(), }; From 7ffa929e26dba1d98464de594302cc0a2aaf88a4 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Fri, 15 Mar 2024 15:47:59 +0530 Subject: [PATCH 12/15] fix: optionally add enrollmentStatusFilter through enroll_verb_builder --- .../lib/src/verb/enroll_verb_builder.dart | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/packages/at_commons/lib/src/verb/enroll_verb_builder.dart b/packages/at_commons/lib/src/verb/enroll_verb_builder.dart index ed3630aa..af5e60db 100644 --- a/packages/at_commons/lib/src/verb/enroll_verb_builder.dart +++ b/packages/at_commons/lib/src/verb/enroll_verb_builder.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:at_commons/src/enroll/enrollment.dart'; import 'package:at_commons/src/verb/abstract_verb_builder.dart'; import 'package:at_commons/src/verb/enroll_params.dart'; import 'package:meta/meta.dart'; @@ -35,29 +36,34 @@ class EnrollVerbBuilder extends AbstractVerbBuilder { String? encryptedDefaultSelfEncryptionKey; String? encryptedAPKAMSymmetricKey; + List? enrollmentStatusFilter; + @override String buildCommand() { var sb = StringBuffer(); sb.write('enroll:'); sb.write(getEnrollOperation(operation)); - Map enrollParams = (EnrollParams() - ..enrollmentId = enrollmentId - ..appName = appName - ..deviceName = deviceName - ..apkamPublicKey = apkamPublicKey - ..otp = otp - ..namespaces = namespaces - ..encryptedDefaultEncryptionPrivateKey = - encryptedDefaultEncryptionPrivateKey - ..encryptedDefaultSelfEncryptionKey = - encryptedDefaultSelfEncryptionKey - ..encryptedAPKAMSymmetricKey = encryptedAPKAMSymmetricKey) - .toJson(); - enrollParams + EnrollParams enrollParams = EnrollParams() + ..enrollmentId = enrollmentId + ..appName = appName + ..deviceName = deviceName + ..apkamPublicKey = apkamPublicKey + ..otp = otp + ..namespaces = namespaces + ..encryptedDefaultEncryptionPrivateKey = + encryptedDefaultEncryptionPrivateKey + ..encryptedDefaultSelfEncryptionKey = encryptedDefaultSelfEncryptionKey + ..encryptedAPKAMSymmetricKey = encryptedAPKAMSymmetricKey; + if (operation == EnrollOperationEnum.list) { + enrollParams.enrollmentStatusFilter = enrollmentStatusFilter; + } + + Map enrollParamsJson = enrollParams.toJson(); + enrollParamsJson .removeWhere((key, value) => value == null || value.toString().isEmpty); - if (enrollParams.isNotEmpty) { - sb.write(':${jsonEncode(enrollParams)}'); + if (enrollParamsJson.isNotEmpty) { + sb.write(':${jsonEncode(enrollParamsJson)}'); } sb.write('\n'); return sb.toString(); From 8f44aeebd27692bdbf5ea2a3335be89db37b66b5 Mon Sep 17 00:00:00 2001 From: Sitaram Kalluri Date: Mon, 18 Mar 2024 10:37:54 +0530 Subject: [PATCH 13/15] fix: Add default values to enrollment status filter and add enrollment status filter only when operation is list. --- .../lib/src/verb/enroll_verb_builder.dart | 29 ++++++++++++++----- .../test/enroll_verb_builder_test.dart | 20 ++++++++----- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/packages/at_commons/lib/src/verb/enroll_verb_builder.dart b/packages/at_commons/lib/src/verb/enroll_verb_builder.dart index af5e60db..a8255be5 100644 --- a/packages/at_commons/lib/src/verb/enroll_verb_builder.dart +++ b/packages/at_commons/lib/src/verb/enroll_verb_builder.dart @@ -36,7 +36,7 @@ class EnrollVerbBuilder extends AbstractVerbBuilder { String? encryptedDefaultSelfEncryptionKey; String? encryptedAPKAMSymmetricKey; - List? enrollmentStatusFilter; + List? enrollmentStatusFilter = EnrollmentStatus.values; @override String buildCommand() { @@ -54,14 +54,11 @@ class EnrollVerbBuilder extends AbstractVerbBuilder { ..encryptedDefaultEncryptionPrivateKey = encryptedDefaultEncryptionPrivateKey ..encryptedDefaultSelfEncryptionKey = encryptedDefaultSelfEncryptionKey - ..encryptedAPKAMSymmetricKey = encryptedAPKAMSymmetricKey; - if (operation == EnrollOperationEnum.list) { - enrollParams.enrollmentStatusFilter = enrollmentStatusFilter; - } + ..encryptedAPKAMSymmetricKey = encryptedAPKAMSymmetricKey + ..enrollmentStatusFilter = enrollmentStatusFilter; Map enrollParamsJson = enrollParams.toJson(); - enrollParamsJson - .removeWhere((key, value) => value == null || value.toString().isEmpty); + enrollParamsJson.removeWhere(_removeElements); if (enrollParamsJson.isNotEmpty) { sb.write(':${jsonEncode(enrollParamsJson)}'); } @@ -69,6 +66,24 @@ class EnrollVerbBuilder extends AbstractVerbBuilder { return sb.toString(); } + /// Checks if the key and its value should be added to the enroll verb command. + /// + /// Returning "false" will leave the key and its value in the map, which gets added to the + /// enroll verb command. Returning true will remove the key and its value from the map to + /// to refrain adding the key and its value to the enroll verb command. + bool _removeElements(String key, dynamic value) { + if (value == null || value.toString().isEmpty) { + return true; + } + // When operation is not list, EnrollmentStatusFilter is not applicable. Hence remove from enrollParamsJson + // to prevent it from adding it enroll verb command. + if (key == 'enrollmentStatusFilter' && + operation != EnrollOperationEnum.list) { + return true; + } + return false; + } + @override bool checkParams() { return appName != null && diff --git a/packages/at_commons/test/enroll_verb_builder_test.dart b/packages/at_commons/test/enroll_verb_builder_test.dart index 6ab75b2b..8d139afb 100644 --- a/packages/at_commons/test/enroll_verb_builder_test.dart +++ b/packages/at_commons/test/enroll_verb_builder_test.dart @@ -1,3 +1,4 @@ +import 'package:at_commons/src/enroll/enrollment.dart'; import 'package:at_commons/src/verb/enroll_verb_builder.dart'; import 'package:at_commons/src/verb/operation_enum.dart'; import 'package:test/test.dart'; @@ -17,7 +18,7 @@ void main() { ..encryptedDefaultSelfEncryptionKey = 'dummy_self_encryption_key'; var command = enrollVerbBuilder.buildCommand(); expect(command, - 'enroll:request:{"enrollmentId":"1234","appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw","__manage":"r"},"encryptedDefaultEncryptionPrivateKey":"dummy_encrypted_private_key","encryptedDefaultSelfEncryptionKey":"dummy_self_encryption_key","encryptedAPKAMSymmetricKey":"dummy_pkam_sym_key","apkamPublicKey":"abcd1234","enrollmentStatusFilter":["pending","approved","denied","revoked","expired"]}\n'); + 'enroll:request:{"enrollmentId":"1234","appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw","__manage":"r"},"encryptedDefaultEncryptionPrivateKey":"dummy_encrypted_private_key","encryptedDefaultSelfEncryptionKey":"dummy_self_encryption_key","encryptedAPKAMSymmetricKey":"dummy_pkam_sym_key","apkamPublicKey":"abcd1234"}\n'); }); test('A test to verify enroll approve operation', () { @@ -33,7 +34,7 @@ void main() { ..encryptedDefaultSelfEncryptionKey = 'dummy_self_encryption_key'; var command = enrollVerbBuilder.buildCommand(); expect(command, - 'enroll:approve:{"enrollmentId":"123","appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw"},"encryptedDefaultEncryptionPrivateKey":"dummy_encrypted_private_key","encryptedDefaultSelfEncryptionKey":"dummy_self_encryption_key","encryptedAPKAMSymmetricKey":"dummy_pkam_sym_key","apkamPublicKey":"abcd1234","enrollmentStatusFilter":["pending","approved","denied","revoked","expired"]}\n'); + 'enroll:approve:{"enrollmentId":"123","appName":"wavi","deviceName":"pixel","namespaces":{"wavi":"rw"},"encryptedDefaultEncryptionPrivateKey":"dummy_encrypted_private_key","encryptedDefaultSelfEncryptionKey":"dummy_self_encryption_key","encryptedAPKAMSymmetricKey":"dummy_pkam_sym_key","apkamPublicKey":"abcd1234"}\n'); }); test('A test to verify enroll deny operation', () { @@ -41,7 +42,7 @@ void main() { ..operation = EnrollOperationEnum.deny ..enrollmentId = '123'; var command = enrollVerbBuilder.buildCommand(); - expect(command, 'enroll:deny:{"enrollmentId":"123","enrollmentStatusFilter":["pending","approved","denied","revoked","expired"]}\n'); + expect(command, 'enroll:deny:{"enrollmentId":"123"}\n'); }); test('A test to verify enroll revoke operation', () { @@ -49,14 +50,19 @@ void main() { ..operation = EnrollOperationEnum.revoke ..enrollmentId = '123'; var command = enrollVerbBuilder.buildCommand(); - expect(command, 'enroll:revoke:{"enrollmentId":"123","enrollmentStatusFilter":["pending","approved","denied","revoked","expired"]}\n'); + expect(command, 'enroll:revoke:{"enrollmentId":"123"}\n'); }); - test('A test to verify enroll list operation', () { + test('A test to verify to override enroll list status', () { var enrollVerbBuilder = EnrollVerbBuilder() - ..operation = EnrollOperationEnum.list; + ..operation = EnrollOperationEnum.list + ..enrollmentStatusFilter = [ + EnrollmentStatus.approved, + EnrollmentStatus.pending + ]; var command = enrollVerbBuilder.buildCommand(); - expect(command, 'enroll:list:{"enrollmentStatusFilter":["pending","approved","denied","revoked","expired"]}\n'); + expect(command, + 'enroll:list:{"enrollmentStatusFilter":["approved","pending"]}\n'); }); }); } From a9389c271b18554416d0767992bab6a4114383c3 Mon Sep 17 00:00:00 2001 From: Sitaram Kalluri Date: Mon, 18 Mar 2024 10:47:25 +0530 Subject: [PATCH 14/15] fix: Add dart documentation --- packages/at_commons/lib/src/verb/enroll_verb_builder.dart | 5 ++++- packages/at_commons/test/enroll_params_test.dart | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/at_commons/lib/src/verb/enroll_verb_builder.dart b/packages/at_commons/lib/src/verb/enroll_verb_builder.dart index a8255be5..362f506d 100644 --- a/packages/at_commons/lib/src/verb/enroll_verb_builder.dart +++ b/packages/at_commons/lib/src/verb/enroll_verb_builder.dart @@ -36,7 +36,10 @@ class EnrollVerbBuilder extends AbstractVerbBuilder { String? encryptedDefaultSelfEncryptionKey; String? encryptedAPKAMSymmetricKey; - List? enrollmentStatusFilter = EnrollmentStatus.values; + /// Filters enrollment requests according to the provided [EnrollmentStatus] criteria. + /// + /// Accepts a list of enrollment statuses, defaulting to all available status values. + List enrollmentStatusFilter = EnrollmentStatus.values; @override String buildCommand() { diff --git a/packages/at_commons/test/enroll_params_test.dart b/packages/at_commons/test/enroll_params_test.dart index 0e9f1d7e..3e850198 100644 --- a/packages/at_commons/test/enroll_params_test.dart +++ b/packages/at_commons/test/enroll_params_test.dart @@ -55,12 +55,12 @@ void main() { test('A test to verify enroll list regex with params', () { String command = - 'enroll:list:{"approvalStatusFilter":"[pending, approved]"}'; + 'enroll:list:{"enrollmentStatusFilter":"[pending, approved]"}'; expect(RegExp(VerbSyntax.enroll).hasMatch(command), true); command = command.replaceAll('enroll:list:', ''); var enrollParams = jsonDecode(command); - expect(enrollParams['approvalStatusFilter'], '[pending, approved]'); + expect(enrollParams['enrollmentStatusFilter'], '[pending, approved]'); }); test('A test to verify enroll list regex without params', () { From feddc9e80d5327223fa0a5fed5f6ff9a3173fe56 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Thu, 21 Mar 2024 14:50:08 +0530 Subject: [PATCH 15/15] docs: update docs + add test --- packages/at_commons/CHANGELOG.md | 2 +- packages/at_commons/lib/src/verb/enroll_params.dart | 2 +- .../at_commons/lib/src/verb/enroll_params.g.dart | 1 + .../at_commons/lib/src/verb/enroll_verb_builder.dart | 12 +++++++----- .../at_commons/test/enroll_verb_builder_test.dart | 8 ++++++++ 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/at_commons/CHANGELOG.md b/packages/at_commons/CHANGELOG.md index 07259736..e46c58b6 100644 --- a/packages/at_commons/CHANGELOG.md +++ b/packages/at_commons/CHANGELOG.md @@ -1,5 +1,5 @@ ## 4.0.4 -- feat: Enhance enroll:list to enable filtering of enrollments based on their status +- feat: Enhance enroll:list to enable filtering based on enrollment status ## 4.0.3 - fix: "toJson()" invoked on "pubKeyHash" leads to NullPointerException. ## 4.0.2 diff --git a/packages/at_commons/lib/src/verb/enroll_params.dart b/packages/at_commons/lib/src/verb/enroll_params.dart index 7c849e37..45fc4c36 100644 --- a/packages/at_commons/lib/src/verb/enroll_params.dart +++ b/packages/at_commons/lib/src/verb/enroll_params.dart @@ -1,6 +1,6 @@ import 'package:json_annotation/json_annotation.dart'; -import '../../at_commons.dart'; +import 'package:at_commons/at_commons.dart'; part 'enroll_params.g.dart'; @JsonSerializable() diff --git a/packages/at_commons/lib/src/verb/enroll_params.g.dart b/packages/at_commons/lib/src/verb/enroll_params.g.dart index ea341765..cc1c788d 100644 --- a/packages/at_commons/lib/src/verb/enroll_params.g.dart +++ b/packages/at_commons/lib/src/verb/enroll_params.g.dart @@ -1,4 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// dart run build_runner build to generate this file part of 'enroll_params.dart'; diff --git a/packages/at_commons/lib/src/verb/enroll_verb_builder.dart b/packages/at_commons/lib/src/verb/enroll_verb_builder.dart index 362f506d..0e35d6d5 100644 --- a/packages/at_commons/lib/src/verb/enroll_verb_builder.dart +++ b/packages/at_commons/lib/src/verb/enroll_verb_builder.dart @@ -36,9 +36,9 @@ class EnrollVerbBuilder extends AbstractVerbBuilder { String? encryptedDefaultSelfEncryptionKey; String? encryptedAPKAMSymmetricKey; - /// Filters enrollment requests according to the provided [EnrollmentStatus] criteria. + /// Filters enrollment requests based on provided [EnrollmentStatus] criteria. /// - /// Accepts a list of enrollment statuses, defaulting to all available status values. + /// Accepts a list of enrollment statuses. Defaults to all EnrollmentStatuses List enrollmentStatusFilter = EnrollmentStatus.values; @override @@ -69,7 +69,9 @@ class EnrollVerbBuilder extends AbstractVerbBuilder { return sb.toString(); } - /// Checks if the key and its value should be added to the enroll verb command. + /// Compares current EnrollOperation with VerbBuilder params and removes any + /// that are NOT applicable + /// /// /// Returning "false" will leave the key and its value in the map, which gets added to the /// enroll verb command. Returning true will remove the key and its value from the map to @@ -78,8 +80,8 @@ class EnrollVerbBuilder extends AbstractVerbBuilder { if (value == null || value.toString().isEmpty) { return true; } - // When operation is not list, EnrollmentStatusFilter is not applicable. Hence remove from enrollParamsJson - // to prevent it from adding it enroll verb command. + // EnrollmentStatusFilter is only applicable to EnrollOperation.list + // Remove it from enrollParamsJson for any operation other than list if (key == 'enrollmentStatusFilter' && operation != EnrollOperationEnum.list) { return true; diff --git a/packages/at_commons/test/enroll_verb_builder_test.dart b/packages/at_commons/test/enroll_verb_builder_test.dart index 8d139afb..4d9be218 100644 --- a/packages/at_commons/test/enroll_verb_builder_test.dart +++ b/packages/at_commons/test/enroll_verb_builder_test.dart @@ -64,5 +64,13 @@ void main() { expect(command, 'enroll:list:{"enrollmentStatusFilter":["approved","pending"]}\n'); }); + + test('A test to validate enroll list command with default filter', () { + var enrollVerbBuilder = EnrollVerbBuilder() + ..operation = EnrollOperationEnum.list; + var command = enrollVerbBuilder.buildCommand(); + expect(command, + 'enroll:list:{"enrollmentStatusFilter":["pending","approved","denied","revoked","expired"]}\n'); + }); }); }