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

Add HEAD authorization tests #670

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions quetz/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,20 +439,23 @@ def test_private_channels_download(db, client, data, channel_dirs):
assert response.text == "file content 0"

# fail on private channel without credentials
response = client.get('/get/privatechannel/noarch/current_repodata.json')
assert response.status_code == 401
for method in [client.get, client.head]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

@jonashaag, what would speak against adding a method callable as a parametrization instead of adding an iteration on each assertion?

Copy link
Author

Choose a reason for hiding this comment

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

That was my first approach. The problem is that you need this in very few places only

Copy link
Collaborator

Choose a reason for hiding this comment

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

Now I see it. 🙈

response = method('/get/privatechannel/noarch/current_repodata.json')
assert response.status_code == 401

# fail on private channel with invalid credentials
response = client.get(
'/t/[invalid-api-key]/get/privatechannel/noarch/current_repodata.json'
)
assert response.status_code == 401
for method in [client.get, client.head]:
response = method(
'/t/[invalid-api-key]/get/privatechannel/noarch/current_repodata.json'
)
assert response.status_code == 401

# fail on private channel with non member user
response = client.get(
f'/t/{data.keyb}/get/privatechannel/noarch/current_repodata.json'
)
assert response.status_code == 403
for method in [client.get, client.head]:
response = method(
f'/t/{data.keyb}/get/privatechannel/noarch/current_repodata.json'
)
assert response.status_code == 403

# succeed on private channel with member user
response = client.get(
Expand Down Expand Up @@ -615,7 +618,6 @@ def test_use_wildcard_api_key_to_authenticate(data, client):
response = client.get(
"/api/channels/my-new-channel/members", headers={"X-API-Key": channel_key}
)

assert response.status_code == 403

response = client.get(
Expand Down Expand Up @@ -665,7 +667,6 @@ def test_authorizations_with_expired_api_key(data, client):
response = client.get(
"/api/channels/privatechannel/members", headers={"X-API-Key": key}
)

assert response.status_code == 401


Expand Down
Loading