Skip to content

Commit

Permalink
Merge pull request #630 from atsign-foundation/629-at_activate-create…
Browse files Browse the repository at this point in the history
…s-atkeys-files-but-in-the-wrong-place-sshnp-v550-binaries

fix: Add .atKeys extension to the custom file path
  • Loading branch information
sitaram-kalluri authored Aug 14, 2024
2 parents 1746e35 + ace8d1a commit 96a77bf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ class AtOnboardingServiceImpl implements AtOnboardingService {
}) async {
if (atKeysFile == null) {
if (!atOnboardingPreference.atKeysFilePath!.endsWith('.atKeys')) {
atOnboardingPreference.atKeysFilePath =
path.join(atOnboardingPreference.atKeysFilePath!, '.atKeys');
atOnboardingPreference.atKeysFilePath = path.setExtension(
atOnboardingPreference.atKeysFilePath!, '.atKeys');
}
atKeysFile = File(atOnboardingPreference.atKeysFilePath!);
}
Expand Down
42 changes: 39 additions & 3 deletions packages/at_onboarding_cli/test/at_onboarding_cli_test.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import 'dart:convert';
import 'dart:io';

import 'package:at_auth/at_auth.dart';
import 'package:at_chops/at_chops.dart';
import 'package:at_client/at_client.dart';
import 'package:at_commons/at_builders.dart';
import 'package:at_lookup/at_lookup.dart';
import 'package:at_onboarding_cli/at_onboarding_cli.dart';
import 'package:at_persistence_secondary_server/at_persistence_secondary_server.dart';
import 'package:at_utils/at_logger.dart';
import 'package:crypton/crypton.dart';
import 'package:mocktail/mocktail.dart';
import 'package:at_lookup/at_lookup.dart';
import 'package:at_client/at_client.dart';
import 'package:test/expect.dart';
import 'package:test/scaffolding.dart';
import 'package:at_auth/at_auth.dart';

class MockAtLookupImpl extends Mock implements AtLookupImpl {}

Expand Down Expand Up @@ -162,6 +163,41 @@ void main() {
await tearDownFunc();
});
});

group('A group of tests related to generation of AtKeys', () {
test(
'A test to verify createAtKeys generates atKeys in the location specified in onboarding preference atKeysFilePath',
() async {
String atsign = '@alice_test';
AtOnboardingPreference atOnboardingPreference = getOnboardingPreference()
..atKeysFilePath = '${Directory.current.path}/test/$atsign';
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.atKeys'), true);

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

Future<void> tearDownFunc() async {
Expand Down

0 comments on commit 96a77bf

Please sign in to comment.