Skip to content

Commit 010ae6f

Browse files
committed
Update deps and API
1 parent 1284c94 commit 010ae6f

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

packages/rules-unit-testing/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"build:deps": "lerna run --scope @firebase/rules-unit-testing --include-dependencies build",
1616
"dev": "rollup -c -w",
1717
"test:nyc": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --config ../../config/mocharc.node.js",
18-
"test": "firebase --project=foo --debug emulators:exec 'yarn test:nyc'",
18+
"test": "FIREBASE_CLI_PREVIEWS=storageemulator firebase --project=foo --debug emulators:exec 'yarn test:nyc'",
1919
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test"
2020
},
2121
"license": "Apache-2.0",
@@ -29,15 +29,15 @@
2929
"devDependencies": {
3030
"@google-cloud/firestore": "4.8.1",
3131
"@types/request": "2.48.5",
32-
"firebase-admin": "9.4.2",
32+
"firebase-admin": "9.7.0",
3333
"firebase-tools": "9.1.0",
3434
"firebase-functions": "3.13.0",
3535
"rollup": "2.35.1",
3636
"rollup-plugin-typescript2": "0.29.0"
3737
},
3838
"peerDependencies": {
3939
"@google-cloud/firestore": "^4.2.0",
40-
"firebase-admin": "^9.0.0"
40+
"firebase-admin": "^9.7.0"
4141
},
4242
"repository": {
4343
"directory": "packages/rules-unit-testing",

packages/rules-unit-testing/src/api/index.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ const FIRESTORE_ADDRESS_ENV: string = 'FIRESTORE_EMULATOR_HOST';
3737
const FIRESTORE_ADDRESS_DEFAULT: string = 'localhost:8080';
3838

3939
/** If this environment variable is set, use it for the Storage emulator. */
40-
const STORAGE_ADDRESS_ENV: string = 'STORAGE_EMULATOR_HOST';
40+
const FIREBASE_STORAGE_ADDRESS_ENV: string = 'FIREBASE_STORAGE_EMULATOR_HOST';
41+
const CLOUD_STORAGE_ADDRESS_ENV: string = 'STORAGE_EMULATOR_HOST';
4142
/** The default address for the local Firestore emulator. */
4243
const STORAGE_ADDRESS_DEFAULT: string = 'localhost:9199';
4344

@@ -378,12 +379,15 @@ function getFirestoreHost() {
378379

379380
function getStorageHost() {
380381
if (!_storageHost) {
381-
const fromEnv = process.env[STORAGE_ADDRESS_ENV];
382+
const fromEnv = process.env[FIREBASE_STORAGE_ADDRESS_ENV] || process.env[CLOUD_STORAGE_ADDRESS_ENV];
382383
if (fromEnv) {
383-
_storageHost = fromEnv;
384+
// The STORAGE_EMULATOR_HOST env var is an older Cloud Standard which includes http:// while
385+
// the FIREBASE_STORAGE_EMULATOR_HOST is a newer variable supported beginning in the Admin
386+
// SDK v9.7.0 which does not have the protocol.
387+
_storageHost = fromEnv.replace("http://", "");
384388
} else {
385389
console.warn(
386-
`Warning: ${STORAGE_ADDRESS_ENV} not set, using default value ${STORAGE_ADDRESS_DEFAULT}`
390+
`Warning: ${FIREBASE_STORAGE_ADDRESS_ENV} not set, using default value ${STORAGE_ADDRESS_DEFAULT}`
387391
);
388392
_storageHost = STORAGE_ADDRESS_DEFAULT;
389393
}
@@ -564,29 +568,21 @@ export async function loadFirestoreRules(
564568
}
565569

566570
export type LoadStorageRulesOptions = {
567-
storageBucket: string;
568571
rules: string;
569572
};
570573
export async function loadStorageRules(
571574
options: LoadStorageRulesOptions
572575
): Promise<void> {
573-
if (!options.storageBucket) {
574-
throw new Error('storageBucket not specified');
575-
}
576-
577576
if (!options.rules) {
578577
throw new Error('must provide rules to loadStorageRules');
579578
}
580579

581-
// TODO: This endpoint is not yet implemented! Will need a change in firebase-tools
582-
// to make this real.
583580
const resp = await requestPromise(request.put, {
584581
method: 'PUT',
585582
uri: `http://${getStorageHost()}/internal/setRules`,
586583
body: JSON.stringify({
587-
storageBucket: options.storageBucket,
588584
rules: {
589-
files: [{ content: options.rules }]
585+
files: [{ name: 'storage.rules', content: options.rules }]
590586
}
591587
})
592588
});

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7463,10 +7463,10 @@ fined@^1.0.1:
74637463
object.pick "^1.2.0"
74647464
parse-filepath "^1.0.1"
74657465

7466-
firebase-admin@9.4.2:
7467-
version "9.4.2"
7468-
resolved "https://registry.npmjs.org/firebase-admin/-/firebase-admin-9.4.2.tgz#190d5d7ca5e3f251d99503feb6e05e7ab1623851"
7469-
integrity sha512-mRnBJbW6BAz6DJkZ0GOUTkmnmCrwVzMreMc6O+RXWukFydOzi5Xr6TKSiPKxoOQw41r9IluP2AZ3Qzvlx2SR+g==
7466+
firebase-admin@9.7.0:
7467+
version "9.7.0"
7468+
resolved "https://registry.npmjs.org/firebase-admin/-/firebase-admin-9.7.0.tgz#c5fde178a1f1e757373b38601eb62a8ccbcb9393"
7469+
integrity sha512-dvxy4lK2P2BikE9lB2hj4dUXGm9tuoGRVtobXzCpk7uhi0/FuTOU1yp4IW7vlMI20fxTdm6FmCXdwUlMeSljBA==
74707470
dependencies:
74717471
"@firebase/database" "^0.8.1"
74727472
"@firebase/database-types" "^0.6.1"
@@ -7487,7 +7487,7 @@ [email protected]:
74877487
"@firebase/app-exp" "0.0.900"
74887488
"@firebase/auth-compat" "0.0.900"
74897489
"@firebase/auth-exp" "0.0.900"
7490-
"@firebase/database" "0.9.11"
7490+
"@firebase/database" "0.9.12"
74917491
"@firebase/firestore" "2.2.5"
74927492
"@firebase/functions-compat" "0.0.900"
74937493
"@firebase/functions-exp" "0.0.900"

0 commit comments

Comments
 (0)