Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test a firestore rule like "allow list" #224

Open
gjanvier opened this issue Dec 20, 2021 · 1 comment
Open

Test a firestore rule like "allow list" #224

gjanvier opened this issue Dec 20, 2021 · 1 comment

Comments

@gjanvier
Copy link

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

@ghost
Copy link

ghost commented Jan 24, 2023

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant