From a3a47fbb983e74462776f617d28032ebf25d9d73 Mon Sep 17 00:00:00 2001 From: Srie Teja Date: Sat, 9 Sep 2023 22:51:06 +0530 Subject: [PATCH] fix: change apkam expiry error code from AT0029 -> AT0028 --- .../src/verb/handler/enroll_verb_handler.dart | 4 +-- .../src/verb/handler/pkam_verb_handler.dart | 4 +-- .../test/enroll_verb_test.dart | 25 ++++++++----------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/packages/at_secondary_server/lib/src/verb/handler/enroll_verb_handler.dart b/packages/at_secondary_server/lib/src/verb/handler/enroll_verb_handler.dart index 7a4c5625e..22a6aad1f 100644 --- a/packages/at_secondary_server/lib/src/verb/handler/enroll_verb_handler.dart +++ b/packages/at_secondary_server/lib/src/verb/handler/enroll_verb_handler.dart @@ -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'); @@ -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'); diff --git a/packages/at_secondary_server/lib/src/verb/handler/pkam_verb_handler.dart b/packages/at_secondary_server/lib/src/verb/handler/pkam_verb_handler.dart index 447b87060..e3ac6043b 100644 --- a/packages/at_secondary_server/lib/src/verb/handler/pkam_verb_handler.dart +++ b/packages/at_secondary_server/lib/src/verb/handler/pkam_verb_handler.dart @@ -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)){ @@ -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: diff --git a/tests/at_functional_test/test/enroll_verb_test.dart b/tests/at_functional_test/test/enroll_verb_test.dart index d77a878c5..1b6c4df5c 100644 --- a/tests/at_functional_test/test/enroll_verb_test.dart +++ b/tests/at_functional_test/test/enroll_verb_test.dart @@ -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'; @@ -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( @@ -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 { @@ -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'], @@ -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); @@ -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'],