-
Notifications
You must be signed in to change notification settings - Fork 902
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into hsinpei/storage-emulator-multiple-targets-5
- Loading branch information
Showing
21 changed files
with
564 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
scripts/storage-emulator-integration/multiple-targets/allowAll.rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
rules_version = '2'; | ||
service firebase.storage { | ||
match /b/{bucket}/o { | ||
match /{allPaths=**} { | ||
allow read, write: if true; | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
scripts/storage-emulator-integration/multiple-targets/allowNone.rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
rules_version = '2'; | ||
service firebase.storage { | ||
match /b/{bucket}/o { | ||
match /{allPaths=**} { | ||
allow read, write: if false; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
scripts/storage-emulator-integration/multiple-targets/firebase.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"storage": [ | ||
{ | ||
"target": "allowNone", | ||
"rules": "allowNone.rules" | ||
}, | ||
{ | ||
"target": "allowAll", | ||
"rules": "allowAll.rules" | ||
} | ||
], | ||
"emulators": { | ||
"storage": { | ||
"port": 9199 | ||
} | ||
} | ||
} | ||
|
||
|
64 changes: 64 additions & 0 deletions
64
scripts/storage-emulator-integration/multiple-targets/tests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import supertest = require("supertest"); | ||
import { Emulators } from "../../../src/emulator/types"; | ||
import { TriggerEndToEndTest } from "../../integration-helpers/framework"; | ||
import { | ||
EMULATORS_SHUTDOWN_DELAY_MS, | ||
FIREBASE_EMULATOR_CONFIG, | ||
getStorageEmulatorHost, | ||
readEmulatorConfig, | ||
TEST_SETUP_TIMEOUT, | ||
} from "../utils"; | ||
|
||
const FIREBASE_PROJECT = process.env.FBTOOLS_TARGET_PROJECT || "fake-project-id"; | ||
|
||
describe("Multiple Storage Deploy Targets", () => { | ||
let test: TriggerEndToEndTest; | ||
const allowNoneBucket = `${FIREBASE_PROJECT}.appspot.com`; | ||
const allowAllBucket = `${FIREBASE_PROJECT}-2.appspot.com`; | ||
const emulatorConfig = readEmulatorConfig(FIREBASE_EMULATOR_CONFIG); | ||
const STORAGE_EMULATOR_HOST = getStorageEmulatorHost(emulatorConfig); | ||
|
||
before(async function (this) { | ||
this.timeout(TEST_SETUP_TIMEOUT); | ||
|
||
test = new TriggerEndToEndTest(FIREBASE_PROJECT, __dirname, emulatorConfig); | ||
await test.applyTargets(Emulators.STORAGE, "allowNone", allowNoneBucket); | ||
await test.applyTargets(Emulators.STORAGE, "allowAll", allowAllBucket); | ||
await test.startEmulators(["--only", Emulators.STORAGE]); | ||
}); | ||
|
||
it("should enforce different rules for different targets", async () => { | ||
const uploadURL = await supertest(STORAGE_EMULATOR_HOST) | ||
.post(`/v0/b/${allowNoneBucket}/o/test_upload.jpg?uploadType=resumable&name=test_upload.jpg`) | ||
.set({ "X-Goog-Upload-Protocol": "resumable", "X-Goog-Upload-Command": "start" }) | ||
.expect(200) | ||
.then((res) => new URL(res.header["x-goog-upload-url"])); | ||
|
||
await supertest(STORAGE_EMULATOR_HOST) | ||
.put(uploadURL.pathname + uploadURL.search) | ||
.set({ | ||
"X-Goog-Upload-Protocol": "resumable", | ||
"X-Goog-Upload-Command": "upload, finalize", | ||
}) | ||
.expect(403); | ||
|
||
const otherUploadURL = await supertest(STORAGE_EMULATOR_HOST) | ||
.post(`/v0/b/${allowAllBucket}/o/test_upload.jpg?uploadType=resumable&name=test_upload.jpg`) | ||
.set({ "X-Goog-Upload-Protocol": "resumable", "X-Goog-Upload-Command": "start" }) | ||
.expect(200) | ||
.then((res) => new URL(res.header["x-goog-upload-url"])); | ||
|
||
await supertest(STORAGE_EMULATOR_HOST) | ||
.put(otherUploadURL.pathname + otherUploadURL.search) | ||
.set({ | ||
"X-Goog-Upload-Protocol": "resumable", | ||
"X-Goog-Upload-Command": "upload, finalize", | ||
}) | ||
.expect(200); | ||
}); | ||
|
||
after(async function (this) { | ||
this.timeout(EMULATORS_SHUTDOWN_DELAY_MS); | ||
await test.stopEmulators(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.