-
Notifications
You must be signed in to change notification settings - Fork 77
# fix: implement graphspace-scoped auth routing in Python client #325
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
Merged
imbajin
merged 11 commits into
apache:main
from
Muawiya-contact:fix/graphspace-auth-routing
May 8, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
aa9fad2
fix: implement graphspace-scoped auth routing in Python client (#322)
Muawiya-contact d9af033
test: add auth routing unit coverage
Muawiya-contact 84abc90
Add test_auth..py.
Muawiya-contact 4f44c75
style: apply ruff fixes; test: skip auth integration when server unre…
Muawiya-contact 4c3ef90
ci(ruff): install only dev extras and remove heavy DGL check
Muawiya-contact bb59072
test: accept target_resources dict shape in auth integration test
Muawiya-contact 56576b5
test: unwrap keyed target_resources in auth integration test
Muawiya-contact b3d6a07
style: format auth client for ruff
Muawiya-contact 03135fc
fix: address imbajin review feedback on graphspace auth routing (#325)
Muawiya-contact b82bdf8
style: format auth.py for ruff
Muawiya-contact 77332e1
style: simplify graphspace path formatting after fallback removal
imbajin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
hugegraph-python-client/src/tests/api/test_auth_routing.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| from urllib.parse import urljoin | ||
|
|
||
| import pytest | ||
| from pyhugegraph.api.auth import AuthManager | ||
|
|
||
|
|
||
| class DummyCfg: | ||
| def __init__(self, url, graphspace, gs_supported, graph_name): | ||
| self.url = url | ||
| self.graphspace = graphspace | ||
| self.gs_supported = gs_supported | ||
| self.graph_name = graph_name | ||
|
|
||
|
|
||
| class DummySession: | ||
| """Minimal session mimic implementing resolve and request used by router.""" | ||
|
|
||
| def __init__(self, cfg: DummyCfg): | ||
| self.cfg = cfg | ||
| self.last = None | ||
|
|
||
| def resolve(self, path: str) -> str: | ||
| base = f"{self.cfg.url.rstrip('/')}/" | ||
| if self.cfg.gs_supported: | ||
| base = urljoin(base, f"graphspaces/{self.cfg.graphspace}/graphs/{self.cfg.graph_name}/") | ||
| else: | ||
| base = urljoin(base, f"graphs/{self.cfg.graph_name}/") | ||
| return urljoin(base, path).strip("/") | ||
|
|
||
| def request(self, path: str, method: str = "GET", validator=None, **kwargs): | ||
| # mirror behavior of real session.request used by router: resolve path | ||
| self.last = self.resolve(path) | ||
| return {"url": self.last, "method": method} | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "endpoint, method_call, args, expected_subpath", | ||
| [ | ||
| ("users", "list_users", (), "graphspaces/GS/auth/users"), | ||
| ("users", "get_user", ("u1",), "graphspaces/GS/auth/users/u1"), | ||
| ("accesses", "list_accesses", (), "graphspaces/GS/auth/accesses"), | ||
| ( | ||
| "accesses", | ||
| "get_accesses", | ||
| ("a1",), | ||
| "graphspaces/GS/auth/accesses/a1", | ||
| ), | ||
| ("targets", "list_targets", (), "graphspaces/GS/auth/targets"), | ||
|
Muawiya-contact marked this conversation as resolved.
|
||
| ("belongs", "list_belongs", (), "graphspaces/GS/auth/belongs"), | ||
| ], | ||
| ) | ||
| def test_graphspace_scoped_endpoints_use_graphspace(endpoint, method_call, args, expected_subpath): | ||
| cfg = DummyCfg(url="http://127.0.0.1:8080", graphspace="GS", gs_supported=True, graph_name="g") | ||
| sess = DummySession(cfg) | ||
| auth = AuthManager(sess) | ||
|
|
||
| getattr(auth, method_call)(*args) | ||
| assert expected_subpath in sess.last | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "endpoint, method_call, args", | ||
| [ | ||
| ("users", "list_users", ()), | ||
| ("users", "get_user", ("u1",)), | ||
| ("accesses", "list_accesses", ()), | ||
| ("accesses", "get_accesses", ("a1",)), | ||
| ("targets", "list_targets", ()), | ||
| ("belongs", "list_belongs", ()), | ||
| ], | ||
| ) | ||
| def test_graphspace_scoped_endpoints_require_graphspace(endpoint, method_call, args): | ||
| # HugeGraph 1.7.0+ requires graphspace for these auth endpoints. | ||
| cfg = DummyCfg(url="http://127.0.0.1:8080", graphspace=None, gs_supported=False, graph_name="g") | ||
| sess = DummySession(cfg) | ||
| auth = AuthManager(sess) | ||
|
|
||
| with pytest.raises(ValueError, match="graphspace is required for auth endpoints"): | ||
| getattr(auth, method_call)(*args) | ||
|
|
||
|
|
||
| def test_groups_are_server_level(): | ||
| # With graphspace support | ||
| cfg = DummyCfg(url="http://127.0.0.1:8080", graphspace="GS", gs_supported=True, graph_name="g") | ||
| sess = DummySession(cfg) | ||
| auth = AuthManager(sess) | ||
| auth.list_groups() | ||
| assert "auth/groups" in sess.last | ||
|
|
||
| # Without graphspace support | ||
| cfg2 = DummyCfg(url="http://127.0.0.1:8080", graphspace=None, gs_supported=False, graph_name="g") | ||
| sess2 = DummySession(cfg2) | ||
| auth2 = AuthManager(sess2) | ||
| auth2.list_groups() | ||
| assert "auth/groups" in sess2.last | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.