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

feat: use firebase-json to load rules #111

Merged
merged 1 commit into from
Jan 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions bin/targaryen
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

'use strict';

const fs = require('fs');
const stripJsonComments = require('strip-json-comments');
const json = require('firebase-json');

const path = require('path');
const Table = require('cli-table');
Expand All @@ -21,8 +20,7 @@ if (argv._.length < 2) {

const rulesJSONPath = path.resolve(argv._[0]);
const testJSONPath = path.resolve(argv._[1]);
const rulesJSONFile = fs.readFileSync(rulesJSONPath);
const rules = JSON.parse(stripJsonComments(rulesJSONFile.toString()));
const rules = json.loadSync(rulesJSONPath, 'utf8');
const tests = require(testJSONPath);

const jig = new TestJig(rules, tests);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"colors": "^1.0.3",
"debug": "^2.3.3",
"esprima": "^1.2.2",
"firebase-json": "^0.1.0",
"firebase-token-generator": "^2.0.0",
"lodash.set": "^4.3.2",
"minimist": "^1.1.0",
Expand Down
12 changes: 11 additions & 1 deletion test/integration/rules.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
{
"rules": {
"posts": {
/**
* Post.
*
* Read: anybody with the correct clearance level; each post has its own level requirement
* Write: by the author only.
*/
"$post": {
".read": "root.child('users').child(auth.uid).child('clearance-level').val() >= data.child('clearance-level').val()",
".write": "root.child('users').child(auth.uid).child('author').val() === true",
".validate": "newData.hasChildren() && newData.hasChild('date')",
"date": {
".validate": "data.parent().exists() === false && newData.val() <= now"
".validate": "
data.parent().exists() === false
&& newData.val() <= now
"
}
}
},
"flight-routes": {
// Flight routes are public and can be added/edited bu ticket agents
"$from": {
"$to": {
".read": "true",
Expand Down