-
Notifications
You must be signed in to change notification settings - Fork 0
Test and Update Authentication Module #124
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
base: develop
Are you sure you want to change the base?
Test and Update Authentication Module #124
Conversation
# Motivation The **Codegen on OSS** package provides a pipeline that: - **Collects repository URLs** from different sources (e.g., CSV files or GitHub searches). - **Parses repositories** using the codegen tool. - **Profiles performance** and logs metrics for each parsing run. - **Logs errors** to help pinpoint parsing failures or performance bottlenecks. <!-- Why is this change necessary? --> # Content <!-- Please include a summary of the change --> see [codegen-on-oss/README.md](https://github.com/codegen-sh/codegen-sdk/blob/acfe3dc07b65670af33b977fa1e7bc8627fd714e/codegen-on-oss/README.md) # Testing <!-- How was the change tested? --> `uv run modal run modal_run.py` No unit tests yet 😿 # Please check the following before marking your PR as ready for review - [ ] I have added tests for my changes - [x] I have updated the documentation or added new documentation as needed
Original commit by Tawsif Kamal: Revert "Revert "Adding Schema for Tool Outputs"" (codegen-sh#894) Reverts codegen-sh#892 --------- Co-authored-by: Rushil Patel <rpatel@codegen.com> Co-authored-by: rushilpatel0 <171610820+rushilpatel0@users.noreply.github.com>
Original commit by Ellen Agarwal: fix: Workaround for relace not adding newlines (codegen-sh#907)
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Join our Discord community for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Reviewer's GuideThis PR introduces a comprehensive unit test suite for the Authentication module, hardens token storage and removal with atomic file operations and strict permissions, enhances error handling and logging across authentication workflows, refines the decorator-based login flow, updates documentation and docstrings, and tweaks project configuration for testing and release management. Sequence Diagram for Secure Token Saving (TokenManager.save_token)sequenceDiagram
participant C as Client
participant TM as TokenManager
participant FS as FileSystem
C->>TM: save_token(api_token)
TM->>TM: _ensure_config_dir() // Ensures dir exists with 0700 permissions
Note over TM,FS: Writes token to a temporary file first
TM->>FS: open(temp_file, "w")
TM->>FS: json.dump({"token": api_token}, f)
TM->>FS: os.chmod(temp_file, 0o600) // Secure temp file
Note over TM,FS: Atomically replaces the old token file
TM->>FS: os.replace(temp_file, self.token_file)
alt Error During Save
TM->>FS: Operation Fails (e.g., I/O error)
FS-->>TM: Raises OSError
TM-->>C: Raises OSError (logs error)
end
Sequence Diagram for Secure Token Retrieval (TokenManager.get_token)sequenceDiagram
participant C as Client
participant TM as TokenManager
participant FS as FileSystem
C->>TM: get_token()
TM->>FS: os.access(config_dir, R_OK)?
alt Config directory not readable
FS-->>TM: False (or raises error)
TM->>TM: Log warning
TM-->>C: None
end
TM->>FS: os.path.exists(token_file)?
alt Token file does not exist
FS-->>TM: False
TM-->>C: None
end
TM->>FS: os.stat(token_file) // Get file mode
FS-->>TM: file_mode
alt Insecure file permissions (group/other access)
TM->>TM: Log warning "Token file has insecure permissions, fixing..."
TM->>FS: os.chmod(token_file, 0o600) // Set to read/write for owner only
end
TM->>FS: open(token_file, "r")
FS-->>TM: File handle
TM->>TM: data = json.load(f)
alt Invalid JSON or No Token in file
TM->>TM: Log error (e.g., "Invalid JSON in token file")
TM-->>C: None
else Token Key Missing
TM->>TM: Log warning ("Token file exists but contains no token")
TM-->>C: None
end
TM-->>C: token
alt OSError during read
TM->>TM: Log error
TM-->>C: None
end
Sequence Diagram for
|
Change | Details | Files |
---|---|---|
Added comprehensive test suite for authentication components |
|
tests/unit/codegen/cli/auth/test_session.py tests/unit/codegen/cli/auth/test_token_manager.py tests/unit/codegen/cli/auth/test_decorators.py tests/unit/codegen/cli/auth/test_login.py tests/unit/codegen/cli/auth/simple_test.py tests/unit/codegen/cli/auth/test_constants.py tests/unit/codegen/cli/auth/conftest.py |
Enhanced security and atomic operations in TokenManager |
|
src/codegen/cli/auth/token_manager.py |
Improved error handling and logging across auth workflows |
|
src/codegen/cli/auth/token_manager.py src/codegen/cli/auth/login.py |
Refined requires_auth decorator and login flow |
|
src/codegen/cli/auth/decorators.py |
Augmented documentation and docstrings |
|
src/codegen/cli/auth/README.md src/codegen/cli/auth/token_manager.py src/codegen/cli/auth/decorators.py src/codegen/cli/auth/login.py |
Updated project configuration for testing and release |
|
pyproject.toml package.json |
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai review
on the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with@sourcery-ai issue
to create an issue from it. - Generate a pull request title: Write
@sourcery-ai
anywhere in the pull
request title to generate a title at any time. You can also comment
@sourcery-ai title
on the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summary
anywhere in
the pull request body to generate a PR summary at any time exactly where you
want it. You can also comment@sourcery-ai summary
on the pull request to
(re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guide
on the pull
request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolve
on the
pull request to resolve all Sourcery comments. Useful if you've already
addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismiss
on the pull
request to dismiss all existing Sourcery reviews. Especially useful if you
want to start fresh with a new review - don't forget to comment
@sourcery-ai review
to trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request
summary, the reviewer's guide, and others. - Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
I see a check failed - I'm on it! 🫡 |
✅ Fixed the failing pre-commit checks in this commit. The issues were primarily formatting-related:
The CI should now pass successfully. 💻 View my work • React 👍 or 👎 |
Overview
This PR implements comprehensive testing and security updates for the Authentication module in the Codegen SDK.
Changes
Added Comprehensive Test Suite:
Security Improvements:
Error Handling Enhancements:
Documentation Updates:
Testing
All tests pass successfully, verifying the functionality and security of the authentication module.
Related Issues
Resolves ZAM-412
💻 View my work • About Codegen
Note
I'm currently writing a description for your pull request. I should be done shortly (<1 minute). Please don't edit the description field until I'm finished, or we may overwrite each other. If I find nothing to write about, I'll delete this message.
Summary by Sourcery
Secure and harden the Authentication module by enforcing file/dir permission controls, using atomic writes and secure deletion for tokens, improving error handling and logging in authentication flows and decorators, and adding comprehensive unit tests and documentation. Also adjust CI config in package.json and pyproject.toml.
Enhancements:
CI:
Documentation:
Tests: