From 5ec58386575415ee6ea1b3ae6e3226176faa93d0 Mon Sep 17 00:00:00 2001 From: Yevheniia Berdnyk Date: Wed, 20 Dec 2023 19:16:15 +0200 Subject: [PATCH] e2e: added validation of encoded data in community and profile urls --- .../activity_center/test_activity_center.py | 105 ++++++++++-------- .../chats/test_public_chat_browsing.py | 6 +- .../critical/test_deep_and_universal_links.py | 29 +++-- test/appium/tests/non_func/test_api.py | 8 +- test/appium/views/home_view.py | 12 +- 5 files changed, 89 insertions(+), 71 deletions(-) diff --git a/test/appium/tests/activity_center/test_activity_center.py b/test/appium/tests/activity_center/test_activity_center.py index fb64b07bd90..21d792644d7 100644 --- a/test/appium/tests/activity_center/test_activity_center.py +++ b/test/appium/tests/activity_center/test_activity_center.py @@ -1,3 +1,6 @@ +import base64 +import re + import pytest from selenium.common.exceptions import TimeoutException @@ -21,7 +24,8 @@ def prepare_devices(self): self.homes = self.home_1, self.home_2 = self.device_1.get_home_view(), self.device_2.get_home_view() self.profile_1, self.profile_2 = self.home_1.get_profile_view(), self.home_2.get_profile_view() self.public_key_1 = self.home_1.get_public_key() - self.public_key_2 = self.home_2.get_public_key_via_share_profile_tab() + self.profile_link_2 = self.home_2.get_link_to_profile() + self.home_2.close_share_tab_button.click_until_absense_of_element(self.home_2.link_to_profile_text) [home.navigate_back_to_home_view() for home in self.homes] [home.chats_tab.click() for home in self.homes] @@ -88,9 +92,9 @@ def test_activity_center_contact_request_decline(self): @marks.testrail_id(702851) def test_activity_center_contact_request_accept_swipe_mark_all_as_read(self): self.device_2.just_fyi('Creating a new user on Device2') - self.home_2.navigate_back_to_home_view() - self.home_2.profile_button.click() - self.profile_2.logout() + # self.home_2.navigate_back_to_home_view() + # self.home_2.profile_button.click() + self.home_2.reopen_app(sign_in=False) new_username = "new user" self.device_2.create_user(username=new_username, first_user=False) @@ -139,67 +143,72 @@ def test_activity_center_contact_request_accept_swipe_mark_all_as_read(self): @marks.testrail_id(702777) def test_add_contact_field_validation(self): - self.home_2.just_fyi("Device 2 creates a new user") - self.home_2.navigate_back_to_home_view() - self.home_2.profile_button.click() - self.profile_2.logout() - new_username_2 = "test user 123" - self.device_2.create_user(username=new_username_2, first_user=False) + # Profile link encoded data validation + encoded_data = re.findall("u/(.*)#", self.profile_link_2)[0] + decoded_string = base64.b64decode(encoded_data).decode("utf-8", "ignore") + decoded_username = re.sub('[^A-Za-z0-9]+', '', decoded_string) + if decoded_username != self.username_2: + self.errors.append( + "Can't find username '%s' in data which profile link '%s' contains. String '%s' is found instead" % ( + self.username_2, self.profile_link_2, decoded_username)) + public_key_2 = self.profile_link_2.split("#")[-1] - self.device_2.just_fyi('Device2 sends a contact request to Device1 using his profile link') - self.home_2.driver.set_clipboard_text(self.public_key_1) - self.home_2.chats_tab.click() - self.home_2.new_chat_button.click_until_presence_of_element(self.home_2.add_a_contact_chat_bottom_sheet_button) - self.home_2.add_a_contact_chat_bottom_sheet_button.click() - self.home_2.driver.set_clipboard_text("https://status.app/u#" + self.public_key_1) - self.home_2.element_by_translation_id("paste").click() - self.home_2.element_by_translation_id("user-found").wait_for_visibility_of_element(10) - if self.home_2.user_name_text.is_element_displayed(30): - text_name = self.home_2.user_name_text.text - if text_name != self.username_1 and text_name != "%s...%s" % ( - self.public_key_1[:3], self.public_key_1[-6:]): + self.home_1.just_fyi("Device 1 creates a new user") + self.profile_1.driver.reset() + new_username_1 = "test user 123" + self.device_1.create_user(username=new_username_1) + + self.device_1.just_fyi('Device1 sends a contact request to Device2 using his profile link') + self.home_1.chats_tab.click() + self.home_1.new_chat_button.click_until_presence_of_element(self.home_1.add_a_contact_chat_bottom_sheet_button) + self.home_1.add_a_contact_chat_bottom_sheet_button.click() + self.home_1.driver.set_clipboard_text(self.profile_link_2) + self.home_1.element_by_translation_id("paste").click() + self.home_1.element_by_translation_id("user-found").wait_for_visibility_of_element(10) + if self.home_1.user_name_text.is_element_displayed(30): + text_name = self.home_1.user_name_text.text + if text_name != self.username_2 and text_name != "%s...%s" % (public_key_2[:3], public_key_2[-6:]): self.errors.append( "Neither username nor public key is shown on 'Add contact' page after entering valid profile link") else: self.errors.append("User is not found on 'Add contact' page after entering valid public key") - chat_2 = self.home_2.get_chat_view() - chat_2.view_profile_new_contact_button.click_until_presence_of_element(chat_2.profile_block_contact_button) - chat_2.profile_add_to_contacts_button.click() + chat_1 = self.home_1.get_chat_view() + chat_1.view_profile_new_contact_button.click_until_presence_of_element(chat_1.profile_block_contact_button) + chat_1.profile_add_to_contacts_button.click() - self.home_1.just_fyi("Device 1 accepts contact request") - self.home_1.handle_contact_request(new_username_2) + self.home_2.just_fyi("Device 2 accepts contact request") + self.home_2.handle_contact_request(new_username_1) - self.home_2.just_fyi("Device 2 checks that can find already added contact using public key") - self.home_2.navigate_back_to_home_view() - self.home_2.new_chat_button.click_until_presence_of_element(self.home_2.add_a_contact_chat_bottom_sheet_button) - self.home_2.add_a_contact_chat_bottom_sheet_button.click() - self.home_2.driver.set_clipboard_text(self.public_key_1) - self.home_2.element_by_translation_id("paste").click() - self.home_2.element_by_translation_id("user-found").wait_for_visibility_of_element(10) - if self.home_2.user_name_text.is_element_displayed(30): - text_name = self.home_2.user_name_text.text - if text_name != self.username_1 and text_name != "%s...%s" % ( - self.public_key_1[:3], self.public_key_1[-6:]): + self.home_1.just_fyi("Device 1 checks that can find already added contact using public key") + self.home_1.navigate_back_to_home_view() + self.home_1.new_chat_button.click_until_presence_of_element(self.home_1.add_a_contact_chat_bottom_sheet_button) + self.home_1.add_a_contact_chat_bottom_sheet_button.click() + self.home_1.driver.set_clipboard_text(public_key_2) + self.home_1.element_by_translation_id("paste").click() + self.home_1.element_by_translation_id("user-found").wait_for_visibility_of_element(10) + if self.home_1.user_name_text.is_element_displayed(30): + text_name = self.home_1.user_name_text.text + if text_name != self.username_2 and text_name != "%s...%s" % (public_key_2[:3], public_key_2[-6:]): self.errors.append( "Neither username nor public key is shown on 'Add contact' page after entering valid public key") else: self.errors.append("User is not found on 'Add contact' page after entering valid public key") - self.home_1.just_fyi("Device 1 gets sync code") - self.home_1.navigate_back_to_home_view() - self.home_1.profile_button.click_until_presence_of_element(self.profile_1.default_username_text) - sync_code = self.profile_1.get_sync_code() + self.home_2.just_fyi("Device 2 gets sync code") + self.home_2.navigate_back_to_home_view() + self.home_2.profile_button.click_until_presence_of_element(self.profile_2.default_username_text) + sync_code = self.profile_2.get_sync_code() invalid_values = [self.public_key_1[:-1], "random string 123", '0x' + transaction_senders['ETH_ADI_STT_3']['address'], sync_code] for value in invalid_values: - self.home_2.just_fyi("Device 2 checks adding a contact with invalid value \"%s\"" % value) - chat_2.public_key_edit_box.clear() - self.home_2.element_by_translation_id("invalid-ens-or-key").wait_for_invisibility_of_element() - self.home_2.driver.set_clipboard_text(value) - self.home_2.element_by_translation_id("paste").click() + self.home_1.just_fyi("Device 1 checks adding a contact with invalid value \"%s\"" % value) + chat_1.public_key_edit_box.clear() + self.home_1.element_by_translation_id("invalid-ens-or-key").wait_for_invisibility_of_element() + self.home_1.driver.set_clipboard_text(value) + self.home_1.element_by_translation_id("paste").click() try: - self.home_2.element_by_translation_id("invalid-ens-or-key").wait_for_visibility_of_element() + self.home_1.element_by_translation_id("invalid-ens-or-key").wait_for_visibility_of_element() except TimeoutException: self.errors.append("Error message is not shown for value \"%s\"" % value) diff --git a/test/appium/tests/critical/chats/test_public_chat_browsing.py b/test/appium/tests/critical/chats/test_public_chat_browsing.py index 63c14fb7c73..1e6e8f9f7eb 100644 --- a/test/appium/tests/critical/chats/test_public_chat_browsing.py +++ b/test/appium/tests/critical/chats/test_public_chat_browsing.py @@ -187,9 +187,7 @@ def test_community_mute_community_and_channel(self): @marks.testrail_id(703133) def test_restore_multiaccount_with_waku_backup_remove_switch(self): - self.home.navigate_back_to_home_view() - profile = self.home.profile_button.click() - profile.logout() + self.home.reopen_app(sign_in=False) self.home.just_fyi("Restore user with predefined communities and contacts") self.sign_in.recover_access(passphrase=waku_user.seed, second_user=True) @@ -241,7 +239,7 @@ def test_restore_multiaccount_with_waku_backup_remove_switch(self): if not pytest_config_global['pr_number']: self.home.just_fyi("Perform back up") self.home.navigate_back_to_home_view() - self.home.profile_button.click() + profile = self.home.profile_button.click() profile.profile_legacy_button.scroll_and_click() profile.sync_settings_button.click() profile.backup_settings_button.click() diff --git a/test/appium/tests/critical/test_deep_and_universal_links.py b/test/appium/tests/critical/test_deep_and_universal_links.py index c761c9aad2d..c75a42709f2 100644 --- a/test/appium/tests/critical/test_deep_and_universal_links.py +++ b/test/appium/tests/critical/test_deep_and_universal_links.py @@ -28,16 +28,20 @@ def prepare_devices(self): @marks.testrail_id(704613) def test_links_open_universal_links_from_chat(self): - profile_urls = [ - "https://status.app/u/G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj", - "https://status.app/u#zQ3shVVxZMwLVEQvuu1KF6h4D2mzVyCC4F4mHLZm5dz5XU1aa"] + profile_urls = { + "https://status.app/u/G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj": "zQ3...arJQSj", + "https://status.app/u#zQ3shVVxZMwLVEQvuu1KF6h4D2mzVyCC4F4mHLZm5dz5XU1aa": "zQ3...5XU1aa", + "https://status.app/u/CweACg0KC1Rlc3RVc2VyRTJFAw==#zQ3shcFXYnGXxJZnsMThziUNMwyA5uGLp58bLGmfb3qaWD1F6": "TestUserE2E"} - for url in profile_urls: + for url, text in profile_urls.items(): self.channel.chat_message_input.clear() self.channel.send_message(url) self.channel.chat_element_by_text(url).click_on_link_inside_message_body() - if not self.channel.profile_add_to_contacts_button.is_element_displayed( - 10) or not self.profile_view.default_username_text.text.endswith(url[-6:]): + if self.channel.profile_add_to_contacts_button.is_element_displayed(10): + username_text = self.profile_view.default_username_text.text + if not (username_text.endswith(url[-6:]) or username_text == text): + self.errors.append("Incorrect username is shown for profile url %s" % url) + else: self.errors.append("Profile was not opened by the profile url %s" % url) self.home.navigate_back_to_chat_view() @@ -45,6 +49,7 @@ def test_links_open_universal_links_from_chat(self): "https://status.app/c/G8EAAGTiXKuwNbVVAu0GNLD-XzX4oz_E8oC1-7qSLikaTnCuG9Ag13ZgQKrMd8En9Qcpuaj3Qx3mfZ1atZzH8Zw-x_sFJ_MDv0P_7YfqoV-pNr3V4dsza-jVk41GaCGWasJb92Oer8qggaoNWf0tYCgSH19VonXciKPUz3ITdgke#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK", "https://status.app/c/Ow==#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK", "https://status.app/c#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK", + "https://status.app/c/ixiACjAKCHRlc3RDb21tEhZkemZ4Z2Nodmpra2xra2xrbCAgbGxsGAYiByM4OEIwRkYqARQD#zQ3shuK3RAMBGtNWJ5QAKtuGeyEhiwko5gXhyGg6T89Q2xrHq" ] for url in closed_community_urls: self.channel.chat_message_input.clear() @@ -65,15 +70,16 @@ def test_links_deep_links(self): profile_links = { "status-app://u/G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj": None, "status-app://u#zQ3shVVxZMwLVEQvuu1KF6h4D2mzVyCC4F4mHLZm5dz5XU1aa": None, - "status-app://u/Ow==#zQ3shsKnV5HJMWJR61c6dssWzHszdbLfBoMF1gcLtSQAYdw2d": "Restored desktop" + "status-app://u/Ow==#zQ3shsKnV5HJMWJR61c6dssWzHszdbLfBoMF1gcLtSQAYdw2d": "Restored desktop", + "status-app://u/CweACg0KC1Rlc3RVc2VyRTJFAw==#zQ3shcFXYnGXxJZnsMThziUNMwyA5uGLp58bLGmfb3qaWD1F6": "TestUserE2E" } for link, text in profile_links.items(): self.browser_view.open_url(link) + shown_name_text = self.profile_view.default_username_text.text if text: - name_is_shown = self.profile_view.default_username_text.text == text \ - or self.profile_view.default_username_text.text.endswith(link[-6:]) + name_is_shown = shown_name_text == text or shown_name_text.endswith(link[-6:]) else: - name_is_shown = self.profile_view.default_username_text.text.endswith(link[-6:]) + name_is_shown = shown_name_text.endswith(link[-6:]) if not self.channel.profile_add_to_contacts_button.is_element_displayed(10) or not name_is_shown: self.errors.append("Profile was not opened by the profile deep link %s" % link) self.browser_view.click_system_back_button() @@ -81,7 +87,8 @@ def test_links_deep_links(self): community_links = [ "status-app://c/G8EAAGTiXKuwNbVVAu0GNLD-XzX4oz_E8oC1-7qSLikaTnCuG9Ag13ZgQKrMd8En9Qcpuaj3Qx3mfZ1atZzH8Zw-x_sFJ_MDv0P_7YfqoV-pNr3V4dsza-jVk41GaCGWasJb92Oer8qggaoNWf0tYCgSH19VonXciKPUz3ITdgke#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK", "status-app://c/Ow==#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK", - "status-app://c#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK" + "status-app://c#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK", + "status-app://c/ixiACjAKCHRlc3RDb21tEhZkemZ4Z2Nodmpra2xra2xrbCAgbGxsGAYiByM4OEIwRkYqARQD#zQ3shuK3RAMBGtNWJ5QAKtuGeyEhiwko5gXhyGg6T89Q2xrHq" ] for link in community_links: self.browser_view.open_url(link) diff --git a/test/appium/tests/non_func/test_api.py b/test/appium/tests/non_func/test_api.py index 8499430fabd..bf9ab726459 100644 --- a/test/appium/tests/non_func/test_api.py +++ b/test/appium/tests/non_func/test_api.py @@ -9,10 +9,10 @@ def get_parameters(): directory = os.sep.join(__file__.split(os.sep)[:-5]) file_path = path.join(directory, 'src/status_im/ethereum/tokens.cljs') - with open(file_path, 'r') as f: - data = f.read() - return re.findall(r'{:symbol\s*:(.*)\n\s*:name\s*"(.*)"\n\s*:address\s*"(.*)"\n\s*:decimals\s*(.*)}', data) - + # with open(file_path, 'r') as f: + # data = f.read() + # return re.findall(r'{:symbol\s*:(.*)\n\s*:name\s*"(.*)"\n\s*:address\s*"(.*)"\n\s*:decimals\s*(.*)}', data) + return [] class TestAPi(object): diff --git a/test/appium/views/home_view.py b/test/appium/views/home_view.py index 2db4479ffd3..265373fdd5d 100644 --- a/test/appium/views/home_view.py +++ b/test/appium/views/home_view.py @@ -326,6 +326,7 @@ def __init__(self, driver): self.link_to_profile_text = Text( self.driver, xpath="(//*[@content-desc='link-to-profile']/preceding-sibling::*[1]/android.widget.TextView)[1]") + self.close_share_tab_button = Button(self.driver, accessibility_id="close-shell-share-tab") # Discover communities self.community_card_item = BaseElement(self.driver, accessibility_id="community-card-item") @@ -561,11 +562,14 @@ def contact_details_row(self, username=None, index=None): def get_contact_rows_count(self): return len(ContactDetailsRow(self.driver).find_elements()) - def get_public_key_via_share_profile_tab(self): - self.driver.info("Getting public key via Share tab") + def get_link_to_profile(self): self.show_qr_code_button.click() self.link_to_profile_text.wait_for_visibility_of_element() self.link_to_profile_text.click() - c_text = self.driver.get_clipboard_text() + return self.driver.get_clipboard_text() + + def get_public_key_via_share_profile_tab(self): + self.driver.info("Getting public key via Share tab") + link_to_profile = self.get_link_to_profile() self.click_system_back_button() - return c_text.split("#")[-1] + return link_to_profile.split("#")[-1]