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

Added Default User Login in Connect Flow And Environment based Cache Suffix #89

Merged
merged 4 commits into from
Sep 13, 2023

Conversation

Raj-Shah1
Copy link
Contributor

@Raj-Shah1 Raj-Shah1 commented Sep 13, 2023

Summary by CodeRabbit

  • New Feature: Added support for differentiating between test and production users in Salesforce authentication flow.
  • Refactor: Updated cache constants and keys to ensure consistency across the application. Cache keys now include a suffix based on the environment.
  • Test: Modified test cases to accommodate changes in method signatures and behavior.
  • Chore: Introduced new methods to retrieve default test user credentials and determine the current environment.

@coderabbitai
Copy link

coderabbitai bot commented Sep 13, 2023

Walkthrough

The changes primarily focus on enhancing the application's environment detection, cache management, and test user handling. The code now differentiates between staging and production environments, modifies cache keys based on the environment, and introduces a new authentication flow for test users.

Changes

File(s) Summary
.../api/config/CoreConstants.java
.../globalConstants/SecretConstants.java
Introduced methods to detect environment and retrieve default test user credentials.
.../api/config/MemcachedConfig.java
.../globalConstants/CacheConstants.java
.../repositories/SalesforceOauthTokenRepository.java
.../repositories/SalesforceUserRepository.java
Renamed cache constants and added a cache suffix based on the environment to ensure consistent cache keys.
.../lib/globalConstants/SalesforceConstants.java Added a function to return the password grant type string.
.../lib/salesforce/wrappers/SalesforceTokens.java
.../services/salesforce/AuthService.java
Modified the getTokens method to handle different authentication flows for test users and regular users.
.../functional/controllers/authController/PostDisconnectTest.java
.../controllers/authController/PostSalesforceConnectTest.java
.../unit/lib/salesforce/wrappers/SalesforceTokensTest.java
Updated test methods to accommodate the changes in the getTokens method.

"In the land of code, where logic is king, 🐇👑

Changes were made, oh what joy they bring! 🎉

Environments detected, caches refined, 🌍💾

Test users handled, with ease of mind. 🧪👥

Celebrate, dear rabbit, for the code is bright, 🎊💡

Dancing in the glow of the monitor's light." 💃🖥️


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.

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.

Review Status

Actionable comments generated: 8

Commits Files that changed from the base of the PR and between 39190a6 and 7dbee79 commits.
Files ignored due to filter (1)
  • sample.secrets.json
Files selected for processing (12)
  • src/main/java/com/salessparrow/api/config/CoreConstants.java (2 hunks)
  • src/main/java/com/salessparrow/api/config/MemcachedConfig.java (1 hunks)
  • src/main/java/com/salessparrow/api/lib/globalConstants/CacheConstants.java (1 hunks)
  • src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java (1 hunks)
  • src/main/java/com/salessparrow/api/lib/globalConstants/SecretConstants.java (1 hunks)
  • src/main/java/com/salessparrow/api/lib/salesforce/wrappers/SalesforceTokens.java (1 hunks)
  • src/main/java/com/salessparrow/api/repositories/SalesforceOauthTokenRepository.java (4 hunks)
  • src/main/java/com/salessparrow/api/repositories/SalesforceUserRepository.java (4 hunks)
  • src/main/java/com/salessparrow/api/services/salesforce/AuthService.java (3 hunks)
  • src/test/java/com/salessparrow/api/functional/controllers/authController/PostDisconnectTest.java (3 hunks)
  • src/test/java/com/salessparrow/api/functional/controllers/authController/PostSalesforceConnectTest.java (5 hunks)
  • src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceTokensTest.java (2 hunks)
Files skipped from review due to trivial changes (5)
  • src/main/java/com/salessparrow/api/config/CoreConstants.java
  • src/main/java/com/salessparrow/api/config/MemcachedConfig.java
  • src/main/java/com/salessparrow/api/lib/globalConstants/SalesforceConstants.java
  • src/main/java/com/salessparrow/api/lib/globalConstants/SecretConstants.java
  • src/main/java/com/salessparrow/api/repositories/SalesforceOauthTokenRepository.java
Additional comments (Suppressed): 14
src/main/java/com/salessparrow/api/repositories/SalesforceUserRepository.java (4)
  • 33-34: The cache eviction key has been updated to include a suffix based on the environment. Ensure that this change is reflected in all places where the cache is accessed.

  • 53-54: The cache eviction key has been updated to include a suffix based on the environment. Ensure that this change is reflected in all places where the cache is accessed.

  • 71-72: The cacheable key has been updated to include a suffix based on the environment. Ensure that this change is reflected in all places where the cache is accessed.

  • 82-83: The cache eviction key has been updated to include a suffix based on the environment. Ensure that this change is reflected in all places where the cache is accessed.

src/main/java/com/salessparrow/api/lib/globalConstants/CacheConstants.java (1)
  • 29-37: Ensure that all references to these constants throughout the codebase have been updated to match the new names.
src/main/java/com/salessparrow/api/services/salesforce/AuthService.java (1)
  • 130-131: The TODO comment indicates that there might be some unfinished work related to calling the getTokens method with different parameters. Ensure that this has been addressed before merging.
src/main/java/com/salessparrow/api/lib/salesforce/wrappers/SalesforceTokens.java (1)
  • 34-53: Ensure that all calls to getTokens method throughout the codebase have been updated to match the new signature with the additional isTestUser parameter.
src/test/java/com/salessparrow/api/functional/controllers/authController/PostDisconnectTest.java (3)
  • 4-6: The new import import static org.mockito.ArgumentMatchers.anyBoolean; has been added to accommodate the changes in the method signature of getTokens. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 96-96: The getTokens method now includes an additional boolean parameter. This change is consistent with the PR summary and seems to be correctly implemented here.

- when(mockGetTokens.getTokens(anyString(), anyString())).thenReturn(getTokensMockRes);
+ when(mockGetTokens.getTokens(anyString(), anyString(), anyBoolean())).thenReturn(getTokensMockRes);
  • 133-133: The getTokens method now includes an additional boolean parameter. This change is consistent with the PR summary and seems to be correctly implemented here.
- when(mockGetTokens.getTokens(anyString(), anyString())).thenReturn(getTokensMockRes);
+ when(mockGetTokens.getTokens(anyString(), anyString(), anyBoolean())).thenReturn(getTokensMockRes);
src/test/java/com/salessparrow/api/functional/controllers/authController/PostSalesforceConnectTest.java (2)
  • 11-14: The import import static org.mockito.ArgumentMatchers.anyBoolean; has been added. Ensure that the new test cases cover scenarios where this argument matcher is used.

  • 169-170: The verification of the getTokens method now includes a check for the additional boolean parameter. This is a good practice as it ensures that the method is being called with the correct number of arguments.

src/test/java/com/salessparrow/api/unit/lib/salesforce/wrappers/SalesforceTokensTest.java (2)
  • 88-94: Ensure that all calls to getTokens method throughout the codebase have been updated to match the new signature.

  • 118-120: Ensure that all calls to getTokens method throughout the codebase have been updated to match the new signature.

Comment on lines +112 to 113
when(mockGetTokens.getTokens(anyString(), anyString(), anyBoolean())).thenReturn(getTokensMockRes);
when(mockGetIdentity.getUserIdentity(anyString(), anyString())).thenReturn(getIdentityMockRes);
Copy link

Choose a reason for hiding this comment

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

The method getTokens now accepts an additional boolean parameter. Make sure all calls to this method in your tests have been updated accordingly.

- when(mockGetTokens.getTokens(anyString(), anyString())).thenReturn(getTokensMockRes);
+ when(mockGetTokens.getTokens(anyString(), anyString(), anyBoolean())).thenReturn(getTokensMockRes);

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.

Review Status

Actionable comments generated: 2

Commits Files that changed from the base of the PR and between 7dbee79 and fb5d026 commits.
Files selected for processing (5)
  • src/main/java/com/salessparrow/api/config/CoreConstants.java (2 hunks)
  • src/main/java/com/salessparrow/api/lib/globalConstants/CacheConstants.java (1 hunks)
  • src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceRequest.java (1 hunks)
  • src/main/java/com/salessparrow/api/lib/salesforce/wrappers/SalesforceTokens.java (1 hunks)
  • src/main/java/com/salessparrow/api/services/salesforce/AuthService.java (2 hunks)
Files skipped from review due to trivial changes (2)
  • src/main/java/com/salessparrow/api/config/CoreConstants.java
  • src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceRequest.java
Additional comments (Suppressed): 5
src/main/java/com/salessparrow/api/lib/globalConstants/CacheConstants.java (2)
  • 9-10: The CACHE_SUFFIX is declared as a constant but its value is determined at runtime. This could lead to unexpected behavior if the environment changes after the class has been loaded. Consider making it a regular static variable or ensure that the environment does not change during the application's lifetime.

  • 16-17: The cache keys no longer have the SalesSparrow prefix ("ss_"). If this was intentional and all uses of these keys in the codebase have been updated accordingly, then this is fine. Otherwise, this might cause issues with key mismatches.

src/main/java/com/salessparrow/api/services/salesforce/AuthService.java (2)
  • 93-109: The new code introduces a mechanism to handle test users. However, it's important to ensure that the defaultTestUserCode() method in CoreConstants is returning a unique and constant value for each environment. If this value changes or overlaps with actual user codes, it could lead to unexpected behavior.
String testUserCode = CoreConstants.defaultTestUserCode();
Boolean isTestUser = false;

code = params.getCode();
if (code.equals(testUserCode)) {
    isTestUser = true;
}
  • 126-133: The fetchOauthTokensFromSalesforce method now accepts a boolean parameter isTestUser. Ensure that all calls to this method throughout the codebase have been updated to match the new signature. Also, verify that the getTokens method in salesforceTokens correctly handles the isTestUser parameter.
private void fetchOauthTokensFromSalesforce(Boolean isTestUser) {
    logger.info("Fetching OAuth Tokens from Salesforce");
    HttpResponse response = salesforceTokens.getTokens(this.code, this.redirectUri, isTestUser);
    JsonNode jsonNode = util.getJsonNode(response.getResponseBody());
}
src/main/java/com/salessparrow/api/lib/salesforce/wrappers/SalesforceTokens.java (1)
  • 34-34: Ensure that all calls to getTokens method throughout the codebase have been updated to match the new signature.

Copy link
Member

@mohitcharkha mohitcharkha left a comment

Choose a reason for hiding this comment

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

LGTM

@mohitcharkha mohitcharkha merged commit 3640a0c into master Sep 13, 2023
1 check passed
@Raj-Shah1 Raj-Shah1 deleted the login-changes branch September 27, 2023 04:56
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.

2 participants