Skip to content

Commit 2d257e2

Browse files
BufferUnderflowerdavimacedo
authored andcommitted
CLP objectId size validation fix (#6332)
* Relax regex for customId ; allow varying id length * test * remove trycatch, fix typo * de-duplicate test names; test pointer targetclass * fixed early return; detailed errors for protected
1 parent 9842c6e commit 2d257e2

File tree

4 files changed

+221
-84
lines changed

4 files changed

+221
-84
lines changed

spec/PointerPermissions.spec.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ describe('Pointer Permissions', () => {
399399
});
400400
});
401401

402-
it('should prevent creating pointer permission on bad field', done => {
402+
it('should prevent creating pointer permission on bad field (of wrong type)', done => {
403403
const config = Config.get(Parse.applicationId);
404404
config.database
405405
.loadSchema()
@@ -426,7 +426,34 @@ describe('Pointer Permissions', () => {
426426
});
427427
});
428428

429-
it('should prevent creating pointer permission on bad field', done => {
429+
it('should prevent creating pointer permission on bad field (non-user pointer)', done => {
430+
const config = Config.get(Parse.applicationId);
431+
config.database
432+
.loadSchema()
433+
.then(schema => {
434+
return schema.addClassIfNotExists(
435+
'AnObject',
436+
{ owner: { type: 'Pointer', targetClass: '_Session' } },
437+
{
438+
create: {},
439+
writeUserFields: ['owner'],
440+
readUserFields: ['owner'],
441+
}
442+
);
443+
})
444+
.then(() => {
445+
fail('should not succeed');
446+
})
447+
.catch(err => {
448+
expect(err.code).toBe(107);
449+
expect(err.message).toBe(
450+
"'owner' is not a valid column for class level pointer permissions writeUserFields"
451+
);
452+
done();
453+
});
454+
});
455+
456+
it('should prevent creating pointer permission on bad field (non-existing)', done => {
430457
const config = Config.get(Parse.applicationId);
431458
const object = new Parse.Object('AnObject');
432459
object.set('owner', 'value');
@@ -984,7 +1011,7 @@ describe('Pointer Permissions', () => {
9841011
);
9851012
});
9861013

987-
it('should fail with invalid pointer perms', done => {
1014+
it('should fail with invalid pointer perms (not array)', done => {
9881015
const config = Config.get(Parse.applicationId);
9891016
config.database
9901017
.loadSchema()
@@ -1002,7 +1029,7 @@ describe('Pointer Permissions', () => {
10021029
});
10031030
});
10041031

1005-
it('should fail with invalid pointer perms', done => {
1032+
it('should fail with invalid pointer perms (non-existing field)', done => {
10061033
const config = Config.get(Parse.applicationId);
10071034
config.database
10081035
.loadSchema()
@@ -1398,7 +1425,7 @@ describe('Pointer Permissions', () => {
13981425
}
13991426
});
14001427

1401-
it('should prevent creating pointer permission on bad field', async done => {
1428+
it('should prevent creating pointer permission on bad field (of wrong type)', async done => {
14021429
const config = Config.get(Parse.applicationId);
14031430
const schema = await config.database.loadSchema();
14041431
try {
@@ -1421,7 +1448,7 @@ describe('Pointer Permissions', () => {
14211448
}
14221449
});
14231450

1424-
it('should prevent creating pointer permission on bad field', async done => {
1451+
it('should prevent creating pointer permission on bad field (non-existing)', async done => {
14251452
const config = Config.get(Parse.applicationId);
14261453
const object = new Parse.Object('AnObject');
14271454
object.set('owners', 'value');
@@ -1955,7 +1982,7 @@ describe('Pointer Permissions', () => {
19551982
}
19561983
});
19571984

1958-
it('should fail with invalid pointer perms', async done => {
1985+
it('should fail with invalid pointer perms (not array)', async done => {
19591986
const config = Config.get(Parse.applicationId);
19601987
const schema = await config.database.loadSchema();
19611988
try {
@@ -1971,7 +1998,7 @@ describe('Pointer Permissions', () => {
19711998
}
19721999
});
19732000

1974-
it('should fail with invalid pointer perms', async done => {
2001+
it('should fail with invalid pointer perms (non-existing field)', async done => {
19752002
const config = Config.get(Parse.applicationId);
19762003
const schema = await config.database.loadSchema();
19772004
try {

spec/Schema.spec.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ describe('Class Level Permissions for requiredAuth', () => {
16651665
);
16661666
});
16671667

1668-
it('required auth test create/get/update/delete not authenitcated', done => {
1668+
it('required auth test get not authenitcated', done => {
16691669
config.database
16701670
.loadSchema()
16711671
.then(schema => {
@@ -1677,12 +1677,6 @@ describe('Class Level Permissions for requiredAuth', () => {
16771677
get: {
16781678
requiresAuthentication: true,
16791679
},
1680-
delete: {
1681-
requiresAuthentication: true,
1682-
},
1683-
update: {
1684-
requiresAuthentication: true,
1685-
},
16861680
create: {
16871681
'*': true,
16881682
},
@@ -1710,7 +1704,7 @@ describe('Class Level Permissions for requiredAuth', () => {
17101704
);
17111705
});
17121706

1713-
it('required auth test create/get/update/delete not authenitcated', done => {
1707+
it('required auth test find not authenitcated', done => {
17141708
config.database
17151709
.loadSchema()
17161710
.then(schema => {
@@ -1722,12 +1716,6 @@ describe('Class Level Permissions for requiredAuth', () => {
17221716
find: {
17231717
requiresAuthentication: true,
17241718
},
1725-
delete: {
1726-
requiresAuthentication: true,
1727-
},
1728-
update: {
1729-
requiresAuthentication: true,
1730-
},
17311719
create: {
17321720
'*': true,
17331721
},

spec/schemas.spec.js

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,46 +1835,94 @@ describe('schemas', () => {
18351835
});
18361836
});
18371837

1838-
it('should throw with invalid userId (>10 chars)', done => {
1839-
request({
1838+
it('should aceept class-level permission with userid of any length', async done => {
1839+
await global.reconfigureServer({
1840+
customIdSize: 11,
1841+
});
1842+
1843+
const id = 'e1evenChars';
1844+
1845+
const { data } = await request({
18401846
method: 'POST',
18411847
url: 'http://localhost:8378/1/schemas/AClass',
18421848
headers: masterKeyHeaders,
18431849
json: true,
18441850
body: {
18451851
classLevelPermissions: {
18461852
find: {
1847-
'1234567890A': true,
1853+
[id]: true,
18481854
},
18491855
},
18501856
},
1851-
}).then(fail, response => {
1852-
expect(response.data.error).toEqual(
1853-
"'1234567890A' is not a valid key for class level permissions"
1854-
);
1855-
done();
18561857
});
1858+
1859+
expect(data.classLevelPermissions.find[id]).toBe(true);
1860+
1861+
done();
18571862
});
18581863

1859-
it('should throw with invalid userId (<10 chars)', done => {
1860-
request({
1864+
it('should allow set class-level permission for custom userid of any length and chars', async done => {
1865+
await global.reconfigureServer({
1866+
allowCustomObjectId: true,
1867+
});
1868+
1869+
const symbolsId = 'set:ID+symbol$=@llowed';
1870+
const shortId = '1';
1871+
const { data } = await request({
18611872
method: 'POST',
18621873
url: 'http://localhost:8378/1/schemas/AClass',
18631874
headers: masterKeyHeaders,
18641875
json: true,
18651876
body: {
18661877
classLevelPermissions: {
18671878
find: {
1868-
a12345678: true,
1879+
[symbolsId]: true,
1880+
[shortId]: true,
18691881
},
18701882
},
18711883
},
1872-
}).then(fail, response => {
1873-
expect(response.data.error).toEqual(
1874-
"'a12345678' is not a valid key for class level permissions"
1875-
);
1876-
done();
18771884
});
1885+
1886+
expect(data.classLevelPermissions.find[symbolsId]).toBe(true);
1887+
expect(data.classLevelPermissions.find[shortId]).toBe(true);
1888+
1889+
done();
1890+
});
1891+
1892+
it('should allow set ACL for custom userid', async done => {
1893+
await global.reconfigureServer({
1894+
allowCustomObjectId: true,
1895+
});
1896+
1897+
const symbolsId = 'symbols:id@allowed=';
1898+
const shortId = '1';
1899+
const normalId = 'tensymbols';
1900+
1901+
const { data } = await request({
1902+
method: 'POST',
1903+
url: 'http://localhost:8378/1/classes/AClass',
1904+
headers: masterKeyHeaders,
1905+
json: true,
1906+
body: {
1907+
ACL: {
1908+
[symbolsId]: { read: true, write: true },
1909+
[shortId]: { read: true, write: true },
1910+
[normalId]: { read: true, write: true },
1911+
},
1912+
},
1913+
});
1914+
1915+
const { data: created } = await request({
1916+
method: 'GET',
1917+
url: `http://localhost:8378/1/classes/AClass/${data.objectId}`,
1918+
headers: masterKeyHeaders,
1919+
json: true,
1920+
});
1921+
1922+
expect(created.ACL[normalId].write).toBe(true);
1923+
expect(created.ACL[symbolsId].write).toBe(true);
1924+
expect(created.ACL[shortId].write).toBe(true);
1925+
done();
18781926
});
18791927

18801928
it('should throw with invalid userId (invalid char)', done => {

0 commit comments

Comments
 (0)