Skip to content

Commit

Permalink
test: fix functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srieteja committed Jan 11, 2024
1 parent 3d16f43 commit 3dfaaff
Showing 1 changed file with 8 additions and 62 deletions.
70 changes: 8 additions & 62 deletions tests/at_functional_test/test/enrollment_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,68 +136,10 @@ void main() {
print(enrollmentRequests.entries);
expect(enrollmentRequests.length, 2);

String firstEnrollmentKey = enrollmentRequests.keys.toList()[0];
String secondEnrollmentKey = enrollmentRequests.keys.toList()[1];

expect(
(enrollmentRequests[firstEnrollmentKey]['namespace']
as Map<String, dynamic>)['buzz'],
'rw');
expect(
(enrollmentRequests[secondEnrollmentKey]['namespace']
as Map<String, dynamic>)['buzz'],
'rw');
expect(
(enrollmentRequests[secondEnrollmentKey]['namespace']
as Map<String, dynamic>)['wavi'],
'r');
});

test('validate client functionality to fetch pending enrollments', () async {
AtClient? client = atClientManager.atClient;
// fetch first otp
String? otp =
await TestUtils.executeCommandAndParse(client, 'otp:get', auth: true);
expect(otp, isNotNull);
// create first enrollment request
RemoteSecondary? secondRemoteSecondary =
RemoteSecondary(atSign, getClient2Preferences());
var publicKey =
at_demos.pkamPublicKeyMap['@bob🛠']; // can be any random public key
var newEnrollRequest = TestUtils.formatCommand(
'enroll:request:{"appName":"buzz","deviceName":"pixel","namespaces":{"buzz":"rw"},"otp":"$otp","apkamPublicKey":"$publicKey"}');
var enrollResponse = await TestUtils.executeCommandAndParse(
null, newEnrollRequest,
remoteSecondary: secondRemoteSecondary);
Map<String, dynamic> enrollResponse1JsonDecoded =
jsonDecode(enrollResponse!);
expect(enrollResponse1JsonDecoded['enrollmentId'], isNotNull);
expect(enrollResponse1JsonDecoded['status'], 'pending');
// approve first enrollment request
enrollResponse = await TestUtils.executeCommandAndParse(client,
'enroll:approve:{"enrollmentId":"${enrollResponse1JsonDecoded['enrollmentId']}"}');

// fetch second otp
otp = await TestUtils.executeCommandAndParse(client, 'otp:get', auth: true);
expect(otp, isNotNull);
// create second enrollment request
newEnrollRequest = TestUtils.formatCommand(
'enroll:request:{"appName":"wavi","deviceName":"pixel7","namespaces":{"buzz":"rw", "wavi":"r"},"otp":"$otp","apkamPublicKey":"$publicKey"}');
enrollResponse = await TestUtils.executeCommandAndParse(
null, newEnrollRequest,
remoteSecondary: secondRemoteSecondary);
var enrollResponse2JsonDecoded = jsonDecode(enrollResponse!);
expect(enrollResponse2JsonDecoded['enrollmentId'], isNotNull);
expect(enrollResponse2JsonDecoded['status'], 'pending');

// fetch enrollment requests through client
Map<String, dynamic> enrollmentRequests =
await client.fetchEnrollmentRequests();
print(enrollmentRequests.entries);
expect(enrollmentRequests.length, 2);

String firstEnrollmentKey = enrollmentRequests.keys.toList()[0];
String secondEnrollmentKey = enrollmentRequests.keys.toList()[1];
String firstEnrollmentKey = getEnrollmentKey(
enrollResponse1JsonDecoded['enrollmentId'], secondAtsign);
String secondEnrollmentKey = getEnrollmentKey(
enrollResponse2JsonDecoded['enrollmentId'], secondAtsign);

expect(
(enrollmentRequests[firstEnrollmentKey]['namespace']
Expand Down Expand Up @@ -237,6 +179,10 @@ Future<void> setLastReceivedNotificationDateTime() async {
.put(lastReceivedNotificationAtKey, jsonEncode(atNotification.toJson()));
}

String getEnrollmentKey(String enrollmentId, String atsign) {
return '$enrollmentId.new.enrollments.__manage$atsign';
}

AtClientPreference getClient2Preferences() {
return AtClientPreference()
..commitLogPath = 'test/hive/client_2/commit'
Expand Down

0 comments on commit 3dfaaff

Please sign in to comment.