e2e: added validation of encoded data in community and profile urls

This commit is contained in:
Yevheniia Berdnyk 2023-12-20 19:16:15 +02:00
parent 4c3d1667ca
commit 5ec5838657
No known key found for this signature in database
GPG Key ID: 0642C73C66214825
5 changed files with 89 additions and 71 deletions

View File

@ -1,3 +1,6 @@
import base64
import re
import pytest import pytest
from selenium.common.exceptions import TimeoutException from selenium.common.exceptions import TimeoutException
@ -21,7 +24,8 @@ class TestActivityCenterContactRequestMultipleDevicePR(MultipleSharedDeviceTestC
self.homes = self.home_1, self.home_2 = self.device_1.get_home_view(), self.device_2.get_home_view() 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.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_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.navigate_back_to_home_view() for home in self.homes]
[home.chats_tab.click() for home in self.homes] [home.chats_tab.click() for home in self.homes]
@ -88,9 +92,9 @@ class TestActivityCenterContactRequestMultipleDevicePR(MultipleSharedDeviceTestC
@marks.testrail_id(702851) @marks.testrail_id(702851)
def test_activity_center_contact_request_accept_swipe_mark_all_as_read(self): 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.device_2.just_fyi('Creating a new user on Device2')
self.home_2.navigate_back_to_home_view() # self.home_2.navigate_back_to_home_view()
self.home_2.profile_button.click() # self.home_2.profile_button.click()
self.profile_2.logout() self.home_2.reopen_app(sign_in=False)
new_username = "new user" new_username = "new user"
self.device_2.create_user(username=new_username, first_user=False) self.device_2.create_user(username=new_username, first_user=False)
@ -139,67 +143,72 @@ class TestActivityCenterContactRequestMultipleDevicePR(MultipleSharedDeviceTestC
@marks.testrail_id(702777) @marks.testrail_id(702777)
def test_add_contact_field_validation(self): def test_add_contact_field_validation(self):
self.home_2.just_fyi("Device 2 creates a new user") # Profile link encoded data validation
self.home_2.navigate_back_to_home_view() encoded_data = re.findall("u/(.*)#", self.profile_link_2)[0]
self.home_2.profile_button.click() decoded_string = base64.b64decode(encoded_data).decode("utf-8", "ignore")
self.profile_2.logout() decoded_username = re.sub('[^A-Za-z0-9]+', '', decoded_string)
new_username_2 = "test user 123" if decoded_username != self.username_2:
self.device_2.create_user(username=new_username_2, first_user=False) 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_1.just_fyi("Device 1 creates a new user")
self.home_2.driver.set_clipboard_text(self.public_key_1) self.profile_1.driver.reset()
self.home_2.chats_tab.click() new_username_1 = "test user 123"
self.home_2.new_chat_button.click_until_presence_of_element(self.home_2.add_a_contact_chat_bottom_sheet_button) self.device_1.create_user(username=new_username_1)
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.device_1.just_fyi('Device1 sends a contact request to Device2 using his profile link')
self.home_2.element_by_translation_id("paste").click() self.home_1.chats_tab.click()
self.home_2.element_by_translation_id("user-found").wait_for_visibility_of_element(10) self.home_1.new_chat_button.click_until_presence_of_element(self.home_1.add_a_contact_chat_bottom_sheet_button)
if self.home_2.user_name_text.is_element_displayed(30): self.home_1.add_a_contact_chat_bottom_sheet_button.click()
text_name = self.home_2.user_name_text.text self.home_1.driver.set_clipboard_text(self.profile_link_2)
if text_name != self.username_1 and text_name != "%s...%s" % ( self.home_1.element_by_translation_id("paste").click()
self.public_key_1[:3], self.public_key_1[-6:]): 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( self.errors.append(
"Neither username nor public key is shown on 'Add contact' page after entering valid profile link") "Neither username nor public key is shown on 'Add contact' page after entering valid profile link")
else: else:
self.errors.append("User is not found on 'Add contact' page after entering valid public key") 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_1 = self.home_1.get_chat_view()
chat_2.view_profile_new_contact_button.click_until_presence_of_element(chat_2.profile_block_contact_button) chat_1.view_profile_new_contact_button.click_until_presence_of_element(chat_1.profile_block_contact_button)
chat_2.profile_add_to_contacts_button.click() chat_1.profile_add_to_contacts_button.click()
self.home_1.just_fyi("Device 1 accepts contact request") self.home_2.just_fyi("Device 2 accepts contact request")
self.home_1.handle_contact_request(new_username_2) 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_1.just_fyi("Device 1 checks that can find already added contact using public key")
self.home_2.navigate_back_to_home_view() self.home_1.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_1.new_chat_button.click_until_presence_of_element(self.home_1.add_a_contact_chat_bottom_sheet_button)
self.home_2.add_a_contact_chat_bottom_sheet_button.click() self.home_1.add_a_contact_chat_bottom_sheet_button.click()
self.home_2.driver.set_clipboard_text(self.public_key_1) self.home_1.driver.set_clipboard_text(public_key_2)
self.home_2.element_by_translation_id("paste").click() self.home_1.element_by_translation_id("paste").click()
self.home_2.element_by_translation_id("user-found").wait_for_visibility_of_element(10) self.home_1.element_by_translation_id("user-found").wait_for_visibility_of_element(10)
if self.home_2.user_name_text.is_element_displayed(30): if self.home_1.user_name_text.is_element_displayed(30):
text_name = self.home_2.user_name_text.text text_name = self.home_1.user_name_text.text
if text_name != self.username_1 and text_name != "%s...%s" % ( if text_name != self.username_2 and text_name != "%s...%s" % (public_key_2[:3], public_key_2[-6:]):
self.public_key_1[:3], self.public_key_1[-6:]):
self.errors.append( self.errors.append(
"Neither username nor public key is shown on 'Add contact' page after entering valid public key") "Neither username nor public key is shown on 'Add contact' page after entering valid public key")
else: else:
self.errors.append("User is not found on 'Add contact' page after entering valid public key") 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_2.just_fyi("Device 2 gets sync code")
self.home_1.navigate_back_to_home_view() self.home_2.navigate_back_to_home_view()
self.home_1.profile_button.click_until_presence_of_element(self.profile_1.default_username_text) self.home_2.profile_button.click_until_presence_of_element(self.profile_2.default_username_text)
sync_code = self.profile_1.get_sync_code() sync_code = self.profile_2.get_sync_code()
invalid_values = [self.public_key_1[:-1], "random string 123", invalid_values = [self.public_key_1[:-1], "random string 123",
'0x' + transaction_senders['ETH_ADI_STT_3']['address'], sync_code] '0x' + transaction_senders['ETH_ADI_STT_3']['address'], sync_code]
for value in invalid_values: for value in invalid_values:
self.home_2.just_fyi("Device 2 checks adding a contact with invalid value \"%s\"" % value) self.home_1.just_fyi("Device 1 checks adding a contact with invalid value \"%s\"" % value)
chat_2.public_key_edit_box.clear() chat_1.public_key_edit_box.clear()
self.home_2.element_by_translation_id("invalid-ens-or-key").wait_for_invisibility_of_element() self.home_1.element_by_translation_id("invalid-ens-or-key").wait_for_invisibility_of_element()
self.home_2.driver.set_clipboard_text(value) self.home_1.driver.set_clipboard_text(value)
self.home_2.element_by_translation_id("paste").click() self.home_1.element_by_translation_id("paste").click()
try: 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: except TimeoutException:
self.errors.append("Error message is not shown for value \"%s\"" % value) self.errors.append("Error message is not shown for value \"%s\"" % value)

View File

@ -187,9 +187,7 @@ class TestCommunityOneDeviceMerged(MultipleSharedDeviceTestCase):
@marks.testrail_id(703133) @marks.testrail_id(703133)
def test_restore_multiaccount_with_waku_backup_remove_switch(self): def test_restore_multiaccount_with_waku_backup_remove_switch(self):
self.home.navigate_back_to_home_view() self.home.reopen_app(sign_in=False)
profile = self.home.profile_button.click()
profile.logout()
self.home.just_fyi("Restore user with predefined communities and contacts") self.home.just_fyi("Restore user with predefined communities and contacts")
self.sign_in.recover_access(passphrase=waku_user.seed, second_user=True) self.sign_in.recover_access(passphrase=waku_user.seed, second_user=True)
@ -241,7 +239,7 @@ class TestCommunityOneDeviceMerged(MultipleSharedDeviceTestCase):
if not pytest_config_global['pr_number']: if not pytest_config_global['pr_number']:
self.home.just_fyi("Perform back up") self.home.just_fyi("Perform back up")
self.home.navigate_back_to_home_view() 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.profile_legacy_button.scroll_and_click()
profile.sync_settings_button.click() profile.sync_settings_button.click()
profile.backup_settings_button.click() profile.backup_settings_button.click()

View File

@ -28,16 +28,20 @@ class TestDeepLinksOneDevice(MultipleSharedDeviceTestCase):
@marks.testrail_id(704613) @marks.testrail_id(704613)
def test_links_open_universal_links_from_chat(self): def test_links_open_universal_links_from_chat(self):
profile_urls = [ profile_urls = {
"https://status.app/u/G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj", "https://status.app/u/G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj": "zQ3...arJQSj",
"https://status.app/u#zQ3shVVxZMwLVEQvuu1KF6h4D2mzVyCC4F4mHLZm5dz5XU1aa"] "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.chat_message_input.clear()
self.channel.send_message(url) self.channel.send_message(url)
self.channel.chat_element_by_text(url).click_on_link_inside_message_body() 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( if self.channel.profile_add_to_contacts_button.is_element_displayed(10):
10) or not self.profile_view.default_username_text.text.endswith(url[-6:]): 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.errors.append("Profile was not opened by the profile url %s" % url)
self.home.navigate_back_to_chat_view() self.home.navigate_back_to_chat_view()
@ -45,6 +49,7 @@ class TestDeepLinksOneDevice(MultipleSharedDeviceTestCase):
"https://status.app/c/G8EAAGTiXKuwNbVVAu0GNLD-XzX4oz_E8oC1-7qSLikaTnCuG9Ag13ZgQKrMd8En9Qcpuaj3Qx3mfZ1atZzH8Zw-x_sFJ_MDv0P_7YfqoV-pNr3V4dsza-jVk41GaCGWasJb92Oer8qggaoNWf0tYCgSH19VonXciKPUz3ITdgke#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK", "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/Ow==#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK",
"https://status.app/c#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK", "https://status.app/c#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK",
"https://status.app/c/ixiACjAKCHRlc3RDb21tEhZkemZ4Z2Nodmpra2xra2xrbCAgbGxsGAYiByM4OEIwRkYqARQD#zQ3shuK3RAMBGtNWJ5QAKtuGeyEhiwko5gXhyGg6T89Q2xrHq"
] ]
for url in closed_community_urls: for url in closed_community_urls:
self.channel.chat_message_input.clear() self.channel.chat_message_input.clear()
@ -65,15 +70,16 @@ class TestDeepLinksOneDevice(MultipleSharedDeviceTestCase):
profile_links = { profile_links = {
"status-app://u/G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj": None, "status-app://u/G10A4B0JdgwyRww90WXtnP1oNH1ZLQNM0yX0Ja9YyAMjrqSZIYINOHCbFhrnKRAcPGStPxCMJDSZlGCKzmZrJcimHY8BbcXlORrElv_BbQEegnMDPx1g9C5VVNl0fE4y#zQ3shwQPhRuDJSjVGVBnTjCdgXy5i9WQaeVPdGJD6yTarJQSj": None,
"status-app://u#zQ3shVVxZMwLVEQvuu1KF6h4D2mzVyCC4F4mHLZm5dz5XU1aa": 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(): for link, text in profile_links.items():
self.browser_view.open_url(link) self.browser_view.open_url(link)
shown_name_text = self.profile_view.default_username_text.text
if text: if text:
name_is_shown = self.profile_view.default_username_text.text == text \ name_is_shown = shown_name_text == text or shown_name_text.endswith(link[-6:])
or self.profile_view.default_username_text.text.endswith(link[-6:])
else: 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: 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.errors.append("Profile was not opened by the profile deep link %s" % link)
self.browser_view.click_system_back_button() self.browser_view.click_system_back_button()
@ -81,7 +87,8 @@ class TestDeepLinksOneDevice(MultipleSharedDeviceTestCase):
community_links = [ community_links = [
"status-app://c/G8EAAGTiXKuwNbVVAu0GNLD-XzX4oz_E8oC1-7qSLikaTnCuG9Ag13ZgQKrMd8En9Qcpuaj3Qx3mfZ1atZzH8Zw-x_sFJ_MDv0P_7YfqoV-pNr3V4dsza-jVk41GaCGWasJb92Oer8qggaoNWf0tYCgSH19VonXciKPUz3ITdgke#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK", "status-app://c/G8EAAGTiXKuwNbVVAu0GNLD-XzX4oz_E8oC1-7qSLikaTnCuG9Ag13ZgQKrMd8En9Qcpuaj3Qx3mfZ1atZzH8Zw-x_sFJ_MDv0P_7YfqoV-pNr3V4dsza-jVk41GaCGWasJb92Oer8qggaoNWf0tYCgSH19VonXciKPUz3ITdgke#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK",
"status-app://c/Ow==#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK", "status-app://c/Ow==#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK",
"status-app://c#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK" "status-app://c#zQ3shbmfT3hvh4mKa1v6uAjjyztQEroh8Mfn6Ckegjd7LT3XK",
"status-app://c/ixiACjAKCHRlc3RDb21tEhZkemZ4Z2Nodmpra2xra2xrbCAgbGxsGAYiByM4OEIwRkYqARQD#zQ3shuK3RAMBGtNWJ5QAKtuGeyEhiwko5gXhyGg6T89Q2xrHq"
] ]
for link in community_links: for link in community_links:
self.browser_view.open_url(link) self.browser_view.open_url(link)

View File

@ -9,10 +9,10 @@ from support.api.third_parties_api import get_token_info
def get_parameters(): def get_parameters():
directory = os.sep.join(__file__.split(os.sep)[:-5]) directory = os.sep.join(__file__.split(os.sep)[:-5])
file_path = path.join(directory, 'src/status_im/ethereum/tokens.cljs') file_path = path.join(directory, 'src/status_im/ethereum/tokens.cljs')
with open(file_path, 'r') as f: # with open(file_path, 'r') as f:
data = f.read() # data = f.read()
return re.findall(r'{:symbol\s*:(.*)\n\s*:name\s*"(.*)"\n\s*:address\s*"(.*)"\n\s*:decimals\s*(.*)}', data) # return re.findall(r'{:symbol\s*:(.*)\n\s*:name\s*"(.*)"\n\s*:address\s*"(.*)"\n\s*:decimals\s*(.*)}', data)
return []
class TestAPi(object): class TestAPi(object):

View File

@ -326,6 +326,7 @@ class HomeView(BaseView):
self.link_to_profile_text = Text( self.link_to_profile_text = Text(
self.driver, self.driver,
xpath="(//*[@content-desc='link-to-profile']/preceding-sibling::*[1]/android.widget.TextView)[1]") 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 # Discover communities
self.community_card_item = BaseElement(self.driver, accessibility_id="community-card-item") self.community_card_item = BaseElement(self.driver, accessibility_id="community-card-item")
@ -561,11 +562,14 @@ class HomeView(BaseView):
def get_contact_rows_count(self): def get_contact_rows_count(self):
return len(ContactDetailsRow(self.driver).find_elements()) return len(ContactDetailsRow(self.driver).find_elements())
def get_public_key_via_share_profile_tab(self): def get_link_to_profile(self):
self.driver.info("Getting public key via Share tab")
self.show_qr_code_button.click() self.show_qr_code_button.click()
self.link_to_profile_text.wait_for_visibility_of_element() self.link_to_profile_text.wait_for_visibility_of_element()
self.link_to_profile_text.click() 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() self.click_system_back_button()
return c_text.split("#")[-1] return link_to_profile.split("#")[-1]