1
0
mirror of https://github.com/quay/quay.git synced 2026-01-26 06:21:37 +03:00
Files
quay/endpoints/test/test_decorators.py
Kenny Lee Sin Cheong 72f7c64ed6 chore: update werkzeug and related package versions (PROJQUAY-5098) (#1982)
* chore: update werkzeug and related package versions (PROJQUAY-5098)

Path converter related change reference: https://github.com/pallets/werkzeug/issues/2506

* Update query count
2023-09-12 11:51:09 -04:00

44 lines
1.3 KiB
Python

from test.fixtures import *
import pytest
from data import model
from endpoints.api import api
from endpoints.api.repository import Repository
from endpoints.test.shared import conduct_call
@pytest.mark.parametrize(
"user_agent, include_header, expected_code",
[
("curl/whatever", True, 200),
("curl/whatever", False, 200),
("Mozilla/whatever", True, 200),
("Mozilla/5.0", True, 200),
(
"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/534.34 (KHTML, like Gecko) Safari/534.34",
False,
400,
),
],
)
def test_require_xhr_from_browser(user_agent, include_header, expected_code, app, client):
# Create a public repo with a dot in its name.
user = model.user.get_user("devtable")
model.repository.create_repository("devtable", "somerepo.bat", user, "public")
# Retrieve the repository and ensure we either allow it through or fail, depending on the
# user agent and header.
params = {"repository": "devtable/somerepo.bat"}
headers = {
"User-Agent": user_agent,
}
if include_header:
headers["X-Requested-With"] = "XMLHttpRequest"
conduct_call(
client, Repository, api.url_for, "GET", params, headers=headers, expected_code=expected_code
)