-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from 4ARMED/ignore-regex
Overhaul of various areas
- Loading branch information
Showing
10 changed files
with
241 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: tests | ||
|
||
on: [workflow_call] | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.x" | ||
- name: Install dependencies | ||
run: | | ||
python3 -m pip install --upgrade pip | ||
pip3 install -r requirements.txt | ||
- name: Run unittests | ||
run: python3 -m unittest discover -s tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ venv | |
sri_check.egg-info/** | ||
build/** | ||
dist/** | ||
.vscode/** | ||
**/__pycache__/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,10 +23,12 @@ def open_local(paths, mode="r", encoding="utf8"): | |
author_email="[email protected]", | ||
description="Subresource Integrity Checker", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
url="https://github.com/4armed/sri-check", | ||
version=version, | ||
packages=setuptools.find_packages(), | ||
install_requires=install_requires, | ||
python_requires=">=3.6", | ||
entry_points={"console_scripts": ["sri-check=sricheck.sricheck:cli"]} | ||
entry_points={"console_scripts": ["sri-check=sricheck.sricheck:cli"]}, | ||
test_suite="tests" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "1.5.0" | ||
__version__ = "1.6.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import unittest | ||
|
||
from sricheck.sricheck import SRICheck | ||
|
||
class TestInit(unittest.TestCase): | ||
|
||
def test_init_with_url(self): | ||
check = SRICheck("https://www.4armed.com") | ||
self.assertEqual(check.url, "https://www.4armed.com") | ||
|
||
def test_init_without_args(self): | ||
with self.assertRaises(TypeError) as error: | ||
s = SRICheck() | ||
self.assertEqual(str(error.exception), "SRICheck.__init__() missing 1 required positional argument: 'url'") | ||
|
||
def test_init_with_empty_url(self): | ||
with self.assertRaises(ValueError) as error: | ||
s = SRICheck("") | ||
self.assertEqual(str(error.exception), "URL cannot be empty") | ||
|
||
def test_init_with_invalid_url(self): | ||
with self.assertRaises(ValueError) as error: | ||
s = SRICheck("ftp://www.4armed.com") | ||
self.assertEqual(str(error.exception), "URL must be http or https") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import unittest | ||
|
||
from sricheck.sricheck import SRICheck | ||
|
||
class TestParsing(unittest.TestCase): | ||
|
||
def test_script_tag_on_third_party_with_no_sri_returns_result(self): | ||
check = SRICheck("https://www.4armed.com") | ||
html = """<html><head><script src="https://cdn.cloudflare.com/script.js"></script></head></html>""" | ||
remote_resource_tags = check.get_remote_resource_tags(html) | ||
self.assertEqual(len(remote_resource_tags), 1) | ||
self.assertEqual(remote_resource_tags[0]['tag']['src'], "https://cdn.cloudflare.com/script.js") | ||
|
||
def test_script_tag_on_own_host_with_no_sri_returns_no_results(self): | ||
check = SRICheck("https://www.4armed.com") | ||
html = """<html><head><script src="https://www.4armed.com/script.js"></script></head></html>""" | ||
remote_resource_tags = check.get_remote_resource_tags(html) | ||
self.assertEqual(len(remote_resource_tags), 0) | ||
|
||
def test_script_tag_on_third_party_with_sri_returns_no_results(self): | ||
check = SRICheck("https://www.4armed.com") | ||
html = """<html><head><script crossorigin="anonymous" integrity="sha384-qkIfm9UUNrOzzGFh3YtL/KOHBwDNjW00Iwd0LK/DAsdmiOWRUfXBRl/s1Rtn9h8/" src="https://cdn.cloudflare.com/script.js"></script></head></html>""" | ||
remote_resource_tags = check.get_remote_resource_tags(html) | ||
self.assertEqual(len(remote_resource_tags), 0) |
Oops, something went wrong.