Skip to content

Commit

Permalink
fix: functional test issue fix and add error code change for apkam au…
Browse files Browse the repository at this point in the history
…th failed
  • Loading branch information
murali-shris committed Sep 15, 2023
1 parent acc2923 commit 6838c9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,11 @@ class AtOnboardingServiceImpl implements AtOnboardingService {
return true;
}
} on UnAuthenticatedException catch (e) {
if (e.message.contains('error:AT0401')) {
if (e.message.contains('error:AT0401') ||
e.message.contains('error:AT0026')) {
logger.finer('Retrying pkam auth');
await Future.delayed(retryInterval);
} else if (e.message.contains('error:AT0025')) {
//# TODO change the error code once server bug is fixed
logger.finer(
'enrollmentId $enrollmentIdFromServer denied.Exiting pkam retry logic');
throw AtEnrollmentException('enrollment denied');
Expand All @@ -329,7 +329,7 @@ class AtOnboardingServiceImpl implements AtOnboardingService {
Future<void> _activateAtsign(AtLookupImpl atLookUpImpl) async {
//1. Generate pkam key pair(if authMode is keyFile), encryption key pair, self encryption key and apkam symmetric key pair
AtSecurityKeys atSecurityKeys = _generateKeyPairs();
var enrollmentIdFromServer;
String? enrollmentIdFromServer;

//2. Send enrollment request to server if enable enrollment is set in preference
if (atOnboardingPreference.enableEnrollmentDuringOnboard) {
Expand Down Expand Up @@ -510,7 +510,7 @@ class AtOnboardingServiceImpl implements AtOnboardingService {

///write newly created encryption keypairs into atKeys file
Future<void> _generateAtKeysFile(
String currentEnrollmentId, AtSecurityKeys atSecurityKeys) async {
String? currentEnrollmentId, AtSecurityKeys atSecurityKeys) async {
final atKeysMap = <String, String>{
AuthKeyType.pkamPublicKey: EncryptionUtil.encryptValue(
atSecurityKeys.apkamPublicKey!,
Expand All @@ -526,10 +526,13 @@ class AtOnboardingServiceImpl implements AtOnboardingService {
),
AuthKeyType.selfEncryptionKey: atSecurityKeys.defaultSelfEncryptionKey!,
_atSign: atSecurityKeys.defaultSelfEncryptionKey!,
AuthKeyType.apkamSymmetricKey: atSecurityKeys.apkamSymmetricKey!,
'enrollmentId': currentEnrollmentId,
AuthKeyType.apkamSymmetricKey: atSecurityKeys.apkamSymmetricKey!
};

if (currentEnrollmentId != null) {
atKeysMap['enrollmentId'] = currentEnrollmentId;
}

if (atOnboardingPreference.authMode == PkamAuthMode.keysFile) {
atKeysMap[AuthKeyType.pkamPrivateKey] = EncryptionUtil.encryptValue(
atSecurityKeys.apkamPrivateKey!,
Expand Down
10 changes: 10 additions & 0 deletions tests/at_onboarding_cli_functional_tests/test/enrollment_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void main() {
expect(authResultWithEnrollment, true);
enrolledClientKeysFile.deleteSync();
}, timeout: Timeout(Duration(minutes: 3)));
tearDown(() async {
await tearDownFunc();
});
});

test(
Expand Down Expand Up @@ -244,3 +247,10 @@ Future<void> getAtKeys(String atSign) async {
encryptionPrivateKey = EncryptionUtil.decryptValue(
keysJSON['aesEncryptPrivateKey'], selfEncryptionKey);
}

Future<void> tearDownFunc() async {
bool isExists = await Directory('storage/').exists();
if (isExists) {
Directory('storage/').deleteSync(recursive: true);
}
}

0 comments on commit 6838c9e

Please sign in to comment.