-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replaces python-jose with pyjwt using cryptography as a backend #103
base: 0_7_0
Are you sure you want to change the base?
Conversation
Co-authored-by: Grzegorz Redlicki <redlicki.grzegorz@gmail.com>
# Conflicts: # requirements-dev.txt # requirements.txt # setup.py # tests/conftest.py
Co-authored-by: Grzegorz Redlicki <redlicki.grzegorz@gmail.com>
@@ -52,28 +51,6 @@ def test_proper_jwt( | |||
decoded_jwt_data = decode_jwt(full_access_auth_header) | |||
assert decoded_jwt_data == full_access_authz_payload | |||
|
|||
def test_expired_jwt(self) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get why you moved these tests below if they remained in the same class 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accident ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It just makes the review unnecessarily harder 😉
Co-authored-by: Grzegorz Redlicki <redlicki.grzegorz@gmail.com>
token_payload = { | ||
"iss": "test-issuer", | ||
"aud": "test-audience", | ||
"kid": "x", | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, the payload does not matter for this test 🤔
token_payload = { | |
"iss": "test-issuer", | |
"aud": "test-audience", | |
"kid": "x", | |
} |
public_key = deepcopy(SAMPLE_PUBLIC_KEY) | ||
public_key["kid"] = "9494ad75-aaaa-aaaa-aaaa-c1a17da22b35" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be much simpler to change input data instead of manipulating the test environment:
public_key = deepcopy(SAMPLE_PUBLIC_KEY) | |
public_key["kid"] = "9494ad75-aaaa-aaaa-aaaa-c1a17da22b35" | |
private_key = deepcopy(SAMPLE_PRIVATE_KEY) | |
private_key["kid"] = kid = "9494ad75-aaaa-aaaa-aaaa-c1a17da22b35" |
"aud": "test-audience", | ||
"kid": "x", | ||
} | ||
jwt_token = encode_jwt(token_payload, SAMPLE_PRIVATE_KEY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the above comments:
jwt_token = encode_jwt(token_payload, SAMPLE_PRIVATE_KEY) | |
jwt_token = encode_jwt(data={}, private_key_jwk=private_key) |
with patch.dict(environ, {"ALLOWED_PUBLIC_KEYS": json.dumps({"keys": [public_key]})}): | ||
with pytest.raises(Unauthorized): | ||
decode_jwt(jwt_token) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the above comments:
with patch.dict(environ, {"ALLOWED_PUBLIC_KEYS": json.dumps({"keys": [public_key]})}): | |
with pytest.raises(Unauthorized): | |
decode_jwt(jwt_token) | |
with pytest.raises(Unauthorized): | |
decode_jwt(jwt_token) |
with patch.dict(environ, {"ALLOWED_PUBLIC_KEYS": json.dumps({"keys": [public_key]})}): | ||
with pytest.raises(Unauthorized): | ||
decode_jwt(jwt_token) | ||
assert "The key with id=" in caplog.text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rather check the whole log instead of relying on its small parts:
assert "The key with id=" in caplog.text | |
assert caplog.record_tuples == [ | |
( | |
"lbz.jwt_utils", | |
logging.WARNING, | |
f"The key with id={kid} was not found in the environment variable.", | |
) | |
] |
@@ -98,8 +98,7 @@ bandit: | |||
.PHONY: pip-audit | |||
pip-audit: | |||
pip-audit --version | |||
# TODO: Fix the issue with the vulnerable ecdsa and jose libraries | |||
pip-audit -r requirements.txt --ignore-vuln GHSA-wj6h-64fc-37mp --ignore-vuln GHSA-cjwg-qfpm-7377 --ignore-vuln GHSA-6c5p-j8vq-pqhj | |||
pip-audit -r requirements.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use OSV as a vulnerability service as it collects vulnerabilities from multiple sources:
pip-audit -r requirements.txt | |
pip-audit --vulnerability-service osv -r requirements.txt |
Quality Gate passedIssues Measures |
No description provided.