2019-08-07 01:05:03 +03:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
2018-07-21 11:04:18 +03:00
|
|
|
|
2019-06-07 12:59:07 +03:00
|
|
|
import base64
|
2016-12-28 13:05:42 +03:00
|
|
|
import json
|
2017-10-19 19:21:35 +03:00
|
|
|
import os
|
2019-02-08 07:49:22 +03:00
|
|
|
from hashlib import sha256
|
2021-02-22 19:51:32 +03:00
|
|
|
from pathlib import Path
|
2018-07-21 11:04:18 +03:00
|
|
|
from time import sleep
|
2021-02-22 19:51:32 +03:00
|
|
|
from typing import List, Optional, Set, Tuple
|
2019-11-20 16:26:15 +03:00
|
|
|
from urllib.parse import urlparse
|
2016-11-30 03:20:14 +03:00
|
|
|
|
2019-06-18 09:13:34 +03:00
|
|
|
import pytest
|
2018-08-15 17:30:21 +03:00
|
|
|
|
2020-11-24 19:34:04 +03:00
|
|
|
from openwpm import command_sequence, task_manager
|
2021-02-22 19:51:32 +03:00
|
|
|
from openwpm.command_sequence import CommandSequence
|
2021-01-09 13:15:01 +03:00
|
|
|
from openwpm.commands.types import BaseCommand
|
2021-02-22 19:51:32 +03:00
|
|
|
from openwpm.config import BrowserParams, ManagerParams
|
|
|
|
from openwpm.storage.leveldb import LevelDbProvider
|
|
|
|
from openwpm.storage.sql_provider import SQLiteStorageProvider
|
2020-11-19 16:24:06 +03:00
|
|
|
from openwpm.utilities import db_utils
|
|
|
|
|
2019-04-26 20:07:40 +03:00
|
|
|
from . import utilities
|
2018-07-21 11:04:18 +03:00
|
|
|
from .openwpmtest import OpenWPMTest
|
2016-10-06 02:35:22 +03:00
|
|
|
|
2017-10-10 21:57:12 +03:00
|
|
|
# Data for test_page_visit
|
2017-10-18 05:39:20 +03:00
|
|
|
# format: (
|
|
|
|
# request_url,
|
|
|
|
# top_level_url,
|
|
|
|
# triggering_origin,
|
|
|
|
# loading_origin,
|
|
|
|
# loading_href,
|
2020-03-19 21:39:41 +03:00
|
|
|
# is_XHR, is_tp_content, is_tp_window,
|
2019-02-08 06:30:56 +03:00
|
|
|
# resource_type
|
2017-10-09 23:29:50 +03:00
|
|
|
HTTP_REQUESTS = {
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
"undefined",
|
|
|
|
"undefined",
|
|
|
|
"undefined",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"main_frame",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_favicon.ico",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_image_2.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page_2.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_script_2.js",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page_2.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"script",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_script.js",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"script",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_image.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page_2.html",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"sub_frame",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_style.css",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"stylesheet",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/404.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page_2.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/frame1.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page_2.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/frame2.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page_2.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/req1.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/req2.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/req3.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_image_2.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2017-03-16 18:59:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# format: (request_url, referrer, location)
|
2019-02-08 06:30:56 +03:00
|
|
|
# TODO: webext instrumentation doesn't support referrer yet
|
2017-10-09 23:29:50 +03:00
|
|
|
HTTP_RESPONSES = {
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2019-02-26 13:44:24 +03:00
|
|
|
# u'',
|
2021-04-13 18:39:03 +03:00
|
|
|
"",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_favicon.ico",
|
2019-02-26 13:44:24 +03:00
|
|
|
# u'',
|
2021-04-13 18:39:03 +03:00
|
|
|
"",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_style.css",
|
|
|
|
# u'http://localhost:8000/test_pages/http_test_page.html',
|
|
|
|
"",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_script.js",
|
|
|
|
# u'http://localhost:8000/test_pages/http_test_page.html',
|
|
|
|
"",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_image.png",
|
|
|
|
# u'http://localhost:8000/test_pages/http_test_page.html',
|
|
|
|
"",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page_2.html",
|
|
|
|
# u'http://localhost:8000/test_pages/http_test_page.html',
|
|
|
|
"",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_image_2.png",
|
|
|
|
# u'http://localhost:8000/test_pages/http_test_page_2.html',
|
|
|
|
"",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_script_2.js",
|
|
|
|
# u'http://localhost:8000/test_pages/http_test_page_2.html',
|
|
|
|
"",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/404.png",
|
|
|
|
# u'http://localhost:8000/test_pages/http_test_page_2.html',
|
|
|
|
"",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_image_2.png",
|
|
|
|
# u'http://localhost:8000/test_pages/http_test_page.html',
|
|
|
|
"",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
2017-10-18 05:39:20 +03:00
|
|
|
}
|
|
|
|
|
2020-05-05 22:04:13 +03:00
|
|
|
# format: (source_url, destination_url, location header)
|
2017-10-18 05:39:20 +03:00
|
|
|
HTTP_REDIRECTS = {
|
2020-09-11 16:14:09 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/req1.png",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/req2.png",
|
|
|
|
"req2.png?dst=req3.png&dst=/test_pages/shared/test_image_2.png",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/req2.png",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/req3.png",
|
|
|
|
"req3.png?dst=/test_pages/shared/test_image_2.png",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/req3.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_image_2.png",
|
|
|
|
"/test_pages/shared/test_image_2.png",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/frame1.png",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/frame2.png",
|
|
|
|
"frame2.png?dst=/404.png",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/frame2.png",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/404.png",
|
|
|
|
"/404.png",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
2017-03-16 18:59:17 +03:00
|
|
|
}
|
|
|
|
|
2017-10-10 21:57:12 +03:00
|
|
|
# Data for test_cache_hits_recorded
|
2017-10-09 23:29:50 +03:00
|
|
|
HTTP_CACHED_REQUESTS = {
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
"undefined",
|
|
|
|
"undefined",
|
|
|
|
"undefined",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"main_frame",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_script_2.js",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page_2.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"script",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_script.js",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"script",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page_2.html",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"sub_frame",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/404.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page_2.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/frame1.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page_2.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/frame2.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page_2.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/req1.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-02-08 07:27:06 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/req2.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-05-16 05:51:12 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/req3.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-02-08 07:27:06 +03:00
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_image_2.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-02-08 07:27:06 +03:00
|
|
|
),
|
2017-03-16 18:59:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# format: (request_url, referrer, is_cached)
|
2019-02-08 07:27:06 +03:00
|
|
|
# TODO: referrer isn't recorded by webext instrumentation yet.
|
2017-10-09 23:29:50 +03:00
|
|
|
HTTP_CACHED_RESPONSES = {
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page.html",
|
2019-02-26 13:44:24 +03:00
|
|
|
# u'',
|
2020-09-11 16:14:09 +03:00
|
|
|
1,
|
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_script.js",
|
|
|
|
# u'http://localhost:8000/test_pages/http_test_page.html',
|
2020-09-11 16:14:09 +03:00
|
|
|
1,
|
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/http_test_page_2.html",
|
|
|
|
# u'http://localhost:8000/test_pages/http_test_page.html',
|
2020-09-11 16:14:09 +03:00
|
|
|
1,
|
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_script_2.js",
|
|
|
|
# u'http://localhost:8000/test_pages/http_test_page_2.html',
|
2020-09-11 16:14:09 +03:00
|
|
|
1,
|
|
|
|
),
|
2019-02-26 13:44:24 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/404.png",
|
|
|
|
# u'http://localhost:8000/test_pages/http_test_page_2.html',
|
2020-09-11 16:14:09 +03:00
|
|
|
1,
|
|
|
|
),
|
2021-04-13 18:39:03 +03:00
|
|
|
(f"{utilities.BASE_TEST_URL}/shared/test_image_2.png", 1),
|
2017-10-18 05:39:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# format: (source_url, destination_url)
|
|
|
|
HTTP_CACHED_REDIRECTS = {
|
2020-09-11 16:14:09 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/frame1.png",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/frame2.png",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/frame2.png",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/404.png",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/req1.png",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/req2.png",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/req2.png",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/req3.png",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}/MAGIC_REDIRECT/req3.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_image_2.png",
|
2020-09-11 16:14:09 +03:00
|
|
|
),
|
2017-03-16 18:59:17 +03:00
|
|
|
}
|
|
|
|
|
2019-09-12 18:28:00 +03:00
|
|
|
# Test URL attribution for worker script requests
|
|
|
|
HTTP_WORKER_SCRIPT_REQUESTS = {
|
2019-09-05 16:13:34 +03:00
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/http_worker_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_worker_page.html",
|
|
|
|
"undefined",
|
|
|
|
"undefined",
|
|
|
|
"undefined",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"main_frame",
|
2019-09-05 16:13:34 +03:00
|
|
|
),
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_favicon.ico",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_worker_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_worker_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-09-05 16:13:34 +03:00
|
|
|
),
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/worker.js",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_worker_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_worker_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"script",
|
2019-09-05 16:13:34 +03:00
|
|
|
),
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_image.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_worker_page.html",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/http_worker_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
1,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"xmlhttprequest",
|
2019-09-05 16:13:34 +03:00
|
|
|
),
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
f"{utilities.BASE_TEST_URL}/shared/test_image.png",
|
|
|
|
f"{utilities.BASE_TEST_URL}/shared/worker.js",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL_NOPATH}",
|
|
|
|
f"{utilities.BASE_TEST_URL}/shared/worker.js",
|
2020-09-11 16:14:09 +03:00
|
|
|
1,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"xmlhttprequest",
|
2019-09-05 16:13:34 +03:00
|
|
|
),
|
|
|
|
}
|
|
|
|
|
2019-09-12 18:28:00 +03:00
|
|
|
# Test URL-attribution for Service Worker requests.
|
|
|
|
HTTP_SERVICE_WORKER_REQUESTS = {
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
"http://localhost:8000/test_pages/http_service_worker_page.html",
|
|
|
|
"http://localhost:8000/test_pages/http_service_worker_page.html",
|
|
|
|
"undefined",
|
|
|
|
"undefined",
|
|
|
|
"undefined",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"main_frame",
|
2019-09-12 18:28:00 +03:00
|
|
|
),
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
"http://localhost:8000/test_pages/shared/test_favicon.ico",
|
|
|
|
"http://localhost:8000/test_pages/http_service_worker_page.html",
|
|
|
|
"http://localhost:8000",
|
|
|
|
"http://localhost:8000",
|
|
|
|
"http://localhost:8000/test_pages/http_service_worker_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"image",
|
2019-09-12 18:28:00 +03:00
|
|
|
),
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
"http://localhost:8000/test_pages/shared/service_worker.js",
|
|
|
|
"http://localhost:8000/test_pages/http_service_worker_page.html",
|
|
|
|
"http://localhost:8000",
|
|
|
|
"http://localhost:8000",
|
|
|
|
"http://localhost:8000/test_pages/http_service_worker_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
0,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"script",
|
2019-09-12 18:28:00 +03:00
|
|
|
),
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
"http://localhost:8000/test_pages/shared/test_image.png",
|
|
|
|
"http://localhost:8000/test_pages/http_service_worker_page.html",
|
|
|
|
"http://localhost:8000",
|
|
|
|
"http://localhost:8000",
|
|
|
|
"http://localhost:8000/test_pages/http_service_worker_page.html",
|
2020-09-11 16:14:09 +03:00
|
|
|
1,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"xmlhttprequest",
|
2019-09-12 18:28:00 +03:00
|
|
|
),
|
|
|
|
(
|
2021-04-13 18:39:03 +03:00
|
|
|
"http://localhost:8000/test_pages/shared/test_image_2.png",
|
|
|
|
"http://localhost:8000/test_pages/shared/service_worker.js",
|
|
|
|
"http://localhost:8000",
|
|
|
|
"http://localhost:8000",
|
|
|
|
"http://localhost:8000/test_pages/shared/service_worker.js",
|
2020-09-11 16:14:09 +03:00
|
|
|
1,
|
|
|
|
None,
|
|
|
|
None,
|
2021-04-13 18:39:03 +03:00
|
|
|
"xmlhttprequest",
|
2019-09-12 18:28:00 +03:00
|
|
|
),
|
|
|
|
}
|
|
|
|
|
2017-10-19 19:21:35 +03:00
|
|
|
BASE_PATH = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
2019-08-20 13:04:44 +03:00
|
|
|
|
2016-10-06 00:38:08 +03:00
|
|
|
class TestHTTPInstrument(OpenWPMTest):
|
2021-02-22 19:51:32 +03:00
|
|
|
def get_config(
|
|
|
|
self, data_dir: Optional[Path]
|
|
|
|
) -> Tuple[ManagerParams, List[BrowserParams]]:
|
2016-12-18 20:42:45 +03:00
|
|
|
manager_params, browser_params = self.get_test_config(data_dir)
|
2020-12-02 12:10:45 +03:00
|
|
|
browser_params[0].http_instrument = True
|
2016-10-06 00:38:08 +03:00
|
|
|
return manager_params, browser_params
|
|
|
|
|
2019-09-12 18:28:00 +03:00
|
|
|
def test_worker_script_requests(self):
|
|
|
|
"""Check correct URL attribution for requests made by worker script"""
|
2020-09-11 16:14:09 +03:00
|
|
|
test_url = utilities.BASE_TEST_URL + "/http_worker_page.html"
|
2019-09-05 16:13:34 +03:00
|
|
|
db = self.visit(test_url)
|
|
|
|
|
|
|
|
request_id_to_url = dict()
|
|
|
|
|
|
|
|
# HTTP Requests
|
|
|
|
rows = db_utils.query_db(db, "SELECT * FROM http_requests")
|
|
|
|
observed_records = set()
|
|
|
|
for row in rows:
|
2020-09-11 16:14:09 +03:00
|
|
|
observed_records.add(
|
|
|
|
(
|
|
|
|
row["url"].split("?")[0],
|
|
|
|
row["top_level_url"],
|
|
|
|
row["triggering_origin"],
|
|
|
|
row["loading_origin"],
|
|
|
|
row["loading_href"],
|
|
|
|
row["is_XHR"],
|
|
|
|
row["is_third_party_channel"],
|
|
|
|
row["is_third_party_to_top_window"],
|
|
|
|
row["resource_type"],
|
|
|
|
)
|
2019-09-12 18:28:00 +03:00
|
|
|
)
|
2020-09-11 16:14:09 +03:00
|
|
|
request_id_to_url[row["request_id"]] = row["url"]
|
2019-09-12 18:28:00 +03:00
|
|
|
|
|
|
|
assert HTTP_WORKER_SCRIPT_REQUESTS == observed_records
|
|
|
|
|
|
|
|
def test_service_worker_requests(self):
|
|
|
|
"""Check correct URL attribution for requests made by service worker"""
|
2021-04-13 18:39:03 +03:00
|
|
|
test_url = utilities.BASE_TEST_URL + "/http_service_worker_page.html"
|
2019-09-12 18:28:00 +03:00
|
|
|
db = self.visit(test_url)
|
|
|
|
|
|
|
|
request_id_to_url = dict()
|
|
|
|
|
|
|
|
# HTTP Requests
|
|
|
|
rows = db_utils.query_db(db, "SELECT * FROM http_requests")
|
|
|
|
observed_records = set()
|
|
|
|
for row in rows:
|
2020-09-11 16:14:09 +03:00
|
|
|
observed_records.add(
|
|
|
|
(
|
|
|
|
row["url"].split("?")[0],
|
|
|
|
row["top_level_url"],
|
|
|
|
row["triggering_origin"],
|
|
|
|
row["loading_origin"],
|
|
|
|
row["loading_href"],
|
|
|
|
row["is_XHR"],
|
|
|
|
row["is_third_party_channel"],
|
|
|
|
row["is_third_party_to_top_window"],
|
|
|
|
row["resource_type"],
|
|
|
|
)
|
2019-09-05 16:13:34 +03:00
|
|
|
)
|
2020-09-11 16:14:09 +03:00
|
|
|
request_id_to_url[row["request_id"]] = row["url"]
|
2019-09-05 16:13:34 +03:00
|
|
|
|
|
|
|
assert HTTP_SERVICE_WORKER_REQUESTS == observed_records
|
|
|
|
|
2016-12-14 04:54:20 +03:00
|
|
|
|
|
|
|
class TestPOSTInstrument(OpenWPMTest):
|
|
|
|
"""Make sure we can capture all the POST request data.
|
|
|
|
|
|
|
|
The encoding types tested are explained here:
|
|
|
|
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Using_nothing_but_XMLHttpRequest
|
|
|
|
"""
|
2020-09-11 16:14:09 +03:00
|
|
|
|
|
|
|
post_data = (
|
|
|
|
'{"email":["test@example.com"],'
|
|
|
|
'"username":["name surname+你好"],'
|
|
|
|
'"test":["ПриватБанк – банк для тих, хто йде вперед"]}'
|
|
|
|
)
|
2019-02-26 16:48:54 +03:00
|
|
|
post_data_json = json.loads(post_data)
|
2020-09-11 16:14:09 +03:00
|
|
|
post_data_multiline = (
|
|
|
|
r'{"email":["test@example.com"],"username":'
|
|
|
|
r'["name surname+你好"],'
|
|
|
|
r'"test":["ПриватБанк – банк для тих, хто йде вперед"],'
|
2019-02-26 17:43:11 +03:00
|
|
|
r'"multiline_text":["line1\r\n\r\nline2 line2_word2"]}'
|
2020-09-11 16:14:09 +03:00
|
|
|
)
|
2019-02-26 16:48:54 +03:00
|
|
|
post_data_multiline_json = json.loads(post_data_multiline)
|
2020-09-11 16:14:09 +03:00
|
|
|
post_data_multiline_raw = (
|
|
|
|
"email=test@example.com\r\n"
|
|
|
|
"username=name surname+你好\r\n"
|
|
|
|
"test=ПриватБанк – банк для тих, хто йде вперед\r\n"
|
|
|
|
"multiline_text=line1\r\n\r\n"
|
|
|
|
"line2 line2_word2\r\n"
|
|
|
|
)
|
2016-12-14 04:54:20 +03:00
|
|
|
|
2021-02-22 19:51:32 +03:00
|
|
|
def get_config(
|
|
|
|
self, data_dir: Optional[Path] = None
|
|
|
|
) -> Tuple[ManagerParams, List[BrowserParams]]:
|
2016-12-14 04:54:20 +03:00
|
|
|
manager_params, browser_params = self.get_test_config(data_dir)
|
2020-12-02 12:10:45 +03:00
|
|
|
browser_params[0].http_instrument = True
|
2016-12-14 04:54:20 +03:00
|
|
|
return manager_params, browser_params
|
|
|
|
|
|
|
|
def get_post_requests_from_db(self, db):
|
|
|
|
"""Query the crawl database and return the POST requests."""
|
2020-09-11 16:14:09 +03:00
|
|
|
return db_utils.query_db(
|
|
|
|
db,
|
|
|
|
"SELECT * FROM http_requests\
|
|
|
|
WHERE method = 'POST'",
|
|
|
|
)
|
2016-12-14 04:54:20 +03:00
|
|
|
|
2019-06-07 12:59:07 +03:00
|
|
|
def get_post_request_body_from_db(self, db, raw=False):
|
2016-12-14 04:54:20 +03:00
|
|
|
"""Return the body of the first POST request in crawl db."""
|
|
|
|
posts = self.get_post_requests_from_db(db)
|
2019-06-07 12:59:07 +03:00
|
|
|
if raw:
|
2020-09-11 16:14:09 +03:00
|
|
|
return base64.b64decode(json.loads(posts[0]["post_body_raw"])[0][1])
|
2019-06-07 12:59:07 +03:00
|
|
|
else:
|
2020-09-11 16:14:09 +03:00
|
|
|
return posts[0]["post_body"]
|
2016-12-14 04:54:20 +03:00
|
|
|
|
|
|
|
def test_record_post_data_x_www_form_urlencoded(self):
|
2016-12-28 13:05:42 +03:00
|
|
|
encoding_type = "application/x-www-form-urlencoded"
|
|
|
|
db = self.visit("/post_request.html?encoding_type=" + encoding_type)
|
2016-12-14 04:54:20 +03:00
|
|
|
post_body = self.get_post_request_body_from_db(db)
|
2019-02-26 16:48:54 +03:00
|
|
|
assert json.loads(post_body) == self.post_data_multiline_json
|
2016-12-14 04:54:20 +03:00
|
|
|
|
|
|
|
def test_record_post_data_text_plain(self):
|
2016-12-28 13:05:42 +03:00
|
|
|
encoding_type = "text/plain"
|
2020-09-11 16:14:09 +03:00
|
|
|
db = self.visit("/post_request.html?encoding_type=" + encoding_type)
|
2019-06-07 12:59:07 +03:00
|
|
|
post_body = self.get_post_request_body_from_db(db, True)
|
2019-11-20 16:26:15 +03:00
|
|
|
if not isinstance(self.post_data_multiline_raw, str):
|
2020-09-11 16:14:09 +03:00
|
|
|
expected = self.post_data_multiline_raw.decode("utf-8")
|
2019-08-07 01:05:03 +03:00
|
|
|
else:
|
|
|
|
expected = self.post_data_multiline_raw
|
2020-09-11 16:14:09 +03:00
|
|
|
assert post_body.decode("utf8") == expected
|
2016-12-14 04:54:20 +03:00
|
|
|
|
|
|
|
def test_record_post_data_multipart_formdata(self):
|
|
|
|
encoding_type = "multipart/form-data"
|
2020-09-11 16:14:09 +03:00
|
|
|
db = self.visit("/post_request.html?encoding_type=" + encoding_type)
|
2016-12-14 04:54:20 +03:00
|
|
|
post_body = self.get_post_request_body_from_db(db)
|
2019-02-26 16:48:54 +03:00
|
|
|
assert json.loads(post_body) == self.post_data_multiline_json
|
2016-12-14 04:54:20 +03:00
|
|
|
post_row = self.get_post_requests_from_db(db)[0]
|
2020-09-11 16:14:09 +03:00
|
|
|
headers = post_row["headers"]
|
2016-12-14 04:54:20 +03:00
|
|
|
# make sure the "request headers from upload stream" are stored in db
|
|
|
|
assert "Content-Type" in headers
|
|
|
|
assert encoding_type in headers
|
2020-09-11 16:14:09 +03:00
|
|
|
assert "Content-Length" in post_row["headers"]
|
2016-12-14 04:54:20 +03:00
|
|
|
|
|
|
|
def test_record_post_data_ajax(self, tmpdir):
|
|
|
|
post_format = "object"
|
|
|
|
db = self.visit("/post_request_ajax.html?format=" + post_format)
|
|
|
|
post_body = self.get_post_request_body_from_db(db)
|
2019-02-26 16:48:54 +03:00
|
|
|
assert json.loads(post_body) == self.post_data_json
|
2016-12-14 04:54:20 +03:00
|
|
|
|
|
|
|
def test_record_post_data_ajax_no_key_value(self):
|
|
|
|
"""Test AJAX payloads that are not in the key=value form."""
|
|
|
|
post_format = "noKeyValue"
|
|
|
|
db = self.visit("/post_request_ajax.html?format=" + post_format)
|
2019-05-28 08:32:39 +03:00
|
|
|
post_body = self.get_post_request_body_from_db(db, True)
|
2020-09-11 16:14:09 +03:00
|
|
|
assert post_body.decode("utf8") == "test@example.com + name surname"
|
2016-12-14 04:54:20 +03:00
|
|
|
|
2016-12-28 13:05:42 +03:00
|
|
|
def test_record_post_data_ajax_no_key_value_base64_encoded(self):
|
|
|
|
"""Test Base64 encoded AJAX payloads (no key=value form)."""
|
|
|
|
post_format = "noKeyValueBase64"
|
|
|
|
db = self.visit("/post_request_ajax.html?format=" + post_format)
|
2019-05-28 08:32:39 +03:00
|
|
|
post_body = self.get_post_request_body_from_db(db, True)
|
2020-09-11 16:14:09 +03:00
|
|
|
assert post_body.decode("utf8") == (
|
|
|
|
"dGVzdEBleGFtcGxlLmNvbSArIG5hbWUgc3VybmFtZQ=="
|
|
|
|
)
|
2016-12-28 13:05:42 +03:00
|
|
|
|
2016-12-14 04:54:20 +03:00
|
|
|
def test_record_post_formdata(self):
|
|
|
|
post_format = "formData"
|
|
|
|
db = self.visit("/post_request_ajax.html?format=" + post_format)
|
|
|
|
post_body = self.get_post_request_body_from_db(db)
|
2019-02-28 15:48:42 +03:00
|
|
|
assert json.loads(post_body) == self.post_data_json
|
2016-12-14 04:54:20 +03:00
|
|
|
|
|
|
|
def test_record_binary_post_data(self):
|
|
|
|
post_format = "binary"
|
|
|
|
db = self.visit("/post_request_ajax.html?format=" + post_format)
|
2019-06-07 12:59:07 +03:00
|
|
|
post_body = self.get_post_request_body_from_db(db, True)
|
2017-03-16 20:34:42 +03:00
|
|
|
# Binary strings get put into the database as-if they were latin-1.
|
2019-11-20 16:26:15 +03:00
|
|
|
assert bytes(bytearray(range(100))) == post_body
|
2016-12-28 13:05:42 +03:00
|
|
|
|
2020-09-11 16:14:09 +03:00
|
|
|
@pytest.mark.skip(
|
|
|
|
reason="Firefox is currently not able to return the "
|
|
|
|
"file content for an upload, only the filename"
|
|
|
|
)
|
2021-02-22 19:51:32 +03:00
|
|
|
def test_record_file_upload(self, task_manager_creator):
|
2016-12-28 13:05:42 +03:00
|
|
|
"""Test that we correctly capture the uploaded file contents.
|
|
|
|
|
|
|
|
We upload a CSS file and a PNG file to test both text based and
|
|
|
|
binary files.
|
|
|
|
|
|
|
|
File uploads are not expected in the crawl data, but we make sure we
|
|
|
|
correctly parse the POST data in this very common scenario.
|
2019-06-18 09:13:34 +03:00
|
|
|
|
|
|
|
Firefox is currently not able to return the FormData with the file
|
|
|
|
contents, currently only the filenames are returned. This is due to
|
|
|
|
a limitation in the current API implementation:
|
|
|
|
|
|
|
|
https://searchfox.org/mozilla-central/rev/b3b401254229f0a26f7ee625ef5f09c6c31e3949/toolkit/components/extensions/webrequest/WebRequestUpload.jsm#339
|
|
|
|
|
|
|
|
Therefore, the test is currently skipped.
|
2016-12-28 13:05:42 +03:00
|
|
|
"""
|
|
|
|
img_file_path = os.path.abspath("test_pages/shared/test_image.png")
|
|
|
|
css_file_path = os.path.abspath("test_pages/shared/test_style.css")
|
|
|
|
|
|
|
|
manager_params, browser_params = self.get_config()
|
2021-02-22 19:51:32 +03:00
|
|
|
manager, db_path = task_manager_creator((manager_params, browser_params))
|
2016-12-28 13:05:42 +03:00
|
|
|
test_url = utilities.BASE_TEST_URL + "/post_file_upload.html"
|
2020-11-24 19:34:04 +03:00
|
|
|
cs = command_sequence.CommandSequence(test_url)
|
2016-12-28 13:05:42 +03:00
|
|
|
cs.get(sleep=0, timeout=60)
|
2021-01-09 13:15:01 +03:00
|
|
|
cs.append_command(FilenamesIntoFormCommand(img_file_path, css_file_path))
|
2016-12-28 13:05:42 +03:00
|
|
|
manager.execute_command_sequence(cs)
|
|
|
|
manager.close()
|
|
|
|
|
2021-02-22 19:51:32 +03:00
|
|
|
post_body = self.get_post_request_body_from_db(db_path)
|
2017-03-16 20:34:42 +03:00
|
|
|
# Binary strings get put into the database as-if they were latin-1.
|
2020-09-11 16:14:09 +03:00
|
|
|
with open(img_file_path, "rb") as f:
|
|
|
|
img_file_content = f.read().strip().decode("latin-1")
|
|
|
|
with open(css_file_path, "rt") as f:
|
2017-10-11 04:59:52 +03:00
|
|
|
css_file_content = f.read().strip()
|
2016-12-28 13:05:42 +03:00
|
|
|
# POST data is stored as JSON in the DB
|
|
|
|
post_body_decoded = json.loads(post_body)
|
2020-09-11 16:14:09 +03:00
|
|
|
expected_body = {
|
2021-04-13 18:39:03 +03:00
|
|
|
"username": "name surname+",
|
|
|
|
"upload-css": css_file_content,
|
|
|
|
"upload-img": img_file_content,
|
2020-09-11 16:14:09 +03:00
|
|
|
}
|
2016-12-28 13:05:42 +03:00
|
|
|
assert expected_body == post_body_decoded
|
2021-01-09 13:15:01 +03:00
|
|
|
|
|
|
|
|
2021-05-03 13:57:56 +03:00
|
|
|
@pytest.mark.parametrize("delayed", [True, False])
|
|
|
|
def test_page_visit(task_manager_creator, http_params, delayed):
|
|
|
|
test_url = utilities.BASE_TEST_URL + "/http_test_page.html"
|
|
|
|
manager_params, browser_params = http_params()
|
|
|
|
if delayed:
|
|
|
|
for browser_param in browser_params:
|
|
|
|
browser_param.custom_params[
|
|
|
|
"pre_instrumentation_code"
|
|
|
|
] = """
|
2021-05-24 14:05:41 +03:00
|
|
|
const startTime = Date.now();
|
|
|
|
while (Date.now() - startTime < 5000) { // Delaying for 5s
|
|
|
|
console.log("delaying startup");
|
|
|
|
};
|
2021-05-03 13:57:56 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
tm, db = task_manager_creator((manager_params, browser_params))
|
|
|
|
with tm as tm:
|
|
|
|
tm.get(test_url)
|
|
|
|
|
|
|
|
request_id_to_url = dict()
|
|
|
|
|
|
|
|
# HTTP Requests
|
|
|
|
rows = db_utils.query_db(db, "SELECT * FROM http_requests")
|
|
|
|
observed_records = set()
|
|
|
|
for row in rows:
|
|
|
|
observed_records.add(
|
|
|
|
(
|
|
|
|
row["url"].split("?")[0],
|
|
|
|
row["top_level_url"],
|
|
|
|
row["triggering_origin"],
|
|
|
|
row["loading_origin"],
|
|
|
|
row["loading_href"],
|
|
|
|
row["is_XHR"],
|
|
|
|
row["is_third_party_channel"],
|
|
|
|
row["is_third_party_to_top_window"],
|
|
|
|
row["resource_type"],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
request_id_to_url[row["request_id"]] = row["url"]
|
|
|
|
assert HTTP_REQUESTS == observed_records
|
|
|
|
|
|
|
|
# HTTP Responses
|
|
|
|
rows = db_utils.query_db(db, "SELECT * FROM http_responses")
|
|
|
|
observed_records: Set[Tuple[str, str]] = set()
|
|
|
|
for row in rows:
|
|
|
|
observed_records.add(
|
|
|
|
(
|
|
|
|
row["url"].split("?")[0],
|
|
|
|
# TODO: webext-instrumentation doesn't support referrer
|
|
|
|
# yet | row['referrer'],
|
|
|
|
row["location"],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assert row["request_id"] in request_id_to_url
|
|
|
|
assert request_id_to_url[row["request_id"]] == row["url"]
|
|
|
|
assert HTTP_RESPONSES == observed_records
|
|
|
|
|
|
|
|
# HTTP Redirects
|
|
|
|
rows = db_utils.query_db(db, "SELECT * FROM http_redirects")
|
|
|
|
observed_records = set()
|
|
|
|
for row in rows:
|
|
|
|
# TODO: webext instrumentation doesn't support new_request_id yet
|
|
|
|
# src = request_id_to_url[row['old_request_id']].split('?')[0]
|
|
|
|
# dst = request_id_to_url[row['new_request_id']].split('?')[0]
|
|
|
|
src = row["old_request_url"].split("?")[0]
|
|
|
|
dst = row["new_request_url"].split("?")[0]
|
|
|
|
headers = json.loads(row["headers"])
|
|
|
|
location = None
|
|
|
|
for header, value in headers:
|
|
|
|
if header.lower() == "location":
|
|
|
|
location = value
|
|
|
|
break
|
|
|
|
observed_records.add((src, dst, location))
|
|
|
|
assert HTTP_REDIRECTS == observed_records
|
|
|
|
|
|
|
|
|
2021-02-22 19:51:32 +03:00
|
|
|
def test_javascript_saving(http_params, xpi, server):
|
2021-05-10 19:48:47 +03:00
|
|
|
"""check that javascript content is saved and hashed correctly"""
|
2021-02-22 19:51:32 +03:00
|
|
|
test_url = utilities.BASE_TEST_URL + "/http_test_page.html"
|
|
|
|
manager_params, browser_params = http_params()
|
|
|
|
|
|
|
|
for browser_param in browser_params:
|
|
|
|
browser_param.http_instrument = True
|
|
|
|
browser_param.save_content = "script"
|
|
|
|
|
|
|
|
structured_storage = SQLiteStorageProvider(
|
|
|
|
db_path=manager_params.data_directory / "crawl-data.sqlite"
|
|
|
|
)
|
|
|
|
ldb_path = Path(manager_params.data_directory) / "content.ldb"
|
|
|
|
unstructured_storage = LevelDbProvider(db_path=ldb_path)
|
|
|
|
manager = task_manager.TaskManager(
|
|
|
|
manager_params, browser_params, structured_storage, unstructured_storage
|
|
|
|
)
|
|
|
|
manager.get(url=test_url, sleep=1)
|
|
|
|
manager.close()
|
|
|
|
expected_hashes = {
|
|
|
|
"0110c0521088c74f179615cd7c404816816126fa657550032f75ede67a66c7cc",
|
|
|
|
"b34744034cd61e139f85f6c4c92464927bed8343a7ac08acf9fb3c6796f80f08",
|
|
|
|
}
|
|
|
|
for chash, content in db_utils.get_content(ldb_path):
|
|
|
|
chash = chash.decode("ascii").lower()
|
|
|
|
pyhash = sha256(content).hexdigest().lower()
|
|
|
|
assert pyhash == chash # Verify expected key (sha256 of content)
|
|
|
|
assert chash in expected_hashes
|
|
|
|
expected_hashes.remove(chash)
|
|
|
|
assert len(expected_hashes) == 0 # All expected hashes have been seen
|
|
|
|
|
|
|
|
|
|
|
|
def test_document_saving(http_params, xpi, server):
|
2021-05-10 19:48:47 +03:00
|
|
|
"""check that document content is saved and hashed correctly"""
|
2021-02-22 19:51:32 +03:00
|
|
|
test_url = utilities.BASE_TEST_URL + "/http_test_page.html"
|
|
|
|
expected_hashes = {
|
|
|
|
"2390eceab422db15bc45940b7e042e83e6cbd5f279f57e714bc4ad6cded7f966",
|
|
|
|
"25343f42d9ffa5c082745f775b172db87d6e14dfbc3160b48669e06d727bfc8d",
|
|
|
|
}
|
|
|
|
manager_params, browser_params = http_params()
|
|
|
|
for browser_param in browser_params:
|
|
|
|
browser_param.http_instrument = True
|
|
|
|
browser_param.save_content = "main_frame,sub_frame"
|
|
|
|
|
|
|
|
structured_storage = SQLiteStorageProvider(
|
|
|
|
db_path=manager_params.data_directory / "crawl-data.sqlite"
|
|
|
|
)
|
|
|
|
ldb_path = Path(manager_params.data_directory) / "content.ldb"
|
|
|
|
unstructured_storage = LevelDbProvider(db_path=ldb_path)
|
|
|
|
manager = task_manager.TaskManager(
|
|
|
|
manager_params, browser_params, structured_storage, unstructured_storage
|
|
|
|
)
|
|
|
|
|
|
|
|
manager.get(url=test_url, sleep=1)
|
|
|
|
manager.close()
|
|
|
|
for chash, content in db_utils.get_content(ldb_path):
|
|
|
|
chash = chash.decode("ascii").lower()
|
|
|
|
pyhash = sha256(content).hexdigest().lower()
|
|
|
|
assert pyhash == chash # Verify expected key (sha256 of content)
|
|
|
|
assert chash in expected_hashes
|
|
|
|
expected_hashes.remove(chash)
|
|
|
|
assert len(expected_hashes) == 0 # All expected hashes have been seen
|
|
|
|
|
|
|
|
|
|
|
|
def test_content_saving(http_params, xpi, server):
|
2021-05-10 19:48:47 +03:00
|
|
|
"""check that content is saved and hashed correctly"""
|
2021-02-22 19:51:32 +03:00
|
|
|
test_url = utilities.BASE_TEST_URL + "/http_test_page.html"
|
|
|
|
manager_params, browser_params = http_params()
|
|
|
|
for browser_param in browser_params:
|
|
|
|
browser_param.http_instrument = True
|
|
|
|
browser_param.save_content = True
|
|
|
|
db = manager_params.data_directory / "crawl-data.sqlite"
|
|
|
|
structured_storage = SQLiteStorageProvider(db_path=db)
|
|
|
|
ldb_path = Path(manager_params.data_directory) / "content.ldb"
|
|
|
|
unstructured_storage = LevelDbProvider(db_path=ldb_path)
|
|
|
|
manager = task_manager.TaskManager(
|
|
|
|
manager_params, browser_params, structured_storage, unstructured_storage
|
|
|
|
)
|
|
|
|
manager.get(url=test_url, sleep=1)
|
|
|
|
manager.close()
|
|
|
|
|
|
|
|
rows = db_utils.query_db(db, "SELECT * FROM http_responses;")
|
|
|
|
disk_content = dict()
|
|
|
|
for row in rows:
|
|
|
|
if "MAGIC_REDIRECT" in row["url"] or "404" in row["url"]:
|
|
|
|
continue
|
|
|
|
path = urlparse(row["url"]).path
|
|
|
|
with open(os.path.join(BASE_PATH, path[1:]), "rb") as f:
|
|
|
|
content = f.read()
|
|
|
|
chash = sha256(content).hexdigest()
|
|
|
|
assert chash == row["content_hash"]
|
|
|
|
disk_content[chash] = content
|
|
|
|
|
|
|
|
ldb_content = dict()
|
|
|
|
for chash, content in db_utils.get_content(ldb_path):
|
|
|
|
chash = chash.decode("ascii")
|
|
|
|
ldb_content[chash] = content
|
|
|
|
|
|
|
|
for k, v in disk_content.items():
|
|
|
|
assert v == ldb_content[k]
|
|
|
|
|
|
|
|
|
|
|
|
def test_cache_hits_recorded(http_params, task_manager_creator):
|
|
|
|
"""Verify all http responses are recorded, including cached responses
|
|
|
|
|
|
|
|
Note that we expect to see all of the same requests and responses
|
|
|
|
during the second vist (even if cached) except for images. Cached
|
|
|
|
images do not trigger Observer Notification events.
|
|
|
|
See Bug 634073: https://bugzilla.mozilla.org/show_bug.cgi?id=634073
|
|
|
|
|
|
|
|
The test page includes an image which does several permanent redirects
|
|
|
|
before returning a 404. We expect to see new requests and responses
|
|
|
|
for this image when the page is reloaded. Additionally, the redirects
|
|
|
|
should be cached.
|
|
|
|
"""
|
|
|
|
test_url = utilities.BASE_TEST_URL + "/http_test_page.html"
|
|
|
|
manager_params, browser_params = http_params()
|
|
|
|
# ensuring that we only spawn one browser
|
|
|
|
manager_params.num_browsers = 1
|
|
|
|
manager, db = task_manager_creator((manager_params, [browser_params[0]]))
|
|
|
|
for i in range(2):
|
|
|
|
cs = CommandSequence(test_url, site_rank=i)
|
|
|
|
cs.get(sleep=5)
|
|
|
|
manager.execute_command_sequence(cs)
|
|
|
|
|
|
|
|
manager.close()
|
|
|
|
|
|
|
|
request_id_to_url = dict()
|
|
|
|
|
|
|
|
# HTTP Requests
|
|
|
|
rows = db_utils.query_db(
|
|
|
|
db,
|
|
|
|
"""
|
|
|
|
SELECT hr.*
|
|
|
|
FROM http_requests as hr
|
|
|
|
JOIN site_visits sv ON sv.visit_id = hr.visit_id and sv.browser_id = hr.browser_id
|
|
|
|
WHERE sv.site_rank = 1""",
|
|
|
|
)
|
|
|
|
observed_records = set()
|
|
|
|
for row in rows:
|
|
|
|
# HACK: favicon caching is unpredictable, don't bother checking it
|
|
|
|
if row["url"].split("?")[0].endswith("favicon.ico"):
|
|
|
|
continue
|
|
|
|
observed_records.add(
|
|
|
|
(
|
|
|
|
row["url"].split("?")[0],
|
|
|
|
row["top_level_url"],
|
|
|
|
row["triggering_origin"],
|
|
|
|
row["loading_origin"],
|
|
|
|
row["loading_href"],
|
|
|
|
row["is_XHR"],
|
|
|
|
row["is_third_party_channel"],
|
|
|
|
row["is_third_party_to_top_window"],
|
|
|
|
row["resource_type"],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
request_id_to_url[row["request_id"]] = row["url"]
|
|
|
|
assert observed_records == HTTP_CACHED_REQUESTS
|
|
|
|
|
|
|
|
# HTTP Responses
|
|
|
|
rows = db_utils.query_db(
|
|
|
|
db,
|
|
|
|
"""
|
|
|
|
SELECT hp.*
|
|
|
|
FROM http_responses as hp
|
|
|
|
JOIN site_visits sv ON sv.visit_id = hp.visit_id and sv.browser_id = hp.browser_id
|
|
|
|
WHERE sv.site_rank = 1""",
|
|
|
|
)
|
|
|
|
observed_records = set()
|
|
|
|
for row in rows:
|
|
|
|
# HACK: favicon caching is unpredictable, don't bother checking it
|
|
|
|
if row["url"].split("?")[0].endswith("favicon.ico"):
|
|
|
|
continue
|
|
|
|
observed_records.add(
|
|
|
|
(
|
|
|
|
row["url"].split("?")[0],
|
|
|
|
# TODO: referrer isn't available yet in the
|
|
|
|
# webext instrumentation | row['referrer'],
|
|
|
|
row["is_cached"],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assert row["request_id"] in request_id_to_url
|
|
|
|
assert request_id_to_url[row["request_id"]] == row["url"]
|
|
|
|
assert HTTP_CACHED_RESPONSES == observed_records
|
|
|
|
|
|
|
|
# HTTP Redirects
|
|
|
|
rows = db_utils.query_db(
|
|
|
|
db,
|
|
|
|
"""
|
|
|
|
SELECT hr.*
|
|
|
|
FROM http_redirects as hr
|
|
|
|
JOIN site_visits sv ON sv.visit_id = hr.visit_id and sv.browser_id = hr.browser_id
|
|
|
|
WHERE sv.site_rank = 1""",
|
|
|
|
)
|
|
|
|
observed_records = set()
|
|
|
|
for row in rows:
|
|
|
|
# TODO: new_request_id isn't supported yet
|
|
|
|
# src = request_id_to_url[row['old_request_id']].split('?')[0]
|
|
|
|
# dst = request_id_to_url[row['new_request_id']].split('?')[0]
|
|
|
|
src = row["old_request_url"].split("?")[0]
|
|
|
|
dst = row["new_request_url"].split("?")[0]
|
|
|
|
observed_records.add((src, dst))
|
|
|
|
assert HTTP_CACHED_REDIRECTS == observed_records
|
|
|
|
|
|
|
|
|
2021-01-09 13:15:01 +03:00
|
|
|
class FilenamesIntoFormCommand(BaseCommand):
|
2021-02-22 19:51:32 +03:00
|
|
|
def __init__(self, img_file_path: str, css_file_path: str) -> None:
|
2021-01-09 13:15:01 +03:00
|
|
|
self.img_file_path = img_file_path
|
|
|
|
self.css_file_path = css_file_path
|
|
|
|
|
|
|
|
def execute(
|
|
|
|
self,
|
|
|
|
webdriver,
|
|
|
|
browser_params,
|
|
|
|
manager_params,
|
|
|
|
extension_socket,
|
2021-02-22 19:51:32 +03:00
|
|
|
):
|
2021-01-09 13:15:01 +03:00
|
|
|
img_file_upload_element = webdriver.find_element_by_id("upload-img")
|
|
|
|
css_file_upload_element = webdriver.find_element_by_id("upload-css")
|
|
|
|
img_file_upload_element.send_keys(self.img_file_path)
|
|
|
|
css_file_upload_element.send_keys(self.css_file_path)
|
|
|
|
sleep(5) # wait for the form submission (3 sec after onload)
|