Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make compatible with <1.0 and >1.0a #16

Merged
merged 4 commits into from
Apr 26, 2024
Merged

Make compatible with <1.0 and >1.0a #16

merged 4 commits into from
Apr 26, 2024

Conversation

simonw
Copy link
Contributor

@simonw simonw commented Apr 26, 2024

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
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 on lines +99 to +105
plugin_config={
"datasette-secrets": {
"database": "_internal",
"encryption-key": TEST_ENCRYPTION_KEY,
}
},
permissions={"manage-secrets": {"id": "admin"}},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -131,7 +136,7 @@ async def test_permissions(ds, path, verb, data, user):

@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
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
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
Copy link
Contributor Author

simonw commented Apr 26, 2024

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
Copy link
Contributor Author

simonw commented Apr 26, 2024

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
Copy link
Contributor Author

simonw commented Apr 26, 2024

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 merged commit 015c521 into main Apr 26, 2024
20 checks passed
@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.

None yet

1 participant