Skip to content

Commit

Permalink
e2e: added validation of encoded data in community and profile urls
Browse files Browse the repository at this point in the history
  • Loading branch information
yevh-berdnyk committed Dec 20, 2023
1 parent 04184b4 commit 006b481
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 59 deletions.
100 changes: 56 additions & 44 deletions test/appium/tests/activity_center/test_activity_center.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import base64
import re

import pytest
from selenium.common.exceptions import TimeoutException

Expand All @@ -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()
[home.navigate_back_to_home_view() for home in self.homes]
[home.chats_tab.click() for home in self.homes]

Expand Down Expand Up @@ -139,66 +143,74 @@ 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.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.home_1.navigate_back_to_home_view()
self.home_1.profile_button.click()
self.profile_1.logout()
new_username_1 = "test user 123"
self.device_1.create_user(username=new_username_1, first_user=False)

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)

Expand Down
29 changes: 18 additions & 11 deletions test/appium/tests/critical/test_deep_and_universal_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,28 @@ 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()

closed_community_urls = [
"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()
Expand All @@ -65,23 +70,25 @@ 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()

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)
Expand Down
12 changes: 8 additions & 4 deletions test/appium/views/home_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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]

0 comments on commit 006b481

Please sign in to comment.