Skip to content

Commit

Permalink
Merge pull request #378 from atsign-foundation/enable_onb_cli_func_test
Browse files Browse the repository at this point in the history
test: remove skip tags for all the skipped tests
  • Loading branch information
murali-shris authored Mar 21, 2024
2 parents 0ac4d7d + 8ebe783 commit dc45270
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
6 changes: 3 additions & 3 deletions packages/at_onboarding_cli/bin/activate_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Future<void> main(List<String> args) async {
try {
await activate_cli.main(args);
} on IllegalArgumentException catch (e) {
stderr.writeln('[Exception] Incorrect arguments provided \nCause:$e');
stderr.writeln('[Exception] Incorrect arguments provided\nCause: $e');
exit(1);
} on Exception catch (e) {
stderr.writeln('[Exception] Aborting process with exit code:2 \nCause:$e');
stderr.writeln('[Exception] Aborting process with exit code:2\nCause: $e');
exit(2);
} on Error catch (e) {
stderr.writeln('[Error] Aborting process with exit code:3\nCause:$e');
stderr.writeln('[Error] Aborting process with exit code:3\nCause: $e');
exit(3);
}
// The onboarding_service_impl creates an AtClient instance which will start
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'dart:io';

import 'package:args/args.dart';
import 'package:at_commons/at_commons.dart';
import 'package:at_onboarding_cli/at_onboarding_cli.dart';
import 'package:args/args.dart';
import 'package:at_onboarding_cli/src/util/at_onboarding_exceptions.dart';
import 'dart:io';
import 'package:at_utils/at_logger.dart';

Future<void> main(List<String> arguments) async {
//defaults
String rootServer = 'root.atsign.org';
String registrarUrl = 'my.atsign.com';
AtSignLogger.root_level = 'severe';

//get atSign and CRAM key from args
final parser = ArgParser()
..addOption('atsign', abbr: 'a', help: 'atSign to activate')
Expand Down Expand Up @@ -42,8 +42,7 @@ Future<void> main(List<String> arguments) async {
await activate(argResults);
}

Future<void> activate(ArgResults argResults,
{AtOnboardingService? atOnboardingService}) async {
Future<void> activate(ArgResults argResults, {AtOnboardingService? atOnboardingService}) async {
stdout.writeln('[Information] Root server is ${argResults['rootServer']}');
stdout.writeln(
'[Information] Registrar url provided is ${argResults['registrarUrl']}');
Expand Down
3 changes: 2 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 @@ -29,7 +29,8 @@ void main() {
test('A test to check authenticate true', () async {
final atSign = '@alice🛠';
AtOnboardingPreference onboardingPreference = AtOnboardingPreference()
..atKeysFilePath = 'test/data/@alice🛠.atKeys';
..atKeysFilePath = 'test/data/@alice🛠.atKeys'
..namespace = 'unit_test';
AtOnboardingService onboardingService =
AtOnboardingServiceImpl(atSign, onboardingPreference);
onboardingService.atLookUp = mockAtLookup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import 'package:at_client/at_client.dart';
import 'package:at_demo_data/at_demo_data.dart' as at_demos;
import 'package:at_lookup/at_lookup.dart';
import 'package:at_onboarding_cli/at_onboarding_cli.dart';
import 'package:at_onboarding_cli/src/activate_cli/activate_cli.dart' as activate_cli;
import 'package:at_utils/at_utils.dart';
import 'package:test/test.dart';

import 'onboarding_service_impl_override.dart';

final String atKeysFilePath = '${Platform.environment['HOME']}/.atsign/keys';
Map<String, bool> keysCreatedMap = {};
void main() {
Expand Down Expand Up @@ -155,6 +158,35 @@ void main() {
await tearDownFunc();
});
});

group('A group of tests to verify activate_cli', () {
String atSign = '@colin🛠';
AtOnboardingPreference onboardingPreference = getPreferences(atSign);
AtOnboardingService onboardingService =
OnboardingServiceImplOverride(atSign, onboardingPreference);
test(
'A test to verify atSign is activated and .atKeys file is generated using activate_cli',
() async {
List<String> args = [
'-a',
atSign,
'-c',
at_demos.cramKeyMap[atSign]!,
'-r',
'vip.ve.atsign.zone'
];
// perform activation of atSign
await activate_cli.main(args);

expect(await onboardingService.authenticate(), true);
// Authenticate atSign with the .atKeys file generated via the activate_cli tool.
expect(await File(onboardingPreference.atKeysFilePath!).exists(), true);
});

tearDownAll(() async {
await tearDownFunc();
});
});
}

AtOnboardingPreference getPreferences(String atSign) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:at_utils/at_logger.dart';
import 'package:test/test.dart';
import 'package:at_demo_data/at_demo_data.dart' as at_demos;
import 'at_chops_secure_element_mock.dart';
import 'onboarding_service_impl_override.dart';

/// Usage: dart main.dart <cram_secret>
void main() {
Expand All @@ -18,7 +19,7 @@ void main() {
test('Test auth functionality', () async {
AtOnboardingPreference preference = getPreferences(atSign);
AtOnboardingService onboardingService =
AtOnboardingServiceImpl(atSign, preference);
OnboardingServiceImplOverride(atSign, preference);
// create empty keys in atchops. Encryption key pair will be set later on after generation
final atChopsImpl =
AtChopsSecureElementMock(AtChopsKeys.create(null, null));
Expand Down Expand Up @@ -51,7 +52,7 @@ void main() {
var deleteResponse = await atClient?.delete(key);
stdout.writeln('[Test] Got Delete Response: $deleteResponse');
expect(deleteResponse, true);
}, skip: true);
});

tearDown(() async {
await tearDownFunc();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:at_onboarding_cli/at_onboarding_cli.dart';
import 'package:at_server_status/at_server_status.dart';

class OnboardingServiceImplOverride extends AtOnboardingServiceImpl {
OnboardingServiceImplOverride(
atsign, AtOnboardingPreference atOnboardingPreference)
: super(atsign, atOnboardingPreference);

AtStatus status = AtStatus()
..rootStatus = RootStatus.found
..serverStatus = ServerStatus.ready
..atSignStatus = AtSignStatus.teapot;

@override
Future<AtStatus> getServerStatus() {
print('[Test] Using overrided getServerStatus()');
print('[Test] Returning ${status.atSignStatus}');
return Future.value(status);
}
}

0 comments on commit dc45270

Please sign in to comment.