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

Include Storage Location In Fake Cache Key #8203

Merged
merged 1 commit into from
Mar 5, 2024
Merged

Conversation

justindbaur
Copy link
Member

Type of change

- [x] Bug fix
- [ ] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

Include storage location in cache key for fake state. states is publicly exposed but wasn't used in any tests.

The storage location is already used in the cache key for the real state providers.

Code changes

  • Use storage location in cache key.

Screenshots

Before you submit

  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team
  • Ensure that all UI additions follow WCAG AA requirements

@justindbaur justindbaur requested a review from a team as a code owner March 4, 2024 20:45
@github-actions github-actions bot added the needs-qa Marks a PR as requiring QA approval label Mar 4, 2024
Copy link

codecov bot commented Mar 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 25.05%. Comparing base (4ba2717) to head (ccbd811).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8203      +/-   ##
==========================================
- Coverage   25.06%   25.05%   -0.01%     
==========================================
  Files        2248     2246       -2     
  Lines       65776    65773       -3     
  Branches    12410    12404       -6     
==========================================
- Hits        16484    16481       -3     
  Misses      47952    47952              
  Partials     1340     1340              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bitwarden-bot
Copy link

Logo
Checkmarx One – Scan Summary & Details1ed38afd-8478-4624-b242-1548ef29e5c5

No New Or Fixed Issues Found

@JaredSnider-Bitwarden
Copy link
Contributor

I tested this change locally, and this solved both of my issues that I encountered:

(1) When setting up test data, you couldn't set data for different KeyDefinitions without overriding the previous ones.

// set real value in memory  
 singleUserStateProvider
          .getFake(userIdFromAccessToken, ACCESS_TOKEN_MEMORY)
          .stateSubject.next([userIdFromAccessToken, accessTokenJwt]);

// set undefined value in disk
  singleUserStateProvider
          .getFake(userIdFromAccessToken, ACCESS_TOKEN_DISK)
          .stateSubject.next([userIdFromAccessToken, undefined]);  // this sets ACCESS_TOKEN_MEMORY to undefined.

(2): When asserting data was stored in a specific location, the tests would pass even if data wasn't actually stored in the asserted KeyDefinition

 expect(
            singleUserStateProvider.getFake(userIdFromAccessToken, REFRESH_TOKEN_DISK).nextMock,
          ).toHaveBeenCalledWith(refreshToken); // passes even if data was stored on REFRESH_TOKEN_MEMORY and not on REFRESH_TOKEN_DISK

@justindbaur justindbaur requested review from MGibson1 and removed request for willmartian March 5, 2024 16:58
Copy link
Member

@MGibson1 MGibson1 left a comment

Choose a reason for hiding this comment

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

Thanks for shoring this up!

@justindbaur justindbaur merged commit c9b5125 into main Mar 5, 2024
61 checks passed
@justindbaur justindbaur deleted the fix-fake-state-cache branch March 5, 2024 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-qa Marks a PR as requiring QA approval
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants