Skip to content

Commit

Permalink
Merge pull request #638 from atsign-foundation/635-at_cli_onboarding-…
Browse files Browse the repository at this point in the history
…does-not-create-atkeys-as-expected

fix: `.atKeys` filename was trimmed when filename has period('.') in it
  • Loading branch information
sitaram-kalluri authored Aug 22, 2024
2 parents 2068675 + 584ad3e commit b9fcf8a
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 12 deletions.
2 changes: 2 additions & 0 deletions packages/at_onboarding_cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 1.6.3
- fix: `.atKeys` filename was trimmed when filename has period('.') in it
## 1.6.2
- fix: `.atKeys` file was being generated in the wrong location in some cases
## 1.6.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:at_auth/at_auth.dart' as at_auth;
import 'package:at_auth/at_auth.dart';
import 'package:at_chops/at_chops.dart';
import 'package:at_client/at_client.dart';
import 'package:at_auth/at_auth.dart' as at_auth;
import 'package:at_persistence_secondary_server/at_persistence_secondary_server.dart';
import 'package:at_lookup/at_lookup.dart';
import 'package:at_onboarding_cli/at_onboarding_cli.dart';
import 'package:at_onboarding_cli/src/factory/service_factories.dart';
import 'package:at_onboarding_cli/src/util/at_onboarding_exceptions.dart';
import 'package:at_persistence_secondary_server/at_persistence_secondary_server.dart';
import 'package:at_server_status/at_server_status.dart';
import 'package:at_utils/at_utils.dart';
import 'package:at_onboarding_cli/src/factory/service_factories.dart';
import 'package:at_lookup/at_lookup.dart';
import 'package:at_onboarding_cli/at_onboarding_cli.dart';
import 'package:crypton/crypton.dart';
import 'package:encrypt/encrypt.dart';
import 'package:image/image.dart';
import 'package:meta/meta.dart';
import 'package:zxing2/qrcode.dart';
import 'package:image/image.dart';
import 'package:path/path.dart' as path;

import '../util/home_directory_util.dart';
import '../util/onboarding_util.dart';
Expand Down Expand Up @@ -386,8 +385,8 @@ class AtOnboardingServiceImpl implements AtOnboardingService {
}) async {
if (atKeysFile == null) {
if (!atOnboardingPreference.atKeysFilePath!.endsWith('.atKeys')) {
atOnboardingPreference.atKeysFilePath = path.setExtension(
atOnboardingPreference.atKeysFilePath!, '.atKeys');
atOnboardingPreference.atKeysFilePath =
'${atOnboardingPreference.atKeysFilePath}.atKeys';
}
atKeysFile = File(atOnboardingPreference.atKeysFilePath!);
}
Expand Down Expand Up @@ -654,7 +653,8 @@ class AtOnboardingServiceImpl implements AtOnboardingService {
@override
Future<void> close() async {
logger.info('Closing');
if (_atLookUp != null && (_atLookUp as AtLookupImpl).isConnectionAvailable()) {
if (_atLookUp != null &&
(_atLookUp as AtLookupImpl).isConnectionAvailable()) {
await _atLookUp!.close();
}
atClient?.notificationService.stopAllSubscriptions();
Expand Down
2 changes: 1 addition & 1 deletion packages/at_onboarding_cli/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: at_onboarding_cli
description: Dart tools for initial client onboarding, subsequent client enrollment, and enrollment management.
version: 1.6.2
version: 1.6.3
repository: https://github.com/atsign-foundation/at_libraries
homepage: https://atsign.com
documentation: https://docs.atsign.com/
Expand Down
97 changes: 96 additions & 1 deletion packages/at_onboarding_cli/test/at_onboarding_cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,102 @@ void main() {
// Delete the file at the end of the test.
file.deleteSync(recursive: true);
});
;

test(
'A test to verify createAtKeys when keys location as . in the filename',
() async {
String atsign = '@alice_test';
AtOnboardingPreference atOnboardingPreference = getOnboardingPreference()
..atKeysFilePath = '${Directory.current.path}/test/$atsign.me';
AtOnboardingServiceImpl onboardingService =
AtOnboardingServiceImpl(atsign, atOnboardingPreference);

AtEnrollmentResponse atEnrollmentResponse =
AtEnrollmentResponse('123', EnrollmentStatus.approved);

RSAKeypair encryptionRsaKeyPair = onboardingService.generateRsaKeypair();
atEnrollmentResponse.atAuthKeys = AtAuthKeys()
..enrollmentId = '123'
..defaultSelfEncryptionKey = onboardingService.generateAESKey()
..defaultEncryptionPublicKey = encryptionRsaKeyPair.publicKey.toString()
..defaultEncryptionPrivateKey =
encryptionRsaKeyPair.privateKey.toString()
..apkamPrivateKey = encryptionRsaKeyPair.privateKey.toString()
..apkamPublicKey = encryptionRsaKeyPair.publicKey.toString()
..apkamSymmetricKey = onboardingService.generateAESKey();

var f = await onboardingService.createAtKeysFile(atEnrollmentResponse);
expect(f.path.endsWith('$atsign.me.atKeys'), true);

File file = File(f.path);
expect(file.existsSync(), true);
// Delete the file at the end of the test.
file.deleteSync(recursive: true);
});

test(
'A test to verify createAtKeys when keys location as - in the filename',
() async {
String atsign = '@alice_test';
AtOnboardingPreference atOnboardingPreference = getOnboardingPreference()
..atKeysFilePath = '${Directory.current.path}/test/$atsign-me';
AtOnboardingServiceImpl onboardingService =
AtOnboardingServiceImpl(atsign, atOnboardingPreference);

AtEnrollmentResponse atEnrollmentResponse =
AtEnrollmentResponse('123', EnrollmentStatus.approved);

RSAKeypair encryptionRsaKeyPair = onboardingService.generateRsaKeypair();
atEnrollmentResponse.atAuthKeys = AtAuthKeys()
..enrollmentId = '123'
..defaultSelfEncryptionKey = onboardingService.generateAESKey()
..defaultEncryptionPublicKey = encryptionRsaKeyPair.publicKey.toString()
..defaultEncryptionPrivateKey =
encryptionRsaKeyPair.privateKey.toString()
..apkamPrivateKey = encryptionRsaKeyPair.privateKey.toString()
..apkamPublicKey = encryptionRsaKeyPair.publicKey.toString()
..apkamSymmetricKey = onboardingService.generateAESKey();

var f = await onboardingService.createAtKeysFile(atEnrollmentResponse);
expect(f.path.endsWith('$atsign-me.atKeys'), true);

File file = File(f.path);
expect(file.existsSync(), true);
// Delete the file at the end of the test.
file.deleteSync(recursive: true);
});

test(
'A test to verify createAtKeys does not append .atKeys when filename has .atKeys extension',
() async {
String atsign = '@alice_test';
AtOnboardingPreference atOnboardingPreference = getOnboardingPreference()
..atKeysFilePath = '${Directory.current.path}/test/$atsign-me.atKeys';
AtOnboardingServiceImpl onboardingService =
AtOnboardingServiceImpl(atsign, atOnboardingPreference);

AtEnrollmentResponse atEnrollmentResponse =
AtEnrollmentResponse('123', EnrollmentStatus.approved);

RSAKeypair encryptionRsaKeyPair = onboardingService.generateRsaKeypair();
atEnrollmentResponse.atAuthKeys = AtAuthKeys()
..enrollmentId = '123'
..defaultSelfEncryptionKey = onboardingService.generateAESKey()
..defaultEncryptionPublicKey = encryptionRsaKeyPair.publicKey.toString()
..defaultEncryptionPrivateKey =
encryptionRsaKeyPair.privateKey.toString()
..apkamPrivateKey = encryptionRsaKeyPair.privateKey.toString()
..apkamPublicKey = encryptionRsaKeyPair.publicKey.toString()
..apkamSymmetricKey = onboardingService.generateAESKey();

var f = await onboardingService.createAtKeysFile(atEnrollmentResponse);
expect(f.path.endsWith('$atsign-me.atKeys'), true);

File file = File(f.path);
expect(file.existsSync(), true);
// Delete the file at the end of the test.
file.deleteSync(recursive: true);
});
});
}

Expand Down

0 comments on commit b9fcf8a

Please sign in to comment.