Skip to content

Commit

Permalink
test: improve assertions in functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srieteja committed Oct 3, 2023
1 parent e422f35 commit aa514f9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
30 changes: 13 additions & 17 deletions tests/at_functional_test/test/enroll_namespace_access_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ void main() {
await socket_writer(
socketConnection1!, 'update:$atmosphereKey atmospherevalue');
var updateResponse = await read();
assert(updateResponse.contains('data:'));
assert((!updateResponse.contains('Invalid syntax')) &&
(!updateResponse.contains('null')));

Expand All @@ -338,17 +339,15 @@ void main() {
expect(enrollJsonMap['status'], 'approved');

var enrollmentId = enrollJsonMap['enrollmentId'];

await socketConnection1?.close();
// now do the apkam using the enrollment id
var pkamDigest = generatePKAMDigest(firstAtsign, fromResponse);
var apkamEnrollId = 'pkam:enrollmentId:$enrollmentId:$pkamDigest\n';

await socket_writer(socketConnection1!, apkamEnrollId);
var apkamEnrollIdResponse = await read();
expect(apkamEnrollIdResponse, 'data:success\n');
await _connect();
await prepare(socketConnection1!, firstAtsign,
isApkam: true, enrollmentId: enrollmentId);

await socket_writer(socketConnection1!, 'scan');
var scanResponse = await read();
String scanResponse = await read();
print('scanResponse: $scanResponse');
expect(scanResponse.contains(atmosphereKey), true);
});

Expand Down Expand Up @@ -496,17 +495,14 @@ void main() {
var enrollJsonMap = jsonDecode(enrollResponse);
expect(enrollJsonMap['enrollmentId'], isNotEmpty);
expect(enrollJsonMap['status'], 'approved');

var enrollmentId = enrollJsonMap['enrollmentId'];
await socketConnection1?.close();

// now do the apkam using the enrollment id
var pkamDigest = generatePKAMDigest(firstAtsign, fromResponse);
var apkamEnrollId = 'pkam:enrollmentId:$enrollmentId:$pkamDigest\n';

await socket_writer(socketConnection1!, apkamEnrollId);
var apkamEnrollIdResponse = await read();
expect(apkamEnrollIdResponse, 'data:success\n');

await _connect();
// this authenticates to the server using apkam authentication with the
// enrollment_is that has just been created
await prepare(socketConnection1!, firstAtsign,
isApkam: true, enrollmentId: enrollmentId);
await socket_writer(socketConnection1!, 'scan');
var scanResponse = await read();
print(scanResponse);
Expand Down
8 changes: 4 additions & 4 deletions tests/at_functional_test/test/enroll_verb_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ void main() {
await prepare(socketConnection1!, firstAtsign,
isApkam: true, enrollmentId: enrollId);
// scan keys with only access to 'wavi' namespace
socket_writer(socketConnection1!, 'scan');
await socket_writer(socketConnection1!, 'scan');
var scanResponse = await read();
assert(scanResponse.contains('apkam_update_wavi.wavi$firstAtsign'));
// scan should not contain keys with 'buzz' namespace
Expand All @@ -815,7 +815,7 @@ void main() {
expect(jsonDecode(updateResponse)['status'], 'approved');
expect(jsonDecode(updateResponse)['enrollmentId'], enrollId);
// assert scan now contains both the keys
socket_writer(socketConnection1!, 'scan');
await socket_writer(socketConnection1!, 'scan');
scanResponse = await read();
print(scanResponse);
assert(scanResponse.contains('apkam_update_wavi.wavi$firstAtsign'));
Expand All @@ -836,7 +836,7 @@ void main() {
await prepare(socketConnection1!, firstAtsign,
isApkam: true, enrollmentId: enrollId);
// scan keys with only access to 'wavi' namespace
socket_writer(socketConnection1!, 'scan');
await socket_writer(socketConnection1!, 'scan');
var scanResponse = await read();
assert(scanResponse.contains('apkam_update_wavi.wavi$firstAtsign'));
// scan should not contain keys with 'buzz' namespace
Expand All @@ -856,7 +856,7 @@ void main() {
expect(jsonDecode(updateResponse)['status'], 'denied');
expect(jsonDecode(updateResponse)['enrollmentId'], enrollId);

socket_writer(socketConnection1!, 'scan');
await socket_writer(socketConnection1!, 'scan');
scanResponse = await read();
assert(scanResponse.contains('apkam_update_wavi.wavi$firstAtsign'));
// scan should not contain keys with 'buzz' namespace
Expand Down
2 changes: 1 addition & 1 deletion tests/at_functional_test/test/functional_test_commons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Future<void> prepare(Socket socket, String atsign, {bool isApkam = false, String
} else {
await socket_writer(socket, 'pkam:enrollmentId:$enrollmentId:$pkamDigest');
response = await read();
print('APKAM response: $response');
print('APKAM auth response: $response');
expect(response, 'data:success\n');
}
}
Expand Down

0 comments on commit aa514f9

Please sign in to comment.