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

Add new API for Legacy Device Migration #252

Merged
merged 7 commits into from
Jan 26, 2024

Conversation

overheadhunter
Copy link
Member

@overheadhunter overheadhunter commented Jan 25, 2024

This adds two new API endpoints:

  • deprecated GET /api/devices/{deviceId}/legacy-access-tokens (to be removed after all users migrated from 1.2.x)
  • permanent POST /api/users/me/access-tokens

The response body of the former and the request body of the latter are both JSON objects with these key-value-pairs:

{
  "vault1": "token1",
  "vault2": "token2",
  ...
}

The difference is that the deprecated legacy access tokens are encrypted using the device key, while the current access tokens posted to the users resource shall be encrypted using the user key.

Both endpoints are accessible to all users, as they only expose information owned by the currently logged in user.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added the ability to list legacy access tokens for devices.
    • Introduced a new feature to update user-specific vault keys.
  • Bug Fixes

    • Improved the retrieval of legacy access tokens by ensuring they are filtered by device and owner.
  • Tests

    • Implemented new tests to verify the functionality of legacy access token retrieval.
    • Added tests to ensure proper handling of access token POST requests.

`{"vault1": "jwe1", "vault2": "jwe2"}` instead of `[{"vaultId": "vault1", "token": "jwe1"}, ...]`
Copy link

coderabbitai bot commented Jan 25, 2024

Warning

Rate Limit Exceeded

@overheadhunter has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 20 minutes and 16 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between c7a2d70 and 58ff0d6.

Walkthrough

The recent updates involve enhancing the management of legacy access tokens and user-specific vault key handling. Key changes include the introduction of methods to list and update legacy tokens, the addition of new imports to support these functionalities, and the adjustment of methods to include user authentication. Test cases have been added and updated to ensure the correct behavior of the new and modified endpoints.

Changes

File Path Change Summary
.../api/DeviceResource.java
.../entities/LegacyAccessToken.java
Added imports, deprecated method for legacy tokens, LegacyAccessTokenDto record, and modified methods to include user authentication and owner details.
.../api/UsersResource.java New imports and updateMyAccessTokens method for vault key updates.
.../api/DeviceResourceTest.java
.../api/UsersResourceTest.java
Added/updated test methods. Updated imports and matchers in UsersResourceTest.

Poem

In the code where secrets nest,
A rabbit hopped to the devs' behest.
Tokens old, and keys anew,
🐇 Patched and tested, through and through. 🌟

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5c1cf28 and 94b3483.
Files selected for processing (5)
  • backend/src/main/java/org/cryptomator/hub/api/DeviceResource.java (4 hunks)
  • backend/src/main/java/org/cryptomator/hub/api/UsersResource.java (4 hunks)
  • backend/src/main/java/org/cryptomator/hub/entities/LegacyAccessToken.java (3 hunks)
  • backend/src/test/java/org/cryptomator/hub/api/DeviceResourceTest.java (1 hunks)
  • backend/src/test/java/org/cryptomator/hub/api/UsersResourceTest.java (2 hunks)
Additional comments: 14
backend/src/test/java/org/cryptomator/hub/api/UsersResourceTest.java (2)
  • 8-8: Removed import for org.hamcrest.CoreMatchers and added io.restassured.http.ContentType. This change is consistent with the rest of the file where ContentType is used.
  • 73-83: The new test method testPostAccessTokens correctly tests the POST request for access tokens. It uses a JSON body with UUIDs as keys and strings as values, which aligns with the PR's objective to handle user-specific vault keys.
backend/src/main/java/org/cryptomator/hub/entities/LegacyAccessToken.java (2)
  • 26-32: The @NamedNativeQuery annotation for LegacyAccessToken.getByDevice has been modified to LegacyAccessToken.getByDeviceAndOwner. This change is consistent with the PR's objective to clarify method names and align with the new functionality.
  • 54-58: The method getByDeviceAndOwner replaces the old getByDevice method, reflecting the change in the @NamedNativeQuery name. This change is correct and improves clarity by specifying that the tokens are fetched by both device and owner.
backend/src/main/java/org/cryptomator/hub/api/UsersResource.java (4)
  • 8-8: Added import for jakarta.validation.constraints.NotEmpty. This is necessary for the new updateMyAccessTokens method which requires a non-empty map as input.
  • 19-19: Added import for org.cryptomator.hub.entities.AuditEventVaultAccessGrant. This is used in the new updateMyAccessTokens method to log an audit event after updating access tokens.
  • 22-22: Added import for org.cryptomator.hub.entities.Vault. This is used in the new updateMyAccessTokens method to find vaults by their ID.
  • 70-94: The new method updateMyAccessTokens correctly handles the updating of user-specific vault keys. It takes a map of UUIDs to strings as input, checks for non-archived vaults, and updates or creates access tokens accordingly. It also logs an audit event for each access token update, which is a good security practice.
backend/src/main/java/org/cryptomator/hub/api/DeviceResource.java (4)
  • 26-26: Added import for org.cryptomator.hub.entities.LegacyAccessToken. This is necessary for the new getLegacyAccessTokens method which retrieves legacy access tokens.
  • 44-46: Added imports for java.util.Map, java.util.UUID, and java.util.stream.Collectors. These are used in the new getLegacyAccessTokens method to collect and return the tokens in a map.
  • 123-135: The new method getLegacyAccessTokens is correctly annotated as deprecated, which aligns with the PR's objective to support legacy devices temporarily. It retrieves legacy access tokens for a specific device and formats them into a map, which is consistent with the PR's description.
  • 175-175: The new record LegacyAccessTokenDto is added but not used within the provided code. It's unclear if this is an oversight or if it's intended for future use. However, since it's not causing any issues, it's acceptable.
backend/src/test/java/org/cryptomator/hub/api/DeviceResourceTest.java (2)
  • 81-87: The test method testGetLegacyAccessTokens1 correctly tests the retrieval of legacy access tokens for a specific device. It asserts the status code and the body content, ensuring the legacy tokens are returned as expected.
  • 90-96: The test method testGetLegacyAccessTokens2 performs a similar check as testGetLegacyAccessTokens1 for a different device. It also asserts the status code and the body content correctly.

Copy link
Member

@SailReal SailReal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; just one question :)

@overheadhunter overheadhunter requested a review from infeo January 26, 2024 10:48
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 94b3483 and ff0967e.
Files selected for processing (2)
  • backend/src/main/java/org/cryptomator/hub/api/UsersResource.java (4 hunks)
  • backend/src/test/java/org/cryptomator/hub/api/DeviceResourceTest.java (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • backend/src/main/java/org/cryptomator/hub/api/UsersResource.java
  • backend/src/test/java/org/cryptomator/hub/api/DeviceResourceTest.java

@overheadhunter overheadhunter added this to the 1.3.2 milestone Jan 26, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ff0967e and c7a2d70.
Files selected for processing (1)
  • backend/src/test/java/org/cryptomator/hub/api/DeviceResourceTest.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • backend/src/test/java/org/cryptomator/hub/api/DeviceResourceTest.java

@overheadhunter overheadhunter requested a review from infeo January 26, 2024 11:35
@overheadhunter overheadhunter merged commit 3dc07d3 into develop Jan 26, 2024
4 checks passed
@overheadhunter overheadhunter deleted the feature/legacy-device-migration-api branch January 26, 2024 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants