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

Improve typing for options.auth #3876

Merged
merged 2 commits into from
Oct 2, 2020
Merged

Conversation

samtstern
Copy link
Contributor

Discussion

This is a non-breaking change to improve the typing for options.auth in initializeTestApp. Note that this removes the uid property of the token which should never have been there in the first place (sub is the canonical uid field).

Related issues:

Testing

Improved existing unit tests

API Changes

N/A

@changeset-bot
Copy link

changeset-bot bot commented Oct 1, 2020

🦋 Changeset detected

Latest commit: 39cd8ff

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@firebase/rules-unit-testing Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Oct 1, 2020

Size Analysis Report

Affected Products

No changes between base commit (a10c18f) and head commit (f87eb8b).

Test Logs

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Oct 1, 2020

Binary Size Report

Affected SDKs

  • @firebase/rules-unit-testing

    Type Base (a10c18f) Head (44411cd) Diff
    main 7.28 kB 7.84 kB +561 B (+7.7%)

Test Logs

@mdirolf
Copy link

mdirolf commented Oct 9, 2020

When using custom claims in firestore rules I grab them off the top-level token object, as documented here https://firebase.google.com/docs/auth/admin/custom-claims:

    function isAdmin() {
      return request.auth.token.admin;
    }

In testing I was able to create an app instance that passed those rules like this:

firebaseTesting.initializeTestApp({
    projectId,
    auth: {
      uid: 'mike', admin: true, firebase: {
        sign_in_provider: 'google.com'
      }
    }
  })

This change makes that admin: true a type error, so I tried moving it into a claims object like:

firebaseTesting.initializeTestApp({
    projectId,
    auth: {
      uid: 'mike', claims: {admin: true}, firebase: {
        sign_in_provider: 'google.com'
      }
    }
  })

That passes type checking but doesn't seem to work when testing those security rules. Am I doing something wrong or do custom claims need to get hoisted up a level at some point?

@samtstern
Copy link
Contributor Author

@mdirolf hmmm that's interesting, would you mind opening a new issue rather than discussing it here on this closed PR?

@samtstern samtstern mentioned this pull request Oct 9, 2020
@samtstern
Copy link
Contributor Author

@mdirolf fixed in #3915 !

@mdirolf
Copy link

mdirolf commented Oct 9, 2020

@samtstern thanks! sorry for not opening a new issue to begin with

@firebase firebase locked and limited conversation to collaborators Nov 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants