mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
CSRF tests for canned query POST, closes #835
This commit is contained in:
parent
08b4928a75
commit
3ec5b1abf6
1 changed files with 23 additions and 1 deletions
|
|
@ -55,7 +55,11 @@ def test_canned_query_with_named_parameter(app_client):
|
|||
|
||||
def test_insert(canned_write_client):
|
||||
response = canned_write_client.post(
|
||||
"/data/add_name", {"name": "Hello"}, allow_redirects=False, csrftoken_from=True,
|
||||
"/data/add_name",
|
||||
{"name": "Hello"},
|
||||
allow_redirects=False,
|
||||
csrftoken_from=True,
|
||||
cookies={"foo": "bar"},
|
||||
)
|
||||
assert 302 == response.status
|
||||
assert "/data/add_name?success" == response.headers["Location"]
|
||||
|
|
@ -65,6 +69,24 @@ def test_insert(canned_write_client):
|
|||
assert [["Query executed, 1 row affected", 1]] == messages
|
||||
|
||||
|
||||
def test_insert_with_cookies_requires_csrf(canned_write_client):
|
||||
response = canned_write_client.post(
|
||||
"/data/add_name",
|
||||
{"name": "Hello"},
|
||||
allow_redirects=False,
|
||||
cookies={"foo": "bar"},
|
||||
)
|
||||
assert 403 == response.status
|
||||
|
||||
|
||||
def test_insert_no_cookies_no_csrf(canned_write_client):
|
||||
response = canned_write_client.post(
|
||||
"/data/add_name", {"name": "Hello"}, allow_redirects=False
|
||||
)
|
||||
assert 302 == response.status
|
||||
assert "/data/add_name?success" == response.headers["Location"]
|
||||
|
||||
|
||||
def test_custom_success_message(canned_write_client):
|
||||
response = canned_write_client.post(
|
||||
"/data/delete_name",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue