mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
datasette.sign() and datasette.unsign() methods, refs #785
This commit is contained in:
parent
1fc6ceefb9
commit
fa27e44fe0
7 changed files with 61 additions and 0 deletions
|
|
@ -75,6 +75,7 @@ def test_metadata_yaml():
|
|||
static=[],
|
||||
memory=False,
|
||||
config=[],
|
||||
secret=None,
|
||||
version_note=None,
|
||||
help_config=False,
|
||||
return_instance=True,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
"""
|
||||
Tests for the datasette.app.Datasette class
|
||||
"""
|
||||
from itsdangerous import BadSignature
|
||||
from .fixtures import app_client
|
||||
import pytest
|
||||
|
||||
|
|
@ -21,3 +22,14 @@ def test_get_database_no_argument(datasette):
|
|||
# Returns the first available database:
|
||||
db = datasette.get_database()
|
||||
assert "fixtures" == db.name
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", ["hello", 123, {"key": "value"}])
|
||||
@pytest.mark.parametrize("namespace", [None, "two"])
|
||||
def test_sign_unsign(datasette, value, namespace):
|
||||
extra_args = [namespace] if namespace else []
|
||||
signed = datasette.sign(value, *extra_args)
|
||||
assert value != signed
|
||||
assert value == datasette.unsign(signed, *extra_args)
|
||||
with pytest.raises(BadSignature):
|
||||
datasette.unsign(signed[:-1] + ("!" if signed[-1] != "!" else ":"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue