commit 1d448fb9470938e81bd22039448982f413de7b9b80f7b6178b5209b42fbd4024 Author: Matej Cepl Date: Sat May 1 22:10:49 2021 +0000 Accepting request 889768 from home:mcepl:branches:devel:languages:python Dependency for python-httpx OBS-URL: https://build.opensuse.org/request/show/889768 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-hstspreload?expand=0&rev=1 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9b03811 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +## Default LFS +*.7z filter=lfs diff=lfs merge=lfs -text +*.bsp filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.gem filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.jar filter=lfs diff=lfs merge=lfs -text +*.lz filter=lfs diff=lfs merge=lfs -text +*.lzma filter=lfs diff=lfs merge=lfs -text +*.obscpio filter=lfs diff=lfs merge=lfs -text +*.oxt filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.rpm filter=lfs diff=lfs merge=lfs -text +*.tbz filter=lfs diff=lfs merge=lfs -text +*.tbz2 filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.txz filter=lfs diff=lfs merge=lfs -text +*.whl filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57affb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.osc diff --git a/hstspreload-2020.11.21.tar.gz b/hstspreload-2020.11.21.tar.gz new file mode 100644 index 0000000..09a5bf8 --- /dev/null +++ b/hstspreload-2020.11.21.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a0c2ce53e4e065a830995db5bb4e5c1991ec4c277ba1868d4eb5f88301b920b3 +size 978263 diff --git a/python-hstspreload.changes b/python-hstspreload.changes new file mode 100644 index 0000000..9853059 --- /dev/null +++ b/python-hstspreload.changes @@ -0,0 +1,24 @@ +------------------------------------------------------------------- +Sat Nov 21 11:10:55 UTC 2020 - John Vandenberg + +- Update to v2020.11.21 + +------------------------------------------------------------------- +Tue Oct 13 10:19:43 UTC 2020 - John Vandenberg + +- Update to v2020.10.6 + +------------------------------------------------------------------- +Thu Aug 27 17:06:16 UTC 2020 - John Vandenberg + +- Update to v2020.8.25 + +------------------------------------------------------------------- +Tue Feb 18 16:40:08 UTC 2020 - John Vandenberg + +- Update to v2020.2.15 + +------------------------------------------------------------------- +Tue Oct 8 08:22:54 AM UTC 2019 - John Vandenberg + +- Initial spec for v2019.9.30 diff --git a/python-hstspreload.spec b/python-hstspreload.spec new file mode 100644 index 0000000..d35459e --- /dev/null +++ b/python-hstspreload.spec @@ -0,0 +1,60 @@ +# +# spec file for package python-hstspreload +# +# Copyright (c) 2021 SUSE LLC +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# + + +%{?!python_module:%define python_module() python-%{**} python3-%{**}} +%define skip_python2 1 +Name: python-hstspreload +Version: 2020.11.21 +Release: 0 +Summary: Python Chromium HSTS Preload list +License: BSD-3-Clause +Group: Development/Languages/Python +URL: https://github.com/python-http/hstspreload +Source: https://files.pythonhosted.org/packages/source/h/hstspreload/hstspreload-%{version}.tar.gz +Source1: https://raw.githubusercontent.com/python-http/hstspreload/master/test_hstspreload.py +BuildRequires: %{python_module pytest} +BuildRequires: %{python_module setuptools} +BuildRequires: fdupes +BuildRequires: python-rpm-macros +BuildArch: noarch +%python_subpackages + +%description +Chromium HSTS Preload list as a Python package. + +%prep +%setup -q -n hstspreload-%{version} +cp %{SOURCE1} . + +%build +%python_build + +%install +%python_install +%python_expand %fdupes %{buildroot}%{$python_sitelib} + +#%%check depends on httpx, which depends on hstspreload +# Also, depends on the huge static data, and tests seem to fail ATM. +#%%pytest + +%files %{python_files} +%doc README.md +%license LICENSE +%{python_sitelib}/* + +%changelog diff --git a/test_hstspreload.py b/test_hstspreload.py new file mode 100644 index 0000000..e4105fc --- /dev/null +++ b/test_hstspreload.py @@ -0,0 +1,79 @@ +import base64 +import hashlib +import json + +import pytest +import urllib3 + +import hstspreload + +HSTS_PRELOAD_URL = ( + "https://chromium.googlesource.com/chromium/src/+/master/" + "net/http/transport_security_state_static.json?format=TEXT" +) + + +def load_test_cases(): + http = urllib3.PoolManager() + r = http.request( + "GET", + HSTS_PRELOAD_URL, + headers={"Accept": "application/json"}, + preload_content=True, + ) + content = base64.b64decode(r.data) + content_checksum = hashlib.sha256(content).hexdigest() + + assert content_checksum == hstspreload.__checksum__ + + content = content.decode("ascii") + entries = json.loads( + "\n".join( + [line for line in content.split("\n") if not line.strip().startswith("//")] + ) + )["entries"] + + allow_subdomains = [] + + for entry in sorted(entries, key=lambda x: len(x["name"])): + host = entry["name"].encode("ascii") + include_subdomains = entry.get("include_subdomains", False) + force_https = entry.get("mode", "") == "force-https" + + if force_https: + yield host, True + if include_subdomains: + allow_subdomains.append(b"." + host) + + # Handle cases where a subdomain like 'example.org' is + # given 'includeSubdomains' but then the 'www.example.org' + # entry isn't assigned 'includeSubdomains'. Thankfully + # this isn't allowed anymore and they only accept + # 'example.org' domains now. + if not include_subdomains: + for subdom in allow_subdomains: + if host.endswith(subdom): + include_subdomains = True + break + + yield b"zzz-subdomain." + host, include_subdomains + + +@pytest.mark.parametrize( + ["host", "expected"], + [ + (b"www.google.com", False), + ("www.google.com", False), + (b"google.com", False), + ("google.com", False), + ("paypal.com", True), + (b"paypal.com", True), + ], +) +def test_data_types(host, expected): + assert hstspreload.in_hsts_preload(host) is expected + + +@pytest.mark.parametrize(["host", "expected"], list(load_test_cases())) +def test_in_hsts_preload(host, expected): + assert hstspreload.in_hsts_preload(host) is expected