goldibex / targaryen

Test Firebase security rules without connecting to Firebase.
ISC License
242 stars 36 forks source link

Report invalid regex #143

Closed a-xin closed 6 years ago

a-xin commented 6 years ago

This regex is invalid in firebase but valid in targaryen tests:

newData.val().matches(/^(up|down|)$/)

Firebase reports: Illegal regular expression, expected ')' at position 10 (and points to the first / character).

It would be great if running targaryen on a rule file including this regex already reports the invalid regex.

dinoboff commented 6 years ago

@a-xin Could you try with targaryen@beta?

a-xin commented 6 years ago

@dinoboff Thanks for the update, I installed targaryen@beta ("version": "3.1.0-beta.1",) and when I try to run my db rules tests I get the following exception:

Error: Cannot find module './parser'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/user/app/node_modules/targaryen/lib/parser/regexp/index.js:4:17)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

The import of ./parser does not exist within the path lib/parser/regexp - do I have to change anything else to make the tests run with the beta version?

a-xin commented 6 years ago

Looks like this .gitignore file prevents parser.js from getting published to npm: https://github.com/goldibex/targaryen/blob/master/lib/parser/regexp/.gitignore#L1

dinoboff commented 6 years ago

Thanks, I will publish a fix.

dinoboff commented 6 years ago

Fixed in latest beta release.

a-xin commented 6 years ago

@dinoboff Cool, I can exeucte the tests now but they fail on the following regex:

".validate": "newData.child('url').val().matches(/^https?:\\/\\/.+$/i)"

with this error:

    Error: Proposed Firebase rules are not valid: unknown regexp node type ("dot").
        at Object.exports.setFirebaseRules (/home/user/app/node_modules/targaryen/lib/util.js:145:11)
        at UserContext.beforeEach (/home/user/app/test-database/database.test.js:97:15)
        at <Jasmine>
        at runCallback (timers.js:794:20)
        at tryOnImmediate (timers.js:752:5)

Above's rule works fine when deployed to firebase

dinoboff commented 6 years ago

@a-xin should be fixed in last beta

a-xin commented 6 years ago

@dinoboff Awesome, my tests are green now and the invalid regex is correctly flagged. Great work! :tada:

dinoboff commented 6 years ago

Thanks @a-xin. Published with 3.1.0.