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

TESTING EXTERNAL SCRIPT: external merge request from Contributor #37393

Open
wants to merge 7 commits into
base: release
Choose a base branch
from

Conversation

sneha122
Copy link
Contributor

@sneha122 sneha122 commented Nov 14, 2024

Description

Fixes #

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.Datasource"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11839915463
Commit: 7293e2c
Cypress dashboard.
Tags: @tag.Datasource
Spec:


Thu, 14 Nov 2024 15:46:46 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced SMTP plugin flexibility for authentication, allowing connections without mandatory credentials.
    • Improved error handling for connection issues related to SMTP authentication.
  • Bug Fixes

    • Expanded error handling in testing to provide clearer feedback on connection issues.
  • Tests

    • Introduced new tests for SMTP connections without authentication.
    • Updated existing tests for clarity and alignment with new authentication logic.

@sneha122 sneha122 added the ok-to-test Required label for CI label Nov 14, 2024
Copy link
Contributor

coderabbitai bot commented Nov 14, 2024

Walkthrough

The changes in the pull request involve modifications to the SmtpPlugin.java and SmtpPluginTest.java files. The SmtpPlugin.java file updates the datasourceCreate and validateDatasource methods to enhance SMTP authentication handling, allowing for optional credentials. The SmtpPluginTest.java file introduces new tests for SMTP connections without authentication, restructuring the setup method for better clarity and functionality in testing scenarios.

Changes

File Change Summary
app/server/appsmith-plugins/smtpPlugin/src/main/java/com/external/plugins/SmtpPlugin.java Updated datasourceCreate for conditional session creation based on authentication presence. Removed strict checks in validateDatasource. Enhanced error handling in testDatasource.
app/server/appsmith-plugins/smtpPlugin/src/test/java/com/external/plugins/SmtpPluginTest.java Added smtpWithoutAuth container for testing without authentication. Renamed testNullAuthentication to testConnectionWithoutAuth. Updated setup and assertions for clarity.

Suggested labels

Bug, Task, Datasources, Integrations Pod General

Suggested reviewers

  • abhvsn
  • sharat87

🎉 In the realm of code, changes unfold,
SMTP's logic, now brave and bold.
With tests that dance, and auth that bends,
Flexibility reigns, as the plugin mends.
A journey of bytes, where clarity sings,
Cheers to the code, and the joy it brings! 🎊


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>, 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.

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
Contributor

@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 and nitpick comments (2)
app/server/appsmith-plugins/smtpPlugin/src/test/java/com/external/plugins/SmtpPluginTest.java (1)

143-157: Add a comment explaining the configuration reset.

The test is well-structured, but consider adding a comment before line 157 explaining why we reset to the default SMTP configuration:

  })
  .verifyComplete();
+ // Reset to default SMTP configuration to avoid affecting subsequent tests
  configureSmtpConnection(smtp);
app/server/appsmith-plugins/smtpPlugin/src/main/java/com/external/plugins/SmtpPlugin.java (1)

215-232: Refactor: Set 'mail.smtp.auth' property conditionally

Consider setting the mail.smtp.auth property only when authentication is provided.

Apply this diff to simplify the code:

prop.put("mail.transport.protocol", "smtp");
-prop.put("mail.smtp.auth", true);
prop.put("mail.smtp.starttls.enable", "true");
prop.put("mail.smtp.host", endpoint.getHost());
Long port = (endpoint.getPort() == null || endpoint.getPort() < 0) ? 25 : endpoint.getPort();
prop.put("mail.smtp.port", String.valueOf(port));
prop.put("mail.smtp.ssl.trust", endpoint.getHost());

Session session;

if (authentication != null && StringUtils.hasText(authentication.getUsername())
    && StringUtils.hasText(authentication.getPassword())) {

+   prop.put("mail.smtp.auth", "true");

    String username = authentication.getUsername();
    String password = authentication.getPassword();

    session = Session.getInstance(prop, new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }
    });
} else {
+   prop.put("mail.smtp.auth", "false");

    session = Session.getInstance(prop);
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 17537e7 and 51eb3bb.

📒 Files selected for processing (2)
  • app/server/appsmith-plugins/smtpPlugin/src/main/java/com/external/plugins/SmtpPlugin.java (2 hunks)
  • app/server/appsmith-plugins/smtpPlugin/src/test/java/com/external/plugins/SmtpPluginTest.java (3 hunks)
🔇 Additional comments (2)
app/server/appsmith-plugins/smtpPlugin/src/test/java/com/external/plugins/SmtpPluginTest.java (1)

62-77: LGTM! Well-structured container setup and refactoring.

The addition of smtpWithoutAuth container and the refactoring of the setup method improve test maintainability and coverage.

app/server/appsmith-plugins/smtpPlugin/src/main/java/com/external/plugins/SmtpPlugin.java (1)

Line range hint 268-277: Good use of specific exception handling

Catching NoSuchProviderException and AuthenticationFailedException separately provides clearer error messages.

Copy link

Failed server tests

  • com.appsmith.server.configurations.CommonConfigTest#objectMapper_BeanCreated_WithPublicJsonViewAsDefault

Copy link
Contributor

@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 and nitpick comments (1)
app/server/appsmith-plugins/smtpPlugin/src/test/java/com/external/plugins/SmtpPluginTest.java (1)

143-157: LGTM! Consider adding error case assertions.

The happy path is well tested. Consider adding assertions for invalid configurations (e.g., wrong port) to ensure proper error handling.

Add error case test:

+@Test
+public void testConnectionWithoutAuth_invalidPort() {
+    configureSmtpConnection(smtpWithoutAuth);
+    DatasourceConfiguration invalidConfig = createDatasourceConfiguration();
+    invalidConfig.setAuthentication(null);
+    invalidConfig.setEndpoints(List.of(new Endpoint(host, 9999L)));
+
+    StepVerifier.create(pluginExecutor.testDatasource(invalidConfig))
+            .assertNext(result -> {
+                assertNotNull(result);
+                assertFalse(result.isSuccess());
+            })
+            .verifyComplete();
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 51eb3bb and 7293e2c.

📒 Files selected for processing (2)
  • app/server/appsmith-plugins/smtpPlugin/src/main/java/com/external/plugins/SmtpPlugin.java (2 hunks)
  • app/server/appsmith-plugins/smtpPlugin/src/test/java/com/external/plugins/SmtpPluginTest.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/server/appsmith-plugins/smtpPlugin/src/main/java/com/external/plugins/SmtpPlugin.java
🔇 Additional comments (3)
app/server/appsmith-plugins/smtpPlugin/src/test/java/com/external/plugins/SmtpPluginTest.java (3)

71-73: LGTM! Good refactoring of setup method.

Clean separation of concerns by delegating configuration to a helper method.


61-65: LGTM! Container configuration looks good.

The container is properly configured with empty credentials and a different port to avoid conflicts.

Let's verify the port availability:

#!/bin/bash
# Check if port 1025 is commonly used by other services
rg -l "1025" | grep -i "docker\|container\|config"

75-78: ⚠️ Potential issue

Consider thread safety implications.

The method modifies static fields (host and port), which could cause issues if tests are run in parallel. Consider making these fields instance-specific or using thread-local storage.

Let's check for parallel test execution configurations:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants