-
Notifications
You must be signed in to change notification settings - Fork 0
fix: eliminate agent card JSON dependency from connect, simple_guard, and fastapi integration #37
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f204e78
docs: align README with Agent Guard product branding
beonde 97f06db
fix: eliminate agent card JSON dependency from connect, simple_guard,…
beonde 1e3ec7a
fix: address copilot review comments on PR #37
beonde 005b50a
Merge branch 'main' into fix/eliminate-agent-card-json
beonde 3e5c51e
ci: increase integration test timeout from 15m to 25m
beonde 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -428,6 +428,75 @@ async def test_endpoint(request: Request): | |
| assert data["agent_id"] is None | ||
|
|
||
|
|
||
| class TestLazyGuardBinding: | ||
| """Tests for lazy guard binding (callable and set_guard).""" | ||
|
|
||
| def test_middleware_with_callable_guard(self): | ||
| """Test that guard can be a callable that returns the SimpleGuard.""" | ||
| mock_guard = MagicMock() | ||
| mock_guard.agent_id = "test-agent" | ||
| mock_guard.verify_inbound.return_value = {"iss": "did:key:caller", "sub": "test"} | ||
|
|
||
| app = FastAPI() | ||
| app.add_middleware( | ||
| CapiscioMiddleware, | ||
| guard=lambda: mock_guard, | ||
| exclude_paths=["/health"], | ||
| ) | ||
|
|
||
| @app.post("/test") | ||
| async def test_endpoint(request: Request): | ||
| return {"agent_id": getattr(request.state, 'agent_id', None)} | ||
|
|
||
| client = TestClient(app) | ||
| headers = {"X-Capiscio-Badge": "mock.jws.token", "Content-Type": "application/json"} | ||
| response = client.post("/test", json={}, headers=headers) | ||
| assert response.status_code == 200 | ||
| assert response.json()["agent_id"] == "did:key:caller" | ||
|
|
||
| def test_middleware_with_none_guard_passes_through(self): | ||
| """Test that None guard returns 503 (fail closed).""" | ||
| app = FastAPI() | ||
| app.add_middleware( | ||
| CapiscioMiddleware, | ||
| guard=None, | ||
| exclude_paths=["/health"], | ||
| ) | ||
|
|
||
| @app.post("/test") | ||
| async def test_endpoint(request: Request): | ||
| return { | ||
| "agent": getattr(request.state, 'agent', 'not-set'), | ||
| "agent_id": getattr(request.state, 'agent_id', 'not-set'), | ||
| } | ||
|
|
||
| client = TestClient(app) | ||
| response = client.post("/test", json={}) | ||
| assert response.status_code == 503 | ||
| assert "guard is not available" in response.json()["error"] | ||
|
|
||
|
Comment on lines
+457
to
+477
|
||
| def test_middleware_callable_returning_none(self): | ||
| """Test that callable returning None (guard not ready) returns 503.""" | ||
| app = FastAPI() | ||
| app.add_middleware( | ||
| CapiscioMiddleware, | ||
| guard=lambda: None, | ||
| exclude_paths=["/health"], | ||
| ) | ||
|
|
||
| @app.post("/test") | ||
| async def test_endpoint(request: Request): | ||
| return { | ||
| "agent": getattr(request.state, 'agent', 'not-set'), | ||
| "agent_id": getattr(request.state, 'agent_id', 'not-set'), | ||
| } | ||
|
|
||
| client = TestClient(app) | ||
| response = client.post("/test", json={}) | ||
| assert response.status_code == 503 | ||
| assert "guard is not available" in response.json()["error"] | ||
|
|
||
|
|
||
| class TestAutoEvents: | ||
| """Tests for middleware auto-event emission.""" | ||
|
|
||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log call uses an f-string but doesn't interpolate anything. Consider using a plain string to avoid unnecessary formatting overhead and keep logging consistent.