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 support for referral promos #428

Merged
merged 13 commits into from
Sep 26, 2018
Merged

Add support for referral promos #428

merged 13 commits into from
Sep 26, 2018

Conversation

emerick
Copy link
Contributor

@emerick emerick commented Sep 10, 2018

Fixes brave/brave-browser#287

Also relies on brave/brave-browser#1244

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed.
  • Add appropriate QA labels (QA/Needed or QA/No-QA-Needed) to include the closed issue in milestone

Automated Test Plan

npm run test -- brave_unit_tests --filter=BraveReferralsNetworkDelegateHelperTest.*

Test Plan:

  • Install a version of Brave with an associated referral code in its filename (on Mac, this requires running the .pkg installer not the .dmg)
    • Verify that after installation but before running Brave for the first time, promoCode file is in user-data-directory and contains the appropriate code. Also verify that this works as expected when the installer is run from a folder containing spaces.
  • Run installed Brave
    • Verify that promo-appropriate URL (if any) opens in a new browser tab.
    • Verify that when visiting a referral domain, we send the promo-appropriate request headers.
    • Verify that we no longer send referral code to update server after 90 days.
    • Verify that promoCode file is deleted after promo code is read and stored in local_state preferences.
    • Verify that service checks for referral finalization 30 days after referral initialization.
    • Verify that service retries checking for referral finalization up to 30 times (with 24-hour pauses between attempts) if it doesn't receive "true" on its first try.
    • Verify that stats.brave.com includes referral code when appropriate.

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

// on to setup.exe
AppendCommandLineFlags(configuration.command_line(), &cmd_line);

+#if defined(BRAVE_CHROMIUM_BUILD)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to implement this via a chromium_src override, but RunSetup is both defined and called in this file so it wasn't working correctly. My other thought was to provide our own implementation of CreateProcess, which is called exactly once in this file and has the argument that I need to override.

@emerick emerick closed this Sep 15, 2018
@emerick emerick reopened this Sep 15, 2018
@emerick emerick force-pushed the referral-promo-support branch 13 times, most recently from 31ce3cf to f713eb1 Compare September 21, 2018 16:57
@emerick emerick requested a review from bbondy September 21, 2018 17:05
@emerick emerick force-pushed the referral-promo-support branch 5 times, most recently from 7fdbb2a to bb8787f Compare September 21, 2018 23:07
@emerick emerick closed this Sep 21, 2018
@emerick emerick reopened this Sep 21, 2018
@bbondy
Copy link
Member

bbondy commented Sep 22, 2018

@emerick can you do a brain dump on where this is at? Thanks!

After parsing the referral code, we pass it to setup.exe via the
--brave-referral-code flag. The setup program will write the referral
code out to user-data-dir.
The mini installer passes the referral code to setup via the
--brave-referral-code command line option
When run against the release channel, this creates a signed install
pkg that parses a referral code (if any) from its filename and
writes it to user-data-dir. When run against any other channel,
no pkg is created.
Retrieving the time is a blocking operation and will trigger an
assertion on the main thread. Instead, post a task to retrieve the
first run time and when it completes post tasks back to the main
thread to perform associated bookkeeping (these need to run on the
main thread as they interact with the preference service).
Copy link
Member

@diracdeltas diracdeltas left a comment

Choose a reason for hiding this comment

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

non-security/privacy question: are we planning on migrating referral codes from muon brave to brave-core?

std::unique_ptr<network::SimpleURLLoader> referral_headers_loader_;
std::unique_ptr<network::SimpleURLLoader> referral_init_loader_;
std::unique_ptr<network::SimpleURLLoader> referral_finalization_check_loader_;
std::unique_ptr<base::RepeatingTimer> fetch_referral_headers_timer_;
Copy link
Member

Choose a reason for hiding this comment

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

[Privacy review] We should add a randomized delay to the timing so as to prevent the server from being able to correlate these requests as being from the same user. The same goes for all Brave requests that occur on a regular interval.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, I'll get that in there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added 0649d184e33c070625c2a537d70a95ec662100ef to address this.

# (who may not be an admin).
sudo chmod -R 775 "$installationAppPath"
sudo chown -R $userName "$installationAppPath"
sudo chgrp -R admin "$installationAppPath"
Copy link
Member

Choose a reason for hiding this comment

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

[Security review] How does this compare to Chrome's directory permissions? In general we want to match that (or be more restrictive)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is how Chrome installs in my /Applications folder on Mac:

$ ls -l | grep Chrome
drwxrwxr-x@  3 emerick  admin     96 Sep 15 04:30 Google Chrome.app/

So I think we're exactly matching the permissions/owner/group of Chrome.

Copy link
Member

@bsclifton bsclifton Sep 25, 2018

Choose a reason for hiding this comment

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

That is correct, as far as I know- @petemill did the initial work on this (browser-laptop) and I remember digging in with him. We wanted to match Chrome

@@ -35,6 +35,8 @@ int OnBeforeURLRequest_StaticRedirectWork(
static std::vector<URLPattern> allowed_patterns({
// Brave updates
URLPattern(URLPattern::SCHEME_HTTPS, "https://go-updater.brave.com/*"),
// Brave updates staging
URLPattern(URLPattern::SCHEME_HTTPS, "https://laptop-updates-staging.herokuapp.com/*"),
Copy link
Member

@diracdeltas diracdeltas Sep 24, 2018

Choose a reason for hiding this comment

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

Not a big deal since this is just for debugging right now, but can we add a way to restrict whitelisting of staging endpoints to non-prod builds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only problem is that we also rely on this URL for unit tests, but maybe we can add a define for that.

Copy link
Contributor Author

@emerick emerick Sep 25, 2018

Choose a reason for hiding this comment

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

Actually, now that I'm looking closer at this code I noticed that it's wrapped in the following:

#if !defined(NDEBUG)
#endif

So it will only be called in debug versions. There's a comment at the end of the block to turn this into a DCHECK eventually, but that would also mean this block is compiled out in release builds.

We normally fetch every 24 hours, this will add a random delay to
prevent the server from being able to correlate these requests as
coming from the same user.
Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

Feedback addressed; LGTM! Re-approving 😄

@diracdeltas diracdeltas dismissed their stale review September 25, 2018 19:15

comments addressed. @evq will take a quick look but lgtm otherwise.

@bsclifton bsclifton merged commit 09572b2 into master Sep 26, 2018
@bsclifton bsclifton deleted the referral-promo-support branch September 26, 2018 04:42
@bsclifton
Copy link
Member

bsclifton commented Sep 26, 2018

master 09572b2
0.55.x 0cbf1b1

bsclifton added a commit that referenced this pull request Sep 26, 2018
@bbondy
Copy link
Member

bbondy commented Sep 26, 2018

WHOOOOOOOOO!!!! 🎉

@diracdeltas
Copy link
Member

q i had which i don't think was addressed: what is the plan for migrating referred users from b-l-b? for instance if someone had downloaded a Dow Jones promo build and then updates to brave-core, do their promo benefits continue?

@emerick
Copy link
Contributor Author

emerick commented Sep 26, 2018

@diracdeltas That's a really good question. If we do want to migrate, I think we could import the local_state settings without too much trouble as I followed the b-l-b state settings pretty closely.

@bsclifton Any thoughts here?

@bsclifton
Copy link
Member

@diracdeltas good question- I captured brave/brave-browser#1294 to address this 😄

@bbondy bbondy added this to the 0.55.x - Release milestone Jan 14, 2019
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.

Referral promo support (& Dow Jones)
5 participants