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

[ECO-4330] Feature - server initiated auth #661

Merged
merged 14 commits into from
Sep 6, 2024

Conversation

sacOO7
Copy link
Collaborator

@sacOO7 sacOO7 commented Aug 16, 2024

Fixed #228

Summary by CodeRabbit

  • New Features

    • Added a logger method to the Realtime struct for improved logging access.
    • Defined a new authentication action constant for better action management.
    • Introduced a method to the MessageRecorder for flexible verification of received actions.
  • Improvements

    • Enhanced error handling in the authorization process for more robust management of potential issues.
    • Updated connection state management logic for improved clarity and control during reauthorization and reconnection.
  • Tests

    • Modified existing tests to align with new connection state expectations during reauthorization.
    • Added new tests to validate connection state transitions during reconnection scenarios.

@sacOO7 sacOO7 changed the title [ECO-4330][Feature] server initiated auth [ECO-4330]Feature - server initiated auth Aug 16, 2024
@github-actions github-actions bot temporarily deployed to staging/pull/661/godoc August 16, 2024 12:26 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/661/features August 16, 2024 12:26 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/661/godoc August 20, 2024 11:47 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/661/features August 20, 2024 11:47 Inactive
Copy link

coderabbitai bot commented Aug 21, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes involve enhancements to the authorization and connection management processes within the Ably library. Key modifications include the introduction of error handling in authorization callbacks, improved connection state management during reauthorization, and the addition of new logging and action constants. These updates aim to ensure compliance with the specified API design and improve the robustness of the connection lifecycle.

Changes

Files Change Summary
ably/auth.go Modified onExplicitAuthorize to return an error, enhancing error handling in authorization.
ably/export_test.go Added Logger() method to Realtime struct and introduced ActionAuth constant for actions.
ably/proto_protocol_message.go Enhanced String method of protocolMessage to include actionAuth in string representation.
ably/realtime_conn.go Renamed onClientAuthorize to onExplicitAuthorize with improved logic for connection states.
ably/realtime_conn_spec_integration_test.go Updated tests to reflect new connection state behaviors during reauthorization.
ably/ably_test.go Introduced CheckIfReceived method in MessageRecorder for flexible action receipt verification.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Auth
    participant Connection

    Client->>Auth: Request Token
    Auth->>Connection: Authorize with Token
    Connection-->>Auth: Token Valid
    Auth-->>Client: Token Granted
    Client->>Connection: Connect
    Connection->>Client: Connection Established
    Client->>Connection: Reauthorize with new Token
    Connection->>Auth: Request New Token
    Auth-->>Connection: New Token Granted
    Connection-->>Client: Reconnection Successful
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure compliance with RTN22, RTC8 (228)
Write spec tests for server-initiated reauth (228)

🐇 In the meadow, I hop with glee,
New tokens dance, oh so free!
Connections flow, like streams so bright,
With logs to guide us, day and night.
Hooray for changes, let’s all cheer,
For seamless reauth, we have no fear! 🌼


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 testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sacOO7 sacOO7 changed the title [ECO-4330]Feature - server initiated auth [ECO-4330] Feature - server initiated auth Aug 21, 2024
@github-actions github-actions bot temporarily deployed to staging/pull/661/godoc August 21, 2024 10:34 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/661/features August 21, 2024 10:34 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/661/features August 23, 2024 10:38 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/661/godoc August 23, 2024 10:38 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/661/features August 29, 2024 06:34 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/661/godoc August 29, 2024 06:34 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/661/godoc August 30, 2024 10:19 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/661/features August 30, 2024 10:19 Inactive
@sacOO7 sacOO7 force-pushed the feature/server-initiated-auth branch from 8dabea2 to 9bea0c0 Compare August 30, 2024 11:30
@github-actions github-actions bot temporarily deployed to staging/pull/661/features August 30, 2024 11:31 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/661/godoc August 30, 2024 11:31 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/661/godoc September 2, 2024 07:49 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/661/features September 2, 2024 07:49 Inactive
@sacOO7 sacOO7 force-pushed the feature/server-initiated-auth branch from cfce4b2 to 0352214 Compare September 2, 2024 08:06
@github-actions github-actions bot temporarily deployed to staging/pull/661/features September 2, 2024 08:07 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/661/godoc September 2, 2024 08:07 Inactive
@sacOO7 sacOO7 marked this pull request as ready for review September 2, 2024 08:38
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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 673864c and 0352214.

Files selected for processing (6)
  • ably/ably_test.go (1 hunks)
  • ably/auth.go (3 hunks)
  • ably/export_test.go (2 hunks)
  • ably/proto_protocol_message.go (1 hunks)
  • ably/realtime_conn.go (6 hunks)
  • ably/realtime_conn_spec_integration_test.go (4 hunks)
Additional comments not posted (13)
ably/export_test.go (2)

265-267: LGTM!

The code changes are approved.


317-317: LGTM!

The code changes are approved.

ably/proto_protocol_message.go (1)

186-188: LGTM!

The code changes are approved. The new case for handling actionAuth in the String method of the protocolMessage struct is correctly implemented and improves the method's functionality by allowing it to represent authentication-related messages distinctly. This change enhances the clarity and utility of the output for debugging or logging purposes.

ably/ably_test.go (1)

264-280: LGTM!

The new CheckIfReceived method looks good:

  • It correctly checks if a specified action has been received a certain number of times.
  • It handles the case when times is zero correctly by returning true if the counter is also zero.
  • It returns false if the specified number of occurrences is not found, which is the expected behavior.
  • The function is named appropriately and the parameters are clear and well-defined.
  • The function is well-structured and easy to understand.

Great job!

ably/auth.go (2)

85-85: LGTM!

The code changes are approved:

  • The onExplicitAuthorize field in the Auth struct has been updated to return an error, matching the new function signature.
  • The newAuth constructor correctly initializes the onExplicitAuthorize field with a function that returns nil error.

Also applies to: 96-96


317-320: LGTM!

The code changes are approved:

  • The Authorize method now handles the error returned by the onExplicitAuthorize callback.
  • It correctly propagates the error if onExplicitAuthorize returns a non-nil error.

These changes improve the error handling by allowing the callback to signal failure conditions.

ably/realtime_conn.go (3)

Line range hint 114-124: LGTM!

The code changes are approved.


Line range hint 758-878: LGTM!

The code changes are approved. The error handling logic is correct and follows the Ably protocol.


Line range hint 938-1013: LGTM!

The code changes are approved. The onExplicitAuthorize method handles the client-requested authorization correctly in different connection states.

ably/realtime_conn_spec_integration_test.go (4)

1591-1596: Looks good!

The changes improve the test by expecting and verifying the correct connection state transitions from Disconnected to Connecting during a reauthorization and reconnection attempt.


1674-1681: LGTM!

The changes align with the previous segment and correctly verify the expected connection state transitions from Disconnected to Connecting during reauthorization.


1697-1702: Approved.

The changes correctly verify that after transitioning to the "Connecting" state, a successful reconnection results in a "CONNECTED" event being emitted.


1709-1784: New test function looks great!

The new TestRealtimeConn_RTN15h3_Success function covers an important scenario where the connection encounters a non-fatal disconnection (status code 506) and is expected to reconnect successfully with the existing token.

The test verifies the correct connection state transitions:

  1. Disconnected due to the non-fatal error
  2. Transition to "Connecting" state for reconnection attempt
  3. Successful reconnection with the existing token, emitting a "CONNECTED" event

Adding this test improves the coverage of the realtime connection behavior.

ably/ably_test.go Outdated Show resolved Hide resolved
ably/realtime_conn_spec_integration_test.go Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to staging/pull/661/godoc September 4, 2024 06:19 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/661/features September 4, 2024 06:19 Inactive
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.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
ably/export_test.go (1)

269-271: Add Documentation for Logger() Method

The Logger() method in the Realtime struct is not documented in the Go file, and there is no mention of it in the markdown files for API design documentation. It is important to document this method to ensure clarity and consistency in the public API.

  • Add documentation for the Logger() method in ably/export_test.go.
  • Ensure that the Logger() method is included in the API design documentation to align with the project's API design principles.
Analysis chain

LGTM!

The code changes are approved.

Verify if the method is documented and follows the API design principles.

Since the Logger() method is exported and part of the public API, ensure that it is well-documented and follows the API design principles established in the 1.2 API design documentation.

Run the following script to verify the documentation and API design compliance:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description:
# - Verify if the `Logger()` method is documented.
# - Verify if the `Logger()` method follows the API design principles.

# Test 1: Search for the method documentation. Expect: Documentation for the `Logger()` method.
rg --type go -A 5 $'func \(r \*Realtime\) Logger\(\)'

# Test 2: Search for the API design documentation. Expect: API design principles for the `Logger()` method.
rg --type md -A 5 $'Logger\(\)'

Length of output: 704

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0352214 and 9689fcd.

Files selected for processing (5)
  • README.md (1 hunks)
  • ably/auth.go (3 hunks)
  • ably/export_test.go (2 hunks)
  • ably/realtime_conn.go (6 hunks)
  • ably/realtime_conn_spec_integration_test.go (4 hunks)
Files skipped from review due to trivial changes (1)
  • README.md
Files skipped from review as they are similar to previous changes (1)
  • ably/auth.go
Additional comments not posted (12)
ably/export_test.go (1)

326-326: LGTM!

The code changes are approved.

Verify if the constant is documented and follows the API design principles.

Since the ActionAuth constant is exported and part of the public API, ensure that it is well-documented and follows the API design principles established in the 1.2 API design documentation.

Run the following script to verify the documentation and API design compliance:

Verify if the constant is used correctly in the implementation of the server-initiated reauthentication feature.

The ActionAuth constant is related to the server-initiated reauthentication feature (RTN22) mentioned in the PR objectives. Ensure that the constant is used correctly in the implementation of the feature.

Run the following script to verify the usage of the constant:

ably/realtime_conn.go (6)

Line range hint 115-125: LGTM!

The code changes are approved.


Line range hint 783-789: LGTM!

The code changes are approved.


833-835: LGTM!

The code changes are approved.


891-913: LGTM!

The code changes are approved.


921-924: LGTM!

The code changes are approved.


Line range hint 963-1038: LGTM!

The code changes are approved.

ably/realtime_conn_spec_integration_test.go (5)

1525-1530: LGTM!

The code correctly waits for and asserts the expected connection state transitions from Disconnected to Connecting before a reauthorization and reconnection attempt.


1608-1615: LGTM!

The code correctly waits for and asserts the expected connection state transitions from Disconnected to Connecting before a reauthorization and reconnection attempt. It also verifies that the connection state is Connecting after the transition.


1631-1636: LGTM!

The code correctly waits for and asserts the expected CONNECTED event after the connection transitions to CONNECTING state.


1686-1693: LGTM!

The code correctly waits for and asserts the expected connection state transitions from Disconnected to Connecting before a reconnection attempt. It also verifies that the connection state is Connecting after the transition.


1708-1714: LGTM!

The code correctly waits for and asserts the expected CONNECTED event after the connection transitions to CONNECTING state.

@sacOO7 sacOO7 requested a review from amnonbc September 4, 2024 10:59
Copy link
Contributor

@amnonbc amnonbc left a comment

Choose a reason for hiding this comment

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

nice work.

ably/ably_test.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

RTN22, RTC8: Server-initiated reauth
2 participants