From 813cdd6692c82d0899caa71d1dc75064bf80c8b0 Mon Sep 17 00:00:00 2001 From: Sitaram Kalluri Date: Thu, 5 Oct 2023 20:41:46 +0530 Subject: [PATCH 1/2] feat: Modify the OTP syntax for client to set the expire duration --- packages/at_commons/CHANGELOG.md | 2 ++ packages/at_commons/lib/src/verb/syntax.dart | 2 +- packages/at_commons/pubspec.yaml | 2 +- packages/at_commons/test/otp_verb_test.dart | 32 ++++++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 packages/at_commons/test/otp_verb_test.dart diff --git a/packages/at_commons/CHANGELOG.md b/packages/at_commons/CHANGELOG.md index c0fd26bf..a7de6a74 100644 --- a/packages/at_commons/CHANGELOG.md +++ b/packages/at_commons/CHANGELOG.md @@ -1,3 +1,5 @@ +## 3.0.57 +- feat: Introduced TTL(Time to Live) for OTP verb to configure OTP expiry ## 3.0.56 - feat: Introduce "AtInvalidEnrollmentException" which is thrown when an enrollment is expired or invalid - feat: Introduce error code 'AT0030' for Invalid Enrollment Status diff --git a/packages/at_commons/lib/src/verb/syntax.dart b/packages/at_commons/lib/src/verb/syntax.dart index 780816c8..2011ab42 100644 --- a/packages/at_commons/lib/src/verb/syntax.dart +++ b/packages/at_commons/lib/src/verb/syntax.dart @@ -129,7 +129,7 @@ class VerbSyntax { static const enroll = // The non-capturing group (?::)? matches ":" if the operation is request|approve|deny|revoke r'^enroll:(?(?:list$|(request|approve|deny|revoke|update)))(?::)?(?.+)?$'; - static const otp = r'^otp:(?get|validate)(:(?\w+))?$'; + static const otp = r'^otp:(?get|validate)(:(?\w+))?(:(?:ttl:(?\d+)))?$'; static const keys = r'^keys:((?put|get|delete):?)' r'(?:(?public|private|self):?)?' r'(?:namespace:(?[a-zA-Z0-9_]+):?)?' diff --git a/packages/at_commons/pubspec.yaml b/packages/at_commons/pubspec.yaml index 8582feea..69055bba 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: 3.0.56 +version: 3.0.57 repository: https://github.com/atsign-foundation/at_libraries homepage: https://atsign.dev diff --git a/packages/at_commons/test/otp_verb_test.dart b/packages/at_commons/test/otp_verb_test.dart new file mode 100644 index 00000000..dc3dc220 --- /dev/null +++ b/packages/at_commons/test/otp_verb_test.dart @@ -0,0 +1,32 @@ +import 'package:at_commons/at_commons.dart'; +import 'package:test/test.dart'; + +import 'syntax_test.dart'; + +void main() { + group('A group of tests related to OTP verb syntax', () { + test('A test to verify otp:get regex', () { + Map verbParams = + getVerbParams(VerbSyntax.otp, "otp:get"); + expect(verbParams[AtConstants.operation], "get"); + expect(verbParams['ttl'], null); + expect(verbParams['otp'], null); + }); + + test('A test to verify otp:get regex with TTL', () { + Map verbParams = + getVerbParams(VerbSyntax.otp, "otp:get:ttl:100"); + expect(verbParams[AtConstants.operation], "get"); + expect(verbParams['ttl'], '100'); + expect(verbParams['otp'], null); + }); + + test('A test to verify otp:validate regex', () { + Map verbParams = + getVerbParams(VerbSyntax.otp, "otp:validate:ABC123"); + expect(verbParams[AtConstants.operation], "validate"); + expect(verbParams['otp'], 'ABC123'); + expect(verbParams['ttl'], null); + }); + }); +} From cd07f87fab582b26677ebb771624bb46ce6ab9ec Mon Sep 17 00:00:00 2001 From: Sitaram Kalluri Date: Tue, 17 Oct 2023 13:05:04 +0530 Subject: [PATCH 2/2] fix: Remove validate operation from OTP --- packages/at_commons/lib/src/verb/syntax.dart | 2 +- packages/at_commons/test/otp_verb_test.dart | 8 -------- packages/at_commons/test/syntax_test.dart | 8 -------- 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/packages/at_commons/lib/src/verb/syntax.dart b/packages/at_commons/lib/src/verb/syntax.dart index 2011ab42..050beb33 100644 --- a/packages/at_commons/lib/src/verb/syntax.dart +++ b/packages/at_commons/lib/src/verb/syntax.dart @@ -129,7 +129,7 @@ class VerbSyntax { static const enroll = // The non-capturing group (?::)? matches ":" if the operation is request|approve|deny|revoke r'^enroll:(?(?:list$|(request|approve|deny|revoke|update)))(?::)?(?.+)?$'; - static const otp = r'^otp:(?get|validate)(:(?\w+))?(:(?:ttl:(?\d+)))?$'; + static const otp = r'^otp:(?get)(:(?:ttl:(?\d+)))?$'; static const keys = r'^keys:((?put|get|delete):?)' r'(?:(?public|private|self):?)?' r'(?:namespace:(?[a-zA-Z0-9_]+):?)?' diff --git a/packages/at_commons/test/otp_verb_test.dart b/packages/at_commons/test/otp_verb_test.dart index dc3dc220..8510b0d3 100644 --- a/packages/at_commons/test/otp_verb_test.dart +++ b/packages/at_commons/test/otp_verb_test.dart @@ -20,13 +20,5 @@ void main() { expect(verbParams['ttl'], '100'); expect(verbParams['otp'], null); }); - - test('A test to verify otp:validate regex', () { - Map verbParams = - getVerbParams(VerbSyntax.otp, "otp:validate:ABC123"); - expect(verbParams[AtConstants.operation], "validate"); - expect(verbParams['otp'], 'ABC123'); - expect(verbParams['ttl'], null); - }); }); } diff --git a/packages/at_commons/test/syntax_test.dart b/packages/at_commons/test/syntax_test.dart index 679301fc..03484248 100644 --- a/packages/at_commons/test/syntax_test.dart +++ b/packages/at_commons/test/syntax_test.dart @@ -307,14 +307,6 @@ void main() { VerbUtil.getVerbParam(VerbSyntax.otp, command.trim())!; expect(enrollVerbParams['operation'], 'get'); }); - - test('A test to verify otp verb for validate operation', () { - String command = 'otp:validate:ABC123\n'; - var enrollVerbParams = - VerbUtil.getVerbParam(VerbSyntax.otp, command.trim()); - expect(enrollVerbParams!['operation'], 'validate'); - expect(enrollVerbParams['otp'], 'ABC123'); - }); }); }