Skip to content

Commit

Permalink
Merge pull request #398 from atsign-foundation/update_topt_verb
Browse files Browse the repository at this point in the history
fix: Update totp verb
  • Loading branch information
sitaram-kalluri authored Aug 31, 2023
2 parents 5f3f50d + ed259ca commit d387a86
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 11 deletions.
3 changes: 3 additions & 0 deletions packages/at_commons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.0.54
- fix: Modify "totp" verb regex to include alpha-numeric characters
- feat: Introduce "EnrollResponse" class which represents the enrollment response.
## 3.0.53
- feat: Modify "enroll" verb regex.
- feat: Introduce "EnrollParams" class to encapsulate enrollment attributes.
Expand Down
1 change: 1 addition & 0 deletions packages/at_commons/lib/at_commons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ export 'package:at_commons/src/verb/update_json.dart';
export 'package:at_commons/src/verb/verb_util.dart';
export 'package:at_commons/src/auth/auth_mode.dart';
export 'package:at_commons/src/verb/enroll_params.dart';
export 'package:at_commons/src/enroll/enrollment.dart';
@experimental
export 'package:at_commons/src/telemetry/at_telemetry.dart';
28 changes: 28 additions & 0 deletions packages/at_commons/lib/src/enroll/enrollment.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class EnrollResponse {
String enrollmentId;
EnrollStatus enrollStatus;

EnrollResponse(this.enrollmentId, this.enrollStatus);

@override
String toString() {
return 'EnrollResponse{enrollmentId: $enrollmentId, enrollStatus: $enrollStatus}';
}
}

enum EnrollStatus { pending, approved, denied, revoked }

EnrollStatus getEnrollStatusFromString(String value) {
switch (value) {
case 'approved':
return EnrollStatus.approved;
case 'denied':
return EnrollStatus.denied;
case 'pending':
return EnrollStatus.pending;
case 'revoked':
return EnrollStatus.revoked;
default:
throw ArgumentError('Unknown enroll status string: $value');
}
}
2 changes: 1 addition & 1 deletion packages/at_commons/lib/src/verb/enroll_params.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class EnrollParams {
String? appName;
String? deviceName;
Map<String, String>? namespaces;
String? totp;
String? otp;
String? encryptedDefaultEncryptedPrivateKey;
String? encryptedDefaultSelfEncryptionKey;
String? encryptedAPKAMSymmetricKey;
Expand Down
4 changes: 2 additions & 2 deletions packages/at_commons/lib/src/verb/enroll_params.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/at_commons/lib/src/verb/enroll_verb_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class EnrollVerbBuilder extends AbstractVerbBuilder {
/// Public key of an asymmetric key pair generated on the app or client.
String? apkamPublicKey;

/// totp for the enroll request. totp must be fetched from an already enrolled app.
/// otp for the enroll request. otp must be fetched from an already enrolled app.
@experimental
String? totp;
String? otp;

Map<String, String>? namespaces;

Expand All @@ -43,7 +43,7 @@ class EnrollVerbBuilder extends AbstractVerbBuilder {
..appName = appName
..deviceName = deviceName
..apkamPublicKey = apkamPublicKey
..totp = totp
..otp = otp
..namespaces = namespaces
..encryptedDefaultEncryptedPrivateKey =
encryptedDefaultEncryptedPrivateKey
Expand All @@ -66,7 +66,7 @@ class EnrollVerbBuilder extends AbstractVerbBuilder {
deviceName != null &&
namespaces != null &&
namespaces!.isNotEmpty &&
totp != null &&
otp != null &&
apkamPublicKey != null;
}
}
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)))(?::)?(?<enrollParams>.+)?$';
static const totp = r'^totp:(?<operation>get|validate)(:(?<totp>[0-9]+))?$';
static const otp = r'^otp:(?<operation>get|validate)(:(?<otp>\w+))?$';
static const keys = r'^keys:((?<operation>put|get|delete):?)'
r'(?:(?<visibility>public|private|self):?)?'
r'(?:namespace:(?<namespace>[a-zA-Z0-9_]+):?)?'
Expand Down
2 changes: 1 addition & 1 deletion packages/at_commons/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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.53
version: 3.0.54
repository: https://github.com/atsign-foundation/at_libraries
homepage: https://atsign.dev

Expand Down
4 changes: 2 additions & 2 deletions packages/at_commons/test/enroll_params_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void main() {
'dummy_encrypted_private_key';
enrollParamsMap['encryptedDefaultSelfEncryptionKey'] =
'dummy_self_encryption_key';
enrollParamsMap['totp'] = '123';
enrollParamsMap['otp'] = '123';

var enrollParams = EnrollParams.fromJson(enrollParamsMap);
expect(enrollParams.appName, 'wavi');
Expand All @@ -104,7 +104,7 @@ void main() {
'dummy_encrypted_private_key');
expect(enrollParams.encryptedDefaultSelfEncryptionKey,
'dummy_self_encryption_key');
expect(enrollParams.totp, '123');
expect(enrollParams.otp, '123');
expect(enrollParams.namespaces, {'wavi': 'rw', '__manage': 'r'});
});
});
Expand Down
17 changes: 17 additions & 0 deletions packages/at_commons/test/syntax_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,23 @@ void main() {
e.message == 'command does not match the regex')));
});
});

group('A group of tests related to otp verb', () {
test('A test to verify otp verb for get operation', () {
String command = 'otp:get\n';
var enrollVerbParams =
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');
});
});
}

Map getVerbParams(String regex, String command) {
Expand Down

0 comments on commit d387a86

Please sign in to comment.