Skip to content
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

Open
wants to merge 10 commits into
base: 0_7_0
Choose a base branch
from

Conversation

pdyba
Copy link
Owner

@pdyba pdyba commented Nov 14, 2024

No description provided.

setup.py Show resolved Hide resolved
lbz/jwt_utils.py Outdated Show resolved Hide resolved
lbz/jwt_utils.py Outdated Show resolved Hide resolved
lbz/jwt_utils.py Outdated Show resolved Hide resolved
lbz/jwt_utils.py Outdated Show resolved Hide resolved
tests/utils.py Outdated Show resolved Hide resolved
tests/test_authentication.py Outdated Show resolved Hide resolved
tests/test_authentication.py Outdated Show resolved Hide resolved
tests/test_jwt_utils.py Outdated Show resolved Hide resolved
tests/test_jwt_utils.py Outdated Show resolved Hide resolved
pdyba and others added 3 commits November 19, 2024 12:04
Co-authored-by: Grzegorz Redlicki <redlicki.grzegorz@gmail.com>
# Conflicts:
#	requirements-dev.txt
#	requirements.txt
#	setup.py
#	tests/conftest.py
lbz/jwt_utils.py Show resolved Hide resolved
requirements-dev.txt Outdated Show resolved Hide resolved
requirements.txt Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
tests/test_authz_authorizer.py Outdated Show resolved Hide resolved
tests/test_jwt_utils.py Outdated Show resolved Hide resolved
tests/test_jwt_utils.py Outdated Show resolved Hide resolved
tests/test_jwt_utils.py Outdated Show resolved Hide resolved
tests/test_jwt_utils.py Show resolved Hide resolved
pdyba and others added 2 commits November 25, 2024 11:21
Co-authored-by: Grzegorz Redlicki <redlicki.grzegorz@gmail.com>
requirements-dev.txt Outdated Show resolved Hide resolved
requirements-dev.txt Outdated Show resolved Hide resolved
requirements.txt Outdated Show resolved Hide resolved
Makefile Show resolved Hide resolved
@@ -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:
Copy link
Collaborator

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 🤷

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accident ?

Copy link
Collaborator

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 😉

tests/test_jwt_utils.py Show resolved Hide resolved
lbz/jwt_utils.py Show resolved Hide resolved
pdyba and others added 2 commits December 11, 2024 12:51
Co-authored-by: Grzegorz Redlicki <redlicki.grzegorz@gmail.com>
requirements-dev.txt Outdated Show resolved Hide resolved
requirements-dev.txt Outdated Show resolved Hide resolved
requirements-dev.txt Outdated Show resolved Hide resolved
Comment on lines +37 to +41
token_payload = {
"iss": "test-issuer",
"aud": "test-audience",
"kid": "x",
}
Copy link
Collaborator

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 🤔

Suggested change
token_payload = {
"iss": "test-issuer",
"aud": "test-audience",
"kid": "x",
}

Comment on lines +35 to +36
public_key = deepcopy(SAMPLE_PUBLIC_KEY)
public_key["kid"] = "9494ad75-aaaa-aaaa-aaaa-c1a17da22b35"
Copy link
Collaborator

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:

Suggested change
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)
Copy link
Collaborator

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:

Suggested change
jwt_token = encode_jwt(token_payload, SAMPLE_PRIVATE_KEY)
jwt_token = encode_jwt(data={}, private_key_jwk=private_key)

Comment on lines +44 to +46
with patch.dict(environ, {"ALLOWED_PUBLIC_KEYS": json.dumps({"keys": [public_key]})}):
with pytest.raises(Unauthorized):
decode_jwt(jwt_token)
Copy link
Collaborator

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:

Suggested change
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
Copy link
Collaborator

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:

Suggested change
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
Copy link
Collaborator

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:

Suggested change
pip-audit -r requirements.txt
pip-audit --vulnerability-service osv -r requirements.txt

Copy link

sonarqubecloud bot commented Jan 2, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants