Allow missing created field (#23)

* Do not add created field if algorithm is rsa, hmac or ecdsa

* Disable check for W504

This is mutually exclusive with W503, but it seems to check for both. So
no matter where the linebreak is, the linter says its wrong. This fixes
this behavior and allows to use at least one option.

* Allow github actions to run on pull request

* Make created field optional on verification
pull/27/head
Georg Krause 2021-04-26 01:10:03 +02:00 committed by GitHub
parent 7f668ef084
commit d1129fdd9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

View File

@ -1,6 +1,6 @@
name: Python package
on: [push]
on: [push, pull_request]
jobs:
build:

View File

@ -87,7 +87,7 @@ class HTTPSignatureAuth(requests.auth.AuthBase):
if header == "(request-target)":
path_url = requests.models.RequestEncodingMixin.path_url.fget(request)
sts.append("{}: {} {}".format(header, request.method.lower(), path_url))
elif header == "(created)":
elif header == "(created)" and created_timestamp:
sts.append("{}: {}".format(header, created_timestamp))
elif header == "(expires)":
assert (expires_timestamp is not None), \
@ -123,8 +123,10 @@ class HTTPSignatureAuth(requests.auth.AuthBase):
("algorithm", self.algorithm),
("headers", " ".join(self.headers)),
("signature", sig),
("created", int(created_timestamp)),
]
if not (self.algorithm.startswith("rsa") or self.algorithm.startswith("hmac") or
self.algorithm.startswith("ecdsa")):
sig_struct.append(("created", int(created_timestamp)))
if expires_timestamp is not None:
sig_struct.append(("expires", int(expires_timestamp)))
return ",".join('{}="{}"'.format(k, v) for k, v in sig_struct)
@ -155,7 +157,7 @@ class HTTPSignatureAuth(requests.auth.AuthBase):
for field in "keyId", "algorithm", "signature":
assert field in sig_struct, 'Required signature parameter "{}" not found'.format(field)
assert sig_struct["algorithm"] in self.known_algorithms, "Unknown signature algorithm"
created_timestamp = int(sig_struct['created'])
created_timestamp = int(sig_struct['created']) if 'created' in sig_struct else None
expires_timestamp = sig_struct.get('expires')
if expires_timestamp is not None:
expires_timestamp = int(expires_timestamp)

View File

@ -2,4 +2,4 @@
universal=1
[flake8]
max-line-length=120
ignore: E301, E302, E401, E261, E265, E226, F401
ignore: E301, E302, E401, E261, E265, E226, F401, W504