1
0

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
This commit is contained in:
Matej Cepl 2021-05-01 22:10:49 +00:00 committed by Git OBS Bridge
commit 1d448fb947
6 changed files with 190 additions and 0 deletions

23
.gitattributes vendored Normal file
View File

@ -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

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.osc

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a0c2ce53e4e065a830995db5bb4e5c1991ec4c277ba1868d4eb5f88301b920b3
size 978263

View File

@ -0,0 +1,24 @@
-------------------------------------------------------------------
Sat Nov 21 11:10:55 UTC 2020 - John Vandenberg <jayvdb@gmail.com>
- Update to v2020.11.21
-------------------------------------------------------------------
Tue Oct 13 10:19:43 UTC 2020 - John Vandenberg <jayvdb@gmail.com>
- Update to v2020.10.6
-------------------------------------------------------------------
Thu Aug 27 17:06:16 UTC 2020 - John Vandenberg <jayvdb@gmail.com>
- Update to v2020.8.25
-------------------------------------------------------------------
Tue Feb 18 16:40:08 UTC 2020 - John Vandenberg <jayvdb@gmail.com>
- Update to v2020.2.15
-------------------------------------------------------------------
Tue Oct 8 08:22:54 AM UTC 2019 - John Vandenberg <jayvdb@gmail.com>
- Initial spec for v2019.9.30

60
python-hstspreload.spec Normal file
View File

@ -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

79
test_hstspreload.py Normal file
View File

@ -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