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

Add new purchase state OUT_OF_CREDENTIALS for VPN service #26272

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bsclifton
Copy link
Member

@bsclifton bsclifton commented Oct 29, 2024

This handles the condition where the all the credentials for a given day are redeemed and there are none left. This shouldn't happen - but can happen if there are network issues. Specifically, when the client doesn't receive response from server after redeeming the credential.

Fixes brave/brave-browser#33031

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

  1. Login to account.brave.com with an account with VPN or buy VPN
  2. Use VPN - connect to a server, disconnect
  3. Exit Brave
  4. Open the Local State file in a text editor of your choosing
  5. Search for the sku > state area
  6. Next part is tricky - @bsclifton can help. But you'll need to find the credentials that were just used (you can search for spent: true). Find the second credential for that same day and change spent: false to spent: true. Now they should both be true - meaning you are out of credentials for the time window you're in (if code asks for new credentials).
  7. Look for brave_vpn > subscriber_credential and set credential to empty string "". This will force the next launch to try to get new credentials.
  8. Save the file
  9. Reload Brave
  10. Open VPN menu
  11. You should see messaging like this:
    image

@bsclifton bsclifton self-assigned this Oct 29, 2024
@bsclifton bsclifton requested a review from a team as a code owner October 29, 2024 08:55
@github-actions github-actions bot added the CI/storybook-url Deploy storybook and provide a unique URL for each build label Oct 29, 2024
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

Copy link
Member

@simonhong simonhong left a comment

Choose a reason for hiding this comment

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

it would be great to have unit test for OUT_OF_CREDENTIALS state.

components/brave_vpn/resources/panel/state/async.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@deeppandya deeppandya left a comment

Choose a reason for hiding this comment

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

@bsclifton i went through the changes, i think we should add an exception for android for out of credentials state as we don't do anything about it in android and we need to know if user is linked or not.

@bsclifton
Copy link
Member Author

Thanks @deeppandya! I checked and UpdatePurchasedStateForSessionExpired is never called on Android - so we should be good here 😄 Maybe I can put a check in there to force failure for Android (in case code is reworked)

@bsclifton
Copy link
Member Author

OK working on a test now... then it will be ready for a re-review

Copy link
Contributor

The security team is monitoring all repositories for certain keywords. This PR includes the word(s) "login" and so security team members have been added as reviewers to take a look.

No need to request a full security review at this stage, the security team will take a look shortly and either clear the label or request more information/changes.

Notifications have already been sent, but if this is blocking your merge feel free to reach out directly to the security team on Slack so that we can expedite this check.

@bsclifton
Copy link
Member Author

bsclifton commented Oct 31, 2024

@simonhong added test! The SESSION_EXPIRED ones test that same code - just the branch. UpdatePurchasedStateForSessionExpired now uses the date/time to determine if it SHOULD have credentials (out of credentials) or if the session expired.

Copy link
Member

@simonhong simonhong left a comment

Choose a reason for hiding this comment

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

++ 👍🏼

components/brave_vpn/browser/brave_vpn_service.cc Outdated Show resolved Hide resolved
components/brave_vpn/browser/brave_vpn_service_unittest.cc Outdated Show resolved Hide resolved
This handles the condition where the all the credentials for a given day
are redeemed and there are none left. This shouldn't happen - but can
happen if there are network issues. Specifically, when the client doesn't
receive response from server after redeeming the credential.

Fixes brave/brave-browser#33031
Copy link
Member

@kdenhartog kdenhartog left a comment

Choose a reason for hiding this comment

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

Took a look through this and don't see anything of concern. @thypon mentioned on slack he's good with it too so approving and removing sec-review label

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

We should show a unique error when all credentials are spent
6 participants