Firefox Monitor arms you with tools to keep your personal information safe. Find out what hackers already know about you and learn how to stay a step ahead of them.
Перейти к файлу
Kaitlyn Andres 190f4c0056
MNTOR-3057 - Cancel flow discount callout (#4635)
* add dialog strings

* add limitations apply strings

* add both experiment data

* reorg css

* ignore dependency array

* use handler for applycouponcode func

* test endpoint

* add you're all set animation

* add images

* check that the code application is successful

* add go back to dashboard btn

* always show the first dialog state

* add media query to discount cta

* remove animationpath

* check that a user already has a coupon set

* use flags instead of experiment

* Add animation switch

* remove nimbus sticking to flag

* do not import from the table level

* nit: whitespace

* mock actions.ts func in jest

* fix animation switch dialog state

* dont pass reactelem into state

* add unit tests

* remove cmted out code
2024-06-19 10:24:10 -04:00
.github Updated e2e timeout 2024-06-10 12:03:20 -04:00
.husky
.storybook fix: Add missing dev dependency @storybook/addon-actions 2024-05-22 17:14:46 +02:00
.vscode
config chore: Remove separate experiment for last-scan-date-csat-survey 2024-06-11 15:22:34 +02:00
docs
locales Import translations from l10n repository (2024-06-19) (#4695) 2024-06-19 06:39:24 -06:00
locales-pending MNTOR-3057 - Cancel flow discount callout (#4635) 2024-06-19 10:24:10 -04:00
public MNTOR-3057 - Cancel flow discount callout (#4635) 2024-06-19 10:24:10 -04:00
scripts
src MNTOR-3057 - Cancel flow discount callout (#4635) 2024-06-19 10:24:10 -04:00
.dockerignore
.env-dist fix: renaming a couple of vars 2024-06-12 09:56:03 -07:00
.eslintignore
.eslintrc.json
.git-blame-ignore-revs
.gitignore merged with main 2024-06-10 08:47:01 -07:00
.lintstagedrc.js
.prettierignore
.prettierrc.json
.stylelintrc
CODE_OF_CONDUCT.md
Dockerfile
Dockerfile.cloudrun
LICENSE
Procfile
README.md MNTOR-3078 - Update README (#4541) 2024-06-12 10:31:04 -04:00
catalog-info.yaml
esbuild.cronjobs.js
jest.config.cjs
jest.setup.ts
l10n.toml
locationAutocompleteData.json
netlify.toml
next-env.d.ts
next.config.js
package-lock.json Bump the nextjs group with 3 updates (#4682) 2024-06-18 11:14:48 -06:00
package.json Bump the nextjs group with 3 updates (#4682) 2024-06-18 11:14:48 -06:00
playwright.config.js Change e2e retries to 1, fix flaky tests, update readme 2024-06-10 07:29:36 -04:00
requirements.txt
sentry.client.config.ts
tsconfig.cronjobs.json
tsconfig.json

README.md

Firefox Monitor Server

Summary

Firefox Monitor notifies users when their credentials have been compromised in a data breach.

This code is for the monitor.mozilla.org service & website.

Breach data is powered by haveibeenpwned.com.

See the Have I Been Pwned about page for the "what" and "why" of data breach alerts.

Architecture

Image of Monitor architecture

Development

Requirements

Code style

Linting and formatting is enforced via ESLint and Stylelint for JS and CSS. Both are installed as dev-dependencies and can be run with npm run lint. A push to origin will also trigger linting.

ESLint rules are based on eslint-config-standard. To fix all auto-fixable problems, run npx eslint . --fix

Stylelint rules are based on stylelint-config-standard. To fix all auto-fixable problems, run npx stylelint public/css/ --fix

GIT

We track commits that are largely style/formatting via .git-blame-ignore-revs. This allows Git Blame to ignore the format commit author and show the original code author. In order to enable this in GitLens, add the following to VS Code settings.json:

"gitlens.advanced.blame.customArguments": [
   "--ignore-revs-file",
   ".git-blame-ignore-revs"
],

Database

To create the database tables ...

  1. Create the blurts database:

    createdb blurts
    createdb test-blurts # for tests
    
  2. Update the DATABASE_URL value in your .env file with your local db credentials:

    DATABASE_URL="postgres://<username>:<password>@localhost:<port>/blurts"
    
  3. Run the migrations:

    npm run db:migrate
    

Install

  1. Clone and change to the directory:

    git clone https://github.com/mozilla/blurts-server.git
    cd blurts-server
    
  2. Install dependencies:

    npm install
    
  3. Copy the .env-dist file to .env:

    cp .env-dist .env
    
  4. Install fluent linter (requires Python)

    pip install -r .github/requirements.txt
    
    OR
    
    pip3 install -r .github/requirements.txt
    
  5. Generate required Glean files (needs re-ran anytime Glean .yaml files are updated):

    npm run build-glean
    
  6. Generate required Nimbus files (needs re-ran anytime Nimbus' config/nimbus.yaml file is updated):

    npm run build-nimbus
    
  7. Create location data: Running the script manually is only needed for local development. The location data is being used in the onboarding exposures scan for autocompleting the “City and state” input.

    npm run create-location-data
    
  8. Ensure that you have the right env variables/keys set in your .env file. You can retrieve the variables from the Firefox Monitor 1Password Vault, or through Magic-Wormhole, by asking one of the our engineers.

Run

  1. To run the server similar to production using a build phase, which includes minified and bundled assets:

    npm start
    

    OR

    Run in "dev mode" with:

    npm run dev
    
  2. You may receive the error Required environment variable was not set. If this is the case, get the required env var(s) from another team member or ask in #fx-monitor-engineering. Otherwise, if the server started successfully, navigate to localhost:6060

PubSub

Monitor uses GCP PubSub for processing incoming breach data, this can be tested locally using an emulator: https://cloud.google.com/pubsub/docs/emulator

Run the GCP PubSub emulator:

gcloud beta emulators pubsub start --project=your-project-name

In a different shell, set the environment to point at the emulator and run Monitor in dev mode:

$(gcloud beta emulators pubsub env-init)
npm run dev

Incoming WebHook requests from HIBP will be of the form:

curl -d '{ "breachName": "000webhost", "hashPrefix": "test", "hashSuffixes": ["test"] }' \
  -H "Authorization: Bearer unsafe-default-token-for-dev" \
  http://localhost:6060/api/v1/hibp/notify

This pubsub queue will be consumed by this cron job, which is responsible for looking up and emailing impacted users:

node src/scripts/emailBreachAlerts.js

Emails

Monitor generates multiple emails that get sent to subscribers. To preview or test-send these emails see documentation here.

Mozilla accounts ("FxA", formerly known as Firefox accounts)

Subscribe with a Mozilla account is controlled via the FXA_ENABLED environment variable. (See .env-dist)

The repo comes with a development FxA oauth app pre-configured in .env, which should work fine running the app on http://localhost:6060. You'll need to get the OAUTH_CLIENT_SECRET value from a team member or someone in #fxmonitor-engineering.

Testing

The unit test suite can be run via npm test.

At the beginning of a test suite run, the test-blurts database will be populated with test tables and seed data found in src/db/seeds/

At the end of a test suite, coverage info will be sent to Coveralls to assess coverage changes and provide a neat badge. To upload coverage locally, you need a root .coveralls.yml which contains a token – get this from another member of the Monitor team.

End-to-End tests use Playwright and can be run via npm run e2e. E2E-How-To for more info.

Test Firefox Integration

TODO: the following functionality is disabled but the instructions are left here for posterity.

Firefox's internal about:protections page ("Protections Dashboard") fetches and displays breach stats for Firefox users who are signed into their FXA.

To test this part of Monitor:

  1. Set a Firefox profile to use the staging Firefox Accounts server.
  2. In the same profile, go to about:config and replace all https://monitor.firefox.com values with http://localhost:6060
  3. Restart Firefox with that profile.
  4. Go to about:protections
  5. Everything should be using your localhost instance of Monitor.

Localization

All text that is visible to the user is defined in Fluent files inside /locales/en/ and /locales-pending/. After strings get added to files in the former directory on our main branch, they will be made available to our volunteer localizers via Pontoon, Mozilla's localization platform. Be sure to reference the localization documentation for best practices. It's best to only move the strings to /locales/en/ when they are more-or-less final and ready for localization. Your PR should be automatically tagged with a reviewer from the Mozilla L10n team to approve your request.

You can check translation status via the Pontoon site. After strings have been localized, a pull request with the updated strings is automatically opened against our repository. Please be mindful that Mozilla localizers are volunteers, and translations come from different locales at different times – usually after a week or more.

To use the strings in code, you need to obtain a ReactLocalization instance, which selects the right version of your desired string for the user. How to do that depends on where your code runs: in tests, in a cron job, in a server component, or on the client-side. Generally, you will import a getL10n function from one of the modules in /src/app/functions/l10n/, except for Client Components, which use the useL10n hook. Look at existing code for inspiration.

Preview Deployment

We use GCP Cloudrun for dev review – official stage and production apps are built by the Dockerfile and Github Actions. Everything that is merged into main will deploy automatically to stage. The ADR for preview deployment can be found here

TODO: add full deploy process similar to Relay

TODO: consider whether we can re-enable Heroku Review Apps

Preserve sessions in local development

Sessions by default are stored in-memory, which means that when the server restarts (e.g. because you made a code change), you will have to log in again.

To avoid this hassle, you can install and run Redis, which by default runs on redis://localhost:6379. Use that value for REDIS_URL in your .env file to preserve your sessions across server restarts.