-
Notifications
You must be signed in to change notification settings - Fork 36
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
Invalid location in tests are not reported #131
Comments
The problem is with dot in url: it('should handle dot in url', function() {
const rules = {
rules: {
'.write': true,
'.read': true,
$a: {
'.validate': false
}
}
};
const db = database.create(rules, {}).with({debug: true});
expect(db.write('foo', true).allowed).to.be.false();
expect(db.write('foo.bar', true).allowed).to.be.false(); // fails
}); |
Are dot allowed? |
I don't think that's the problem. That's an ES6 template string, these two things are equivalent: const user = { uid: 'foo.bar' };
`/users/${user.uid}/activity/firstSignIn` === '/users/' + user.uid + '/activity/firstSignIn'; |
@dannycochran Firebase doesn't allow path containing dot. ps: try {
"rules": {
".write": true,
"$a": {
".validate": false
}
}
} simulate write to path "/foo.bar/". |
Ah right, that makes sense. In which case, should targaryen throw an error that the path URL is invalid, rather than returning a result which indicates the write was valid? |
It should throw. It must throw for an illegal location and it might need to validate the uid too (the illegal character rule might apply to uid, I need to check). |
Validate path navigation rules or node and when creating/updating data nodes. Fixes goldibex#131
The bug related to invalid path and node key is fixed in 3.0.3 and it's released. Regarding UIDs, |
This change breaks our tests and I believe it restricts a use case that is allowed in Firebase. For safety, we user dummy UIDs that looks like email addresses to run our cloud functions with restricted privileges. Our write rules test paths of the form Here's the error from our tests.
|
I will check with a proper write operation, but the simulator says "/permissions/user@domain.com" is an invalid location. |
@chetbox with rule: {
"rules": {
"$key": {
".write": "$key !== 'admin' && root.child('banned').child(auth.uid).val() !== true"
}
}
} And the following program: 'use strict';
const admin = require('firebase-admin');
const uid = 'bob@example.com';
const adminApp = admin.initializeApp({
databaseURL: 'https://targaryen-42380.firebaseio.com',
credential: admin.credential.cert('./sa.json')
});
const userApp = admin.initializeApp({
databaseURL: 'https://targaryen-42380.firebaseio.com',
credential: admin.credential.cert('./sa.json'),
databaseAuthVariableOverride: {uid}
}, 'bob');
init()
.then(write)
.then(close)
.catch(close);
function init() {
const db = adminApp.database()
return db.ref('/').set({});
}
function write() {
const db = userApp.database()
return db.ref('/foo').set('bar');
}
function close(err) {
if (err !== null) {
console.error(err);
} {
console.log('done');
}
adminApp.delete();
userApp.delete();
} It works regardless of the I will open a new issue. |
".validate" rules are not respected when the auth uid has a period in it. For instance:
However if you change the above user to be "foobar", result.validated will correctly return "false".
I encountered this as I was creating dummy users using Math.random() for the uid, which is easy enough to work around, but it was a headache to track down why this is happening.
The text was updated successfully, but these errors were encountered: