Skip to content

Commit

Permalink
Merge main into release
Browse files Browse the repository at this point in the history
  • Loading branch information
google-oss-bot authored Sep 16, 2024
2 parents 15c36cc + 629919e commit 0884f0d
Show file tree
Hide file tree
Showing 45 changed files with 185 additions and 86 deletions.
6 changes: 6 additions & 0 deletions .changeset/khaki-numbers-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@firebase/auth': patch
'@firebase/util': minor
---

Suppress the use of the `fetch` parameter `referrerPolicy` within Auth for `fetch` requests originating from Cloudflare Workers. Clouldflare Worker environments do not support this parameter and throw when it's used.
5 changes: 5 additions & 0 deletions .changeset/warm-oranges-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/firestore': patch
---

Fix an issue with metadata `fromCache` defaulting to `true` when listening to cache in multi-tabs.
6 changes: 3 additions & 3 deletions .github/workflows/test-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
- name: Run unit tests
# Ignore auth and firestore since they're handled in their own separate jobs.
run: |
xvfb-run yarn lerna run --ignore '{firebase-messaging-integration-test,@firebase/auth*,@firebase/firestore*,firebase-firestore-integration-test}' --concurrency 4 test:ci
xvfb-run yarn lerna run --ignore '{firebase-messaging-integration-test,@firebase/auth*,@firebase/firestore*,firebase-firestore-integration-test}' test:ci
node scripts/print_test_logs.js
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_CLI_TOKEN }}
Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:
run: echo "FIREBASE_CI_TEST_START_TIME=$(date +%s)" >> $GITHUB_ENV
- name: Run unit tests
run: |
xvfb-run yarn lerna run --concurrency 4 test:ci --scope '@firebase/auth*'
xvfb-run yarn lerna run test:ci --scope '@firebase/auth*'
node scripts/print_test_logs.js
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_CLI_TOKEN }}
Expand Down Expand Up @@ -182,7 +182,7 @@ jobs:
run: echo "FIREBASE_CI_TEST_START_TIME=$(date +%s)" >> $GITHUB_ENV
- name: Run unit tests
run: |
xvfb-run yarn lerna run --concurrency 4 test:ci --scope '@firebase/firestore*'
xvfb-run yarn lerna run test:ci --scope '@firebase/firestore*'
node scripts/print_test_logs.js
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_CLI_TOKEN }}
Expand Down
5 changes: 5 additions & 0 deletions common/api-review/util.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ export function isBrowser(): boolean;
// @public (undocumented)
export function isBrowserExtension(): boolean;

// Warning: (ae-missing-release-tag) "isCloudflareWorker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export function isCloudflareWorker(): boolean;

// Warning: (ae-missing-release-tag) "isElectron" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
Expand Down
3 changes: 2 additions & 1 deletion config/karma.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ const config = {

webpackMiddleware: { quiet: true, stats: { colors: true } },

singleRun: false,
// Exit with an exit code of 0 if any of the tests fail.
singleRun: true,

client: {
mocha: {
Expand Down
2 changes: 1 addition & 1 deletion integration/compat-interop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"version": "0.1.0",
"scripts": {
"test": "karma start --single-run",
"test": "karma start",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test",
"test:debug": "karma start --browsers Chrome --auto-watch"
},
Expand Down
2 changes: 1 addition & 1 deletion integration/firebase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"version": "0.2.1",
"scripts": {
"test": "karma start --single-run",
"test": "karma start",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions integration/firestore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"build:deps": "lerna run --scope @firebase/'{app,firestore}' --include-dependencies build",
"build:persistence": "INCLUDE_FIRESTORE_PERSISTENCE=true gulp compile-tests",
"build:memory": "INCLUDE_FIRESTORE_PERSISTENCE=false gulp compile-tests",
"karma:singlerun": "karma start --single-run",
"karma:singlerun": "karma start",
"prettier": "prettier --write '*.js' '*.ts'",
"test:persistence": " yarn build:persistence; karma start --single-run",
"test:persistence": " yarn build:persistence; karma start",
"test:persistence:debug": "yarn build:persistence; karma start --auto-watch --browsers Chrome",
"test:memory": "yarn build:memory; karma start --single-run",
"test:memory": "yarn build:memory; karma start",
"test:memory:debug": "yarn build:memory; karma start --auto-watch --browsers Chrome"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"repl": "node tools/repl.js",
"release": "ts-node-script scripts/release/cli.ts",
"pretest": "node tools/pretest.js",
"test": "lerna run --ignore firebase-messaging-integration-test --concurrency 4 --stream test",
"test:ci": "lerna run --ignore firebase-messaging-integration-test --concurrency 4 test:ci",
"test": "lerna run --ignore firebase-messaging-integration-test --stream test",
"test:ci": "lerna run --ignore firebase-messaging-integration-test test:ci",
"pretest:coverage": "mkdirp coverage",
"ci:coverage": "lcov-result-merger 'packages/**/lcov.info' 'lcov-all.info'",
"test:coverage": "lcov-result-merger 'packages/**/lcov.info' | coveralls",
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics-compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"dev": "rollup -c -w",
"test": "run-p --npm-path npm lint test:browser",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:browser",
"test:browser": "karma start --single-run",
"test:browser": "karma start",
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
"trusted-type-check": "tsec -p tsconfig.json --noEmit",
"add-compat-overloads": "ts-node-script ../../scripts/build/create-overloads.ts -i ../analytics/dist/analytics-public.d.ts -o dist/src/index.d.ts -a -r Analytics:FirebaseAnalytics -r FirebaseApp:FirebaseAppCompat --moduleToEnhance @firebase/analytics"
Expand Down
4 changes: 2 additions & 2 deletions packages/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"test": "run-p --npm-path npm lint test:all",
"test:all": "run-p --npm-path npm test:browser test:integration",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all",
"test:browser": "karma start --single-run --nocache",
"test:integration": "karma start ./karma.integration.conf.js --single-run --nocache",
"test:browser": "karma start --nocache",
"test:integration": "karma start ./karma.integration.conf.js --nocache",
"trusted-type-check": "tsec -p tsconfig.json --noEmit",
"api-report": "api-extractor run --local --verbose",
"doc": "api-documenter markdown --input temp --output docs",
Expand Down
2 changes: 1 addition & 1 deletion packages/app-check-compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dev": "rollup -c -w",
"test": "run-p --npm-path npm lint test:browser",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:browser",
"test:browser": "karma start --single-run --nocache",
"test:browser": "karma start --nocache",
"trusted-type-check": "tsec -p tsconfig.json --noEmit",
"add-compat-overloads": "ts-node-script ../../scripts/build/create-overloads.ts -i ../app-check/dist/app-check-public.d.ts -o dist/src/index.d.ts -a -r AppCheck:FirebaseAppCheck -r FirebaseApp:FirebaseAppCompat --moduleToEnhance @firebase/app-check"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/app-check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dev": "rollup -c -w",
"test": "run-p --npm-path npm lint test:browser",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:browser",
"test:browser": "karma start --single-run --nocache",
"test:browser": "karma start --nocache",
"trusted-type-check": "tsec -p tsconfig.json --noEmit",
"api-report": "api-extractor run --local --verbose",
"doc": "api-documenter markdown --input temp --output docs",
Expand Down
2 changes: 1 addition & 1 deletion packages/app-compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"test": "run-p --npm-path npm lint test:all",
"test:all": "run-p --npm-path npm test:browser test:node",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all",
"test:browser": "karma start --single-run",
"test:browser": "karma start",
"test:browser:debug": "karma start --browsers Chrome --auto-watch",
"test:node": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha test/**/*.test.* src/**/*.test.ts --config ../../config/mocharc.node.js",
"trusted-type-check": "tsec -p tsconfig.json --noEmit",
Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"test": "run-p --npm-path npm lint test:all",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all",
"test:all": "run-p --npm-path npm test:browser test:node",
"test:browser": "karma start --single-run",
"test:browser": "karma start",
"test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha src/**/*.test.ts --config ../../config/mocharc.node.js",
"trusted-type-check": "tsec -p tsconfig.json --noEmit",
"api-report": "api-extractor run --local --verbose",
Expand Down
6 changes: 3 additions & 3 deletions packages/auth-compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"test": "run-p --npm-path npm lint test:all",
"test:all": "run-p --npm-path npm test:browser test:node test:integration",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all",
"test:browser": "karma start --single-run",
"test:browser:unit": "karma start --single-run --unit",
"test:browser:integration": "karma start --single-run --integration",
"test:browser": "karma start",
"test:browser:unit": "karma start --unit",
"test:browser:integration": "karma start --integration",
"test:node": "ts-node -O '{\"module\": \"commonjs\", \"target\": \"es6\"}' scripts/run_node_tests.ts",
"test:node:integration": "ts-node -O '{\"module\": \"commonjs\", \"target\": \"es6\"}' scripts/run_node_tests.ts --integration",
"test:webdriver": "rollup -c test/integration/webdriver/static/rollup.config.js && ts-node -O '{\"module\": \"commonjs\", \"target\": \"es6\"}' scripts/run_node_tests.ts --webdriver",
Expand Down
12 changes: 6 additions & 6 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@
"test:integration": "firebase emulators:exec --project emulatedproject --only auth \"run-s --npm-path npm 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 --npm-path npm test:node:integration:local test:browser:integration:local test:webdriver",
"test:browser": "karma start --single-run --local",
"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": "karma start --local",
"test:browser:unit": "karma start --unit",
"test:browser:integration": "karma start --integration",
"test:browser:integration:local": "karma start --integration --local",
"test:browser:integration:prodbackend": "karma start --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",
"test:cordova": "karma start --cordova",
"test:cordova:debug": "karma start --auto-watch --cordova",
"test:node": "run-s --npm-path npm test:node:unit test:node:integration:local",
"test:node:unit": "ts-node -O '{\"module\": \"commonjs\", \"target\": \"es6\"}' scripts/run_node_tests.ts",
Expand Down
47 changes: 47 additions & 0 deletions packages/auth/src/api/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useFakeTimers } from 'sinon';
import sinonChai from 'sinon-chai';

import { FirebaseError, getUA } from '@firebase/util';
import * as utils from '@firebase/util';

import { mockEndpoint } from '../../test/helpers/api/helper';
import { testAuth, TestAuth } from '../../test/helpers/mock_auth';
Expand Down Expand Up @@ -308,6 +309,52 @@ describe('api/_performApiRequest', () => {
});
});

context('referer policy exists on fetch request', () => {
afterEach(mockFetch.tearDown);

it('should have referrerPolicy set', async () => {
let referrerPolicySet: boolean = false;
mockFetch.setUpWithOverride(
(input: RequestInfo | URL, request?: RequestInit) => {
if (request !== undefined && request.referrerPolicy !== undefined) {
referrerPolicySet = true;
}
return Promise.resolve(new Response(JSON.stringify(serverResponse)));
}
);
const promise = _performApiRequest<typeof request, typeof serverResponse>(
auth,
HttpMethod.POST,
Endpoint.SIGN_UP,
request
);
await expect(promise).to.be.fulfilled;
expect(referrerPolicySet).to.be.true;
});

it('should not have referrerPolicy set on Cloudflare workers', async () => {
sinon.stub(utils, 'isCloudflareWorker').returns(true);
let referrerPolicySet: boolean = false;
mockFetch.setUpWithOverride(
(input: RequestInfo | URL, request?: RequestInit) => {
if (request !== undefined && request.referrerPolicy !== undefined) {
referrerPolicySet = true;
}
return Promise.resolve(new Response(JSON.stringify(serverResponse)));
}
);
const promise = _performApiRequest<typeof request, typeof serverResponse>(
auth,
HttpMethod.POST,
Endpoint.SIGN_UP,
request
);
await expect(promise).to.be.fulfilled;
expect(referrerPolicySet).to.be.false;
sinon.restore();
});
});

context('with network issues', () => {
afterEach(mockFetch.tearDown);

Expand Down
23 changes: 16 additions & 7 deletions packages/auth/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { FirebaseError, querystring } from '@firebase/util';
import { FirebaseError, isCloudflareWorker, querystring } from '@firebase/util';

import { AuthErrorCode, NamedErrorParams } from '../core/errors';
import {
Expand Down Expand Up @@ -148,14 +148,23 @@ export async function _performApiRequest<T, V>(
headers[HttpHeader.X_FIREBASE_LOCALE] = auth.languageCode;
}

const fetchArgs: RequestInit = {
method,
headers,
...body
};

/* Security-conscious server-side frameworks tend to have built in mitigations for referrer
problems". See the Cloudflare GitHub issue #487: Error: The 'referrerPolicy' field on
'RequestInitializerDict' is not implemented."
https://github.com/cloudflare/next-on-pages/issues/487 */
if (!isCloudflareWorker()) {
fetchArgs.referrerPolicy = 'no-referrer';
}

return FetchProvider.fetch()(
_getFinalTarget(auth, auth.config.apiHost, path, query),
{
method,
headers,
referrerPolicy: 'no-referrer',
...body
}
fetchArgs
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"test": "run-p --npm-path npm lint test:all",
"test:all": "run-p --npm-path npm test:browser test:node",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all",
"test:browser": "karma start --single-run",
"test:browser": "karma start",
"test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha src/**/*.test.ts --config ../../config/mocharc.node.js",
"trusted-type-check": "tsec -p tsconfig.json --noEmit"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/database-compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"dev": "rollup -c -w",
"test": "run-p --npm-path npm lint test:browser test:node",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test",
"test:browser": "karma start --single-run",
"test:browser": "karma start",
"test:node": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file src/index.node.ts --config ../../config/mocharc.node.js",
"trusted-type-check": "tsec -p tsconfig.json --noEmit",
"add-compat-overloads": "ts-node-script ../../scripts/build/create-overloads.ts -i ../database/dist/public.d.ts -o dist/database-compat/src/index.d.ts -a -r Database:types.FirebaseDatabase -r Query:types.Query -r DatabaseReference:types.Reference -r FirebaseApp:FirebaseAppCompat --moduleToEnhance @firebase/database"
Expand Down
2 changes: 1 addition & 1 deletion packages/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"test": "run-p --npm-path npm lint test:emulator",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:emulator",
"test:all": "run-p --npm-path npm lint test:browser test:node",
"test:browser": "karma start --single-run",
"test:browser": "karma start",
"test:node": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file src/index.node.ts --config ../../config/mocharc.node.js",
"test:emulator": "ts-node --compiler-options='{\"module\":\"commonjs\"}' ../../scripts/emulator-testing/database-test-runner.ts",
"trusted-type-check": "tsec -p tsconfig.json --noEmit",
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore-compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"test": "run-s --npm-path npm lint test:all",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all",
"test:all": "run-p --npm-path npm test:browser test:node",
"test:browser": "karma start --single-run",
"test:browser": "karma start",
"test:node": "mocha --require babel-register.js --require src/index.node.ts --timeout 5000 'test/*.test.ts'",
"trusted-type-check": "tsec -p tsconfig.json --noEmit",
"add-compat-overloads": "ts-node-script ../../scripts/build/create-overloads.ts -i ../firestore/dist/index.d.ts -o dist/src/index.d.ts -a -r Firestore:types.FirebaseFirestore -r CollectionReference:types.CollectionReference -r DocumentReference:types.DocumentReference -r Query:types.Query -r FirebaseApp:FirebaseAppCompat --moduleToEnhance @firebase/firestore"
Expand Down
16 changes: 8 additions & 8 deletions packages/firestore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@
"test:lite": "ts-node ./scripts/run-tests.ts --emulator --platform node_lite --main=lite/index.ts 'test/lite/**/*.test.ts'",
"test:lite:prod": "ts-node ./scripts/run-tests.ts --platform node_lite --main=lite/index.ts 'test/lite/**/*.test.ts'",
"test:lite:prod:nameddb": "ts-node ./scripts/run-tests.ts --platform node_lite --databaseId=test-db --main=lite/index.ts 'test/lite/**/*.test.ts'",
"test:lite:browser": "karma start --single-run --lite",
"test:lite:browser:nameddb": "karma start --single-run --lite --databaseId=test-db",
"test:lite:browser": "karma start --lite",
"test:lite:browser:nameddb": "karma start --lite --databaseId=test-db",
"test:lite:browser:debug": "karma start --browsers=Chrome --lite --auto-watch",
"test": "run-s --npm-path npm lint test:all",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all:ci",
"test:all:ci": "run-s --npm-path npm test:browser test:travis test:lite:browser test:browser:prod:nameddb test:lite:browser:nameddb",
"test:all": "run-p --npm-path npm test:browser test:lite:browser test:travis test:minified test:browser:prod:nameddb test:lite:browser:nameddb",
"test:browser": "karma start --single-run",
"test:browser": "karma start",
"test:browser:emulator:debug": "karma start --browsers=Chrome --targetBackend=emulator",
"test:browser:emulator": "karma start --single-run --targetBackend=emulator",
"test:browser:nightly": "karma start --single-run --targetBackend=nightly",
"test:browser:prod": "karma start --single-run --targetBackend=prod",
"test:browser:prod:nameddb": "karma start --single-run --targetBackend=prod --databaseId=test-db",
"test:browser:unit": "karma start --single-run --unit",
"test:browser:emulator": "karma start --targetBackend=emulator",
"test:browser:nightly": "karma start --targetBackend=nightly",
"test:browser:prod": "karma start --targetBackend=prod",
"test:browser:prod:nameddb": "karma start --targetBackend=prod --databaseId=test-db",
"test:browser:unit": "karma start --unit",
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
"test:node": "ts-node ./scripts/run-tests.ts --main=test/register.ts --emulator 'test/{,!(browser|lite)/**/}*.test.ts'",
"test:node:prod": "ts-node ./scripts/run-tests.ts --main=test/register.ts 'test/{,!(browser|lite)/**/}*.test.ts'",
Expand Down
8 changes: 5 additions & 3 deletions packages/firestore/src/core/sync_engine_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,11 @@ async function allocateTargetAndMaybeListen(
// not registering it in shared client state, and directly calculate initial snapshots and
// subsequent updates from cache. Otherwise, register the target ID with local Firestore client
// as active watch target.
const status: QueryTargetState = shouldListenToRemote
? syncEngineImpl.sharedClientState.addLocalQueryTarget(targetId)
: 'not-current';
const status: QueryTargetState =
syncEngineImpl.sharedClientState.addLocalQueryTarget(
targetId,
/* addToActiveTargetIds= */ shouldListenToRemote
);

let viewSnapshot;
if (shouldInitializeView) {
Expand Down
Loading

0 comments on commit 0884f0d

Please sign in to comment.