-
Notifications
You must be signed in to change notification settings - Fork 1
Add CI test workflow and schema-aligned test mocks #58
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
Closed
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0ed7149
Add test workflow and schema-aligned test mocks
devin-ai-integration[bot] c118de7
Fix linting issues: remove unused imports and add noqa comment
devin-ai-integration[bot] 645bede
Fix CI: explicitly install pytest before running tests
devin-ai-integration[bot] d8bea3d
Add PyJWT to dev dependencies for authentication tests
devin-ai-integration[bot] 901ecc2
Fix auth: ensure consistent string handling in JWT encoding
devin-ai-integration[bot] 9db43e2
Fix auth: add input validation for JWT creation
devin-ai-integration[bot] d668fe4
Fix client: update auth token parameter name and add validation
devin-ai-integration[bot] 23829dd
Fix tests: properly mock response.text for json.loads
devin-ai-integration[bot] fb7f7fe
Fix tests: improve mock_request fixture setup and remove redundant st…
devin-ai-integration[bot] 980815d
Fix tests: update header assertions to match client headers
devin-ai-integration[bot] 2abcb6c
Fix tests: improve mock request verification with detailed assertions
devin-ai-integration[bot] ee0fb6a
Fix tests: update all test assertions to use consistent verification …
devin-ai-integration[bot] 5526835
Fix client: ensure headers are properly passed through in _request me…
devin-ai-integration[bot] 6b2135e
Fix tests: update mock_request fixture to properly handle headers
devin-ai-integration[bot] 4ad4190
Fix tests: ensure mock_request returns headers in expected format
devin-ai-integration[bot] ae29f7e
Fix tests: update header assertions to handle httpx.Headers objects
devin-ai-integration[bot] 398633c
Fix lint: remove unused ANY import
devin-ai-integration[bot] c10a414
Fix tests: update all header assertions to use consistent case-insens…
devin-ai-integration[bot] ed15b11
Fix client: wrap FileRange fields under 'range' key in read_source_code
devin-ai-integration[bot] 5844c02
Fix tests: update remaining header assertions to use case-insensitive…
devin-ai-integration[bot] bd7544b
Fix client: return full health check response instead of boolean
devin-ai-integration[bot] 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| name: Run Tests and Lint | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [ main ] | ||
|
|
||
| jobs: | ||
| build-and-test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check out code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: '3.10' | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| pip install --upgrade pip | ||
| pip install -e .[dev] | ||
|
|
||
| - name: Lint with ruff | ||
| run: | | ||
| ruff check . | ||
|
|
||
| - name: Run tests | ||
| run: | | ||
| pip install pytest | ||
| pytest --maxfail=1 --disable-warnings -q |
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Unit tests for the lsproxy package.""" |
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,72 @@ | ||
| """Unit tests for authentication utilities.""" | ||
| import pytest | ||
| import jwt | ||
| from datetime import datetime, timedelta, timezone | ||
|
|
||
| from lsproxy.auth import create_jwt, base64url_encode | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def sample_payload(): | ||
| """Create a sample JWT payload.""" | ||
| return { | ||
| "sub": "test-user", | ||
| "exp": int((datetime.now(timezone.utc) + timedelta(hours=1)).timestamp()) | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def sample_secret(): | ||
| """Create a sample secret key.""" | ||
| return "test-secret-key-1234" | ||
|
|
||
|
|
||
| def test_base64url_encode(): | ||
| """Test base64url encoding.""" | ||
| # Test basic encoding | ||
| assert base64url_encode(b"test") == "dGVzdA" | ||
|
|
||
| # Test padding removal | ||
| assert base64url_encode(b"t") == "dA" | ||
| assert base64url_encode(b"te") == "dGU" | ||
| assert base64url_encode(b"tes") == "dGVz" | ||
|
|
||
| # Test URL-safe characters | ||
| assert "+" not in base64url_encode(b"???") | ||
| assert "/" not in base64url_encode(b"???") | ||
|
|
||
|
|
||
| def test_create_jwt(sample_payload, sample_secret): | ||
| """Test JWT creation.""" | ||
| token = create_jwt(sample_payload, sample_secret) | ||
|
|
||
| # Verify token structure | ||
| assert isinstance(token, str) | ||
| assert len(token.split(".")) == 3 | ||
|
|
||
| # Verify token can be decoded | ||
| decoded = jwt.decode(token, sample_secret, algorithms=["HS256"]) | ||
| assert decoded["sub"] == sample_payload["sub"] | ||
| assert decoded["exp"] == sample_payload["exp"] | ||
|
|
||
|
|
||
|
|
||
|
|
||
| def test_create_jwt_invalid_payload(): | ||
| """Test JWT creation with invalid payload.""" | ||
| with pytest.raises(TypeError): | ||
| create_jwt("not a dict", "secret") | ||
|
|
||
| with pytest.raises(ValueError): | ||
| create_jwt({}, "secret") # Empty payload | ||
|
|
||
|
|
||
| def test_create_jwt_invalid_secret(): | ||
| """Test JWT creation with invalid secret.""" | ||
| payload = {"sub": "test"} | ||
|
|
||
| with pytest.raises(ValueError): | ||
| create_jwt(payload, "") # Empty secret | ||
|
|
||
| with pytest.raises(TypeError): | ||
| create_jwt(payload, None) # None secret | ||
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.
Suggestion: Consider adding tests for edge cases such as payloads with special characters or very large payloads to ensure the
create_jwtfunction handles them correctly. [enhancement]