targaryen: Testing against .validate is not performed

Hi all,

I am trying to run the following test:

...
   before(() => {
    ...
    targaryen.setFirebaseData({
      technicians: {
        'technician-admin': {
          created,
          profile,
          type: 'admin',
        }
      }
    });
  });
...
const admin = { uid: 'technician-admin', email: 'admin@echo.com' };
...
expect(admin).cannot.write({ index: 'firebase', query: '*' }).to.path('search/request/:id');
...

against the following rules:

{
  "rules": {
    "search": {
      "request": {
        "$request": {
          ".validate": "newData.hasChildren(['index', 'type', 'query'])",
          "index": {
            ".validate": "newData.isString() && newData.val().length > 0"
          },
          "type": {
            ".validate": "newData.isString() && newData.val().length > 0"
          },
          "query": {
            ".validate": "newData.isString() && newData.val().length > 0"
          },
          "$other": {
            ".validate": "false"
          },
          ".write": "data.val() == null && (auth != null && auth.uid != null) && (newData.child('type').val() == 'item' || newData.child('type').val() == 'practice' || root.child('technicians').child(auth.uid).child('type').val() == 'admin')"
        }
      }
    }
  }
}

but it fails with the following error:

1) database user:technician:admin /search /request /:id pass:
     AssertionError: Expected a user with credentials {"uid":"technician-admin","email":"admin@echo.com"} not to be able to write {"index":"firebase","query":"*"} to search/request/:id, but the rules allowed the write.
/search/request/:id:.write: "data.val() == null && (auth != null && auth.uid != null) && (newData.child('type').val() == 'item' || newData.child('type').val() == 'practice' || root.child('technicians').child(auth.uid).child('type').val() == 'admin')"
    => true
Write was allowed.
      at Assertion.<anonymous> (node_modules/targaryen/lib/chai.js:84:12)
      at Assertion.ctx.(anonymous function) [as path] (node_modules/chai/lib/chai/utils/addMethod.js:41:25)
      at Context.it (test/database/rules.targaryen.js:1234:76)

This test would not have failed if ".validate": "newData.hasChildren(['index', 'type', 'query'])" would have been evaluated, it seems that targaryen didn’t pickup .validate

Any help would be appreciated. We were looking for a way to test Fireabase rules locally (we ran them against a Fireabase app until now) and a few days ago we have been recommended targaryen by Mike from the Firebase support team. We have rewritten 300 tests to run on targaryen but some things we are not able to test.

Thanks in advance, Romans

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 26 (1 by maintainers)

Most upvoted comments

@RomansBermans It’s fixed in upcoming 3.0.0 and 2.3.3 (with #93).