mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
datasette create-token command, refs #1859
This commit is contained in:
parent
c556fad65d
commit
c7956eed77
7 changed files with 130 additions and 8 deletions
|
|
@ -806,6 +806,7 @@ def test_settings_json(app_client):
|
|||
"max_returned_rows": 100,
|
||||
"sql_time_limit_ms": 200,
|
||||
"allow_download": True,
|
||||
"allow_signed_tokens": True,
|
||||
"allow_facet": True,
|
||||
"suggest_facets": True,
|
||||
"default_cache_ttl": 5,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
from .fixtures import app_client
|
||||
from click.testing import CliRunner
|
||||
from datasette.utils import baseconv
|
||||
from datasette.cli import cli
|
||||
import pytest
|
||||
import time
|
||||
|
||||
|
|
@ -235,3 +237,29 @@ def test_auth_with_dstok_token(app_client, scenario, should_work):
|
|||
assert response.json == {"actor": None}
|
||||
finally:
|
||||
app_client.ds._settings["allow_signed_tokens"] = True
|
||||
|
||||
|
||||
@pytest.mark.parametrize("expires", (None, 1000, -1000))
|
||||
def test_cli_create_token(app_client, expires):
|
||||
secret = app_client.ds._secret
|
||||
runner = CliRunner(mix_stderr=False)
|
||||
args = ["create-token", "--secret", secret, "test"]
|
||||
if expires:
|
||||
args += ["--expires-after", str(expires)]
|
||||
result = runner.invoke(cli, args)
|
||||
assert result.exit_code == 0
|
||||
token = result.output.strip()
|
||||
assert token.startswith("dstok_")
|
||||
details = app_client.ds.unsign(token[len("dstok_") :], "token")
|
||||
expected_keys = {"a", "token"}
|
||||
if expires:
|
||||
expected_keys.add("e")
|
||||
assert details.keys() == expected_keys
|
||||
assert details["a"] == "test"
|
||||
response = app_client.get(
|
||||
"/-/actor.json", headers={"Authorization": "Bearer {}".format(token)}
|
||||
)
|
||||
if expires is None or expires > 0:
|
||||
assert response.json == {"actor": {"id": "test", "token": "dstok"}}
|
||||
else:
|
||||
assert response.json == {"actor": None}
|
||||
|
|
|
|||
|
|
@ -971,6 +971,7 @@ def test_hook_register_commands():
|
|||
"plugins",
|
||||
"publish",
|
||||
"uninstall",
|
||||
"create-token",
|
||||
}
|
||||
|
||||
# Now install a plugin
|
||||
|
|
@ -1001,6 +1002,7 @@ def test_hook_register_commands():
|
|||
"uninstall",
|
||||
"verify",
|
||||
"unverify",
|
||||
"create-token",
|
||||
}
|
||||
pm.unregister(name="verify")
|
||||
importlib.reload(cli)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue