Skip to content

assertFails of rules-unit-testing is not working #4667

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

Closed
MattGoldwater opened this issue Mar 22, 2021 · 0 comments
Closed

assertFails of rules-unit-testing is not working #4667

MattGoldwater opened this issue Mar 22, 2021 · 0 comments
Assignees
Labels
api: database testing-sdk testing with emulator

Comments

@MattGoldwater
Copy link
Contributor

MattGoldwater commented Mar 22, 2021

[REQUIRED] Describe your environment

  • Operating System version: macOS 11.2.2
  • Browser version: none
  • Firebase SDK version: @firebase/rules-unit-testing 1.2.5
  • Firebase Product: database

[REQUIRED] Describe the problem

When using assert fails I get the error message, Expected PERMISSION_DENIED but got unexpected error: Error: Permission denied

Steps to reproduce:

Relevant Code:

database.rules.json

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    }
  }
}

test file

const firebase = require('@firebase/rules-unit-testing');
const fs = require('fs');

it('does not let a user read the status of another user', async () => {
  const rules = fs.readFileSync("../database.rules.json", "utf8");
  await firebase.loadDatabaseRules({
    databaseName: 'fsp2-a670d',
    rules,
  })
  const adminApp = firebase.initializeAdminApp({
    databaseName: 'fsp2-a670d'
  })
  const realtimeDb = adminApp.database();
  await realtimeDb.ref('users/foo').set({
    online: true
  })
  const testApp = firebase.initializeTestApp({
    databaseName: 'fsp2-a670d',
    auth: {
      uid: 'bar'
    }
  })
  const testAppDb = testApp.database();
  await firebase.assertFails(testAppDb.ref('users/foo').get())
})

I opened a pull request to fix this issue here

MattGoldwater added a commit to MattGoldwater/firebase-js-sdk that referenced this issue Apr 2, 2021
hsubox76 pushed a commit that referenced this issue Apr 2, 2021
@looptheloop88 looptheloop88 added the testing-sdk testing with emulator label Apr 29, 2021
@firebase firebase locked and limited conversation to collaborators May 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: database testing-sdk testing with emulator
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants