quickstart-testing
quickstart-testing copied to clipboard
Test a firestore rule like "allow list"
In unit-test-security-rules-v9, show should I test an allow list rule, like in this example of firestore rules:
match /users/{userId}/{allPaths=**} {
allow list: if request.auth.token.isAdmin;
}
In my use-case, I want to allow users to get their own info but only admins can list everybody.
Thanks
For your case will be:
-
const adminDb = testEnv.authenticatedContext('admin', { "isAdmin": true }).firestore() -
await assertSucceeds(adminDb.collection('users').get())
.get() on specific collection need at least list rule, see https://fireship.io/snippets/firestore-rules-recipes/