Skip to content

Commit

Permalink
Merge pull request #455 from atsign-foundation/update_otp_syntax
Browse files Browse the repository at this point in the history
feat: Add put operation to OTP syntax for SPP
  • Loading branch information
gkc authored Nov 23, 2023
2 parents 4cbec2a + 8dd298e commit 8ad9acd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/at_commons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 4.0.0
- fix: Improved regex for Reserved keys (Internal keys used by the server)
- fix: Add "put" operation to OTP verb to store semi-permanent pass codes
## 3.0.58
- fix: Deprecate encryptedDefaultEncryptedPrivateKey in EnrollParams and introduce encryptedDefaultEncryptedPrivateKey for readability
- fix: Replace encryptedDefaultEncryptedPrivateKey with encryptedDefaultEncryptionPrivateKey in EnrollVerbBuilder
Expand Down
2 changes: 1 addition & 1 deletion packages/at_commons/lib/src/verb/syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class VerbSyntax {
static const enroll =
// The non-capturing group (?::)? matches ":" if the operation is request|approve|deny|revoke
r'^enroll:(?<operation>(?:list$|(request|approve|deny|revoke|update)))(?::)?(?<enrollParams>.+)?$';
static const otp = r'^otp:(?<operation>get)(:(?:ttl:(?<ttl>\d+)))?$';
static const otp = r'^otp:(?<operation>get|put)(:(?<otp>(?<=put:)\w{6,}))?(:(?:ttl:(?<ttl>\d+)))?$';
static const keys = r'^keys:((?<operation>put|get|delete):?)'
r'(?:(?<visibility>public|private|self):?)?'
r'(?:namespace:(?<namespace>[a-zA-Z0-9_]+):?)?'
Expand Down
28 changes: 28 additions & 0 deletions packages/at_commons/test/otp_verb_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,32 @@ void main() {
expect(verbParams['otp'], null);
});
});

group('A group of test to verify otp:put regex', () {
test('A test to verify otp:put accepts alphanumeric characters', () {
Map<dynamic, dynamic> verbParams =
getVerbParams(VerbSyntax.otp, 'otp:put:abc123');
expect(verbParams[AtConstants.operation], 'put');
expect(verbParams['otp'], 'abc123');
expect(verbParams['ttl'], null);
});

test(
'A test to verify otp:put throws error if otp is not 6 character length',
() {
expect(
() => getVerbParams(VerbSyntax.otp, 'otp:put:abc12'),
throwsA(predicate((dynamic e) =>
e is InvalidSyntaxException &&
e.message == 'command does not match the regex')));
});

test('A test to verify otp:put with ttl', () {
Map<dynamic, dynamic> verbParams =
getVerbParams(VerbSyntax.otp, 'otp:put:abc123:ttl:123');
expect(verbParams[AtConstants.operation], 'put');
expect(verbParams['otp'], 'abc123');
expect(verbParams['ttl'], '123');
});
});
}

0 comments on commit 8ad9acd

Please sign in to comment.