Add test for NotificationManager::decrypt_push.

GitOrigin-RevId: bdc8c815ad7804c8726cee669d1e781efa796e0d
This commit is contained in:
levlam 2019-03-25 03:12:06 +03:00
parent 8f771b8666
commit fdb870da4d

View File

@ -432,25 +432,34 @@ TEST(Mtproto, socks5) {
} }
TEST(Mtproto, notifications) { TEST(Mtproto, notifications) {
string push = vector<string> pushes = {
"eyJwIjoiSkRnQ3NMRWxEaWhyVWRRN1pYM3J1WVU4TlRBMFhMb0N6UWRNdzJ1cWlqMkdRbVR1WXVvYXhUeFJHaG1QQm8yVElYZFBzX2N3b2RIb3lY" "eyJwIjoiSkRnQ3NMRWxEaWhyVWRRN1pYM3J1WVU4TlRBMFhMb0N6UWRNdzJ1cWlqMkdRbVR1WXVvYXhUeFJHaG1QQm8yVElYZFBzX2N3b2RIb3lY"
"b2drVjM1dVl0UzdWeElNX1FNMDRKMG1mV3ZZWm4zbEtaVlJ0aFVBNGhYUWlaN0pfWDMyZDBLQUlEOWgzRnZwRjNXUFRHQWRaVkdFYzg3bnFPZ3hD" "b2drVjM1dVl0UzdWeElNX1FNMDRKMG1mV3ZZWm4zbEtaVlJ0aFVBNGhYUWlaN0pfWDMyZDBLQUlEOWgzRnZwRjNXUFRHQWRaVkdFYzg3bnFPZ3hD"
"NUNMRkM2SU9fZmVqcEpaV2RDRlhBWWpwc1k2aktrbVNRdFZ1MzE5ZW04UFVieXZudFpfdTNud2hjQ0czMk96TGp4S1kyS1lzU21JZm1GMzRmTmw1" "NUNMRkM2SU9fZmVqcEpaV2RDRlhBWWpwc1k2aktrbVNRdFZ1MzE5ZW04UFVieXZudFpfdTNud2hjQ0czMk96TGp4S1kyS1lzU21JZm1GMzRmTmw1"
"QUxaa2JvY2s2cE5rZEdrak9qYmRLckJyU0ZtWU8tQ0FsRE10dEplZFFnY1U5bVJQdU80b1d2NG5sb1VXS19zSlNTaXdIWEZyb1pWTnZTeFJ0Z1dN" "QUxaa2JvY2s2cE5rZEdrak9qYmRLckJyU0ZtWU8tQ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wRUb9RDApwAFKi45zpv8eb3uPCDAmIQ"; "I54Vs28iBx8IbBO1y5z9WSScgW3JCvFFKP2MXIu7Jow5-cpUx6jXdzwRUb9RDApwAFKi45zpv8eb3uPCDAmIQ";
string decrypted_payload = vector<string> decrypted_payloads = {
"fwAAAHsibG9jX2tleSI6Ik1FU1NBR0VfVEVYVCIsImxvY19hcmdzIjpbIkFyc2VueSBTbWlybm92IiwiYWJjZGVmZyJdLCJjdXN0b20iOnsibXNn" "fwAAAHsibG9jX2tleSI6Ik1FU1NBR0VfVEVYVCIsImxvY19hcmdzIjpbIkFyc2VueSBTbWlybm92IiwiYWJjZGVmZyJdLCJjdXN0b20iOnsibXNn"
"X2lkIjoiNTkwMDQ3IiwiZnJvbV9pZCI6IjYyODE0In0sImJhZGdlIjoiNDA5In0"; "X2lkIjoiNTkwMDQ3IiwiZnJvbV9pZCI6IjYyODE0In0sImJhZGdlIjoiNDA5In0",
push = base64url_decode(push).move_as_ok(); "eyJsb2Nfa2V5IjoiIiwibG9jX2FyZ3MiOltdLCJjdXN0b20iOnsiY2hhbm5lbF9pZCI6IjExNzY4OTU0OTciLCJtYXhfaWQiOiIxMzU5In0sImJh"
"ZGdlIjoiMCJ9"};
key = base64url_decode(key).move_as_ok(); key = base64url_decode(key).move_as_ok();
decrypted_payload = base64url_decode(decrypted_payload).move_as_ok();
auto key_id = DhHandshake::calc_key_id(key); for (size_t i = 0; i < pushes.size(); i++) {
ASSERT_EQ(key_id, NotificationManager::get_push_receiver_id(push).ok()); auto push = base64url_decode(pushes[i]).move_as_ok();
ASSERT_EQ(decrypted_payload, NotificationManager::decrypt_push(key_id, key, push).ok()); auto decrypted_payload = base64url_decode(decrypted_payloads[i]).move_as_ok();
auto key_id = DhHandshake::calc_key_id(key);
ASSERT_EQ(key_id, NotificationManager::get_push_receiver_id(push).ok());
ASSERT_EQ(decrypted_payload, NotificationManager::decrypt_push(key_id, key, push).ok());
}
} }