Open anothermh opened 2 years ago
Hi @anothermh, thanks for the detailed report. Our engineers can take a look at this once they have the time.
Thanks for the detailed feature request. I think this is a reasonable field to add to the typing and we welcome Pull Requests.
In the meantime rulesTestEnv.authenticatedContext('alice', { firebase: { tenant: 'foobar' } } as any)
should unblock anyone who wants to test that field. (And for anyone who's using plain JS without TypeScript, you don't need to do anything special.)
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
Firestore rules can reference
request.auth
properties that are not available in theRulesTestContext
returned byauthenticatedContext()
in the rules-unit-testing package. These properties exist in the live Firestore rules environment and can be used successfully there but any attempt to evaluate those rules when using rules-unit-testing will trigger an error because the property that the rules expect to find is missing.For example,
request.auth.token.firebase.tenant
is present when a user authenticates using multi-tenancy with Identity Platform, butfirebase.tenant
doesn't exist in theTokenOptions
interface that can be passed toauthenticatedContext()
so anyRulesTestContext
returned will be missing this property.It seems like this is the right place for this type of custom configuration given the description of
TokenOptions
:A similar problem was brought up by someone else on the Firebase Google Group in June 2021 and a feature request was the recommended answer but I did not find one for this issue.
Steps to reproduce:
tenant
property:FirebaseError: Property tenant is undefined on object.
Relevant Code:
Create the test suite (this example uses jest) at
./tests/rules.test.ts
:Create rules that check the tenant at
./firestore.rules
Run the Firestore emulator and start the test suite:
Observe the output:
Ideally, this would be resolved by being able to pass a
firebase.tenant
property inTokenOptions
:But that presently generates an error: