rudder-transformer icon indicating copy to clipboard operation
rudder-transformer copied to clipboard

fix: handle empty oauth secret for multiple destination

Open maheshkutty opened this issue 7 months ago • 12 comments

What are the changes introduced in this PR?

Check for the OAuth secrets field; if any required field is absent, throw an OAuth error. We made this change for the following destinations:

  • salesforce
  • x_audience
  • twitter_ads

What is the related Linear task?

Resolves INT-3607

Please explain the objectives of your changes below

Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here

Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?

N/A

Any new dependencies introduced with this change?

N/A

Any new generic utility introduced or modified. Please explain the changes.

N/A

Any technical or performance related pointers to consider with the change?

N/A

@coderabbitai review


Developer checklist

  • [x] My code follows the style guidelines of this project

  • [x] No breaking changes are being introduced.

  • [ ] All related docs linked with the PR?

  • [ ] All changes manually tested?

  • [ ] Any documentation changes needed with this change?

  • [x] Is the PR limited to 10 file changes?

  • [x] Is the PR limited to one linear task?

  • [ ] Are relevant unit and component test-cases added in new readability format?

Reviewer checklist

  • [ ] Is the type of change in the PR title appropriate as per the changes?

  • [ ] Verified that there are no credentials or confidential data exposed with the changes.

maheshkutty avatar May 05 '25 08:05 maheshkutty

Summary by CodeRabbit

  • Refactor

    • Centralized OAuth field extraction and validation logic for Twitter Ads and X Audience destinations, improving consistency and error messaging.
    • Streamlined user data processing in X Audience destination for better maintainability.
  • Bug Fixes

    • Enhanced validation for Salesforce OAuth credentials to ensure required fields are present and non-empty.
  • Tests

    • Added comprehensive tests for OAuth field validation to ensure robust error handling.

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation for Salesforce and Twitter Ads OAuth credentials to ensure required fields are present and not empty, resulting in clearer error messages if credentials are incomplete.
  • Refactor
    • Centralized OAuth field extraction logic for Twitter Ads and X Audience integrations, reducing code duplication and streamlining error handling.
    • Simplified user field processing in X Audience integration for better maintainability.
  • Tests
    • Added comprehensive tests for OAuth credential validation to ensure robust error handling and correct extraction of required fields.

Walkthrough

The changes primarily focus on enhancing OAuth credential validation and centralizing related utility functions across Salesforce, Twitter Ads, and X Audience integrations. The Salesforce utility now checks that the access_token and instance_url are not undefined, null, or empty strings. For Twitter Ads and X Audience, the OAuth extraction logic is refactored: a new getOAuthFields utility is introduced in Twitter Ads, imported and reused in X Audience, and local redundant implementations are removed. Function signatures for public APIs remain unchanged, but utility exports are updated to reflect the new structure.

Changes

File(s) Change Summary
src/v0/destinations/salesforce/utils.js Added stricter validation for access_token and instance_url in getAccessTokenOauth, ensuring they are not undefined, null, or empty.
src/v0/destinations/twitter_ads/transform.js Refactored to import getOAuthFields from util.js, removed local definition, updated usage to include context string 'TWITTER ADS'.
src/v0/destinations/twitter_ads/util.js Introduced getOAuthFields function for extracting and validating OAuth fields; updated exports accordingly.
src/v0/destinations/x_audience/utils.js Removed local getOAuthFields, now imports from Twitter Ads util; updated usage with context 'X Audience'; refactored user detail processing; updated exports.
src/v0/destinations/twitter_ads/utils.test.js Added comprehensive tests for getOAuthFields covering valid inputs, missing fields, and error scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant TwitterAdsUtil as twitter_ads/util.js
    participant XAudienceUtil as x_audience/utils.js

    Caller->>TwitterAdsUtil: getOAuthFields({ secret }, "TWITTER ADS")
    TwitterAdsUtil->>TwitterAdsUtil: Validate secret and fields
    TwitterAdsUtil-->>Caller: Return OAuth fields or throw error

    Caller->>XAudienceUtil: buildResponseWithJSON(...)
    XAudienceUtil->>TwitterAdsUtil: getOAuthFields({ secret }, "X Audience")
    TwitterAdsUtil->>TwitterAdsUtil: Validate secret and fields
    TwitterAdsUtil-->>XAudienceUtil: Return OAuth fields or throw error
    XAudienceUtil-->>Caller: Response

Suggestions for Improvement

  • Consider documenting the expected structure and required fields of the secret object for each destination to aid future maintainers and integrators.
  • Explore further centralization of OAuth-related utilities if other destinations share similar authentication patterns to reduce duplication.
  • Review other destination integrations for similar validation gaps to ensure consistency and robustness across the platform.
  • Enhance error messages with more contextual information or remediation steps to aid debugging by integrators.
  • Add integration or end-to-end tests that cover OAuth authentication flows to complement unit tests and validate real-world scenarios.

Suggested reviewers

  • sivashanmukh
  • vinayteki95

📜 Recent review details

Configuration used: .coderabbit.yaml Review profile: CHILL Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c77f971eddae8a3ef56c9636d464c5e6efb0b14 and 6b28a60cfd09dedfe63c86e00ab8ab5a04492b82.

⛔ Files ignored due to path filters (5)
  • test/integrations/destinations/salesforce/processor/data.ts is excluded by !**/test/**
  • test/integrations/destinations/twitter_ads/processor/data.ts is excluded by !**/test/**
  • test/integrations/destinations/twitter_ads/router/data.ts is excluded by !**/test/**
  • test/integrations/destinations/x_audience/processor/data.ts is excluded by !**/test/**
  • test/integrations/destinations/x_audience/router/data.ts is excluded by !**/test/**
📒 Files selected for processing (5)
  • src/v0/destinations/salesforce/utils.js (2 hunks)
  • src/v0/destinations/twitter_ads/transform.js (3 hunks)
  • src/v0/destinations/twitter_ads/util.js (2 hunks)
  • src/v0/destinations/twitter_ads/utils.test.js (1 hunks)
  • src/v0/destinations/x_audience/utils.js (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/v0/destinations/salesforce/utils.js
  • src/v0/destinations/twitter_ads/transform.js
  • src/v0/destinations/twitter_ads/utils.test.js
  • src/v0/destinations/twitter_ads/util.js
  • src/v0/destinations/x_audience/utils.js
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Code Coverage
  • GitHub Check: test_and_publish
  • GitHub Check: UT Tests
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

coderabbitai[bot] avatar May 05 '25 08:05 coderabbitai[bot]

Allure Test reports for this run are available at:

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 91.10%. Comparing base (c684b65) to head (6b28a60). Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4295      +/-   ##
===========================================
- Coverage    91.12%   91.10%   -0.02%     
===========================================
  Files          636      637       +1     
  Lines        33400    33403       +3     
  Branches      7896     7890       -6     
===========================================
- Hits         30435    30433       -2     
- Misses        2696     2701       +5     
  Partials       269      269              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar May 05 '25 09:05 codecov[bot]

Allure Test reports for this run are available at:

Allure Test reports for this run are available at:

Allure Test reports for this run are available at:

Allure Test reports for this run are available at:

Allure Test reports for this run are available at:

Allure Test reports for this run are available at:

Allure Test reports for this run are available at:

Allure Test reports for this run are available at:

Allure Test reports for this run are available at: