quickstart-testing icon indicating copy to clipboard operation
quickstart-testing copied to clipboard

Test a firestore rule like "allow list"

Open gjanvier opened this issue 4 years ago • 1 comments

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

gjanvier avatar Dec 20 '21 20:12 gjanvier

For your case will be:

  1. const adminDb = testEnv.authenticatedContext('admin', { "isAdmin": true }).firestore()

  2. await assertSucceeds(adminDb.collection('users').get())

.get() on specific collection need at least list rule, see https://fireship.io/snippets/firestore-rules-recipes/

ghost avatar Jan 24 '23 09:01 ghost