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

chore: snowflake junit test cases added for key pair auth #34810

Merged
merged 3 commits into from
Jul 9, 2024

Conversation

sneha122
Copy link
Contributor

@sneha122 sneha122 commented Jul 9, 2024

Description

This PR adds JUnit test cases for snowflake Key auth pair feature added. Following cases have been added:

  • For basic authentication mechanism, when we do datasource create -> hikari config should have non empty username and password and datasource object inside hikari config should be null
  • For key pair authentication mechanism with valid private key -> hikari config should have datasource object which is of type SnowflakeBasicDatasource and username, password should be null.
  • For key pair authentication mechanism with invalid private key -> error should be thrown with appropriate error message
  • For key pair authentication mechanism with valid private key -> SnowflakeKeyUtils.readEncryptedPrivateKey should return valid instance of PrivateKey class.

Note: Valid private key generated for above test cases is unencrypted private key (i.e. without passphrase). Adding test cases with private key having passphrase was a little complex than anticipated, hence will create a separate task and tackle it separately.

Fixes #34692
or
Fixes Issue URL

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.Perf"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/9856542221
Commit: 87074a7
Cypress dashboard.
Tags: @tag.Perf
Spec:


Tue, 09 Jul 2024 12:20:08 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • Tests
    • Implemented new tests for key pair authentication with both valid and invalid private keys.
    • Added tests for basic authentication.
    • Introduced tests for reading an encrypted private key.

Copy link
Contributor

coderabbitai bot commented Jul 9, 2024

Walkthrough

The changes in the SnowflakePluginTest.java file include the addition of new methods for generating valid and invalid private keys and creating datasource configurations. It also involves implementing test cases for key pair authentication with both valid and invalid private keys, basic authentication, and reading an encrypted private key. These changes are part of adding new JUnit test cases for the Snowflake key pair authentication mechanism recently added.

Changes

Files Change Summaries
app/server/appsmith-plugins/snowflakePlugin/src/test/java/com/external/plugins/SnowflakePluginTest.java - Imported additional classes/interfaces.
- Added methods for generating private keys and configurations.
- Implemented tests for key pair and basic authentication.
- Modified and added new tests for private keys.

Assessment against linked issues

Objective Addressed Explanation
Add test cases for Snowflake key pair authentication mechanism (#34692)
Validate Snowflake datasource for key pair with tests (#34465)

Possibly related issues

Poem

In code we trust, with keys so fair,
To authenticate with utmost care.
Tests we write to validate,
Secure the path, and celebrate.
Snowflake shines in data's light,
Thanks to code, all works just right. 🚀


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

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

@github-actions github-actions bot added Integrations Pod Issues related to a specific integration snowflake Issues related to the snowflake Integration Task A simple Todo skip-changelog Adding this label to a PR prevents it from being listed in the changelog labels Jul 9, 2024
@sneha122 sneha122 added the ok-to-test Required label for CI label Jul 9, 2024
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ed42302 and ff4c842.

Files selected for processing (1)
  • app/server/appsmith-plugins/snowflakePlugin/src/test/java/com/external/plugins/SnowflakePluginTest.java (4 hunks)
Additional context used
Learnings (1)
app/server/appsmith-plugins/snowflakePlugin/src/test/java/com/external/plugins/SnowflakePluginTest.java (1)
Learnt from: AmanAgarwal041
PR: appsmithorg/appsmith#34491
File: app/server/appsmith-plugins/snowflakePlugin/src/main/java/com/external/plugins/SnowflakePlugin.java:320-338
Timestamp: 2024-06-26T11:16:09.077Z
Learning: The `encryptedPassphrase` field in the `KeyPairAuth` class for Snowflake authentication is optional and does not require validation for emptiness.
Gitleaks
app/server/appsmith-plugins/snowflakePlugin/src/test/java/com/external/plugins/SnowflakePluginTest.java

68-70: Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.

(private-key)

Additional comments not posted (8)
app/server/appsmith-plugins/snowflakePlugin/src/test/java/com/external/plugins/SnowflakePluginTest.java (8)

53-75: Potential Security Issue: Handling Private Keys

The method generates and returns a private key in PEM format. Ensure that this key is not logged or exposed in any way to avoid security risks.

Tools
Gitleaks

68-70: Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.

(private-key)


78-91: Potential Security Issue: Handling Private Keys

The method generates and returns a private key in Base64 encoded format. Ensure that this key is not logged or exposed in any way to avoid security risks.


93-113: LGTM!

The method correctly sets up a DatasourceConfiguration with basic authentication details.


115-137: LGTM!

The method correctly sets up a DatasourceConfiguration with key pair authentication details.


351-366: LGTM!

The test method correctly validates the Hikari config setup for key pair authentication with a valid private key.


368-376: LGTM!

The test method correctly validates the error handling for key pair authentication with an invalid private key.


378-392: LGTM!

The test method correctly validates the Hikari config setup for basic authentication.


394-401: LGTM!

The test method correctly validates the reading of an encrypted private key.

Copy link
Contributor

@NilanshBansal NilanshBansal left a comment

Choose a reason for hiding this comment

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

Just some minor changes. Rest LGTM!

@sneha122 sneha122 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jul 9, 2024
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ff4c842 and 87074a7.

Files selected for processing (1)
  • app/server/appsmith-plugins/snowflakePlugin/src/test/java/com/external/plugins/SnowflakePluginTest.java (4 hunks)
Additional context used
Learnings (1)
app/server/appsmith-plugins/snowflakePlugin/src/test/java/com/external/plugins/SnowflakePluginTest.java (1)
Learnt from: AmanAgarwal041
PR: appsmithorg/appsmith#34491
File: app/server/appsmith-plugins/snowflakePlugin/src/main/java/com/external/plugins/SnowflakePlugin.java:320-338
Timestamp: 2024-06-26T11:16:09.077Z
Learning: The `encryptedPassphrase` field in the `KeyPairAuth` class for Snowflake authentication is optional and does not require validation for emptiness.
Gitleaks
app/server/appsmith-plugins/snowflakePlugin/src/test/java/com/external/plugins/SnowflakePluginTest.java

80-82: Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.

(private-key)

Additional comments not posted (7)
app/server/appsmith-plugins/snowflakePlugin/src/test/java/com/external/plugins/SnowflakePluginTest.java (7)

16-16: Imports approved.

The imports for SnowflakeKeyUtils and SnowflakeBasicDataSource are necessary and correctly used in the code.

Also applies to: 24-24


90-110: Method approved.

The createBasicAuthConfig method correctly creates a datasource configuration for basic authentication.


112-134: Method approved.

The createKeyPairAuthConfig method correctly creates a datasource configuration for key pair authentication.


349-363: Test case approved.

The test case testKeyAuthPairAuthValidPrivateKey_shouldCreateHikariConfigWithoutErrors correctly validates the creation of Hikari configuration with a valid private key.


366-373: Test case approved.

The test case testKeyAuthPairAuthInvalidPrivateKey_shouldThrowError correctly validates that an error is thrown with an invalid private key.


376-389: Test case approved.

The test case testBasicAuth_shouldCreateHikariConfigWithoutErrors correctly validates the creation of Hikari configuration with basic authentication.


391-398: Test case approved.

The test case testReadEncryptedPrivateKeyReturnsValidPrivateKey correctly validates that reading an encrypted private key returns a valid PrivateKey instance.

@sneha122 sneha122 merged commit 65bded9 into release Jul 9, 2024
46 checks passed
@sneha122 sneha122 deleted the chore/snowflake-junit-test-cases branch July 9, 2024 12:22
Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Jul 10, 2024
…g#34810)

## Description
This PR adds JUnit test cases for snowflake Key auth pair feature added.
Following cases have been added:
- For basic authentication mechanism, when we do datasource create ->
hikari config should have non empty username and password and datasource
object inside hikari config should be null
- For key pair authentication mechanism with valid private key -> hikari
config should have datasource object which is of type
SnowflakeBasicDatasource and username, password should be null.
- For key pair authentication mechanism with invalid private key ->
error should be thrown with appropriate error message
- For key pair authentication mechanism with valid private key ->
SnowflakeKeyUtils.readEncryptedPrivateKey should return valid instance
of PrivateKey class.

Note: Valid private key generated for above test cases is unencrypted
private key (i.e. without passphrase). Adding test cases with private
key having passphrase was a little complex than anticipated, hence will
create a separate task and tackle it separately.


Fixes appsmithorg#34692
_or_  
Fixes `Issue URL`
> [!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.Perf"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9856542221>
> Commit: 87074a7
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9856542221&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Perf`
> Spec:
> <hr>Tue, 09 Jul 2024 12:20:08 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Tests**
- Implemented new tests for key pair authentication with both valid and
invalid private keys.
  - Added tests for basic authentication.
  - Introduced tests for reading an encrypted private key.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: “sneha122” <“[email protected]”>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Integrations Pod Issues related to a specific integration ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog snowflake Issues related to the snowflake Integration Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Snowflake JUnit test cases
2 participants