?_hash=1 no longer respected for mutable databases

Closes #471, refs #419
pull/479/head
Simon Willison 2019-05-16 08:10:25 -07:00
rodzic cccea85be6
commit db9dbfb816
2 zmienionych plików z 21 dodań i 4 usunięć

Wyświetl plik

@ -208,7 +208,12 @@ class BaseView(RenderMixin):
if "as_db" in kwargs:
should_redirect += kwargs["as_db"]
if self.ds.config("hash_urls") or "_hash" in request.args:
if (
(self.ds.config("hash_urls") or "_hash" in request.args)
and
# Redirect only if database is immutable
not self.ds.databases[name].is_mutable
):
return name, expected, correct_hash_provided, should_redirect
return name, expected, correct_hash_provided, None

Wyświetl plik

@ -1421,15 +1421,27 @@ def test_ttl_parameter(app_client, path, expected_cache_control):
),
],
)
def test_hash_parameter(app_client_with_hash, path, expected_redirect):
def test_hash_parameter(
app_client_two_attached_databases_one_immutable, path, expected_redirect
):
# First get the current hash for the fixtures database
current_hash = app_client_with_hash.ds.databases["fixtures"].hash[:7]
response = app_client_with_hash.get(path, allow_redirects=False)
current_hash = app_client_two_attached_databases_one_immutable.ds.databases[
"fixtures"
].hash[:7]
response = app_client_two_attached_databases_one_immutable.get(
path, allow_redirects=False
)
assert response.status == 302
location = response.headers["Location"]
assert expected_redirect.replace("HASH", current_hash) == location
def test_hash_parameter_ignored_for_mutable_databases(app_client):
path = "/fixtures/facetable.json?_hash=1"
response = app_client.get(path, allow_redirects=False)
assert response.status == 200
test_json_columns_default_expected = [
{"intval": 1, "strval": "s", "floatval": 0.5, "jsonval": '{"foo": "bar"}'}
]