Skip to content

Commit

Permalink
Add integration test for resource evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
tohhsinpei committed Feb 24, 2022
1 parent 5289f92 commit 39504ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/storage-emulator-integration/storage.rules
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, create, update: if request.auth != null;
allow delete: if request.auth != null && resource.name != null;
allow delete: if request.auth != null && resource.metadata.contentType != 'text/plain';
}

match /public/{allPaths=**} {
Expand Down
26 changes: 26 additions & 0 deletions scripts/storage-emulator-integration/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,32 @@ describe("Storage emulator", () => {

expect(error).to.contain("does not exist.");
});

it("delete prevented by security rule", async () => {
const downloadUrl = await page.evaluate((filename) => {
return firebase.storage().ref(filename).getDownloadURL();
}, filename);

expect(downloadUrl).to.be.not.null;

await page.evaluate((filename) => {
firebase.storage().ref(filename).updateMetadata({ contentType: "text/plain" });
}, filename);

const error = await page.evaluate((filename) => {
return new Promise((resolve) => {
firebase
.storage()
.ref(filename)
.delete()
.catch((err) => {
resolve(err.message);
});
});
}, filename);

expect(error).to.contain("does not have permission to access");
});
});

emulatorSpecificDescribe("Non-SDK Endpoints", () => {
Expand Down

0 comments on commit 39504ff

Please sign in to comment.