Skip to content

Commit

Permalink
Test demonstrating fix for permisisons bug in #2262
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Feb 16, 2024
1 parent 8bfa3a5 commit 244f3ff
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/test_api_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,41 @@ async def test_insert_or_upsert_row_errors(
assert before_count == after_count


@pytest.mark.asyncio
@pytest.mark.parametrize("allowed", (True, False))
async def test_upsert_permissions_per_table(ds_write, allowed):
# https://github.com/simonw/datasette/issues/2262
token = "dstok_{}".format(
ds_write.sign(
{
"a": "root",
"token": "dstok",
"t": int(time.time()),
"_r": {
"r": {
"data": {
"docs" if allowed else "other": ["ir", "ur"],
}
}
},
},
namespace="token",
)
)
response = await ds_write.client.post(
"/data/docs/-/upsert",
json={"rows": [{"id": 1, "title": "One"}]},
headers={
"Authorization": "Bearer {}".format(token),
},
)
if allowed:
assert response.status_code == 200
assert response.json()["ok"] is True
else:
assert response.status_code == 403


@pytest.mark.asyncio
@pytest.mark.parametrize(
"ignore,replace,expected_rows",
Expand Down

0 comments on commit 244f3ff

Please sign in to comment.