Skip to content

Commit

Permalink
fix: change apkam expiry error code from AT0029 -> AT0028
Browse files Browse the repository at this point in the history
  • Loading branch information
srieteja committed Sep 9, 2023
1 parent d451144 commit a3a47fb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class EnrollVerbHandler extends AbstractVerbHandler {
enrollData = await keyStore.get('$enrollmentKey$currentAtSign');
} on KeyNotFoundException catch (e) {
responseJson['isError'] = 'true';
responseJson['errorCode'] = 'AT0029';
responseJson['errorCode'] = 'AT0028';
responseJson['errorMessage'] =
'enrollment_id: $enrollmentId is expired or invalid';
logger.finer('Caught while fetching enrollment key: $e');
Expand All @@ -376,7 +376,7 @@ class EnrollVerbHandler extends AbstractVerbHandler {
// If enrollment is not active, throw AtEnrollmentException
if (!SecondaryUtil.isActiveKey(enrollData)) {
responseJson['isError'] = 'true';
responseJson['errorCode'] = 'AT0029';
responseJson['errorCode'] = 'AT0028';
responseJson['errorMessage'] = 'enrollment_id: $enrollmentId is expired';
throw AtEnrollmentException(
'enrollmentId: $enrollmentId is expired');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class PkamVerbHandler extends AbstractVerbHandler {
} on KeyNotFoundException catch (e) {
logger.finer('Caught exception trying to fetch enrollment key: $e');
apkamResult.response.isError = true;
apkamResult.response.errorCode = 'AT0029';
apkamResult.response.errorCode = 'AT0028';
apkamResult.response.errorMessage = 'enrollment_id: $enrollId is expired or invalid';
}
if(!SecondaryUtil.isActiveKey(enrollData)){
Expand Down Expand Up @@ -136,7 +136,7 @@ class PkamVerbHandler extends AbstractVerbHandler {
break;
case EnrollStatus.expired:
response.isError = true;
response.errorCode = 'AT0029';
response.errorCode = 'AT0028';
response.errorMessage = 'enrollment_id: $enrollId is expired or invalid';
break;
default:
Expand Down
25 changes: 11 additions & 14 deletions tests/at_functional_test/test/enroll_verb_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import 'dart:convert';
import 'dart:io';

import 'package:at_commons/at_commons.dart';
import 'package:at_demo_data/at_demo_data.dart' as at_demos;
import 'package:at_functional_test/conf/config_util.dart';
import 'package:test/test.dart';
Expand Down Expand Up @@ -119,10 +120,8 @@ void main() {
await socket_writer(socketConnection1!, approveEnrollCommand);
var approveEnrollResponse = await read();
approveEnrollResponse = approveEnrollResponse.replaceFirst('error:', '');
expect(
approveEnrollResponse.contains(
'enrollment id: $dummyEnrollmentId not found in keystore'),
true);
expect(approveEnrollResponse,
'AT0028:enrollment_id: $enrollmentId is expired or invalid');
});

test(
Expand All @@ -141,10 +140,8 @@ void main() {
await socket_writer(socketConnection1!, denyEnrollCommand);
var denyEnrollResponse = await read();
denyEnrollResponse = denyEnrollResponse.replaceFirst('error:', '');
expect(
denyEnrollResponse.contains(
'enrollment id: $dummyEnrollmentId not found in keystore'),
true);
expect(denyEnrollResponse,
'AT0028:enrollment_id: $enrollmentId is expired or invalid');
});

test('enroll request on unauthenticated connection without otp', () async {
Expand Down Expand Up @@ -695,8 +692,8 @@ void main() {
expect(jsonDecode(enrollmentResponse)['status'], 'denied');
expect(jsonDecode(enrollmentResponse)['enrollmentId'], enrollmentId);
// Approve enrollment
await socket_writer(
socketConnection1!, 'enroll:approve:{"enrollmentId":"$enrollmentId"}');
await socket_writer(socketConnection1!,
'enroll:approve:{"enrollmentId":"$enrollmentId"}');
enrollmentResponse = (await read()).replaceAll('error:', '');
expect(
jsonDecode(enrollmentResponse)['errorDescription'],
Expand Down Expand Up @@ -728,8 +725,8 @@ void main() {
// Approve enrollment
await _connect();
await prepare(socketConnection1!, firstAtsign);
await socket_writer(
socketConnection1!, 'enroll:approve:{"enrollmentId":"$enrollmentId"}');
await socket_writer(socketConnection1!,
'enroll:approve:{"enrollmentId":"$enrollmentId"}');
enrollmentResponse = (await read()).replaceAll('data:', '');
expect(jsonDecode(enrollmentResponse)['status'], 'approved');
expect(jsonDecode(enrollmentResponse)['enrollmentId'], enrollmentId);
Expand All @@ -740,8 +737,8 @@ void main() {
expect(jsonDecode(enrollmentResponse)['status'], 'revoked');
expect(jsonDecode(enrollmentResponse)['enrollmentId'], enrollmentId);
// Approve a revoked enrollment
await socket_writer(
socketConnection1!, 'enroll:approve:{"enrollmentId":"$enrollmentId"}');
await socket_writer(socketConnection1!,
'enroll:approve:{"enrollmentId":"$enrollmentId"}');
enrollmentResponse = (await read()).replaceAll('error:', '');
expect(
jsonDecode(enrollmentResponse)['errorDescription'],
Expand Down

0 comments on commit a3a47fb

Please sign in to comment.