Skip to content

Commit

Permalink
Merge pull request #49 from Hugo-C/feature/GH-46
Browse files Browse the repository at this point in the history
Add E2E test for latest urls
  • Loading branch information
Hugo-C authored Feb 7, 2024
2 parents 4eed814 + 269d5f3 commit bdab75d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
Binary file modified Doc/website_current_look.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docker-compose.playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
- "80:80"
depends_on:
- jarm_online_api
- playwright_dummy_server

jarm_online_api:
extends:
Expand Down
40 changes: 24 additions & 16 deletions tests/playwright_end_to_end/test_home_page.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,57 @@
import re

import pytest
from playwright.sync_api import Page, expect
from fixtures import home_page # noqa required fixture

INPUT_PLACEHOLDER = "8.8.8.8 | host.com/path"
HOST_TO_SCAN = "playwright_dummy_server_container"
URL_TO_SCAN = f"https://{HOST_TO_SCAN}"
URL_EXPECTED_JARM_RESULT = "21d19d00021d21d00021d19d21d21d1a46380b04d662f0848f508dd171125d"


def test_scan_address(home_page: Page):
url_scanned = "https://playwright_dummy_server_container"
expected_jarm_result = "21d19d00021d21d00021d19d21d21d1a46380b04d662f0848f508dd171125d"
expect(home_page).to_have_title(re.compile("Jarm online"))

submit_scan_address_field = home_page.get_by_placeholder(INPUT_PLACEHOLDER)
submit_scan_address_field.fill(url_scanned)
submit_scan_address_field.fill(URL_TO_SCAN)
submit_scan_address_field.press("Enter")

# check result
result = home_page.get_by_text("Jarm hash is:")
expect(result).to_contain_text(expected_jarm_result)
expect(result).to_contain_text(URL_EXPECTED_JARM_RESULT)
copy_button = home_page.get_by_role("button", name="COPY")
expect(copy_button).to_be_visible() # clipboard button is present

# Alexa overlap is displayed
assert home_page.get_by_text("fake_site_1.com").is_visible()
assert home_page.get_by_text("11th Rank").is_visible()
alexa_overlap_link = home_page.get_by_role("link", name="1 other matching domains")
expect(alexa_overlap_link).to_have_attribute("href", f"/api/v1/alexa-overlap?jarm_hash={expected_jarm_result}")
expect(alexa_overlap_link).to_have_attribute("href", f"/api/v1/alexa-overlap?jarm_hash={URL_EXPECTED_JARM_RESULT}")


@pytest.mark.skip(reason="TODO implement feature and rewrite tests")
def test_latest_urls(home_page: Page):
latest_url_header = home_page.get_by_role("heading", name=re.compile("Latest urls .+"))
expect(latest_url_header).to_be_visible()

# Check details of each url in the list and collapse it afterwards
for i in range(5):
url_detail_button = home_page.get_by_role("button", name=f"URL {i + 1}")
url_detail = home_page.get_by_text(text=f"JARM and it's maliciousness about URL {i + 1}", exact=True)
# Submit an url for it to appears in latest urls
submit_scan_address_field = home_page.get_by_placeholder(INPUT_PLACEHOLDER)
submit_scan_address_field.fill(URL_TO_SCAN)
submit_scan_address_field.press("Enter")

expect(url_detail).to_be_hidden()
url_detail_button.click()
expect(url_detail).not_to_be_hidden()
url_detail_button.click()
expect(url_detail).to_be_hidden()
# Hide the result so it won't interfere with tests
submit_scan_address_field.fill("")
submit_scan_address_field.press("Enter")
result = home_page.get_by_text("Jarm hash is:")
expect(result).to_be_hidden() # sanity check

# TODO when port parsing works, try multiple latest url
latest_url_title = home_page.get_by_text(HOST_TO_SCAN)
latest_url_result = home_page.get_by_text(URL_EXPECTED_JARM_RESULT)
expect(latest_url_title).to_be_visible()
expect(latest_url_result).to_be_hidden()
latest_url_title.click()
expect(latest_url_result).to_be_visible()
latest_url_result.all_text_contents()


def test_scan_error_on_invalid_tld(home_page: Page):
Expand Down

0 comments on commit bdab75d

Please sign in to comment.