Skip to content

Make compatible with <1.0 and >1.0a#16

Merged
simonw merged 4 commits into
mainfrom
pre-1.0
Apr 26, 2024
Merged

Make compatible with <1.0 and >1.0a#16
simonw merged 4 commits into
mainfrom
pre-1.0

Conversation

@simonw

@simonw simonw commented Apr 26, 2024

Copy link
Copy Markdown
Contributor

Comment thread tests/test_secrets.py
Comment on lines +14 to +20
def get_internal_database(ds):
if hasattr(ds, "get_internal_database"):
return ds.get_internal_database()
else:
return ds.get_database("_internal")


Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit of a gross hack here to get the internal database working in tests.

Comment thread tests/test_secrets.py
Comment on lines +99 to +105
plugin_config={
"datasette-secrets": {
"database": "_internal",
"encryption-key": TEST_ENCRYPTION_KEY,
}
},
permissions={"manage-secrets": {"id": "admin"}},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread tests/test_secrets.py
@pytest.mark.asyncio
async def test_set_secret(ds, use_actors_plugin):
cookies = {"ds_actor": ds.client.actor_cookie({"id": "admin"})}
cookies = {"ds_actor": actor_cookie(ds, {"id": "admin"})}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this new feature in datasette-test:

Comment on lines +192 to +194
if hasattr(datasette, "actors_from_ids"):
actors = await datasette.actors_from_ids(
{

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To compensate for datasette.actors_from_ids() not being in Datasette <1.0

@simonw

simonw commented Apr 26, 2024

Copy link
Copy Markdown
Contributor Author

Permission tests are failing for the 1.0a version:

=========================== short test summary info ============================
FAILED tests/test_secrets.py::test_permissions[admin-/-/secrets-GET-None] - assert 403 != 403
 +  where 403 = <Response [403 Forbidden]>.status_code
FAILED tests/test_secrets.py::test_permissions[admin-/-/secrets/EXAMPLE_SECRET-GET-None] - assert 403 != 403
 +  where 403 = <Response [403 Forbidden]>.status_code
FAILED tests/test_secrets.py::test_set_secret - assert 403 == 302
 +  where 403 = <Response [403 Forbidden]>.status_code
FAILED tests/test_secrets.py::test_get_secret - assert 403 == 302
 +  where 403 = <Response [403 Forbidden]>.status_code
FAILED tests/test_secrets.py::test_secret_index_page - assert 403 == 200
 +  where 403 = <Response [403 Forbidden]>.status_code
=================== 5 failed, 6 passed, 20 warnings in 0.90s ===================

@simonw

simonw commented Apr 26, 2024

Copy link
Copy Markdown
Contributor Author

In the debugger for pytest --pdb -x:

(Pdb) from pprint import pprint
(Pdb) pprint(ds._permission_checks)
deque([{'action': 'manage-secrets',
        'actor': {'id': 'root'},
        'resource': None,
        'result': False,
        'used_default': False,
        'when': '2024-04-26T23:02:15.359701'},
       {'action': 'view-instance',
        'actor': {'id': 'root'},
        'resource': None,
        'result': True,
        'used_default': True,
        'when': '2024-04-26T23:02:15.366520'},
       {'action': 'debug-menu',
        'actor': {'id': 'root'},
        'resource': None,
        'result': True,
        'used_default': False,
        'when': '2024-04-26T23:02:15.366554'},
       {'action': 'manage-secrets',
        'actor': {'id': 'root'},
        'resource': None,
        'result': False,
        'used_default': False,
        'when': '2024-04-26T23:02:15.366567'}],
      maxlen=200)

@simonw

simonw commented Apr 26, 2024

Copy link
Copy Markdown
Contributor Author

Why did this check fail?

       {'action': 'manage-secrets',
        'actor': {'id': 'root'},

Here's why:

(Pdb) ds.config
{'plugins': {'datasette-secrets': {...}}, 'permissions': {'manage-secrets': {'id': 'admin'}}}

That's configured to allow admin, not root.

@simonw

simonw commented Apr 26, 2024

Copy link
Copy Markdown
Contributor Author

@simonw simonw merged commit 015c521 into main Apr 26, 2024
@simonw simonw deleted the pre-1.0 branch April 26, 2024 23:17
simonw added a commit that referenced this pull request Apr 26, 2024
simonw added a commit that referenced this pull request Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant