diff --git a/packages/auth/README.md b/packages/auth/README.md index 0592fa595a7..ad8ca35d5eb 100644 --- a/packages/auth/README.md +++ b/packages/auth/README.md @@ -17,6 +17,7 @@ host of npm scripts to run these tests. The most important commands are: | `yarn test::unit:debug` | Runs \ unit tests, auto-watching for file system changes | | `yarn test::integration` | Runs only integration tests against the live environment | | `yarn test::integration:local` | Runs all headless \ integration tests against the emulator (more below) | +| `yarn test:browser:integration:prodbackend` | Runs TOTP MFA integration tests against the backend (more below) | Where \ is "browser" or "node". There are also cordova tests, but they are not broken into such granular details. Check out `package.json` for more. @@ -46,6 +47,25 @@ you would simply execute the following command: firebase emulators:exec --project foo-bar --only auth "yarn test:integration:local" ``` +### Integration testing with the production backend + +Currently, MFA TOTP tests only run against the production backend (since they are not supported on the emulator yet). +Running against the backend also makes it a more reliable end-to-end test. + +The TOTP tests require the following email/password combination to exist in the project, so if you are running this test against your test project, please create this user: + +'totpuser-donotdelete@test.com', 'password' + +You also need to verify this email address, in order to use MFA. This can be done with a curl command like this: + +``` +curl -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" -H "X-Goog-User-Project: ${PROJECT_ID}" -X POST https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode -d '{ + "email": "totpuser-donotdelete@test.com", + "requestType": "VERIFY_EMAIL", + "returnOobLink": true, + }' +``` + ### Selenium Webdriver tests These tests assume that you have both Firefox and Chrome installed on your diff --git a/packages/auth/karma.conf.js b/packages/auth/karma.conf.js index 8c4bcba24d2..4f82e4ab5a7 100644 --- a/packages/auth/karma.conf.js +++ b/packages/auth/karma.conf.js @@ -37,6 +37,9 @@ function getTestFiles(argv) { if (argv.unit) { return ['src/**/*.test.ts', 'test/helpers/**/*.test.ts']; } else if (argv.integration) { + if (argv.prodbackend) { + return ['test/integration/flows/totp.test.ts']; + } return argv.local ? ['test/integration/flows/*.test.ts'] : ['test/integration/flows/*!(local).test.ts']; diff --git a/packages/auth/package.json b/packages/auth/package.json index 732c9fbe30b..ef6ac184f07 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -76,7 +76,7 @@ "build:scripts": "tsc -moduleResolution node --module commonjs scripts/*.ts && ls scripts/*.js | xargs -I % sh -c 'terser % -o %'", "dev": "rollup -c -w", "test": "run-p lint test:all", - "test:all": "run-p test:browser:unit test:node:unit test:integration", + "test:all": "run-p test:browser:unit test:node:unit test:integration test:browser:integration:prodbackend", "test:integration": "firebase emulators:exec --project emulatedproject --only auth \"run-s test:browser:integration:local test:node:integration:local test:webdriver\"", "test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all", "test:integration:local": "run-s test:node:integration:local test:browser:integration:local test:webdriver", @@ -84,6 +84,7 @@ "test:browser:unit": "karma start --single-run --unit", "test:browser:integration": "karma start --single-run --integration", "test:browser:integration:local": "karma start --single-run --integration --local", + "test:browser:integration:prodbackend": "karma start --single-run --integration --prodbackend", "test:browser:debug": "karma start --auto-watch", "test:browser:unit:debug": "karma start --auto-watch --unit", "test:cordova": "karma start --single-run --cordova",