Monorepo for Firefox Accounts
Перейти к файлу
Barry Chen f88ac80984
fix(tests): fix customs server test runner script and tests
This patch fixes two things in Customs tests:
 - it updates test-local.sh so that it no longer exits with status 0 all
 the time; now it exits with the status returned by `tap`
 - it fixes all the failing tests that have gone unnoticed due the bug
 mentioned above
2020-03-10 09:11:22 -05:00
.circleci feat(admin-panel): Add base fxa-admin-panel package (client) shell 2020-03-05 08:47:17 -06:00
.github/ISSUE_TEMPLATE feat: add vscode tasks for running tests and debugger 2019-10-01 17:27:41 -07:00
.vscode feat: add pm2 debug servers and add'l debug scripts 2020-03-06 10:33:20 -08:00
_scripts feat: add pm2 debug servers and add'l debug scripts 2020-03-06 10:33:20 -08:00
assets/product-icons Merge pull request #3879 from mozilla/more-cdn-icons 2020-01-10 08:47:16 -08:00
docs chore(adr): note choices in testing stacks 2020-02-05 16:55:28 -05:00
packages fix(tests): fix customs server test runner script and tests 2020-03-10 09:11:22 -05:00
test refactor(oauth): move oauth-server into auth-server (phase 2) 2019-10-28 10:49:46 -07:00
.eslintrc refactor(auth-server): async/await updates 2019-12-12 09:19:37 -08:00
.gitignore chore(ci): skip email service tests for PRs when not required 2020-03-02 11:18:11 -08:00
.nvmrc chore(node): Update .nvmrc to use Node v12, to match requirement in _scripts/check.sh 2020-02-15 13:13:55 -05:00
AUTHORS Release 1.160.0 2020-02-27 17:54:06 +00:00
CODE_OF_CONDUCT.md prepare for monorepo 2019-04-01 10:58:37 -07:00
CONTRIBUTING.md chore(docs): correct ordering in estimation table in CONTRIBUTING doc 2020-02-28 15:43:08 -08:00
README.md feat: add pm2 debug servers and add'l debug scripts 2020-03-06 10:33:20 -08:00
SECURITY.md task(monorepo): update security.md 2019-10-07 09:55:34 -04:00
circleci_servers.json fix(dev): some processes need to wait for mysql to startup 2020-03-03 12:08:31 -08:00
debug_servers.json feat: add pm2 debug servers and add'l debug scripts 2020-03-06 10:33:20 -08:00
lerna.json prepare for monorepo 2019-04-01 10:58:37 -07:00
mysql_servers.json fix(dev): some processes need to wait for mysql to startup 2020-03-03 12:08:31 -08:00
package-lock.json chore(deps): update dependency concurrently to v5.1.0 2020-02-06 17:37:35 -05:00
package.json fix(tests): fix customs server test runner script and tests 2020-03-10 09:11:22 -05:00
release.sh fix(release): send OS X date the right arguments 2020-03-05 13:57:35 -08:00
renovate.json chore(deps): Enable renovate for all packages in the monorepo 2019-08-19 09:57:58 -07:00

README.md

pullreminders

Firefox Accounts

The Firefox Accounts (fxa) monorepo

Getting Started

  1. Manually install the system dependencies for OS X or Ubuntu. Note that WSL is required for development work on Windows.

  2. Clone this repository.

    git clone https://github.com/mozilla/fxa.git
    
  3. Run:

    cd fxa
    npm install
    npm start
    

Note this starts up all required services, including Redis, MySQL, and Memcached. It is recommended that you don't run these services yourself, or occupy any of the server ports. Doing so may result in errors.

  1. Visit 127.0.0.1:3030.

Use the PM2 tool to stop and start the servers, and read server logs.

To start all servers:

  • npm start

The most common commands are:

  • npm stop - stop all servers.

  • ./pm2 status - display running servers.

  • ./pm2 logs - logs for all servers (note: this must be used to verify accounts).

  • ./pm2 logs 1 - display logs for process 1.

  • ./pm2 stop 1 - stop process 1.

  • ./pm2 restart 1 - restart process 1.

  • More commands in the PM2 Readme.


Contributing

See the separate CONTRIBUTING.md to learn how to contribute.

Workflow

This is an example workflow for fxa.

After installing fxa run npm start. Use ./pm2 status command to check the status of the servers:

To avoid wasting computer resources while not working on FxA make sure to stop the servers using npm stop. Once you are back working on FxA just use the npm start command to bring the servers back up.

Verifying email and viewing logs

Use the ./pm2 logs command to get the logs of all servers. You may also use ./pm2 logs [id] to just see the logs for that particular server.

When you signup for an account using the form on 127.0.0.1:3030/signup the "auth-server local mail helper" logs will print out the verification code that you need to copy paste into your browser to verify your account locally:

If you get an error status for any of the servers please verify that you installed all required dependencies. Otherwise file an issue on this repository.




Dependencies

Required developer dependencies: Git, node.js 12+ with npm 6, Python 2.6+, Java 8+, Rust nightly+, libgmp, graphicsmagick, docker, grunt, gcloud CLI

OS X (with Brew):

Xcode and OS X Command Line Tools are required, install it and verify that command line tools installed:

xcode-select --install

then:

sudo easy_install pip && sudo pip install virtualenv

Install Docker for Mac | Docs

Ubuntu:
sudo apt-get install build-essential git libgmp3-dev graphicsmagick  python-virtualenv python-dev pkg-config libssl-dev curl openjdk-11-jre firefox

Follow the Docker CE instructions to install Docker.

Docker commands require sudo, to avoid it, follow steps below:

  1. Add the docker group if it doesn't already exist
sudo groupadd docker
  1. Add the connected user $USER to the docker group
sudo gpasswd -a $USER docker
  1. Restart the docker daemon
sudo service docker restart

Installing Node.js

We currently use Node 12. See https://nodejs.org

Alternatively, the Node Version Manager makes working with different versions of Node easy.

nvm install 12
nvm alias default 12

Installing Java

Java is used to run Selenium functional tests

OS X:

Download from java.com/en/download/

Installing Rust

Rust Nightly is used for the fxa-email-service

Ubuntu and OS X
curl https://sh.rustup.rs -sSf | sh

Once the installer begins:

  1. Select "2) Customize installation"
  2. Leave "Default host triple" blank, hit "enter"
  3. Type "nightly" for "Default toolchain"
  4. Type "y" for "Modify PATH variable?"
  5. Select "1) Proceed with installation"

Installing grunt

npm install -g grunt-cli



Firefox Custom Profile

Use npm run start-firefox to start Firefox with local server configurations. Available options:

  • FXA_ENV=local or latest or stable or stage (NOTE: local is default).
  • FXA_E10S=true - add this flag to turn on E10S. (NOTE: false by default).
  • FXA_DESKTOP_CONTEXT - context= value. (NOTE: fx_desktop_v2 is default).
  • FIREFOX_BIN=/Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin npm start
  • FIREFOX_DEBUGGER=true - open Browser Toolbox on start (NOTE: false by default for speed).

Functional Tests

The following requires the JDK and tests the local servers only.

To run all functional tests:

npm test

Note that as of 2019-07-08, running this command at the project root will fail (see issue #725). Instead, run the command in the server that needs to be tested.

To run a specific test or tests whose name matches part of a search string:

node tests/intern.js --suites=all --grep="Test string to search for"

Node debugging

It's possible to debug a running node process using a variety of debuggers (see the node debugging docs for details).

We have also extensively documented working with the FxA code-base using VS Code.

Debugging a server

In the case of Firefox Accounts, the pm2 process manager complicates setup a bit. Here's one approach that works:

  1. Start the whole server as usual (npm install && npm start from top-level in the monorepo)
  2. Stop the pm2-managed version of whatever server you care about:
    • Get the pm2 id for the server from ./pm2 ls
    • Stop the process by doing ./pm2 stop NN where NN is the pm2 id
  3. Restart the server manually, passing the --inspect argument:
    • For fxa-content-server, fxa-payments-server, fxa-auth-server, or fxa-event-broker, just go to the package directory and do npm run start-dev-debug to start a debuggable server process.
    • For other servers, we just haven't added a start-dev-debug run script yet; feel free to add one by tracing through the existing run scripts to find the actual script that runs the server (not one that forks another script).
  4. Connect to the process to debug it:
    • Using Google Chrome, go to chrome://inspect, then click the process to connect to devtools.
    • VSCode requires setting up a .vscode/launch.json file; see the VSCode docs for details.

Alternatively if you want to be able to debug any of several servers that is configured with a start-dev-debug script you can start pm2 using the debug_servers.json file:

pm2 kill
pm2 start debug_servers.json
Default Debug Ports

If you're using npm run start-dev-debug or pm2 with the debug_server.json, the following ports are used for --inspect:

Port Service
9140 content-server
9150 admin-server
9160 auth-server
9170 payments-server
9180 event-broker

Debugging tests

The node debugger can also be attached to a running test process. Firefox Accounts uses a variety of test frameworks, so the steps vary for the different servers. The --inspect argument is used in the examples below, but --inspect-brk can also be used to pause the process as soon as it starts.

mocha tests (fxa-shared)

For mocha, pass the --timeout 0 option, otherwise the test will fail if you step through it and exceed the default timeout (currently 2 seconds on fxa-shared):

node --inspect ./node_modules/.bin/mocha --timeout 0 path/to/file

In fxa-shared, this incantation works for some directories, but not yet others.

jest tests (fxa-payments-server)

For jest, pass the --runInBand argument, so it doesn't fork off the test runner to a separate process that isn't available to the inspector:

node --inspect ./node_modules/.bin/jest --runInBand --config server/jest.config.js filematcher

where filematcher is a regex that matches against test file paths. If you omit filematcher, Jest will run all tests (but you have to hit Enter a second time to trigger the test run).


Android debugging

The following technique works with any Android application and can also be used for Firefox for Android (making the Firefox for Android section optional).

Simply forward the following ports from the host machine to the Android device:

adb reverse tcp:3030 tcp:3030 # Content server
adb reverse tcp:9000 tcp:9000 # Auth server
adb reverse tcp:9010 tcp:9010 # OAuth server
adb reverse tcp:1111 tcp:1111 # Profile server
adb reverse tcp:5000 tcp:5000 # Sync server

Then run npm start and get to work!


FxA Email Service

Skip this if you are not working on the fxa-email-service.

The pm2 scripts run the latest docker version of the email service by default. If you want to start making changes to the email service then do the following:

  1. Stop the email-service using ./pm2 stop <email_service_id>
  2. Build the service: cd packages/fxa-email-service; cargo build --bin fxa_email_send
  3. Run the service: cd packages/fxa-email-service; ./scripts/run_send.sh

Firefox for Android

Skip this if you are not working on Firefox for Android and FxA.

You can test sync locally in Firefox for Android using an emulator or a device on the same network. These docs were tested with the Genymotion simulator.

  • Install Firefox on the device or emulator.
  • Run npm run start-android this will: stop all local FxA servers, create a local PM2 configuration and rerun the servers.

The script will tell you which IP to use to work with FxA.

Follow the instructions of the script to update values in about:config.


Firefox for iOS

Skip this if you are not working on Firefox for iOS and FxA.

You can test sync locally in Firefox iOS using the XCode simulator. Follow the steps at github.com/mozilla/firefox-ios and setup firefox-ios build locally. Currently there is no way to dynamically switch servers in Firefox for iOS, to use local servers you need to run the script below:

FIREFOX_IOS_HOME=<path_to_firefox_ios_project> npm run config-fxios

After the script you need to rebuild firefox-ios.


Running with MailDev

If you want to inspect emails, you can run fxa with MailDev.

Install

npm install maildev -g

Run

npm start
./pm2 stop 'auth-server local mail helper'

Once services have started, you can start MailDev on port 9999. You might have to start MailDev with sudo permissions.

sudo maildev -s 9999

All emails sent can be viewed from http://localhost:1080.


Other tasks

Package docs

Each package has it's own README.md and docs/ directory with info specific to that project.