-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(firestore-rules): add test for reads
- Loading branch information
1 parent
6ac726a
commit 73c0d3c
Showing
7 changed files
with
291 additions
and
66 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as firebase from "@firebase/rules-unit-testing"; | ||
import {getAuthedFirestore, reinitializeFirestore} from "./utils"; | ||
import {FirebaseCollection} from '@pipeline/common/build/cjs'; | ||
|
||
const PROJECT_ID = "firestore-emulator-example-" + Math.floor(Math.random() * 1000); | ||
|
||
const COVERAGE_URL = `http://${process.env.FIRESTORE_EMULATOR_HOST}/emulator/v1/projects/${PROJECT_ID}:ruleCoverage.html`; | ||
|
||
beforeEach(async () => { | ||
await reinitializeFirestore(PROJECT_ID); | ||
}); | ||
|
||
after(async () => { | ||
await Promise.all(firebase.apps().map((app) => app.delete())); | ||
console.log(`View firestore rule coverage information at ${COVERAGE_URL}\n`); | ||
}); | ||
|
||
describe("Cards read", () => { | ||
|
||
it("should not allow cards read if not authenticated", async () => { | ||
const db = getAuthedFirestore(PROJECT_ID, undefined); | ||
const cardsRef = db.collection(FirebaseCollection.Cards); | ||
await firebase.assertFails(cardsRef.get()); | ||
}); | ||
|
||
it("should not allow cards read if authenticated but email not verified", async () => { | ||
const userUID = 'id1'; | ||
const email = 'test@email.com'; | ||
const db = getAuthedFirestore(PROJECT_ID, {uid: userUID, email, email_verified: false}); | ||
const cardsRef = db.collection(FirebaseCollection.Cards); | ||
await firebase.assertFails(cardsRef.get()); | ||
}); | ||
|
||
it("should allow deck cards if authenticated and email verified", async () => { | ||
const userUID = 'id1'; | ||
const email = 'test@email.com'; | ||
const db = getAuthedFirestore(PROJECT_ID, {uid: userUID, email, email_verified: true}); | ||
const cardsRef = db.collection(FirebaseCollection.Cards); | ||
await firebase.assertSucceeds(cardsRef.get()); | ||
}); | ||
|
||
}); |
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,44 @@ | ||
import * as firebase from "@firebase/rules-unit-testing"; | ||
import {getAuthedFirestore, reinitializeFirestore} from "./utils"; | ||
import {FirebaseCollection} from '@pipeline/common/build/cjs'; | ||
|
||
const PROJECT_ID = "firestore-emulator-example-" + Math.floor(Math.random() * 1000); | ||
|
||
const COVERAGE_URL = `http://${process.env.FIRESTORE_EMULATOR_HOST}/emulator/v1/projects/${PROJECT_ID}:ruleCoverage.html`; | ||
|
||
const DEFAULT_DECK_ID = '7p5qqvE8kCV9WWysVc2n'; | ||
|
||
beforeEach(async () => { | ||
await reinitializeFirestore(PROJECT_ID); | ||
}); | ||
|
||
after(async () => { | ||
await Promise.all(firebase.apps().map((app) => app.delete())); | ||
console.log(`View firestore rule coverage information at ${COVERAGE_URL}\n`); | ||
}); | ||
|
||
describe("Deck read", () => { | ||
|
||
it("should not allow deck read if not authenticated", async () => { | ||
const db = getAuthedFirestore(PROJECT_ID, undefined); | ||
const deckRef = db.collection(FirebaseCollection.Decks).doc(DEFAULT_DECK_ID); | ||
await firebase.assertFails(deckRef.get()); | ||
}); | ||
|
||
it("should not allow deck read if authenticated but email not verified", async () => { | ||
const userUID = 'id1'; | ||
const email = 'test@email.com'; | ||
const db = getAuthedFirestore(PROJECT_ID, {uid: userUID, email, email_verified: false}); | ||
const deckRef = db.collection(FirebaseCollection.Decks).doc(DEFAULT_DECK_ID); | ||
await firebase.assertFails(deckRef.get()); | ||
}); | ||
|
||
it("should allow deck read if authenticated and email verified", async () => { | ||
const userUID = 'id1'; | ||
const email = 'test@email.com'; | ||
const db = getAuthedFirestore(PROJECT_ID, {uid: userUID, email, email_verified: true}); | ||
const deckRef = db.collection(FirebaseCollection.Decks).doc(DEFAULT_DECK_ID); | ||
await firebase.assertSucceeds(deckRef.get()); | ||
}); | ||
|
||
}); |
44 changes: 44 additions & 0 deletions
44
packages/firestore/test/read-dynamic-data-devops-maturities.spec.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,44 @@ | ||
import * as firebase from "@firebase/rules-unit-testing"; | ||
import {getAuthedFirestore, reinitializeFirestore} from "./utils"; | ||
import {FirebaseCollection, FirebaseDoc} from '@pipeline/common/build/cjs'; | ||
|
||
const PROJECT_ID = "firestore-emulator-example-" + Math.floor(Math.random() * 1000); | ||
|
||
const COVERAGE_URL = `http://${process.env.FIRESTORE_EMULATOR_HOST}/emulator/v1/projects/${PROJECT_ID}:ruleCoverage.html`; | ||
|
||
const GAME_ID = 'randomId'; | ||
|
||
beforeEach(async () => { | ||
await reinitializeFirestore(PROJECT_ID); | ||
}); | ||
|
||
after(async () => { | ||
await Promise.all(firebase.apps().map((app) => app.delete())); | ||
console.log(`View firestore rule coverage information at ${COVERAGE_URL}\n`); | ||
}); | ||
|
||
describe("Dynamic data devops maturities read", () => { | ||
|
||
it("should allow devops maturities read if not authenticated", async () => { | ||
const db = getAuthedFirestore(PROJECT_ID, undefined); | ||
const gameRolesRef = db.collection(FirebaseCollection.DynamicData).doc(FirebaseDoc.DevOpsMaturities); | ||
await firebase.assertSucceeds(gameRolesRef.get()); | ||
}); | ||
|
||
it("should allow devops maturities read if authenticated but email not verified", async () => { | ||
const userUID = 'id1'; | ||
const email = 'test@email.com'; | ||
const db = getAuthedFirestore(PROJECT_ID, {uid: userUID, email, email_verified: false}); | ||
const gameRolesRef = db.collection(FirebaseCollection.DynamicData).doc(FirebaseDoc.DevOpsMaturities); | ||
await firebase.assertSucceeds(gameRolesRef.get()); | ||
}); | ||
|
||
it("should allow devops maturities read if authenticated and email verified", async () => { | ||
const userUID = 'id1'; | ||
const email = 'test@email.com'; | ||
const db = getAuthedFirestore(PROJECT_ID, {uid: userUID, email, email_verified: true}); | ||
const gameRolesRef = db.collection(FirebaseCollection.DynamicData).doc(FirebaseDoc.DevOpsMaturities); | ||
await firebase.assertSucceeds(gameRolesRef.get()); | ||
}); | ||
|
||
}); |
Oops, something went wrong.