Skip to content

Commit

Permalink
Don't persist _save- cruft in query_string, closes #104
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed May 11, 2021
1 parent b76561c commit eefa5fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions django_sql_dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def dashboard_index(request):
(key, value)
for key, value in request.POST.items()
if key not in ("sql", "csrfmiddlewaretoken")
and not key.startswith("_save-")
]
signed_sqls = [sign_sql(sql) for sql in sqls if sql.strip()]
params = {
Expand Down
18 changes: 16 additions & 2 deletions test_project/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,24 @@ def test_dashboard_submit_sql(admin_client, dashboard_db):
assert get_response.status_code == 200
assert get_response["Content-Security-Policy"] == "frame-ancestors 'self'"
sql = "select 14 + 33"
response = admin_client.post("/dashboard/", {"sql": sql})
response = admin_client.post(
"/dashboard/",
{
"sql": sql,
"_save-title": "",
"_save-slug": "",
"_save-description": "",
"_save-view_policy": "private",
"_save-view_group": "",
"_save-edit_policy": "private",
"_save-edit_group": "",
},
)
assert response.status_code == 302
# Should redirect to ?sql=signed-value
signed_sql = urllib.parse.parse_qs(response.url.split("?")[1])["sql"][0]
bits = urllib.parse.parse_qs(response.url.split("?")[1])
assert set(bits.keys()) == {"sql"}
signed_sql = bits["sql"][0]
assert signed_sql == sign_sql(sql)
# GET against this new location should return correct result
get_response = admin_client.get(response.url)
Expand Down

0 comments on commit eefa5fb

Please sign in to comment.