Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactored end2end tests into functional tests #1154

Merged
merged 5 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 0 additions & 101 deletions tests/at_end2end_test/test/collection_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,25 +235,6 @@ void main() async {
.testInitializer(fourthAtSign, namespace);
});

test('Model operations - save() test', () async {
// Setting firstAtSign atClient instance to context.
currentAtClientManager =
await AtClientManager.getInstance().setCurrentAtSign(
firstAtSign,
namespace,
TestPreferences.getInstance().getPreference(firstAtSign),
);

// Save a photo
var phone = Phone()
..id = 'personal phone'
..namespace = 'buzz'
..collectionName = 'phone'
..phoneNumber = '12345';
var shareRes = await phone.save();
expect(shareRes, true);
});

test('Model operations - save() with reshare() as true test', () async {
// Setting firstAtSign atClient instance to context.
currentAtClientManager =
Expand Down Expand Up @@ -391,88 +372,6 @@ void main() async {
);
});

test('Query method - AtCollectionModel.getModel() test', () async {
// Setting firstAtSign atClient instance to context.
currentAtClientManager =
await AtClientManager.getInstance().setCurrentAtSign(
firstAtSign,
namespace,
TestPreferences.getInstance().getPreference(firstAtSign),
);

Phone personalPhone = Phone()
..id = 'new personal Phone'
..namespace = 'buzz'
..collectionName = 'phone'
..phoneNumber = '123456789';
Phone officePhone = Phone()
..id = 'Office Phone'
..namespace = 'buzz.bz'
..collectionName = 'phone'
..phoneNumber = '9999';
await personalPhone.save();
await officePhone.save();

AtCollectionModel.registerFactories([PhoneFactory.getInstance()]);
var personalPhoneLoaded = await AtCollectionModel.getModel(
id: 'new personal Phone',
namespace: 'buzz',
collectionName: 'phone') as Phone;

expect(personalPhoneLoaded.phoneNumber, '123456789');
expect(personalPhoneLoaded.collectionName, 'phone');
expect(personalPhoneLoaded.namespace, 'buzz');
expect(personalPhoneLoaded.id, 'new personal Phone');
var officePhoneLoaded = await AtCollectionModel.getModel(
id: 'Office Phone',
namespace: 'buzz.bz',
collectionName: 'phone') as Phone;

expect(officePhoneLoaded.phoneNumber, '9999');
expect(officePhoneLoaded.collectionName, 'phone');
expect(officePhoneLoaded.namespace, 'buzz.bz');
expect(officePhoneLoaded.id, 'Office Phone');
AtCollectionModelFactoryManager.getInstance()
.unregister(PhoneFactory.getInstance());
});

test('Query method - AtCollectionModel.getModelsByCollectionName() test',
() async {
// Setting firstAtSign atClient instance to context.
currentAtClientManager =
await AtClientManager.getInstance().setCurrentAtSign(
firstAtSign,
namespace,
TestPreferences.getInstance().getPreference(firstAtSign),
);

Phone personalPhone = Phone()
..id = 'new personal Phone'
..namespace = 'buzz'
..collectionName = 'phone'
..phoneNumber = '123456789';
Phone officePhone = Phone()
..id = 'Office Phone'
..namespace = 'buzz'
..collectionName = 'phone'
..phoneNumber = '9999';
await personalPhone.save();
await officePhone.save();

AtCollectionModel.registerFactories([PhoneFactory.getInstance()]);
// Get models with existing collectionName
var phones = await AtCollectionModel.getModelsByCollectionName('phone');
expect(phones.length >= 2, true,
reason: 'Expect phones to be non-empty for an valid collection name');
// Get models with non-existing id/inv collectionName
phones =
await AtCollectionModel.getModelsByCollectionName('phone-dont-exist');
expect(phones.isEmpty, true,
reason: 'Expect phones to be empty for an invalid collection name');
AtCollectionModelFactoryManager.getInstance()
.unregister(PhoneFactory.getInstance());
});

test('Query method - AtCollectionModel.getModelsSharedWith() test', () async {
// Setting firstAtSign atClient instance to context.
currentAtClientManager =
Expand Down
26 changes: 0 additions & 26 deletions tests/at_end2end_test/test/deletion_key_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,6 @@ void main() {
.atClient;
});

test(
'A test to verify deletion of key when overriding the namespace in atKey',
() async {
// The namespace in the preference is "wavi". Overriding the namespace in the atKey to "buzz"
var atKey = (AtKey.shared('keyNamespaceOverriding',
namespace: 'buzz', sharedBy: sharedByAtSign)
..sharedWith(sharedWithAtSign))
.build();
await sharedByAtClient.put(atKey, 'dummy_value');
expect(
sharedByAtClient
.getLocalSecondary()!
.keyStore!
.isKeyExists(atKey.toString()),
true);

// Delete the key
await sharedByAtClient.delete(atKey);
expect(
sharedByAtClient
.getLocalSecondary()!
.keyStore!
.isKeyExists(atKey.toString()),
false);
});

test(
'A test to verify cached key is deleted in sharedWith secondary when CCD is set to true',
() async {
Expand Down
86 changes: 0 additions & 86 deletions tests/at_end2end_test/test/encryption_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,92 +43,6 @@ void main() {
}

int ttl = 60000;
group('Test encryption for self', () {
test('Test put self, then get, no IV, 1.5 to 1.5', () async {
AtClient atClient = await getAtClient(atSign_1, Version(1, 5, 0));

var atKey = (AtKey.self('test_put.15_15')..timeToLive(ttl)).build();
await atClient.put(atKey, clearText);
expect(atKey.metadata?.ivNonce, isNull);

atClient.getPreferences()!.atProtocolEmitted = Version(1, 5, 0);

String selfEncryptionKey =
(await atClient.getLocalSecondary()!.getEncryptionSelfKey())!;
var atData =
await (atClient.getLocalSecondary()!.keyStore!.get(atKey.toString()));
var cipherText = atData.data;
expect(EncryptionUtil.decryptValue(cipherText, selfEncryptionKey),
clearText);

var getResult = await atClient.get(atKey);
expect(getResult.value, clearText);
});

test('Test put self, then get, no IV, 1.5 to 2.0', () async {
AtClient atClient = await getAtClient(atSign_1, Version(1, 5, 0));

var atKey = (AtKey.self('test_put.15_20')..timeToLive(ttl)).build();
await atClient.put(atKey, clearText);
expect(atKey.metadata?.ivNonce, isNull);

atClient.getPreferences()!.atProtocolEmitted = Version(2, 0, 0);
String selfEncryptionKey =
(await atClient.getLocalSecondary()!.getEncryptionSelfKey())!;
var atData =
await (atClient.getLocalSecondary()!.keyStore!.get(atKey.toString()));
var cipherText = atData.data;
expect(EncryptionUtil.decryptValue(cipherText, selfEncryptionKey),
clearText);

var getResult = await atClient.get(atKey);
expect(getResult.value, clearText);
});

test('Test put self, then get, with IV, 2.0 to 2.0', () async {
AtClient atClient = await getAtClient(atSign_1, Version(2, 0, 0));

var atKey = (AtKey.self('test_put.20_20')..timeToLive(ttl)).build();
await atClient.put(atKey, clearText);
expect(atKey.metadata?.ivNonce, isNotNull);

atClient.getPreferences()!.atProtocolEmitted = Version(2, 0, 0);
String selfEncryptionKey =
(await atClient.getLocalSecondary()!.getEncryptionSelfKey())!;
var atData =
await (atClient.getLocalSecondary()!.keyStore!.get(atKey.toString()));
var cipherText = atData.data;
expect(
EncryptionUtil.decryptValue(cipherText, selfEncryptionKey,
ivBase64: atKey.metadata?.ivNonce),
clearText);

var getResult = await atClient.get(atKey);
expect(getResult.value, clearText);
});

test('Test put self, then get, with IV, 2.0 to 1.5', () async {
AtClient atClient = await getAtClient(atSign_1, Version(2, 0, 0));

var atKey = (AtKey.self('test_put.20_15')..timeToLive(ttl)).build();
await atClient.put(atKey, clearText);
expect(atKey.metadata?.ivNonce, isNotNull);

atClient.getPreferences()!.atProtocolEmitted = Version(1, 5, 0);
String selfEncryptionKey =
(await atClient.getLocalSecondary()!.getEncryptionSelfKey())!;
var atData =
await (atClient.getLocalSecondary()!.keyStore!.get(atKey.toString()));
var cipherText = atData.data;
expect(
EncryptionUtil.decryptValue(cipherText, selfEncryptionKey,
ivBase64: atKey.metadata?.ivNonce),
clearText);

var getResult = await atClient.get(atKey);
expect(getResult.value, clearText);
});
});

group(
'Test encryption for sharing, storing shared encryption key in metadata',
Expand Down
55 changes: 0 additions & 55 deletions tests/at_end2end_test/test/notify_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,61 +122,6 @@ void main() async {
});
});
});

group('A group of tests for notification fetch', () {
test('A test to verify non existent notification', () async {
await AtClientManager.getInstance().setCurrentAtSign(
currentAtSign,
namespace,
TestPreferences.getInstance().getPreference(currentAtSign));
var notificationResult = await AtClientManager.getInstance()
.atClient
.notificationService
.fetch('abc-123');
expect(notificationResult.id, 'abc-123');
expect(notificationResult.status, 'NotificationStatus.expired');
});

test('A test to verify the notification expiry', () async {
for (int i = 0; i < 10; i++) {
print('Testing notification expiry - test run #$i');
await AtClientManager.getInstance().setCurrentAtSign(
currentAtSign,
namespace,
TestPreferences.getInstance().getPreference(currentAtSign));
var atKey = (AtKey.shared('test-notification-expiry',
namespace: 'wavi', sharedBy: currentAtSign)
..sharedWith(sharedWithAtSign))
.build();
NotificationResult notificationResult =
await AtClientManager.getInstance()
.atClient
.notificationService
.notify(NotificationParams.forUpdate(atKey,
notificationExpiry: Duration(minutes: 1)));

AtNotification atNotification = await AtClientManager.getInstance()
.atClient
.notificationService
.fetch(notificationResult.notificationID);

var actualExpiresAtInEpochMills = DateTime.fromMillisecondsSinceEpoch(
atNotification.expiresAtInEpochMillis!)
.toUtc()
.millisecondsSinceEpoch;
var expectedExpiresAtInEpochMills =
DateTime.fromMillisecondsSinceEpoch(atNotification.epochMillis)
.toUtc()
.add(Duration(minutes: 1))
.millisecondsSinceEpoch;
expect(
(actualExpiresAtInEpochMills - expectedExpiresAtInEpochMills)
.abs() <
10,
true);
}
});
});
}

/// Class responsible for getting the notifications from the cloud secondary
Expand Down
10 changes: 10 additions & 0 deletions tests/at_functional_test/config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# The @Protocol root server configuration
root_server:
# The url to connect to root server
url: 'vip.ve.atsign.zone'

# alice atsign details
atSign:
firstAtSign: "@alice🛠"
secondAtSign: "@bob🛠"

13 changes: 13 additions & 0 deletions tests/at_functional_test/lib/src/config_util.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// ignore_for_file: depend_on_referenced_packages

import 'package:at_utils/at_utils.dart';
import 'package:yaml/yaml.dart';

class ConfigUtil {
static final ApplicationConfiguration appConfig =
ApplicationConfiguration('config/config.yaml');

static YamlMap getYaml() {
return appConfig.getYaml()!;
}
}
Loading