async def test_build_from_snapshot(): snapshot = make_snapshot() records = await DnsRecordFactory.from_snapshot(snapshot) for record in records: print(record.value) assert len(records) > 0
def test_build_from_snapshot(): snapshot = make_snapshot() classifications = ClassificationFactory.from_snapshot(snapshot) assert len(classifications) > 0 first = classifications[0] assert not first.malicious
async def test_build_from_snapshot(): snapshot = make_snapshot() snapshot.body = '<html><body><script type="text/javascript" src="https://www.w3.org/2008/site/js/main"></body></html>' respx.get("https://www.w3.org/2008/site/js/main", content="foo") scripts = await ScriptFactory.from_snapshot(snapshot) assert len(scripts) == 1 script = scripts[0] assert script.url == "https://www.w3.org/2008/site/js/main" assert "foo" in script.content
def test_build_from_snapshot(): snapshot = make_snapshot() snapshot.body = '<html><body><script type="text/javascript" src="https://www.w3.org/2008/site/js/main"></body></html>' scripts = ScriptBuilder.build_from_snapshot(snapshot) assert len(scripts) == 1 script = scripts[0] assert script.url == "https://www.w3.org/2008/site/js/main" assert ( "/*! See W3C-specific code uncompressed at http://www.w3.org/2008/site/js/core.js */" in script.content)
async def test_build_from_snapshot_with_relative_src(): snapshot = make_snapshot() snapshot.url = "https://www.w3.org" snapshot.body = '<html><body><script type="text/javascript" src="/2008/site/js/main"></body></html>' respx.get("https://www.w3.org/2008/site/js/main").mock( Response(status_code=200, content="foo")) scripts = await ScriptFactory.from_snapshot(snapshot) assert len(scripts) == 1 script = scripts[0] assert script.url == "https://www.w3.org/2008/site/js/main" assert "foo" in script.content
async def test_build_from_snapshot_with_no_src(): snapshot = make_snapshot() snapshot.body = '<html><body><script type="text/javascript"></body></html>' scripts = await ScriptFactory.from_snapshot(snapshot) assert len(scripts) == 0
def test_build_from_snapshot_with_no_src(): snapshot = make_snapshot() snapshot.body = '<html><body><script type="text/javascript"></body></html>' scripts = ScriptBuilder.build_from_snapshot(snapshot) assert len(scripts) == 0
def snapshot_for_test() -> Snapshot: snapshot = make_snapshot() snapshot.scripts = [Script(content="foo"), Script(content="bar")] return snapshot
def mock_import_as_snapshot(url: str): return make_snapshot()
def mock_take_snapshot( url: str, user_agent: None, timeout: None, ignore_https_errors: False ): return make_snapshot()