Skip to content

Fix assertFails not recognising database permission denied error #4093

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

Merged
merged 3 commits into from
Nov 20, 2020

Conversation

mikkelvp
Copy link
Contributor

assertFails does not recognise the permission denied error from database once('value')

example

const app = firebase.initializeTestApp({
  databaseName,
  auth: { uid: 'alice' },
})
app
  .database()
  .ref('secrets/bob/id')
  .once('value')
  .then((snapshot) => {
    console.log('read succeeded')
  })
  .catch((err) => {
    console.log('read failed')
    // current implementation of isPermissionDenied 
    // https://github.com/firebase/firebase-js-sdk/blob/d934f74d6750dc31cca480e126757d53935cefcd/packages/rules-unit-testing/src/api/index.ts#L457
    const isPermissionDenied =
      (err && err.message && err.message.indexOf('PERMISSION_DENIED') >= 0) ||
      (err && err.code === 'permission-denied')
    console.log(`isPermissionDenied ${isPermissionDenied}`)
    console.log(JSON.stringify({ message: err.message, ...err }, null, 2))
  })

output:

read failed
isPermissionDenied false
{
  "message": "permission_denied at /secrets/bob/id: Client doesn't have permission to access the desired data.",
  "code": "PERMISSION_DENIED"
}

@changeset-bot
Copy link

changeset-bot bot commented Nov 19, 2020

🦋 Changeset detected

Latest commit: 878fec2

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

Copy link
Member

@yuchenshi yuchenshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Would you please also add a test for the new case?

@mikkelvp mikkelvp requested a review from yuchenshi November 20, 2020 10:29
@yuchenshi yuchenshi merged commit 3a19f9e into firebase:master Nov 20, 2020
@mikkelvp mikkelvp deleted the fix-assert-fails branch November 21, 2020 19:48
@google-oss-bot google-oss-bot mentioned this pull request Dec 2, 2020
@firebase firebase locked and limited conversation to collaborators Dec 21, 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.

2 participants