diff --git a/tests/at_end2end_test/test/notify_verb_test.dart b/tests/at_end2end_test/test/notify_verb_test.dart index 067261095..2ea4d087a 100644 --- a/tests/at_end2end_test/test/notify_verb_test.dart +++ b/tests/at_end2end_test/test/notify_verb_test.dart @@ -49,7 +49,7 @@ void main() { String response = await sh2.read(); print('notify verb response : $response'); assert( - (!response.contains('Invalid syntax')) && (!response.contains('null'))); + (!response.contains('Invalid syntax')) && (!response.contains('null'))); String notificationId = response.replaceAll('data:', ''); // notify status @@ -69,37 +69,37 @@ void main() { }); test('test to verify notify fetch verb for a valid notification-id', - () async { - /// NOTIFY VERB - var value = 'Copenhagen'; - await sh1.writeCommand( - 'notify:update:messageType:key:notifier:system:ttr:-1:$atSign_2:city.me$atSign_1:$value'); - String response = await sh1.read(); - print('notify verb response : $response'); - assert( + () async { + /// NOTIFY VERB + var value = 'Copenhagen'; + await sh1.writeCommand( + 'notify:update:messageType:key:notifier:system:ttr:-1:$atSign_2:city.me$atSign_1:$value'); + String response = await sh1.read(); + print('notify verb response : $response'); + assert( (!response.contains('Invalid syntax')) && (!response.contains('null'))); - String notificationId = response.replaceAll('data:', ''); - - // Assert notification status - response = await getNotifyStatus(sh1, notificationId, - returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); - print('notify status response : $response'); - expect(response, contains('data:delivered')); - - // Fetch notification - if (atSign1ServerVersion > Version(3, 0, 23)) { - await sh1.writeCommand('notify:fetch:$notificationId'); - response = await sh1.read(); - response = response.replaceFirst('data:', ''); - var atNotificationMap = jsonDecode(response); - expect(atNotificationMap['id'], notificationId); - expect(atNotificationMap['fromAtSign'], atSign_1); - expect(atNotificationMap['toAtSign'], atSign_2); - expect(atNotificationMap['type'], 'NotificationType.sent'); - expect(atNotificationMap['notificationStatus'], - 'NotificationStatus.delivered'); - } - }); + String notificationId = response.replaceAll('data:', ''); + + // Assert notification status + response = await getNotifyStatus(sh1, notificationId, + returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); + print('notify status response : $response'); + expect(response, contains('data:delivered')); + + // Fetch notification + if (atSign1ServerVersion > Version(3, 0, 23)) { + await sh1.writeCommand('notify:fetch:$notificationId'); + response = await sh1.read(); + response = response.replaceFirst('data:', ''); + var atNotificationMap = jsonDecode(response); + expect(atNotificationMap['id'], notificationId); + expect(atNotificationMap['fromAtSign'], atSign_1); + expect(atNotificationMap['toAtSign'], atSign_2); + expect(atNotificationMap['type'], 'NotificationType.sent'); + expect(atNotificationMap['notificationStatus'], + 'NotificationStatus.delivered'); + } + }); test('notify verb without messageType and operation', () async { /// NOTIFY VERB @@ -108,7 +108,7 @@ void main() { String response = await sh2.read(); print('notify verb response : $response'); assert( - (!response.contains('Invalid syntax')) && (!response.contains('null'))); + (!response.contains('Invalid syntax')) && (!response.contains('null'))); String notificationId = response.replaceAll('data:', ''); // notify status @@ -118,11 +118,15 @@ void main() { assert(response.contains('data:delivered')); ///notify:list verb - await sh1.writeCommand('notify:list'); - response = await sh1.read(); - print('notify list verb response : $response'); - expect(response, - contains('"key":"$atSign_1:contact-no$atSign_2","value":"$value')); + print('AtSign 1: $atSign1ServerVersion'); + print('AtSign 2: $atSign2ServerVersion'); + if (atSign1ServerVersion > Version(3, 0, 35)) { + await sh1.writeCommand('notify:list'); + response = await sh1.read(); + print('notify list verb response : $response'); + expect(response, + contains('"key":"$atSign_1:contact-no$atSign_2","value":"$value')); + } }); test('notify verb without messageType', () async { @@ -133,7 +137,7 @@ void main() { String response = await sh2.read(); print('notify verb response : $response'); assert( - (!response.contains('Invalid syntax')) && (!response.contains('null'))); + (!response.contains('Invalid syntax')) && (!response.contains('null'))); String notificationId = response.replaceAll('data:', ''); // notify status @@ -161,7 +165,7 @@ void main() { print('notify verb response : $response'); String notificationId = response.replaceAll('data:', ''); assert( - (!response.contains('Invalid syntax')) && (!response.contains('null'))); + (!response.contains('Invalid syntax')) && (!response.contains('null'))); // notify status response = await getNotifyStatus(sh2, notificationId, @@ -185,7 +189,7 @@ void main() { print('notify verb response : $response'); String notificationId = response.replaceAll('data:', ''); assert( - (!response.contains('Invalid syntax')) && (!response.contains('null'))); + (!response.contains('Invalid syntax')) && (!response.contains('null'))); // notify status response = await getNotifyStatus(sh1, notificationId, @@ -194,13 +198,16 @@ void main() { expect(response, contains('data:delivered')); //notify:list verb with regex + await sh2.writeCommand('notify:list:email'); response = await sh2.read(); print('notify list verb response : $response'); - expect( - response, - contains( - '"key":"$atSign_2:email$atSign_1","value":null,"operation":"delete"')); + if (atSign1ServerVersion > Version(3,0,35)) { + expect( + response, + contains( + '"key":"$atSign_2:email$atSign_1","value":null,"operation":"delete"')); + } }); test('notify verb without giving message type value', () async { @@ -234,7 +241,7 @@ void main() { print('notify verb response : $response'); String notificationId = response.replaceAll('data:', ''); assert( - (!response.contains('Invalid syntax')) && (!response.contains('null'))); + (!response.contains('Invalid syntax')) && (!response.contains('null'))); // notify status response = await getNotifyStatus(sh1, notificationId, @@ -252,7 +259,7 @@ void main() { print('notify verb response : $response'); String notificationId = response.replaceAll('data:', ''); assert( - (!response.contains('Invalid syntax')) && (!response.contains('null'))); + (!response.contains('Invalid syntax')) && (!response.contains('null'))); // notify status response = await getNotifyStatus(sh1, notificationId, @@ -268,7 +275,7 @@ void main() { print('notify verb response : $response'); String notificationId = response.replaceAll('data:', ''); assert( - (!response.contains('Invalid syntax')) && (!response.contains('null'))); + (!response.contains('Invalid syntax')) && (!response.contains('null'))); // notify status response = await getNotifyStatus(sh1, notificationId, @@ -319,7 +326,7 @@ void main() { String response = await sh1.read(); print('notify verb response : $response'); assert( - (!response.contains('Invalid syntax')) && (!response.contains('null'))); + (!response.contains('Invalid syntax')) && (!response.contains('null'))); /// atSign2: notify:list verb with regex String shouldContain = '"key":"$atSign_2:whatsapp$atSign_1"'; @@ -362,9 +369,11 @@ void main() { print('notify verb response : $response'); String notificationId = response.replaceAll('data:', ''); assert( - (!response.contains('Invalid syntax')) && (!response.contains('null'))); + (!response.contains('Invalid syntax')) && (!response.contains('null'))); - int willExpireAt = DateTime.now().millisecondsSinceEpoch + ttln; + int willExpireAt = DateTime + .now() + .millisecondsSinceEpoch + ttln; // // notify status before ttln expiry time response = await getNotifyStatus(sh2, notificationId, @@ -373,7 +382,9 @@ void main() { expect(response, contains('data:delivered')); // Wait until ttln has been reached - int now = DateTime.now().millisecondsSinceEpoch; + int now = DateTime + .now() + .millisecondsSinceEpoch; if (now < willExpireAt) { await Future.delayed(Duration(milliseconds: willExpireAt - now)); } @@ -386,36 +397,40 @@ void main() { }); test('notify verb with notification expiry for errored- invalid atsign', - () async { - // /// NOTIFY VERB - int ttln = 11000; - await sh2.writeCommand( - 'notify:update:messageType:key:ttln:$ttln:ttr:-1:@xyz:message$atSign_2:Hey!'); - String response = await sh2.read(); - print('notify verb response : $response'); - String notificationId = response.replaceAll('data:', ''); - assert( + () async { + // /// NOTIFY VERB + int ttln = 11000; + await sh2.writeCommand( + 'notify:update:messageType:key:ttln:$ttln:ttr:-1:@xyz:message$atSign_2:Hey!'); + String response = await sh2.read(); + print('notify verb response : $response'); + String notificationId = response.replaceAll('data:', ''); + assert( (!response.contains('Invalid syntax')) && (!response.contains('null'))); - int willExpireAt = DateTime.now().millisecondsSinceEpoch + ttln; - - // notify status before ttln expiry time - response = await getNotifyStatus(sh2, notificationId, - returnWhenStatusIn: ['errored'], timeOutMillis: 10000); - expect(response, contains('data:errored')); - - // Wait until ttln has been reached - int now = DateTime.now().millisecondsSinceEpoch; - if (now < willExpireAt) { - await Future.delayed(Duration(milliseconds: willExpireAt - now)); - } - - /// notify status after ttln expiry time - response = await getNotifyStatus(sh2, notificationId, - returnWhenStatusIn: ['expired'], timeOutMillis: 5000); - print('notify status response : $response'); - expect(response, contains('data:expired')); - }); + int willExpireAt = DateTime + .now() + .millisecondsSinceEpoch + ttln; + + // notify status before ttln expiry time + response = await getNotifyStatus(sh2, notificationId, + returnWhenStatusIn: ['errored'], timeOutMillis: 10000); + expect(response, contains('data:errored')); + + // Wait until ttln has been reached + int now = DateTime + .now() + .millisecondsSinceEpoch; + if (now < willExpireAt) { + await Future.delayed(Duration(milliseconds: willExpireAt - now)); + } + + /// notify status after ttln expiry time + response = await getNotifyStatus(sh2, notificationId, + returnWhenStatusIn: ['expired'], timeOutMillis: 5000); + print('notify status response : $response'); + expect(response, contains('data:expired')); + }); test('notify verb with notification expiry with messageType text', () async { // /// NOTIFY VERB @@ -426,9 +441,11 @@ void main() { print('notify verb response : $response'); String notificationId = response.replaceAll('data:', ''); assert( - (!response.contains('Invalid syntax')) && (!response.contains('null'))); + (!response.contains('Invalid syntax')) && (!response.contains('null'))); - int willExpireAt = DateTime.now().millisecondsSinceEpoch + ttln; + int willExpireAt = DateTime + .now() + .millisecondsSinceEpoch + ttln; // notify status before ttln expiry time response = await getNotifyStatus(sh2, notificationId, @@ -437,7 +454,9 @@ void main() { expect(response, contains('data:delivered')); // Wait until ttln has been reached - int now = DateTime.now().millisecondsSinceEpoch; + int now = DateTime + .now() + .millisecondsSinceEpoch; if (now < willExpireAt) { await Future.delayed(Duration(milliseconds: willExpireAt - now)); } @@ -451,17 +470,17 @@ void main() { /// test('notify verb with notification expiry in an incorrect spelling', - () async { - // /// NOTIFY VERB - await sh2.writeCommand( - 'notify:update:ttlnn:5000:ttr:-1:$atSign_1:message$atSign_2:Hey!'); - String response = await sh2.read(); - print('notify verb response : $response'); - expect(response, contains('Invalid syntax')); - // Invalid syntax results in a closed connection so let's do some housekeeping - sh2.close(); - sh2 = await e2e.getSocketHandler(atSign_2); - }); + () async { + // /// NOTIFY VERB + await sh2.writeCommand( + 'notify:update:ttlnn:5000:ttr:-1:$atSign_1:message$atSign_2:Hey!'); + String response = await sh2.read(); + print('notify verb response : $response'); + expect(response, contains('Invalid syntax')); + // Invalid syntax results in a closed connection so let's do some housekeeping + sh2.close(); + sh2 = await e2e.getSocketHandler(atSign_2); + }); test('Test to verify the update and delete caching of key', () async { var key = 'testcachedkey-$lastValue'; @@ -534,30 +553,34 @@ void main() { test( 'notify a key and verifying the time taken for the status to be delivered', - () async { - var timeBeforeNotification = DateTime.now().millisecondsSinceEpoch; - await sh1.writeCommand( - 'notify:update:messageType:key:$atSign_2:company$atSign_1:atsign'); - String response = await sh1.read(); - print('notify verb response : $response'); - assert( + () async { + var timeBeforeNotification = DateTime + .now() + .millisecondsSinceEpoch; + await sh1.writeCommand( + 'notify:update:messageType:key:$atSign_2:company$atSign_1:atsign'); + String response = await sh1.read(); + print('notify verb response : $response'); + assert( (!response.contains('Invalid syntax')) && (!response.contains('null'))); - String notificationId = response.replaceAll('data:', ''); - assert( + String notificationId = response.replaceAll('data:', ''); + assert( (!response.contains('Invalid syntax')) && (!response.contains('null'))); - // notify status - response = await getNotifyStatus(sh1, notificationId, - returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); - print('notify status response : $response'); - expect(response, contains('data:delivered')); - var timeAfterNotification = DateTime.now().millisecondsSinceEpoch; - var timeDifferenceValue = + // notify status + response = await getNotifyStatus(sh1, notificationId, + returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); + print('notify status response : $response'); + expect(response, contains('data:delivered')); + var timeAfterNotification = DateTime + .now() + .millisecondsSinceEpoch; + var timeDifferenceValue = DateTime.fromMillisecondsSinceEpoch(timeAfterNotification).difference( DateTime.fromMillisecondsSinceEpoch(timeBeforeNotification)); - print('time difference is $timeDifferenceValue'); - expect(timeDifferenceValue.inMilliseconds <= 10000, true); - }); + print('time difference is $timeDifferenceValue'); + expect(timeDifferenceValue.inMilliseconds <= 10000, true); + }); /// The purpose of this test is verify the date time of second notification is correct /// not picked from the earlier notification. @@ -576,7 +599,8 @@ void main() { var notificationIdFromAtSign2 = (await sh2.read()).replaceAll('data:', ''); var atNotificationMap = jsonDecode(notificationIdFromAtSign2); var firstNotificationDateInEpoch = - DateTime.parse(atNotificationMap['notificationDateTime']) + DateTime + .parse(atNotificationMap['notificationDateTime']) .microsecondsSinceEpoch; // Sending second notification @@ -593,63 +617,64 @@ void main() { notificationIdFromAtSign2 = (await sh2.read()).replaceAll('data:', ''); atNotificationMap = jsonDecode(notificationIdFromAtSign2); var secondNotificationDateInEpoch = - DateTime.parse(atNotificationMap['notificationDateTime']) + DateTime + .parse(atNotificationMap['notificationDateTime']) .microsecondsSinceEpoch; expect(secondNotificationDateInEpoch > firstNotificationDateInEpoch, true); }); test('notify verb for notifying a key update with shared key metadata', - () async { - /// NOTIFY VERB - await sh1.writeCommand('notify:update:messageType:key:notifier:SYSTEM' - ':ttln:86400000:ttr:60000:ccd:false' - ':sharedKeyEnc:abc:pubKeyCS:3c55db695d94b304827367a4f5cab8ae' - ':$atSign_2:phone.wavi$atSign_1:Some ciphertext'); - String response = await sh1.read(); - print('notify verb response : $response'); - assert( + () async { + /// NOTIFY VERB + await sh1.writeCommand('notify:update:messageType:key:notifier:SYSTEM' + ':ttln:86400000:ttr:60000:ccd:false' + ':sharedKeyEnc:abc:pubKeyCS:3c55db695d94b304827367a4f5cab8ae' + ':$atSign_2:phone.wavi$atSign_1:Some ciphertext'); + String response = await sh1.read(); + print('notify verb response : $response'); + assert( (!response.contains('Invalid syntax')) && (!response.contains('null'))); - String notificationId = response.replaceAll('data:', ''); - - // notify status - response = await getNotifyStatus(sh1, notificationId, - returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); - print('notify status response : $response'); - expect(response, contains('data:delivered')); - - await sh2.writeCommand('llookup:all:cached:$atSign_2:phone.wavi$atSign_1'); - response = await sh2.read(); - response = response.replaceAll('data:', ''); - var decodedResponse = jsonDecode(response); - expect(decodedResponse['key'], 'cached:$atSign_2:phone.wavi$atSign_1'); - expect(decodedResponse['data'], 'Some ciphertext'); - expect(decodedResponse['metaData']['sharedKeyEnc'], 'abc'); - expect(decodedResponse['metaData']['pubKeyCS'], - '3c55db695d94b304827367a4f5cab8ae'); - expect(decodedResponse['metaData']['ttr'], 60000); - }); + String notificationId = response.replaceAll('data:', ''); + + // notify status + response = await getNotifyStatus(sh1, notificationId, + returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); + print('notify status response : $response'); + expect(response, contains('data:delivered')); + + await sh2.writeCommand( + 'llookup:all:cached:$atSign_2:phone.wavi$atSign_1'); + response = await sh2.read(); + response = response.replaceAll('data:', ''); + var decodedResponse = jsonDecode(response); + expect(decodedResponse['key'], 'cached:$atSign_2:phone.wavi$atSign_1'); + expect(decodedResponse['data'], 'Some ciphertext'); + expect(decodedResponse['metaData']['sharedKeyEnc'], 'abc'); + expect(decodedResponse['metaData']['pubKeyCS'], + '3c55db695d94b304827367a4f5cab8ae'); + expect(decodedResponse['metaData']['ttr'], 60000); + }); test('notify verb for notifying a key update with new encryption metadata', - () async { - /// NOTIFY VERB - var sharedKeyEnc = 'abc'; - var pubKeyCS = '3c55db695d94b304827367a4f5cab8ae'; - var encKeyName = 'someEncKeyName'; - var encAlgo = 'AES/CTR/PKCS7Padding'; - var iv = 'anInitializationVector'; - var skeEncKeyName = 'someSkeEncKeyName'; - var skeEncAlgo = 'RSA-2048'; - var ttln = 60 * 1000; // 60 seconds - - if (atSign1ServerVersion < Version(3, 0, 29)) { - // Server version 3.0.28 or earlier will not process new metadata - // No point in trying to send anything - return; - } - - await sh1.writeCommand( - 'notify:update' + () async { + /// NOTIFY VERB + var sharedKeyEnc = 'abc'; + var pubKeyCS = '3c55db695d94b304827367a4f5cab8ae'; + var encKeyName = 'someEncKeyName'; + var encAlgo = 'AES/CTR/PKCS7Padding'; + var iv = 'anInitializationVector'; + var skeEncKeyName = 'someSkeEncKeyName'; + var skeEncAlgo = 'RSA-2048'; + var ttln = 60 * 1000; // 60 seconds + + if (atSign1ServerVersion < Version(3, 0, 29)) { + // Server version 3.0.28 or earlier will not process new metadata + // No point in trying to send anything + return; + } + + await sh1.writeCommand('notify:update' ':messageType:key' ':notifier:SYSTEM' ':ttln:$ttln' @@ -664,245 +689,247 @@ void main() { ':skeEncAlgo:$skeEncAlgo' ':$atSign_2:phone.wavi$atSign_1' ':Some ciphertext'); - String response = await sh1.read(); - print('notify verb response : $response'); - assert( + String response = await sh1.read(); + print('notify verb response : $response'); + assert( (!response.contains('Invalid syntax')) && (!response.contains('null'))); - String notificationId = response.replaceAll('data:', ''); - - // notify status - response = await getNotifyStatus(sh1, notificationId, - returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); - print('notify status response : $response'); - expect(response, contains('data:delivered')); - - await sh2.writeCommand('llookup:all:cached:$atSign_2:phone.wavi$atSign_1'); - response = await sh2.read(); - response = response.replaceAll('data:', ''); - var decodedResponse = jsonDecode(response); - expect(decodedResponse['key'], 'cached:$atSign_2:phone.wavi$atSign_1'); - expect(decodedResponse['data'], 'Some ciphertext'); - expect(decodedResponse['metaData']['sharedKeyEnc'], sharedKeyEnc); - expect(decodedResponse['metaData']['pubKeyCS'], pubKeyCS); - expect(decodedResponse['metaData']['ttr'], 10); - - if (atSign2ServerVersion > Version(3, 0, 28)) { - expect(decodedResponse['metaData']['encKeyName'], encKeyName); - expect(decodedResponse['metaData']['encAlgo'], encAlgo); - expect(decodedResponse['metaData']['ivNonce'], iv); - expect(decodedResponse['metaData']['skeEncKeyName'], skeEncKeyName); - expect(decodedResponse['metaData']['skeEncAlgo'], skeEncAlgo); - } else { - expect(decodedResponse['metaData']['encKeyName'], null); - expect(decodedResponse['metaData']['encAlgo'], null); - expect(decodedResponse['metaData']['ivNonce'], null); - expect(decodedResponse['metaData']['skeEncKeyName'], null); - expect(decodedResponse['metaData']['skeEncAlgo'], null); - } - }); + String notificationId = response.replaceAll('data:', ''); + + // notify status + response = await getNotifyStatus(sh1, notificationId, + returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); + print('notify status response : $response'); + expect(response, contains('data:delivered')); + + await sh2.writeCommand( + 'llookup:all:cached:$atSign_2:phone.wavi$atSign_1'); + response = await sh2.read(); + response = response.replaceAll('data:', ''); + var decodedResponse = jsonDecode(response); + expect(decodedResponse['key'], 'cached:$atSign_2:phone.wavi$atSign_1'); + expect(decodedResponse['data'], 'Some ciphertext'); + expect(decodedResponse['metaData']['sharedKeyEnc'], sharedKeyEnc); + expect(decodedResponse['metaData']['pubKeyCS'], pubKeyCS); + expect(decodedResponse['metaData']['ttr'], 10); + + if (atSign2ServerVersion > Version(3, 0, 28)) { + expect(decodedResponse['metaData']['encKeyName'], encKeyName); + expect(decodedResponse['metaData']['encAlgo'], encAlgo); + expect(decodedResponse['metaData']['ivNonce'], iv); + expect(decodedResponse['metaData']['skeEncKeyName'], skeEncKeyName); + expect(decodedResponse['metaData']['skeEncAlgo'], skeEncAlgo); + } else { + expect(decodedResponse['metaData']['encKeyName'], null); + expect(decodedResponse['metaData']['encAlgo'], null); + expect(decodedResponse['metaData']['ivNonce'], null); + expect(decodedResponse['metaData']['skeEncKeyName'], null); + expect(decodedResponse['metaData']['skeEncAlgo'], null); + } + }); group('A group of tests related to notify ephemeral', () { test( 'notify verb without ttr for messageType-key and operation type - update and with value', - () async { - // The notify ephemeral changes are not into Canary and production. - // So, no point in running against and Canary and Prod servers.` - if (atSign1ServerVersion < Version(3, 0, 36)) { - return; - } - /// NOTIFY VERB - var value = 'testingvalue'; - await sh2.writeCommand( - 'notify:update:messageType:key:$atSign_1:testkey$atSign_2:$value'); - String response = await sh2.read(); - print('notify verb response : $response'); - assert((!response.contains('Invalid syntax')) && - (!response.contains('null'))); - String notificationId = response.replaceAll('data:', ''); - - // notify status - response = await getNotifyStatus(sh2, notificationId, - returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); - print('notify status response : $response'); - assert(response.contains('data:delivered')); - - ///notify:list verb - await sh1.writeCommand('notify:list'); - response = await sh1.read(); - print('notify list verb response : $response'); - expect( - response, - contains( - '"key":"$atSign_1:testkey$atSign_2","value":"$value","operation":"update"')); - }); + () async { + // The notify ephemeral changes are not into Canary and production. + // So, no point in running against and Canary and Prod servers.` + if (atSign1ServerVersion < Version(3, 0, 36)) { + return; + } + + /// NOTIFY VERB + var value = 'testingvalue'; + await sh2.writeCommand( + 'notify:update:messageType:key:$atSign_1:testkey$atSign_2:$value'); + String response = await sh2.read(); + print('notify verb response : $response'); + assert((!response.contains('Invalid syntax')) && + (!response.contains('null'))); + String notificationId = response.replaceAll('data:', ''); + + // notify status + response = await getNotifyStatus(sh2, notificationId, + returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); + print('notify status response : $response'); + assert(response.contains('data:delivered')); + + ///notify:list verb + await sh1.writeCommand('notify:list'); + response = await sh1.read(); + print('notify list verb response : $response'); + expect( + response, + contains( + '"key":"$atSign_1:testkey$atSign_2","value":"$value","operation":"update"')); + }); test('notify verb without ttr and without value for operation type update', - () async { - // The notify ephemeral changes are not into Canary and production. - // So, no point in running against and Canary and Prod servers.` - if (atSign1ServerVersion < Version(3, 0, 36)) { - return; - } - - /// NOTIFY VERB - await sh2.writeCommand('notify:update:$atSign_1:nottrkey$atSign_2'); - String response = await sh2.read(); - print('notify verb response : $response'); - assert((!response.contains('Invalid syntax')) && - (!response.contains('null'))); - String notificationId = response.replaceAll('data:', ''); - - // notify status - response = await getNotifyStatus(sh2, notificationId, - returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); - print('notify status response : $response'); - assert(response.contains('data:delivered')); - - ///notify:list verb - await sh1.writeCommand('notify:list'); - response = await sh1.read(); - print('notify list verb response : $response'); - expect( - response, - contains( - '"key":"$atSign_1:nottrkey$atSign_2","value":null,"operation":"update"')); - }); + () async { + // The notify ephemeral changes are not into Canary and production. + // So, no point in running against and Canary and Prod servers.` + if (atSign1ServerVersion < Version(3, 0, 36)) { + return; + } + + /// NOTIFY VERB + await sh2.writeCommand('notify:update:$atSign_1:nottrkey$atSign_2'); + String response = await sh2.read(); + print('notify verb response : $response'); + assert((!response.contains('Invalid syntax')) && + (!response.contains('null'))); + String notificationId = response.replaceAll('data:', ''); + + // notify status + response = await getNotifyStatus(sh2, notificationId, + returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); + print('notify status response : $response'); + assert(response.contains('data:delivered')); + + ///notify:list verb + await sh1.writeCommand('notify:list'); + response = await sh1.read(); + print('notify list verb response : $response'); + expect( + response, + contains( + '"key":"$atSign_1:nottrkey$atSign_2","value":null,"operation":"update"')); + }); test( 'notify verb without ttr for messageType-text and operation type - update', - () async { - // The notify ephemeral changes are not into Canary and production. - // So, no point in running against and Canary and Prod servers.` - if (atSign1ServerVersion < Version(3, 0, 36)) { - return; - } - - /// NOTIFY VERB - await sh2.writeCommand( - 'notify:update:messageType:text:$atSign_1:hello_world$atSign_2'); - String response = await sh2.read(); - print('notify verb response : $response'); - assert((!response.contains('Invalid syntax')) && - (!response.contains('null'))); - String notificationId = response.replaceAll('data:', ''); - - // notify status - response = await getNotifyStatus(sh2, notificationId, - returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); - print('notify status response : $response'); - assert(response.contains('data:delivered')); - - ///notify:list verb - await sh1.writeCommand('notify:list'); - response = await sh1.read(); - print('notify list verb response : $response'); - expect( - response, - contains( - '"key":"$atSign_1:hello_world","value":null,"operation":"update"')); - }); + () async { + // The notify ephemeral changes are not into Canary and production. + // So, no point in running against and Canary and Prod servers.` + if (atSign1ServerVersion < Version(3, 0, 36)) { + return; + } + + /// NOTIFY VERB + await sh2.writeCommand( + 'notify:update:messageType:text:$atSign_1:hello_world$atSign_2'); + String response = await sh2.read(); + print('notify verb response : $response'); + assert((!response.contains('Invalid syntax')) && + (!response.contains('null'))); + String notificationId = response.replaceAll('data:', ''); + + // notify status + response = await getNotifyStatus(sh2, notificationId, + returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); + print('notify status response : $response'); + assert(response.contains('data:delivered')); + + ///notify:list verb + await sh1.writeCommand('notify:list'); + response = await sh1.read(); + print('notify list verb response : $response'); + expect( + response, + contains( + '"key":"$atSign_1:hello_world","value":null,"operation":"update"')); + }); test( 'notify verb without ttr for messageType-text and operation type - delete', - () async { - // The notify ephemeral changes are not into Canary and production. - // So, no point in running against and Canary and Prod servers.` - if (atSign1ServerVersion < Version(3, 0, 36)) { - return; - } - - /// NOTIFY VERB - await sh2.writeCommand( - 'notify:delete:messageType:text:$atSign_1:hello_world$atSign_2'); - String response = await sh2.read(); - print('notify verb response : $response'); - assert((!response.contains('Invalid syntax')) && - (!response.contains('null'))); - String notificationId = response.replaceAll('data:', ''); - - // notify status - response = await getNotifyStatus(sh2, notificationId, - returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); - print('notify status response : $response'); - assert(response.contains('data:delivered')); - - ///notify:list verb - await sh1.writeCommand('notify:list'); - response = await sh1.read(); - print('notify list verb response : $response'); - expect( - response, - contains( - '"key":"$atSign_1:hello_world","value":null,"operation":"delete"')); - }); + () async { + // The notify ephemeral changes are not into Canary and production. + // So, no point in running against and Canary and Prod servers.` + if (atSign1ServerVersion < Version(3, 0, 36)) { + return; + } + + /// NOTIFY VERB + await sh2.writeCommand( + 'notify:delete:messageType:text:$atSign_1:hello_world$atSign_2'); + String response = await sh2.read(); + print('notify verb response : $response'); + assert((!response.contains('Invalid syntax')) && + (!response.contains('null'))); + String notificationId = response.replaceAll('data:', ''); + + // notify status + response = await getNotifyStatus(sh2, notificationId, + returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); + print('notify status response : $response'); + assert(response.contains('data:delivered')); + + ///notify:list verb + await sh1.writeCommand('notify:list'); + response = await sh1.read(); + print('notify list verb response : $response'); + expect( + response, + contains( + '"key":"$atSign_1:hello_world","value":null,"operation":"delete"')); + }); test( 'notify verb without ttr and without value for operation type update (self notification)', - () async { - // The notify ephemeral changes are not into Canary and production. - // So, no point in running against and Canary and Prod servers.` - if (atSign1ServerVersion < Version(3, 0, 36)) { - return; - } - - /// NOTIFY VERB - await sh2.writeCommand('notify:update:$atSign_2:nottrkey$atSign_2'); - String response = await sh2.read(); - print('notify verb response : $response'); - assert((!response.contains('Invalid syntax')) && - (!response.contains('null'))); - String notificationId = response.replaceAll('data:', ''); - - // notify status - response = await getNotifyStatus(sh2, notificationId, - returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); - print('notify status response : $response'); - assert(response.contains('data:delivered')); - - ///notify:list verb - await sh2.writeCommand('notify:list'); - response = await sh2.read(); - print('notify list verb response : $response'); - expect( - response, - contains( - '"key":"$atSign_2:nottrkey$atSign_2","value":null,"operation":"update"')); - }); + () async { + // The notify ephemeral changes are not into Canary and production. + // So, no point in running against and Canary and Prod servers.` + if (atSign1ServerVersion < Version(3, 0, 36)) { + return; + } + + /// NOTIFY VERB + await sh2.writeCommand('notify:update:$atSign_2:nottrkey$atSign_2'); + String response = await sh2.read(); + print('notify verb response : $response'); + assert((!response.contains('Invalid syntax')) && + (!response.contains('null'))); + String notificationId = response.replaceAll('data:', ''); + + // notify status + response = await getNotifyStatus(sh2, notificationId, + returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); + print('notify status response : $response'); + assert(response.contains('data:delivered')); + + ///notify:list verb + await sh2.writeCommand('notify:list'); + response = await sh2.read(); + print('notify list verb response : $response'); + expect( + response, + contains( + '"key":"$atSign_2:nottrkey$atSign_2","value":null,"operation":"update"')); + }); test( 'notify verb without ttr and with value for operation type update (self notification)', - () async { - // The notify ephemeral changes are not into Canary and production. - // So, no point in running against and Canary and Prod servers.` - if (atSign1ServerVersion < Version(3, 0, 36)) { - return; - } - - /// NOTIFY VERB - var value = 'no-ttr'; - await sh2 - .writeCommand('notify:update:$atSign_2:nottrkey$atSign_2:$value'); - String response = await sh2.read(); - print('notify verb response : $response'); - assert((!response.contains('Invalid syntax')) && - (!response.contains('null'))); - String notificationId = response.replaceAll('data:', ''); - - // notify status - response = await getNotifyStatus(sh2, notificationId, - returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); - print('notify status response : $response'); - assert(response.contains('data:delivered')); - - ///notify:list verb - await sh2.writeCommand('notify:list'); - response = await sh2.read(); - print('notify list verb response : $response'); - expect( - response, - contains( - '"key":"$atSign_2:nottrkey$atSign_2","value":"$value","operation":"update"')); - }); + () async { + // The notify ephemeral changes are not into Canary and production. + // So, no point in running against and Canary and Prod servers.` + if (atSign1ServerVersion < Version(3, 0, 36)) { + return; + } + + /// NOTIFY VERB + var value = 'no-ttr'; + await sh2 + .writeCommand('notify:update:$atSign_2:nottrkey$atSign_2:$value'); + String response = await sh2.read(); + print('notify verb response : $response'); + assert((!response.contains('Invalid syntax')) && + (!response.contains('null'))); + String notificationId = response.replaceAll('data:', ''); + + // notify status + response = await getNotifyStatus(sh2, notificationId, + returnWhenStatusIn: ['delivered'], timeOutMillis: 15000); + print('notify status response : $response'); + assert(response.contains('data:delivered')); + + ///notify:list verb + await sh2.writeCommand('notify:list'); + response = await sh2.read(); + print('notify list verb response : $response'); + expect( + response, + contains( + '"key":"$atSign_2:nottrkey$atSign_2","value":"$value","operation":"update"')); + }); test('notify verb without ttr for operation type delete', () async { // The notify ephemeral changes are not into Canary and production. @@ -938,8 +965,8 @@ void main() { } // get notify status -Future getNotifyStatus( - e2e.SimpleOutboundSocketHandler sh, String notificationId, +Future getNotifyStatus(e2e.SimpleOutboundSocketHandler sh, + String notificationId, {List? returnWhenStatusIn, int timeOutMillis = 5000}) async { returnWhenStatusIn ??= ['expired']; print( @@ -950,8 +977,12 @@ Future getNotifyStatus( String response = 'NO_RESPONSE'; bool readTimedOut = false; - int endTime = DateTime.now().millisecondsSinceEpoch + timeOutMillis; - while (DateTime.now().millisecondsSinceEpoch < endTime) { + int endTime = DateTime + .now() + .millisecondsSinceEpoch + timeOutMillis; + while (DateTime + .now() + .millisecondsSinceEpoch < endTime) { await Future.delayed(Duration(milliseconds: loopDelay)); if (!readTimedOut) { @@ -961,7 +992,7 @@ Future getNotifyStatus( log: true, timeoutMillis: loopDelay, throwTimeoutException: false); readTimedOut = - (response == e2e.SimpleOutboundSocketHandler.readTimedOutMessage); + (response == e2e.SimpleOutboundSocketHandler.readTimedOutMessage); if (response.startsWith('data:')) { String status = response.replaceFirst('data:', '').replaceAll('\n', ''); @@ -987,8 +1018,12 @@ Future retryCommandUntilMatchOrTimeout( String response = 'NO_RESPONSE'; bool readTimedOut = false; - int endTime = DateTime.now().millisecondsSinceEpoch + timeoutMillis; - while (DateTime.now().millisecondsSinceEpoch < endTime) { + int endTime = DateTime + .now() + .millisecondsSinceEpoch + timeoutMillis; + while (DateTime + .now() + .millisecondsSinceEpoch < endTime) { await Future.delayed(Duration(milliseconds: loopDelay)); if (!readTimedOut) { @@ -999,7 +1034,7 @@ Future retryCommandUntilMatchOrTimeout( log: false, timeoutMillis: loopDelay, throwTimeoutException: false); readTimedOut = - (response == e2e.SimpleOutboundSocketHandler.readTimedOutMessage); + (response == e2e.SimpleOutboundSocketHandler.readTimedOutMessage); if (readTimedOut) { continue; }