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

Work on not auto-filling username #792

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ tiled/_version.py

.env
.asv/
venv/
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Write the date in place of the "Unreleased" in the case a new version is release

# Changelog

## Unreleased

- Add kwarg to client logout to auto-clear default identity.
- Do not automatically enter username if default identity is used.

## v0.1.0b9 (2024-09-19)

### Added
Expand Down
6 changes: 3 additions & 3 deletions tiled/_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ..catalog import from_uri, in_memory
from ..client.base import BaseClient
from ..server.settings import get_settings
from .utils import enter_password as utils_enter_password
from .utils import enter_username_password as utils_enter_uname_passwd
from .utils import temp_postgres


Expand Down Expand Up @@ -75,11 +75,11 @@ def tmp_profiles_dir():


@pytest.fixture
def enter_password():
def enter_username_password():
"""
DEPRECATED: Use the normal (non-fixture) context manager in .utils.
"""
return utils_enter_password
return utils_enter_uname_passwd


@pytest.fixture(scope="module")
Expand Down
32 changes: 16 additions & 16 deletions tiled/_tests/test_access_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ..adapters.mapping import MapAdapter
from ..client import Context, from_context
from ..server.app import build_app_from_config
from .utils import enter_password, fail_with_status_code
from .utils import enter_username_password, fail_with_status_code

arr = numpy.ones((5, 5))
arr_ad = ArrayAdapter.from_array(arr)
Expand Down Expand Up @@ -132,7 +132,7 @@ def context(tmpdir_module):
}
app = build_app_from_config(config)
with Context.from_app(app) as context:
with enter_password("admin"):
with enter_username_password("admin", "admin"):
admin_client = from_context(context, username="admin")
for k in ["c", "d", "e"]:
admin_client[k].write_array(arr, key="A1")
Expand All @@ -141,8 +141,8 @@ def context(tmpdir_module):
yield context


def test_top_level_access_control(context, enter_password):
with enter_password("secret1"):
def test_top_level_access_control(context, enter_username_password):
with enter_username_password("alice", "secret1"):
alice_client = from_context(context, username="alice")
assert "a" in alice_client
assert "A2" in alice_client["a"]
Expand All @@ -152,7 +152,7 @@ def test_top_level_access_control(context, enter_password):
with pytest.raises(KeyError):
alice_client["b"]

with enter_password("secret2"):
with enter_username_password("bob", "secret2"):
bob_client = from_context(context, username="bob")
assert not list(bob_client)
with pytest.raises(KeyError):
Expand All @@ -163,9 +163,9 @@ def test_top_level_access_control(context, enter_password):
bob_client.logout()


def test_access_control_with_api_key_auth(context, enter_password):
def test_access_control_with_api_key_auth(context, enter_username_password):
# Log in, create an API key, log out.
with enter_password("secret1"):
with enter_username_password("alice", "secret1"):
context.authenticate(username="alice")
key_info = context.create_api_key()
context.logout()
Expand All @@ -180,9 +180,9 @@ def test_access_control_with_api_key_auth(context, enter_password):
context.api_key = None


def test_node_export(enter_password, context, buffer):
def test_node_export(enter_username_password, context, buffer):
"Exporting a node should include only the children we can see."
with enter_password("secret1"):
with enter_username_password("alice", "secret1"):
alice_client = from_context(context, username="alice")
alice_client.export(buffer, format="application/json")
alice_client.logout()
Expand All @@ -195,8 +195,8 @@ def test_node_export(enter_password, context, buffer):
exported_dict["contents"]["a"]["contents"]["A2"]


def test_create_and_update_allowed(enter_password, context):
with enter_password("secret1"):
def test_create_and_update_allowed(enter_username_password, context):
with enter_username_password("alice", "secret1"):
alice_client = from_context(context, username="alice")

# Update
Expand All @@ -209,17 +209,17 @@ def test_create_and_update_allowed(enter_password, context):
alice_client.logout()


def test_writing_blocked_by_access_policy(enter_password, context):
with enter_password("secret1"):
def test_writing_blocked_by_access_policy(enter_username_password, context):
with enter_username_password("alice", "secret1"):
alice_client = from_context(context, username="alice")
alice_client["d"]["x"].metadata
with fail_with_status_code(HTTP_403_FORBIDDEN):
alice_client["d"]["x"].update_metadata(metadata={"added_key": 3})
alice_client.logout()


def test_create_blocked_by_access_policy(enter_password, context):
with enter_password("secret1"):
def test_create_blocked_by_access_policy(enter_username_password, context):
with enter_username_password("alice", "secret1"):
alice_client = from_context(context, username="alice")
with fail_with_status_code(HTTP_403_FORBIDDEN):
alice_client["e"].write_array([1, 2, 3])
Expand Down Expand Up @@ -278,7 +278,7 @@ def test_service_principal_access(tmpdir):
],
}
with Context.from_app(build_app_from_config(config)) as context:
with enter_password("admin"):
with enter_username_password("admin", "admin"):
admin_client = from_context(context, username="admin")
sp = admin_client.context.admin.create_service_principal("user")
key_info = admin_client.context.admin.create_api_key(sp["uuid"])
Expand Down
Loading
Loading