Skip to content

Commit

Permalink
Strict data typing and upgraded the at_demo_data package
Browse files Browse the repository at this point in the history
Merge pull request #158 from atsign-foundation/minnu/at_onboarding_cli
  • Loading branch information
yahu1031 authored May 2, 2022
2 parents 120fb3d + 3f4bc1d commit 05f0282
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 449 deletions.
2 changes: 1 addition & 1 deletion at_onboarding_cli/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ lib/config/@resultingantarmahal7_keys.atKeys
/.vscode/
/lib/config/
/lib/src/config_utils/
/example/lib/
**/storage/
2 changes: 1 addition & 1 deletion at_onboarding_cli/example/example.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:at_lookup/at_lookup.dart';
import 'package:at_onboarding_cli/at_onboarding_cli.dart';

void main() async {
Future<void> main() async {
//onboarding preference builder can be used to set onboardingService parameters
AtOnboardingPreference atOnboardingPreference = AtOnboardingPreference()
..qrCodePath = 'storage/qr_code.png'
Expand Down
16 changes: 8 additions & 8 deletions at_onboarding_cli/functional_tests/check_docker_readiness.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import 'package:test/test.dart';

import 'check_test_env.dart';

var maxRetryCount = 10;
var retryCount = 1;
int maxRetryCount = 10;
int retryCount = 1;

void main() {
var atsign = '@sitaram🛠';
var atsignPort = 25017;
var rootServer = 'vip.ve.atsign.zone';
String atsign = '@sitaram🛠';
int atsignPort = 25017;
String rootServer = 'vip.ve.atsign.zone';

SecureSocket _secureSocket;

test('checking for test environment readiness', () async {
await Future.delayed(Duration(seconds: 10));
await Future<void>.delayed(const Duration(seconds: 10));
_secureSocket = await secureSocketConnection(rootServer, atsignPort);
print('connection established');
socketListener(_secureSocket);
Expand All @@ -24,8 +24,8 @@ void main() {
_secureSocket.write('lookup:signing_publickey$atsign\n');
response = await read();
print('waiting for signing public key response : $response');
await Future.delayed(Duration(seconds: 5));
await Future<void>.delayed(const Duration(seconds: 5));
}
await _secureSocket.close();
}, timeout: Timeout(Duration(minutes: 5)));
}, timeout: const Timeout(Duration(minutes: 5)));
}
32 changes: 16 additions & 16 deletions at_onboarding_cli/functional_tests/check_test_env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import 'dart:io';

import 'package:test/test.dart';

var _queue = Queue();
var maxRetryCount = 10;
var retryCount = 1;
Queue<String> _queue = Queue<String>();
int maxRetryCount = 10;
int retryCount = 1;

void main() {
var atsign = '@sitaram🛠';
var atsignPort = 25017;
var rootServer = 'vip.ve.atsign.zone';
String atsign = '@sitaram🛠';
int atsignPort = 25017;
String rootServer = 'vip.ve.atsign.zone';

SecureSocket _secureSocket;

test('checking for test environment readiness', () async {
await Future.delayed(Duration(seconds: 10));
await Future<void>.delayed(const Duration(seconds: 10));
_secureSocket = await secureSocketConnection(rootServer, atsignPort);
print('connection established');
socketListener(_secureSocket);
Expand All @@ -25,13 +25,13 @@ void main() {
_secureSocket.write('lookup:publickey$atsign\n');
response = await read();
print('waiting for signing public key response : $response');
await Future.delayed(Duration(seconds: 5));
await Future<void>.delayed(const Duration(seconds: 5));
}
await _secureSocket.close();
}, timeout: Timeout(Duration(minutes: 5)));
}, timeout: const Timeout(Duration(minutes: 5)));
}

Future<SecureSocket> secureSocketConnection(host, port) async {
Future<SecureSocket> secureSocketConnection(String host, int port) async {
dynamic socket;
while (true) {
try {
Expand All @@ -41,7 +41,7 @@ Future<SecureSocket> secureSocketConnection(host, port) async {
}
} on Exception {
print('retrying for connection.. $retryCount');
await Future.delayed(Duration(seconds: 5));
await Future<void>.delayed(const Duration(seconds: 5));
retryCount++;
}
}
Expand All @@ -53,7 +53,7 @@ void socketListener(SecureSocket secureSocket) {
secureSocket.listen(_messageHandler);
}

void _messageHandler(data) {
void _messageHandler(List<int> data) {
if (data.length == 1 && data.first == 64) {
return;
}
Expand All @@ -72,10 +72,10 @@ void _messageHandler(data) {
Future<String> read({int maxWaitMilliSeconds = 5000}) async {
String result = '';
//wait maxWaitMilliSeconds seconds for response from remote socket
var loopCount = (maxWaitMilliSeconds / 50).round();
for (var i = 0; i < loopCount; i++) {
await Future.delayed(Duration(milliseconds: 100));
var queueLength = _queue.length;
int loopCount = (maxWaitMilliSeconds / 50).round();
for (int i = 0; i < loopCount; i++) {
await Future<void>.delayed(const Duration(milliseconds: 100));
int queueLength = _queue.length;
if (queueLength > 0) {
result = _queue.removeFirst();
// result from another secondary is either data or a @<atSign>@ denoting complete
Expand Down
2 changes: 1 addition & 1 deletion at_onboarding_cli/functional_tests/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ dependency_overrides:
dev_dependencies:
lints: ^1.0.0
test: ^1.17.2
at_demo_data: ^0.0.3+1
at_demo_data: ^1.0.0
358 changes: 0 additions & 358 deletions at_onboarding_cli/functional_tests/test/at_demo_credentials.dart

This file was deleted.

37 changes: 20 additions & 17 deletions at_onboarding_cli/functional_tests/test/at_onboarding_cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import 'dart:io';

import 'package:at_client/at_client.dart';
import 'package:at_commons/at_commons.dart';
import 'package:at_persistence_secondary_server/at_persistence_secondary_server.dart';
import 'package:at_lookup/at_lookup.dart';
import 'package:at_utils/at_logger.dart';
import 'package:at_onboarding_cli/at_onboarding_cli.dart';
import 'package:at_server_status/at_server_status.dart';
import 'package:test/test.dart';
import 'package:path/path.dart' as path;
import 'at_demo_credentials.dart' as at_demos;
import 'package:at_demo_data/at_demo_data.dart' as at_demos;

Future<void> main() async {
AtSignLogger.root_level = 'finer';
group('Tests to validate authenticate functionality; ', () {
test('Test authentication using private key', () async {
String atsign = '@alice🛠';
Expand All @@ -22,12 +25,12 @@ Future<void> main() async {
});

test('Test using atKeys File', () async {
var atsign = '@emoji🦄🛠';
String atsign = '@emoji🦄🛠';
AtOnboardingPreference atOnboardingPreference =
getPreferences(atsign, false);
atOnboardingPreference.atKeysFilePath =
atOnboardingPreference.downloadPath;
generateAtKeysFile(atsign, atOnboardingPreference.atKeysFilePath);
await generateAtKeysFile(atsign, atOnboardingPreference.atKeysFilePath);
//setting private key to null to ensure that private key is acquired from the atKeysFile
atOnboardingPreference.privateKey = null;
AtOnboardingService atOnboardingService =
Expand All @@ -38,7 +41,7 @@ Future<void> main() async {
});

test('test atLookup auth status', () async {
var atsign = '@emoji🦄🛠';
String atsign = '@emoji🦄🛠';
AtOnboardingPreference atOnboardingPreference =
getPreferences(atsign, false);
atOnboardingPreference.atKeysFilePath = atOnboardingPreference.downloadPath;
Expand All @@ -52,25 +55,25 @@ Future<void> main() async {
AtKey key = AtKey();
key.key = 'testKey2';
await atLookUp?.update(key.key!, 'value2');
var response = await atLookUp?.llookup(key.key!);
String? response = await atLookUp?.llookup(key.key!);
expect('data:value2', response);
});

test('test atClient authentication', () async {
var atsign = '@eve🛠';
String atsign = '@eve🛠';
AtOnboardingService onboardingService =
AtOnboardingServiceImpl(atsign, getPreferences(atsign, false));
AtClient? atClient = await onboardingService.getAtClient();
await insertSelfEncKey(atClient, atsign);
AtKey key = AtKey();
key.key = 'testKey3';
await atClient?.put(key, 'value3');
var response = await atClient?.get(key);
AtValue? response = await atClient?.get(key);
expect('value3', response?.value);
});

group('tests to check encryption keys persist into local secondary', () {
var atsign = '@eve🛠';
String atsign = '@eve🛠';
AtOnboardingPreference atOnboardingPreference =
getPreferences(atsign, false);
atOnboardingPreference.atKeysFilePath = atOnboardingPreference.downloadPath;
Expand All @@ -81,7 +84,7 @@ Future<void> main() async {
test('test authentication', () async {
await generateAtKeysFile(atsign, atOnboardingPreference.atKeysFilePath);
await insertSelfEncKey(atClient, atsign);
var status = await atOnboardingService.authenticate();
bool status = await atOnboardingService.authenticate();
atClient = await atOnboardingService.getAtClient();
expect(true, status);
});
Expand All @@ -98,7 +101,7 @@ Future<void> main() async {
await atClient?.getLocalSecondary()?.getEncryptionPrivateKey());
});
test('test encryptionPublicKey on local secondary', () async {
var result = await atClient
AtData result = await atClient
?.getLocalSecondary()
?.keyStore
?.get(AT_ENCRYPTION_PUBLIC_KEY);
Expand All @@ -107,13 +110,13 @@ Future<void> main() async {
});

group('tests for onboard functionality', () {
var atsign = '@egcovidlab🛠';
String atsign = '@egcovidlab🛠';
AtOnboardingPreference atOnboardingPreference =
getPreferences(atsign, true);
test('test onboarding functionality', () async {
AtOnboardingService atOnboardingService =
AtOnboardingServiceImpl(atsign, atOnboardingPreference);
var status = await atOnboardingService.onboard();
bool status = await atOnboardingService.onboard();
expect(true, status);
});
test('test to validate generated .atKeys file', () async {
Expand Down Expand Up @@ -151,8 +154,8 @@ AtOnboardingPreference getPreferences(String atsign, bool isOnboarding) {
return atOnboardingPreference;
}

Future<void> generateAtKeysFile(atsign, filePath) async {
Map atKeysMap = {
Future<void> generateAtKeysFile(String atsign, String? filePath) async {
Map<String, String?> atKeysMap = <String, String?>{
AuthKeyType.pkamPublicKey: EncryptionUtil.encryptValue(
at_demos.pkamPublicKeyMap[atsign]!, at_demos.aesKeyMap[atsign]!),
AuthKeyType.pkamPrivateKey: EncryptionUtil.encryptValue(
Expand All @@ -164,21 +167,21 @@ Future<void> generateAtKeysFile(atsign, filePath) async {
AuthKeyType.selfEncryptionKey: at_demos.aesKeyMap[atsign],
atsign: at_demos.aesKeyMap[atsign]
};
IOSink atKeysFile = File(filePath).openWrite();
IOSink atKeysFile = File(filePath!).openWrite();
atKeysFile.write(jsonEncode(atKeysMap));
await atKeysFile.flush();
await atKeysFile.close();
}

Future<void> insertSelfEncKey(atClient, atsign) async {
Future<void> insertSelfEncKey(AtClient? atClient, String atsign) async {
await atClient
?.getLocalSecondary()
?.putValue(AT_ENCRYPTION_SELF_KEY, at_demos.aesKeyMap[atsign]!);
return;
}

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

0 comments on commit 05f0282

Please sign in to comment.