Skip to content

Fix tests - handle oauth consent skipped #43

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 2 commits into from
Apr 16, 2025
Merged

Conversation

eug-L
Copy link
Contributor

@eug-L eug-L commented Apr 15, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of the OAuth login process by making consent handling more robust, ensuring smoother authentication even if the consent window closes automatically or the consent page is not shown.
    • Fixed intermittent session loss issues during OAuth login by specifying a stable Selenium service version in the testing environment.

Copy link

coderabbitai bot commented Apr 15, 2025

Walkthrough

The goto_widget_selection() method in the tests/TestFiles/Modules/Web.php file was updated to enhance the handling of the OAuth login and consent process. The previous logic, which immediately checked for and clicked the consent button after switching to the OAuth window, was replaced with a timed loop. This loop repeatedly checks for the presence of the consent button and the status of the OAuth window, allowing for more robust handling of both the consent page and scenarios where consent is already granted and the window closes automatically. Additionally, the Docker Compose configuration was modified to pin the Selenium image version to "4.28" due to issues with version 4.29 causing intermittent driver session loss.

Changes

File(s) Change Summary
tests/TestFiles/Modules/Web.php Refactored the goto_widget_selection() method to implement a timed loop for handling OAuth consent window, replacing immediate consent button check with a more robust wait-and-retry mechanism. No changes to method signatures or exported entities.
tests/docker/docker-compose.yml Updated Selenium service to use fixed image version "4.28" instead of "latest" with a comment explaining issues with version 4.29 causing intermittent driver session loss on OAuth popout close.

Sequence Diagram(s)

sequenceDiagram
    participant TestScript
    participant BrowserDriver
    participant OAuthWindow

    TestScript->>BrowserDriver: Click login button
    BrowserDriver->>OAuthWindow: Open OAuth login window
    TestScript->>OAuthWindow: Enter email and password, submit form
    loop Wait for consent or window close (up to 5s)
        OAuthWindow-->>TestScript: Is window still open?
        alt Consent button present
            TestScript->>OAuthWindow: Click "#allow" consent button
        else
            TestScript->>TestScript: Wait and retry
        end
    end
    OAuthWindow-->>BrowserDriver: Window closes if consent granted
    TestScript->>BrowserDriver: Switch back to original window
    BrowserDriver->>TestScript: Wait for iframe to load
Loading

Possibly related PRs

  • Tests update for OAuth login #42: Both PRs modify the goto_widget_selection() method in tests/TestFiles/Modules/Web.php to improve handling of the OAuth login and consent flow, with the main PR refining the consent window wait logic introduced in the retrieved PR.

Poem

A rabbit hops through OAuth's gate,
Waiting as windows open, then abate.
No more rushing to click and go—
Now patience reigns, nice and slow.
With loops and checks, consent is won,
The test hops forward—robustly done! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 6048006 and d1cfeec.

📒 Files selected for processing (1)
  • tests/docker/docker-compose.yml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tests/docker/docker-compose.yml

🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.

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

🧹 Nitpick comments (2)
tests/TestFiles/Modules/Web.php (2)

218-223: Consider more specific exception handling.

While the current implementation works, it catches all exceptions rather than just element-not-found exceptions. This could potentially mask other issues.

-try {
-	$this->driver->find_element_and_click( '#allow' );
-	break;
-} catch ( \Exception $e ) { // phpcs:ignore
-	// consent button not found, do nothing.
-}
+try {
+	$this->driver->find_element_and_click( '#allow' );
+	break;
+} catch ( \Facebook\WebDriver\Exception\NoSuchElementException $e ) {
+	// consent button not found, do nothing.
+}

209-210: Consider extracting magic numbers to constants.

The 5-second timeout and 10ms sleep interval could be defined as constants or class properties for better maintainability.

+	private const OAUTH_CONSENT_TIMEOUT_SECONDS = 5;
+	private const OAUTH_CONSENT_POLL_INTERVAL_MICROSECONDS = 10000;

// Then in the method:
-		$start = microtime( true );
-		while ( ( microtime( true ) - $start ) < 5 ) {
+		$start = microtime( true );
+		while ( ( microtime( true ) - $start ) < self::OAUTH_CONSENT_TIMEOUT_SECONDS ) {
// And later:
-			usleep( 10000 );
+			usleep( self::OAUTH_CONSENT_POLL_INTERVAL_MICROSECONDS );

Also applies to: 225-226

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 473d633 and 6048006.

📒 Files selected for processing (1)
  • tests/TestFiles/Modules/Web.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/TestFiles/Modules/Web.php (1)
tests/TestFiles/Modules/Webdriver.php (3)
  • get_driver (43-45)
  • find_element_and_input (77-79)
  • find_element_and_click (73-75)
🔇 Additional comments (4)
tests/TestFiles/Modules/Web.php (4)

195-199: The window handle management looks good.

Properly obtains the window handles and switches to the new OAuth window.


202-202: Helpful comment addition.

Good clarification on why the logged-in page is not shown. This explains the behavior better than the previous comment.


209-226: Great implementation of robust OAuth consent handling.

This is a solid improvement that addresses the core issue. The implementation now handles both cases:

  1. When consent is already granted and the window closes automatically
  2. When the consent page is shown and requires clicking the allow button

The timed loop with exception handling is a much more reliable approach than the previous implementation.


228-230: The window switching after consent looks good.

Correctly switches back to the original window and waits for the iframe to be available.

@eug-L eug-L merged commit d612385 into master Apr 16, 2025
6 checks passed
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.

1 participant