Skip to content

Commit 364604e

Browse files
authored
Run Schema validations after beforeSave #2672 (#2677)
* Adds test to repro #2672 * Run schema validation after beforeSave is run * Makes authData part of base _User object * exclude flaky pg test
1 parent 58a2ee3 commit 364604e

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

spec/CloudCode.spec.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,11 @@ it('beforeSave should not affect fetched pointers', done => {
954954
});
955955
});
956956

957-
it('should fully delete objects when using `unset` with beforeSave (regression test for #1840)', done => {
957+
/*
958+
TODO: fix for Postgres
959+
trying to delete a field that doesn't exists doesn't play nice
960+
*/
961+
it_exclude_dbs(['postgres'])('should fully delete objects when using `unset` with beforeSave (regression test for #1840)', done => {
958962
var TestObject = Parse.Object.extend('TestObject');
959963
var BeforeSaveObject = Parse.Object.extend('BeforeSaveChanged');
960964

spec/ParseAPI.spec.js

+36
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,42 @@ it('ensure that if you try to sign up a user with a unique username and email, b
14941494
done();
14951495
});
14961496
});
1497+
1498+
it('should not update schema beforeSave #2672', (done) => {
1499+
Parse.Cloud.beforeSave('MyObject', (request, response) => {
1500+
if (request.object.get('secret')) {
1501+
response.error('cannot set secret here');
1502+
return;
1503+
}
1504+
response.success();
1505+
});
1506+
1507+
let object = new Parse.Object('MyObject');
1508+
object.set('key', 'value');
1509+
object.save().then(() => {
1510+
return object.save({'secret': 'should not update schema'});
1511+
}).then(() => {
1512+
fail();
1513+
done();
1514+
}, () => {
1515+
return rp({
1516+
method: 'GET',
1517+
headers: {
1518+
'X-Parse-Application-Id': 'test',
1519+
'X-Parse-Master-Key': 'test'
1520+
},
1521+
uri: 'http://localhost:8378/1/schemas/MyObject',
1522+
json: true
1523+
});
1524+
}).then((res) => {
1525+
let fields = res.fields;
1526+
expect(fields.secret).toBeUndefined();
1527+
done();
1528+
}, (err) => {
1529+
jfail(err);
1530+
done();
1531+
});
1532+
});
14971533
});
14981534

14991535
describe_only_db('mongo')('legacy _acl', () => {

spec/schemas.spec.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ const userSchema = {
9696
"username": {"type": "String"},
9797
"password": {"type": "String"},
9898
"email": {"type": "String"},
99-
"emailVerified": {"type": "Boolean"}
99+
"emailVerified": {"type": "Boolean"},
100+
"authData": {"type": "Object"}
100101
},
101102
"classLevelPermissions": defaultClassLevelPermissions,
102103
}
@@ -676,6 +677,7 @@ describe('schemas', () => {
676677
password: {type: 'String'},
677678
email: {type: 'String'},
678679
emailVerified: {type: 'Boolean'},
680+
authData: {type: 'Object'},
679681
newField: {type: 'String'},
680682
ACL: {type: 'ACL'}
681683
},
@@ -696,6 +698,7 @@ describe('schemas', () => {
696698
password: {type: 'String'},
697699
email: {type: 'String'},
698700
emailVerified: {type: 'Boolean'},
701+
authData: {type: 'Object'},
699702
newField: {type: 'String'},
700703
ACL: {type: 'ACL'}
701704
},

src/Controllers/SchemaController.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const defaultColumns = Object.freeze({
3131
"password": {type:'String'},
3232
"email": {type:'String'},
3333
"emailVerified": {type:'Boolean'},
34+
"authData": {type:'Object'}
3435
},
3536
// The additional default columns for the _Installation collection (in addition to DefaultCols)
3637
_Installation: {

src/RestWrite.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ RestWrite.prototype.execute = function() {
6262
return this.getUserAndRoleACL();
6363
}).then(() => {
6464
return this.validateClientClassCreation();
65-
}).then(() => {
66-
return this.validateSchema();
6765
}).then(() => {
6866
return this.handleInstallation();
6967
}).then(() => {
@@ -72,6 +70,8 @@ RestWrite.prototype.execute = function() {
7270
return this.validateAuthData();
7371
}).then(() => {
7472
return this.runBeforeTrigger();
73+
}).then(() => {
74+
return this.validateSchema();
7575
}).then(() => {
7676
return this.setRequiredFieldsIfNeeded();
7777
}).then(() => {
@@ -176,7 +176,6 @@ RestWrite.prototype.runBeforeTrigger = function() {
176176
if (this.query && this.query.objectId) {
177177
delete this.data.objectId
178178
}
179-
return this.validateSchema();
180179
}
181180
});
182181
};

0 commit comments

Comments
 (0)