Skip to content

Commit

Permalink
tests: add enrollment test for enrollment access being updated
Browse files Browse the repository at this point in the history
  • Loading branch information
srieteja committed Sep 25, 2023
1 parent d31a81c commit f2061c8
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions tests/at_functional_test/test/enroll_verb_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,8 @@ void main() {
expect(jsonDecode(enrollmentResponse)['status'], 'pending');
String enrollId = jsonDecode(enrollmentResponse)['enrollmentId'];
// approve enrollment
await socket_writer(socketConnection1!, 'enroll:approve:{"enrollmentId":"$enrollId"}');
await socket_writer(
socketConnection1!, 'enroll:approve:{"enrollmentId":"$enrollId"}');
String approveResponse = await read();
print('enroll:approve response: $approveResponse');
approveResponse = approveResponse.replaceFirst('data:', "");
Expand Down Expand Up @@ -694,25 +695,57 @@ void main() {
String enrollId = await getApprovedEnrollment();
await socketConnection1?.close();
await _connect();
await prepare(socketConnection1!, firstAtsign, isApkam: true, enrollmentId: enrollId);
await socket_writer(
socketConnection1!, 'enroll:update:{"enrollmentId":"invalid_enrollment_id","namespaces":{"buzz":"rw"}}');
await prepare(socketConnection1!, firstAtsign,
isApkam: true, enrollmentId: enrollId);
await socket_writer(socketConnection1!,
'enroll:update:{"enrollmentId":"invalid_enrollment_id","namespaces":{"buzz":"rw"}}');
var response = await read();
response = response.replaceFirst('error:', '');
print(response);
});

test('test enroll:update request returns an enrollmentId with status pending', () async {
test(
'test enroll:update request returns an enrollmentId with status pending',
() async {
String enrollId = await getApprovedEnrollment();
await socketConnection1?.close();
await _connect();
await prepare(socketConnection1!, firstAtsign, isApkam: true, enrollmentId: enrollId);
await prepare(socketConnection1!, firstAtsign,
isApkam: true, enrollmentId: enrollId);
await socket_writer(socketConnection1!,
'enroll:update:{"enrollmentId":"$enrollId","namespaces":{"buzz":"rw"}}');
var response = (await read()).replaceFirst('data:', '');
expect(jsonDecode(response)['enrollmentId'], enrollId);
expect(jsonDecode(response)['status'], 'pending');
});

test(
'verify that enroll:update request approval actually updates the actual enrollment',
() async {
String enrollId = await getApprovedEnrollment();
await socketConnection1?.close();
await _connect();
// apkam authentication
await prepare(socketConnection1!, firstAtsign,
isApkam: true, enrollmentId: enrollId);
await socket_writer(socketConnection1!,
'enroll:update:{"enrollmentId":"$enrollId","namespaces":{"buzz":"rw"}}');
await read();
// approve enrollment update request
await socket_writer(
socketConnection1!, 'enroll:approve:{"enrollmentId":"$enrollId"}');
var updateResponse = await read();
updateResponse = updateResponse.replaceFirst('data:', '');
expect(jsonDecode(updateResponse)['status'], 'approved');
expect(jsonDecode(updateResponse)['enrollmentId'], enrollId);

await socket_writer(socketConnection1!, 'enroll:list');
String fetchUpdatedEnrollment = await read();
fetchUpdatedEnrollment = fetchUpdatedEnrollment.replaceFirst('data:', '');
print('updated enrollment: $fetchUpdatedEnrollment');
assert(fetchUpdatedEnrollment.contains(enrollId) &&
fetchUpdatedEnrollment.contains('{"buzz":"rw"}'));
});
});

group('A group of negative tests on enroll verb', () {
Expand All @@ -733,6 +766,7 @@ void main() {
enrollmentId = jsonDecode(enrollmentResponse)['enrollmentId'];
socketConnection1?.close();
});

test(
'A test to verify error is returned when pending enrollment is revoked',
() async {
Expand Down

0 comments on commit f2061c8

Please sign in to comment.