Fix: objectId size for Pointer in Postgres (#6619)
* Fixing objectId for Pointer in Postgres * add test case for longer objectId pointer. Note that this test fails on Postgres before the addition of previous commit * removed comment that wasn't needed
This commit is contained in:
@@ -16,11 +16,11 @@ describe('rest create', () => {
|
|||||||
database = config.database;
|
database = config.database;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles _id', done => {
|
it('handles _id', (done) => {
|
||||||
rest
|
rest
|
||||||
.create(config, auth.nobody(config), 'Foo', {})
|
.create(config, auth.nobody(config), 'Foo', {})
|
||||||
.then(() => database.adapter.find('Foo', { fields: {} }, {}, {}))
|
.then(() => database.adapter.find('Foo', { fields: {} }, {}, {}))
|
||||||
.then(results => {
|
.then((results) => {
|
||||||
expect(results.length).toEqual(1);
|
expect(results.length).toEqual(1);
|
||||||
const obj = results[0];
|
const obj = results[0];
|
||||||
expect(typeof obj.objectId).toEqual('string');
|
expect(typeof obj.objectId).toEqual('string');
|
||||||
@@ -30,12 +30,12 @@ describe('rest create', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can use custom _id size', done => {
|
it('can use custom _id size', (done) => {
|
||||||
config.objectIdSize = 20;
|
config.objectIdSize = 20;
|
||||||
rest
|
rest
|
||||||
.create(config, auth.nobody(config), 'Foo', {})
|
.create(config, auth.nobody(config), 'Foo', {})
|
||||||
.then(() => database.adapter.find('Foo', { fields: {} }, {}, {}))
|
.then(() => database.adapter.find('Foo', { fields: {} }, {}, {}))
|
||||||
.then(results => {
|
.then((results) => {
|
||||||
expect(results.length).toEqual(1);
|
expect(results.length).toEqual(1);
|
||||||
const obj = results[0];
|
const obj = results[0];
|
||||||
expect(typeof obj.objectId).toEqual('string');
|
expect(typeof obj.objectId).toEqual('string');
|
||||||
@@ -104,14 +104,14 @@ describe('rest create', () => {
|
|||||||
expect(objectId).toBeDefined();
|
expect(objectId).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is backwards compatible when _id size changes', done => {
|
it('is backwards compatible when _id size changes', (done) => {
|
||||||
rest
|
rest
|
||||||
.create(config, auth.nobody(config), 'Foo', { size: 10 })
|
.create(config, auth.nobody(config), 'Foo', { size: 10 })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
config.objectIdSize = 20;
|
config.objectIdSize = 20;
|
||||||
return rest.find(config, auth.nobody(config), 'Foo', { size: 10 });
|
return rest.find(config, auth.nobody(config), 'Foo', { size: 10 });
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then((response) => {
|
||||||
expect(response.results.length).toEqual(1);
|
expect(response.results.length).toEqual(1);
|
||||||
expect(response.results[0].objectId.length).toEqual(10);
|
expect(response.results[0].objectId.length).toEqual(10);
|
||||||
return rest.update(
|
return rest.update(
|
||||||
@@ -125,7 +125,7 @@ describe('rest create', () => {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
return rest.find(config, auth.nobody(config), 'Foo', { size: 10 });
|
return rest.find(config, auth.nobody(config), 'Foo', { size: 10 });
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then((response) => {
|
||||||
expect(response.results.length).toEqual(1);
|
expect(response.results.length).toEqual(1);
|
||||||
expect(response.results[0].objectId.length).toEqual(10);
|
expect(response.results[0].objectId.length).toEqual(10);
|
||||||
expect(response.results[0].update).toEqual(20);
|
expect(response.results[0].update).toEqual(20);
|
||||||
@@ -135,14 +135,14 @@ describe('rest create', () => {
|
|||||||
config.objectIdSize = 10;
|
config.objectIdSize = 10;
|
||||||
return rest.find(config, auth.nobody(config), 'Foo', { size: 20 });
|
return rest.find(config, auth.nobody(config), 'Foo', { size: 20 });
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then((response) => {
|
||||||
expect(response.results.length).toEqual(1);
|
expect(response.results.length).toEqual(1);
|
||||||
expect(response.results[0].objectId.length).toEqual(20);
|
expect(response.results[0].objectId.length).toEqual(20);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles array, object, date', done => {
|
it('handles array, object, date', (done) => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const obj = {
|
const obj = {
|
||||||
array: [1, 2, 3],
|
array: [1, 2, 3],
|
||||||
@@ -165,7 +165,7 @@ describe('rest create', () => {
|
|||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.then(results => {
|
.then((results) => {
|
||||||
expect(results.length).toEqual(1);
|
expect(results.length).toEqual(1);
|
||||||
const mob = results[0];
|
const mob = results[0];
|
||||||
expect(mob.array instanceof Array).toBe(true);
|
expect(mob.array instanceof Array).toBe(true);
|
||||||
@@ -176,17 +176,17 @@ describe('rest create', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles object and subdocument', done => {
|
it('handles object and subdocument', (done) => {
|
||||||
const obj = { subdoc: { foo: 'bar', wu: 'tan' } };
|
const obj = { subdoc: { foo: 'bar', wu: 'tan' } };
|
||||||
|
|
||||||
Parse.Cloud.beforeSave('MyClass', function() {
|
Parse.Cloud.beforeSave('MyClass', function () {
|
||||||
// this beforeSave trigger should do nothing but can mess with the object
|
// this beforeSave trigger should do nothing but can mess with the object
|
||||||
});
|
});
|
||||||
|
|
||||||
rest
|
rest
|
||||||
.create(config, auth.nobody(config), 'MyClass', obj)
|
.create(config, auth.nobody(config), 'MyClass', obj)
|
||||||
.then(() => database.adapter.find('MyClass', { fields: {} }, {}, {}))
|
.then(() => database.adapter.find('MyClass', { fields: {} }, {}, {}))
|
||||||
.then(results => {
|
.then((results) => {
|
||||||
expect(results.length).toEqual(1);
|
expect(results.length).toEqual(1);
|
||||||
const mob = results[0];
|
const mob = results[0];
|
||||||
expect(typeof mob.subdoc).toBe('object');
|
expect(typeof mob.subdoc).toBe('object');
|
||||||
@@ -203,7 +203,7 @@ describe('rest create', () => {
|
|||||||
);
|
);
|
||||||
})
|
})
|
||||||
.then(() => database.adapter.find('MyClass', { fields: {} }, {}, {}))
|
.then(() => database.adapter.find('MyClass', { fields: {} }, {}, {}))
|
||||||
.then(results => {
|
.then((results) => {
|
||||||
expect(results.length).toEqual(1);
|
expect(results.length).toEqual(1);
|
||||||
const mob = results[0];
|
const mob = results[0];
|
||||||
expect(typeof mob.subdoc).toBe('object');
|
expect(typeof mob.subdoc).toBe('object');
|
||||||
@@ -214,7 +214,7 @@ describe('rest create', () => {
|
|||||||
.catch(done.fail);
|
.catch(done.fail);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles create on non-existent class when disabled client class creation', done => {
|
it('handles create on non-existent class when disabled client class creation', (done) => {
|
||||||
const customConfig = Object.assign({}, config, {
|
const customConfig = Object.assign({}, config, {
|
||||||
allowClientClassCreation: false,
|
allowClientClassCreation: false,
|
||||||
});
|
});
|
||||||
@@ -230,7 +230,7 @@ describe('rest create', () => {
|
|||||||
fail('Should throw an error');
|
fail('Should throw an error');
|
||||||
done();
|
done();
|
||||||
},
|
},
|
||||||
err => {
|
(err) => {
|
||||||
expect(err.code).toEqual(Parse.Error.OPERATION_FORBIDDEN);
|
expect(err.code).toEqual(Parse.Error.OPERATION_FORBIDDEN);
|
||||||
expect(err.message).toEqual(
|
expect(err.message).toEqual(
|
||||||
'This user is not allowed to access ' +
|
'This user is not allowed to access ' +
|
||||||
@@ -262,13 +262,13 @@ describe('rest create', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles user signup', done => {
|
it('handles user signup', (done) => {
|
||||||
const user = {
|
const user = {
|
||||||
username: 'asdf',
|
username: 'asdf',
|
||||||
password: 'zxcv',
|
password: 'zxcv',
|
||||||
foo: 'bar',
|
foo: 'bar',
|
||||||
};
|
};
|
||||||
rest.create(config, auth.nobody(config), '_User', user).then(r => {
|
rest.create(config, auth.nobody(config), '_User', user).then((r) => {
|
||||||
expect(Object.keys(r.response).length).toEqual(3);
|
expect(Object.keys(r.response).length).toEqual(3);
|
||||||
expect(typeof r.response.objectId).toEqual('string');
|
expect(typeof r.response.objectId).toEqual('string');
|
||||||
expect(typeof r.response.createdAt).toEqual('string');
|
expect(typeof r.response.createdAt).toEqual('string');
|
||||||
@@ -277,7 +277,7 @@ describe('rest create', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles anonymous user signup', done => {
|
it('handles anonymous user signup', (done) => {
|
||||||
const data1 = {
|
const data1 = {
|
||||||
authData: {
|
authData: {
|
||||||
anonymous: {
|
anonymous: {
|
||||||
@@ -295,14 +295,14 @@ describe('rest create', () => {
|
|||||||
let username1;
|
let username1;
|
||||||
rest
|
rest
|
||||||
.create(config, auth.nobody(config), '_User', data1)
|
.create(config, auth.nobody(config), '_User', data1)
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
expect(typeof r.response.objectId).toEqual('string');
|
expect(typeof r.response.objectId).toEqual('string');
|
||||||
expect(typeof r.response.createdAt).toEqual('string');
|
expect(typeof r.response.createdAt).toEqual('string');
|
||||||
expect(typeof r.response.sessionToken).toEqual('string');
|
expect(typeof r.response.sessionToken).toEqual('string');
|
||||||
expect(typeof r.response.username).toEqual('string');
|
expect(typeof r.response.username).toEqual('string');
|
||||||
return rest.create(config, auth.nobody(config), '_User', data1);
|
return rest.create(config, auth.nobody(config), '_User', data1);
|
||||||
})
|
})
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
expect(typeof r.response.objectId).toEqual('string');
|
expect(typeof r.response.objectId).toEqual('string');
|
||||||
expect(typeof r.response.createdAt).toEqual('string');
|
expect(typeof r.response.createdAt).toEqual('string');
|
||||||
expect(typeof r.response.username).toEqual('string');
|
expect(typeof r.response.username).toEqual('string');
|
||||||
@@ -310,13 +310,13 @@ describe('rest create', () => {
|
|||||||
username1 = r.response.username;
|
username1 = r.response.username;
|
||||||
return rest.create(config, auth.nobody(config), '_User', data2);
|
return rest.create(config, auth.nobody(config), '_User', data2);
|
||||||
})
|
})
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
expect(typeof r.response.objectId).toEqual('string');
|
expect(typeof r.response.objectId).toEqual('string');
|
||||||
expect(typeof r.response.createdAt).toEqual('string');
|
expect(typeof r.response.createdAt).toEqual('string');
|
||||||
expect(typeof r.response.sessionToken).toEqual('string');
|
expect(typeof r.response.sessionToken).toEqual('string');
|
||||||
return rest.create(config, auth.nobody(config), '_User', data2);
|
return rest.create(config, auth.nobody(config), '_User', data2);
|
||||||
})
|
})
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
expect(typeof r.response.objectId).toEqual('string');
|
expect(typeof r.response.objectId).toEqual('string');
|
||||||
expect(typeof r.response.createdAt).toEqual('string');
|
expect(typeof r.response.createdAt).toEqual('string');
|
||||||
expect(typeof r.response.username).toEqual('string');
|
expect(typeof r.response.username).toEqual('string');
|
||||||
@@ -326,7 +326,7 @@ describe('rest create', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles anonymous user signup and upgrade to new user', done => {
|
it('handles anonymous user signup and upgrade to new user', (done) => {
|
||||||
const data1 = {
|
const data1 = {
|
||||||
authData: {
|
authData: {
|
||||||
anonymous: {
|
anonymous: {
|
||||||
@@ -343,7 +343,7 @@ describe('rest create', () => {
|
|||||||
let objectId;
|
let objectId;
|
||||||
rest
|
rest
|
||||||
.create(config, auth.nobody(config), '_User', data1)
|
.create(config, auth.nobody(config), '_User', data1)
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
expect(typeof r.response.objectId).toEqual('string');
|
expect(typeof r.response.objectId).toEqual('string');
|
||||||
expect(typeof r.response.createdAt).toEqual('string');
|
expect(typeof r.response.createdAt).toEqual('string');
|
||||||
expect(typeof r.response.sessionToken).toEqual('string');
|
expect(typeof r.response.sessionToken).toEqual('string');
|
||||||
@@ -353,7 +353,7 @@ describe('rest create', () => {
|
|||||||
sessionToken: r.response.sessionToken,
|
sessionToken: r.response.sessionToken,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(sessionAuth => {
|
.then((sessionAuth) => {
|
||||||
return rest.update(
|
return rest.update(
|
||||||
config,
|
config,
|
||||||
sessionAuth,
|
sessionAuth,
|
||||||
@@ -367,18 +367,18 @@ describe('rest create', () => {
|
|||||||
return Parse.User.logIn('hello', 'world');
|
return Parse.User.logIn('hello', 'world');
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
expect(r.id).toEqual(objectId);
|
expect(r.id).toEqual(objectId);
|
||||||
expect(r.get('username')).toEqual('hello');
|
expect(r.get('username')).toEqual('hello');
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
jfail(err);
|
jfail(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles no anonymous users config', done => {
|
it('handles no anonymous users config', (done) => {
|
||||||
const NoAnnonConfig = Object.assign({}, config);
|
const NoAnnonConfig = Object.assign({}, config);
|
||||||
NoAnnonConfig.authDataManager.setEnableAnonymousUsers(false);
|
NoAnnonConfig.authDataManager.setEnableAnonymousUsers(false);
|
||||||
const data1 = {
|
const data1 = {
|
||||||
@@ -393,7 +393,7 @@ describe('rest create', () => {
|
|||||||
fail('Should throw an error');
|
fail('Should throw an error');
|
||||||
done();
|
done();
|
||||||
},
|
},
|
||||||
err => {
|
(err) => {
|
||||||
expect(err.code).toEqual(Parse.Error.UNSUPPORTED_SERVICE);
|
expect(err.code).toEqual(Parse.Error.UNSUPPORTED_SERVICE);
|
||||||
expect(err.message).toEqual(
|
expect(err.message).toEqual(
|
||||||
'This authentication method is unsupported.'
|
'This authentication method is unsupported.'
|
||||||
@@ -404,7 +404,7 @@ describe('rest create', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('test facebook signup and login', done => {
|
it('test facebook signup and login', (done) => {
|
||||||
const data = {
|
const data = {
|
||||||
authData: {
|
authData: {
|
||||||
facebook: {
|
facebook: {
|
||||||
@@ -416,14 +416,14 @@ describe('rest create', () => {
|
|||||||
let newUserSignedUpByFacebookObjectId;
|
let newUserSignedUpByFacebookObjectId;
|
||||||
rest
|
rest
|
||||||
.create(config, auth.nobody(config), '_User', data)
|
.create(config, auth.nobody(config), '_User', data)
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
expect(typeof r.response.objectId).toEqual('string');
|
expect(typeof r.response.objectId).toEqual('string');
|
||||||
expect(typeof r.response.createdAt).toEqual('string');
|
expect(typeof r.response.createdAt).toEqual('string');
|
||||||
expect(typeof r.response.sessionToken).toEqual('string');
|
expect(typeof r.response.sessionToken).toEqual('string');
|
||||||
newUserSignedUpByFacebookObjectId = r.response.objectId;
|
newUserSignedUpByFacebookObjectId = r.response.objectId;
|
||||||
return rest.create(config, auth.nobody(config), '_User', data);
|
return rest.create(config, auth.nobody(config), '_User', data);
|
||||||
})
|
})
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
expect(typeof r.response.objectId).toEqual('string');
|
expect(typeof r.response.objectId).toEqual('string');
|
||||||
expect(typeof r.response.createdAt).toEqual('string');
|
expect(typeof r.response.createdAt).toEqual('string');
|
||||||
expect(typeof r.response.username).toEqual('string');
|
expect(typeof r.response.username).toEqual('string');
|
||||||
@@ -433,19 +433,19 @@ describe('rest create', () => {
|
|||||||
sessionToken: r.response.sessionToken,
|
sessionToken: r.response.sessionToken,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then((response) => {
|
||||||
expect(response.results.length).toEqual(1);
|
expect(response.results.length).toEqual(1);
|
||||||
const output = response.results[0];
|
const output = response.results[0];
|
||||||
expect(output.user.objectId).toEqual(newUserSignedUpByFacebookObjectId);
|
expect(output.user.objectId).toEqual(newUserSignedUpByFacebookObjectId);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
jfail(err);
|
jfail(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('stores pointers', done => {
|
it('stores pointers', (done) => {
|
||||||
const obj = {
|
const obj = {
|
||||||
foo: 'bar',
|
foo: 'bar',
|
||||||
aPointer: {
|
aPointer: {
|
||||||
@@ -469,7 +469,7 @@ describe('rest create', () => {
|
|||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.then(results => {
|
.then((results) => {
|
||||||
expect(results.length).toEqual(1);
|
expect(results.length).toEqual(1);
|
||||||
const output = results[0];
|
const output = results[0];
|
||||||
expect(typeof output.foo).toEqual('string');
|
expect(typeof output.foo).toEqual('string');
|
||||||
@@ -484,7 +484,46 @@ describe('rest create', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cannot set objectId', done => {
|
it('stores pointers to objectIds larger than 10 characters', (done) => {
|
||||||
|
const obj = {
|
||||||
|
foo: 'bar',
|
||||||
|
aPointer: {
|
||||||
|
__type: 'Pointer',
|
||||||
|
className: 'JustThePointer',
|
||||||
|
objectId: '49F62F92-9B56-46E7-A3D4-BBD14C52F666',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
rest
|
||||||
|
.create(config, auth.nobody(config), 'APointerDarkly', obj)
|
||||||
|
.then(() =>
|
||||||
|
database.adapter.find(
|
||||||
|
'APointerDarkly',
|
||||||
|
{
|
||||||
|
fields: {
|
||||||
|
foo: { type: 'String' },
|
||||||
|
aPointer: { type: 'Pointer', targetClass: 'JustThePointer' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{},
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.then((results) => {
|
||||||
|
expect(results.length).toEqual(1);
|
||||||
|
const output = results[0];
|
||||||
|
expect(typeof output.foo).toEqual('string');
|
||||||
|
expect(typeof output._p_aPointer).toEqual('undefined');
|
||||||
|
expect(output._p_aPointer).toBeUndefined();
|
||||||
|
expect(output.aPointer).toEqual({
|
||||||
|
__type: 'Pointer',
|
||||||
|
className: 'JustThePointer',
|
||||||
|
objectId: '49F62F92-9B56-46E7-A3D4-BBD14C52F666',
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('cannot set objectId', (done) => {
|
||||||
const headers = {
|
const headers = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-Parse-Application-Id': 'test',
|
'X-Parse-Application-Id': 'test',
|
||||||
@@ -498,7 +537,7 @@ describe('rest create', () => {
|
|||||||
foo: 'bar',
|
foo: 'bar',
|
||||||
objectId: 'hello',
|
objectId: 'hello',
|
||||||
}),
|
}),
|
||||||
}).then(fail, response => {
|
}).then(fail, (response) => {
|
||||||
const b = response.data;
|
const b = response.data;
|
||||||
expect(b.code).toEqual(105);
|
expect(b.code).toEqual(105);
|
||||||
expect(b.error).toEqual('objectId is an invalid field name.');
|
expect(b.error).toEqual('objectId is an invalid field name.');
|
||||||
@@ -506,7 +545,7 @@ describe('rest create', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cannot set id', done => {
|
it('cannot set id', (done) => {
|
||||||
const headers = {
|
const headers = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-Parse-Application-Id': 'test',
|
'X-Parse-Application-Id': 'test',
|
||||||
@@ -520,7 +559,7 @@ describe('rest create', () => {
|
|||||||
foo: 'bar',
|
foo: 'bar',
|
||||||
id: 'hello',
|
id: 'hello',
|
||||||
}),
|
}),
|
||||||
}).then(fail, response => {
|
}).then(fail, (response) => {
|
||||||
const b = response.data;
|
const b = response.data;
|
||||||
expect(b.code).toEqual(105);
|
expect(b.code).toEqual(105);
|
||||||
expect(b.error).toEqual('id is an invalid field name.');
|
expect(b.error).toEqual('id is an invalid field name.');
|
||||||
@@ -528,7 +567,7 @@ describe('rest create', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('test default session length', done => {
|
it('test default session length', (done) => {
|
||||||
const user = {
|
const user = {
|
||||||
username: 'asdf',
|
username: 'asdf',
|
||||||
password: 'zxcv',
|
password: 'zxcv',
|
||||||
@@ -538,7 +577,7 @@ describe('rest create', () => {
|
|||||||
|
|
||||||
rest
|
rest
|
||||||
.create(config, auth.nobody(config), '_User', user)
|
.create(config, auth.nobody(config), '_User', user)
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
expect(Object.keys(r.response).length).toEqual(3);
|
expect(Object.keys(r.response).length).toEqual(3);
|
||||||
expect(typeof r.response.objectId).toEqual('string');
|
expect(typeof r.response.objectId).toEqual('string');
|
||||||
expect(typeof r.response.createdAt).toEqual('string');
|
expect(typeof r.response.createdAt).toEqual('string');
|
||||||
@@ -547,7 +586,7 @@ describe('rest create', () => {
|
|||||||
sessionToken: r.response.sessionToken,
|
sessionToken: r.response.sessionToken,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
expect(r.results.length).toEqual(1);
|
expect(r.results.length).toEqual(1);
|
||||||
|
|
||||||
const session = r.results[0];
|
const session = r.results[0];
|
||||||
@@ -564,7 +603,7 @@ describe('rest create', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('test specified session length', done => {
|
it('test specified session length', (done) => {
|
||||||
const user = {
|
const user = {
|
||||||
username: 'asdf',
|
username: 'asdf',
|
||||||
password: 'zxcv',
|
password: 'zxcv',
|
||||||
@@ -576,7 +615,7 @@ describe('rest create', () => {
|
|||||||
|
|
||||||
rest
|
rest
|
||||||
.create(config, auth.nobody(config), '_User', user)
|
.create(config, auth.nobody(config), '_User', user)
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
expect(Object.keys(r.response).length).toEqual(3);
|
expect(Object.keys(r.response).length).toEqual(3);
|
||||||
expect(typeof r.response.objectId).toEqual('string');
|
expect(typeof r.response.objectId).toEqual('string');
|
||||||
expect(typeof r.response.createdAt).toEqual('string');
|
expect(typeof r.response.createdAt).toEqual('string');
|
||||||
@@ -585,7 +624,7 @@ describe('rest create', () => {
|
|||||||
sessionToken: r.response.sessionToken,
|
sessionToken: r.response.sessionToken,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
expect(r.results.length).toEqual(1);
|
expect(r.results.length).toEqual(1);
|
||||||
|
|
||||||
const session = r.results[0];
|
const session = r.results[0];
|
||||||
@@ -600,13 +639,13 @@ describe('rest create', () => {
|
|||||||
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
jfail(err);
|
jfail(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can create a session with no expiration', done => {
|
it('can create a session with no expiration', (done) => {
|
||||||
const user = {
|
const user = {
|
||||||
username: 'asdf',
|
username: 'asdf',
|
||||||
password: 'zxcv',
|
password: 'zxcv',
|
||||||
@@ -616,7 +655,7 @@ describe('rest create', () => {
|
|||||||
|
|
||||||
rest
|
rest
|
||||||
.create(config, auth.nobody(config), '_User', user)
|
.create(config, auth.nobody(config), '_User', user)
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
expect(Object.keys(r.response).length).toEqual(3);
|
expect(Object.keys(r.response).length).toEqual(3);
|
||||||
expect(typeof r.response.objectId).toEqual('string');
|
expect(typeof r.response.objectId).toEqual('string');
|
||||||
expect(typeof r.response.createdAt).toEqual('string');
|
expect(typeof r.response.createdAt).toEqual('string');
|
||||||
@@ -625,7 +664,7 @@ describe('rest create', () => {
|
|||||||
sessionToken: r.response.sessionToken,
|
sessionToken: r.response.sessionToken,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
expect(r.results.length).toEqual(1);
|
expect(r.results.length).toEqual(1);
|
||||||
|
|
||||||
const session = r.results[0];
|
const session = r.results[0];
|
||||||
@@ -633,42 +672,42 @@ describe('rest create', () => {
|
|||||||
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
fail(err);
|
fail(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can create object in volatileClasses if masterKey', done => {
|
it('can create object in volatileClasses if masterKey', (done) => {
|
||||||
rest
|
rest
|
||||||
.create(config, auth.master(config), '_PushStatus', {})
|
.create(config, auth.master(config), '_PushStatus', {})
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
expect(r.response.objectId.length).toBe(10);
|
expect(r.response.objectId.length).toBe(10);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
rest.create(config, auth.master(config), '_JobStatus', {}).then(r => {
|
rest.create(config, auth.master(config), '_JobStatus', {}).then((r) => {
|
||||||
expect(r.response.objectId.length).toBe(10);
|
expect(r.response.objectId.length).toBe(10);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cannot create object in volatileClasses if not masterKey', done => {
|
it('cannot create object in volatileClasses if not masterKey', (done) => {
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return rest.create(config, auth.nobody(config), '_PushStatus', {});
|
return rest.create(config, auth.nobody(config), '_PushStatus', {});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch((error) => {
|
||||||
expect(error.code).toEqual(119);
|
expect(error.code).toEqual(119);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('locks down session', done => {
|
it('locks down session', (done) => {
|
||||||
let currentUser;
|
let currentUser;
|
||||||
Parse.User.signUp('foo', 'bar')
|
Parse.User.signUp('foo', 'bar')
|
||||||
.then(user => {
|
.then((user) => {
|
||||||
currentUser = user;
|
currentUser = user;
|
||||||
const sessionToken = user.getSessionToken();
|
const sessionToken = user.getSessionToken();
|
||||||
const headers = {
|
const headers = {
|
||||||
@@ -682,7 +721,7 @@ describe('rest create', () => {
|
|||||||
headers: headers,
|
headers: headers,
|
||||||
url: 'http://localhost:8378/1/sessions/me',
|
url: 'http://localhost:8378/1/sessions/me',
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then((response) => {
|
||||||
sessionId = response.data.objectId;
|
sessionId = response.data.objectId;
|
||||||
return request({
|
return request({
|
||||||
headers,
|
headers,
|
||||||
@@ -693,7 +732,7 @@ describe('rest create', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(done.fail, res => {
|
.then(done.fail, (res) => {
|
||||||
expect(res.status).toBe(400);
|
expect(res.status).toBe(400);
|
||||||
expect(res.data.code).toBe(105);
|
expect(res.data.code).toBe(105);
|
||||||
return request({
|
return request({
|
||||||
@@ -705,12 +744,12 @@ describe('rest create', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(done.fail, res => {
|
.then(done.fail, (res) => {
|
||||||
expect(res.status).toBe(400);
|
expect(res.status).toBe(400);
|
||||||
expect(res.data.code).toBe(105);
|
expect(res.data.code).toBe(105);
|
||||||
return Parse.User.signUp('other', 'user');
|
return Parse.User.signUp('other', 'user');
|
||||||
})
|
})
|
||||||
.then(otherUser => {
|
.then((otherUser) => {
|
||||||
const user = new Parse.User();
|
const user = new Parse.User();
|
||||||
user.id = otherUser.id;
|
user.id = otherUser.id;
|
||||||
return request({
|
return request({
|
||||||
@@ -722,7 +761,7 @@ describe('rest create', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(done.fail, res => {
|
.then(done.fail, (res) => {
|
||||||
expect(res.status).toBe(400);
|
expect(res.status).toBe(400);
|
||||||
expect(res.data.code).toBe(105);
|
expect(res.data.code).toBe(105);
|
||||||
const user = new Parse.User();
|
const user = new Parse.User();
|
||||||
@@ -742,10 +781,10 @@ describe('rest create', () => {
|
|||||||
.catch(done.fail);
|
.catch(done.fail);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets current user in new sessions', done => {
|
it('sets current user in new sessions', (done) => {
|
||||||
let currentUser;
|
let currentUser;
|
||||||
Parse.User.signUp('foo', 'bar')
|
Parse.User.signUp('foo', 'bar')
|
||||||
.then(user => {
|
.then((user) => {
|
||||||
currentUser = user;
|
currentUser = user;
|
||||||
const sessionToken = user.getSessionToken();
|
const sessionToken = user.getSessionToken();
|
||||||
const headers = {
|
const headers = {
|
||||||
@@ -763,7 +802,7 @@ describe('rest create', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then((response) => {
|
||||||
if (response.data.user.objectId === currentUser.id) {
|
if (response.data.user.objectId === currentUser.id) {
|
||||||
return done();
|
return done();
|
||||||
} else {
|
} else {
|
||||||
@@ -775,7 +814,7 @@ describe('rest create', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('rest update', () => {
|
describe('rest update', () => {
|
||||||
it('ignores createdAt', done => {
|
it('ignores createdAt', (done) => {
|
||||||
const config = Config.get('test');
|
const config = Config.get('test');
|
||||||
const nobody = auth.nobody(config);
|
const nobody = auth.nobody(config);
|
||||||
const className = 'Foo';
|
const className = 'Foo';
|
||||||
@@ -783,7 +822,7 @@ describe('rest update', () => {
|
|||||||
|
|
||||||
rest
|
rest
|
||||||
.create(config, nobody, className, {})
|
.create(config, nobody, className, {})
|
||||||
.then(res => {
|
.then((res) => {
|
||||||
const objectId = res.response.objectId;
|
const objectId = res.response.objectId;
|
||||||
const restObject = {
|
const restObject = {
|
||||||
createdAt: { __type: 'Date', iso: newCreatedAt }, // should be ignored
|
createdAt: { __type: 'Date', iso: newCreatedAt }, // should be ignored
|
||||||
@@ -798,7 +837,7 @@ describe('rest update', () => {
|
|||||||
return rest.find(config, nobody, className, restWhere, {});
|
return rest.find(config, nobody, className, restWhere, {});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(res2 => {
|
.then((res2) => {
|
||||||
const updatedObject = res2.results[0];
|
const updatedObject = res2.results[0];
|
||||||
expect(new Date(updatedObject.createdAt)).not.toEqual(newCreatedAt);
|
expect(new Date(updatedObject.createdAt)).not.toEqual(newCreatedAt);
|
||||||
done();
|
done();
|
||||||
@@ -828,7 +867,7 @@ describe('read-only masterKey', () => {
|
|||||||
}).toThrow();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('properly blocks writes', done => {
|
it('properly blocks writes', (done) => {
|
||||||
reconfigureServer({
|
reconfigureServer({
|
||||||
readOnlyMasterKey: 'yolo-read-only',
|
readOnlyMasterKey: 'yolo-read-only',
|
||||||
})
|
})
|
||||||
@@ -845,7 +884,7 @@ describe('read-only masterKey', () => {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(done.fail)
|
.then(done.fail)
|
||||||
.catch(res => {
|
.catch((res) => {
|
||||||
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||||
expect(res.data.error).toBe(
|
expect(res.data.error).toBe(
|
||||||
"read-only masterKey isn't allowed to perform the create operation."
|
"read-only masterKey isn't allowed to perform the create operation."
|
||||||
@@ -854,13 +893,13 @@ describe('read-only masterKey', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when masterKey and readOnlyMasterKey are the same', done => {
|
it('should throw when masterKey and readOnlyMasterKey are the same', (done) => {
|
||||||
reconfigureServer({
|
reconfigureServer({
|
||||||
masterKey: 'yolo',
|
masterKey: 'yolo',
|
||||||
readOnlyMasterKey: 'yolo',
|
readOnlyMasterKey: 'yolo',
|
||||||
})
|
})
|
||||||
.then(done.fail)
|
.then(done.fail)
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
expect(err).toEqual(
|
expect(err).toEqual(
|
||||||
new Error('masterKey and readOnlyMasterKey should be different')
|
new Error('masterKey and readOnlyMasterKey should be different')
|
||||||
);
|
);
|
||||||
@@ -880,7 +919,7 @@ describe('read-only masterKey', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when trying to create schema', done => {
|
it('should throw when trying to create schema', (done) => {
|
||||||
return request({
|
return request({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: `${Parse.serverURL}/schemas`,
|
url: `${Parse.serverURL}/schemas`,
|
||||||
@@ -892,7 +931,7 @@ describe('read-only masterKey', () => {
|
|||||||
json: {},
|
json: {},
|
||||||
})
|
})
|
||||||
.then(done.fail)
|
.then(done.fail)
|
||||||
.catch(res => {
|
.catch((res) => {
|
||||||
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||||
expect(res.data.error).toBe(
|
expect(res.data.error).toBe(
|
||||||
"read-only masterKey isn't allowed to create a schema."
|
"read-only masterKey isn't allowed to create a schema."
|
||||||
@@ -901,7 +940,7 @@ describe('read-only masterKey', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when trying to create schema with a name', done => {
|
it('should throw when trying to create schema with a name', (done) => {
|
||||||
return request({
|
return request({
|
||||||
url: `${Parse.serverURL}/schemas/MyClass`,
|
url: `${Parse.serverURL}/schemas/MyClass`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -913,7 +952,7 @@ describe('read-only masterKey', () => {
|
|||||||
json: {},
|
json: {},
|
||||||
})
|
})
|
||||||
.then(done.fail)
|
.then(done.fail)
|
||||||
.catch(res => {
|
.catch((res) => {
|
||||||
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||||
expect(res.data.error).toBe(
|
expect(res.data.error).toBe(
|
||||||
"read-only masterKey isn't allowed to create a schema."
|
"read-only masterKey isn't allowed to create a schema."
|
||||||
@@ -922,7 +961,7 @@ describe('read-only masterKey', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when trying to update schema', done => {
|
it('should throw when trying to update schema', (done) => {
|
||||||
return request({
|
return request({
|
||||||
url: `${Parse.serverURL}/schemas/MyClass`,
|
url: `${Parse.serverURL}/schemas/MyClass`,
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
@@ -934,7 +973,7 @@ describe('read-only masterKey', () => {
|
|||||||
json: {},
|
json: {},
|
||||||
})
|
})
|
||||||
.then(done.fail)
|
.then(done.fail)
|
||||||
.catch(res => {
|
.catch((res) => {
|
||||||
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||||
expect(res.data.error).toBe(
|
expect(res.data.error).toBe(
|
||||||
"read-only masterKey isn't allowed to update a schema."
|
"read-only masterKey isn't allowed to update a schema."
|
||||||
@@ -943,7 +982,7 @@ describe('read-only masterKey', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when trying to delete schema', done => {
|
it('should throw when trying to delete schema', (done) => {
|
||||||
return request({
|
return request({
|
||||||
url: `${Parse.serverURL}/schemas/MyClass`,
|
url: `${Parse.serverURL}/schemas/MyClass`,
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
@@ -955,7 +994,7 @@ describe('read-only masterKey', () => {
|
|||||||
json: {},
|
json: {},
|
||||||
})
|
})
|
||||||
.then(done.fail)
|
.then(done.fail)
|
||||||
.catch(res => {
|
.catch((res) => {
|
||||||
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||||
expect(res.data.error).toBe(
|
expect(res.data.error).toBe(
|
||||||
"read-only masterKey isn't allowed to delete a schema."
|
"read-only masterKey isn't allowed to delete a schema."
|
||||||
@@ -964,7 +1003,7 @@ describe('read-only masterKey', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when trying to update the global config', done => {
|
it('should throw when trying to update the global config', (done) => {
|
||||||
return request({
|
return request({
|
||||||
url: `${Parse.serverURL}/config`,
|
url: `${Parse.serverURL}/config`,
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
@@ -976,7 +1015,7 @@ describe('read-only masterKey', () => {
|
|||||||
json: {},
|
json: {},
|
||||||
})
|
})
|
||||||
.then(done.fail)
|
.then(done.fail)
|
||||||
.catch(res => {
|
.catch((res) => {
|
||||||
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||||
expect(res.data.error).toBe(
|
expect(res.data.error).toBe(
|
||||||
"read-only masterKey isn't allowed to update the config."
|
"read-only masterKey isn't allowed to update the config."
|
||||||
@@ -985,7 +1024,7 @@ describe('read-only masterKey', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when trying to send push', done => {
|
it('should throw when trying to send push', (done) => {
|
||||||
return request({
|
return request({
|
||||||
url: `${Parse.serverURL}/push`,
|
url: `${Parse.serverURL}/push`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -997,7 +1036,7 @@ describe('read-only masterKey', () => {
|
|||||||
json: {},
|
json: {},
|
||||||
})
|
})
|
||||||
.then(done.fail)
|
.then(done.fail)
|
||||||
.catch(res => {
|
.catch((res) => {
|
||||||
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||||
expect(res.data.error).toBe(
|
expect(res.data.error).toBe(
|
||||||
"read-only masterKey isn't allowed to send push notifications."
|
"read-only masterKey isn't allowed to send push notifications."
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const parseTypeToPostgresType = (type) => {
|
|||||||
case 'Boolean':
|
case 'Boolean':
|
||||||
return 'boolean';
|
return 'boolean';
|
||||||
case 'Pointer':
|
case 'Pointer':
|
||||||
return 'char(10)';
|
return 'text';
|
||||||
case 'Number':
|
case 'Number':
|
||||||
return 'double precision';
|
return 'double precision';
|
||||||
case 'GeoPoint':
|
case 'GeoPoint':
|
||||||
|
|||||||
Reference in New Issue
Block a user