Skip to content

bugfix: run tests with directAccess #9690

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

Open
wants to merge 4 commits into
base: alpha
Choose a base branch
from
Open
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
91 changes: 43 additions & 48 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2006,13 +2006,14 @@ describe('Cloud Code', () => {
});

describe('cloud functions', () => {
it('Should have request ip', done => {
it('Should have request ip', async () => {
await reconfigureServer({directAccess: false});
Parse.Cloud.define('myFunction', req => {
expect(req.ip).toBeDefined();
return 'success';
});

Parse.Cloud.run('myFunction', {}).then(() => done());
await Parse.Cloud.run('myFunction', {});
});
});

Expand All @@ -2027,14 +2028,15 @@ describe('beforeSave hooks', () => {
myObject.save().then(() => done());
});

it('should have request ip', done => {
it('should have request ip', async () => {
await reconfigureServer({directAccess: false});
Parse.Cloud.beforeSave('MyObject', req => {
expect(req.ip).toBeDefined();
});

const MyObject = Parse.Object.extend('MyObject');
const myObject = new MyObject();
myObject.save().then(() => done());
await myObject.save()
});

it('should respect custom object ids (#6733)', async () => {
Expand Down Expand Up @@ -2082,14 +2084,15 @@ describe('afterSave hooks', () => {
myObject.save().then(() => done());
});

it('should have request ip', done => {
it('should have request ip', async () => {
await reconfigureServer({directAccess: false});
Parse.Cloud.afterSave('MyObject', req => {
expect(req.ip).toBeDefined();
});

const MyObject = Parse.Object.extend('MyObject');
const myObject = new MyObject();
myObject.save().then(() => done());
await myObject.save();
});

it('should unset in afterSave', async () => {
Expand Down Expand Up @@ -2137,17 +2140,16 @@ describe('beforeDelete hooks', () => {
.then(() => done());
});

it('should have request ip', done => {
it('should have request ip', async () => {
await reconfigureServer({directAccess: false});
Parse.Cloud.beforeDelete('MyObject', req => {
expect(req.ip).toBeDefined();
});

const MyObject = Parse.Object.extend('MyObject');
const myObject = new MyObject();
myObject
.save()
.then(myObj => myObj.destroy())
.then(() => done());
await myObject.save()
await myObject.destroy();
});
});

Expand All @@ -2165,17 +2167,17 @@ describe('afterDelete hooks', () => {
.then(() => done());
});

it('should have request ip', done => {
it('should have request ip', async () => {
await reconfigureServer({directAccess: false});
Parse.Cloud.afterDelete('MyObject', req => {
expect(req.ip).toBeDefined();
});

const MyObject = Parse.Object.extend('MyObject');
const myObject = new MyObject();
myObject
.save()
.then(myObj => myObj.destroy())
.then(() => done());
await myObject.save();
await myObject.destroy();

});
});

Expand Down Expand Up @@ -2467,21 +2469,19 @@ describe('beforeFind hooks', () => {
.then(() => done());
});

it('should have request ip', done => {
it('should have request ip', async () => {
await reconfigureServer({directAccess: false});
Parse.Cloud.beforeFind('MyObject', req => {
expect(req.ip).toBeDefined();
});

const MyObject = Parse.Object.extend('MyObject');
const myObject = new MyObject();
myObject
.save()
.then(myObj => {
const query = new Parse.Query('MyObject');
query.equalTo('objectId', myObj.id);
return Promise.all([query.get(myObj.id), query.first(), query.find()]);
})
.then(() => done());
await myObject.save()

const query = new Parse.Query('MyObject');
query.equalTo('objectId', myObject.id);
await Promise.all([query.get(myObject.id), query.first(), query.find()]);
});

it('should run beforeFind on pointers and array of pointers from an object', async () => {
Expand Down Expand Up @@ -2850,22 +2850,19 @@ describe('afterFind hooks', () => {
.then(() => done());
});

it('should have request ip', done => {
it('should have request ip', async () => {
await reconfigureServer({directAccess: false});
Parse.Cloud.afterFind('MyObject', req => {
expect(req.ip).toBeDefined();
});

const MyObject = Parse.Object.extend('MyObject');
const myObject = new MyObject();
myObject
.save()
.then(myObj => {
const query = new Parse.Query('MyObject');
query.equalTo('objectId', myObj.id);
return Promise.all([query.get(myObj.id), query.first(), query.find()]);
})
.then(() => done())
.catch(done.fail);
await myObject.save()

const query = new Parse.Query('MyObject');
query.equalTo('objectId', myObject.id);
await Promise.all([query.get(myObject.id), query.first(), query.find()]);
});

it('should validate triggers correctly', () => {
Expand Down Expand Up @@ -3224,7 +3221,8 @@ describe('beforeLogin hook', () => {
done();
});

it('should be able to block login if an error is thrown', async done => {
it('should be able to block login if an error is thrown', async () => {
await reconfigureServer({directAccess: false});
let hit = 0;
Parse.Cloud.beforeLogin(req => {
hit++;
Expand All @@ -3243,10 +3241,10 @@ describe('beforeLogin hook', () => {
expect(e.message).toBe('banned account');
}
expect(hit).toBe(1);
done();
});

it('should be able to block login if an error is thrown even if the user has a attached file', async done => {
it('should be able to block login if an error is thrown even if the user has a attached file', async () => {
await reconfigureServer({directAccess: false});
let hit = 0;
Parse.Cloud.beforeLogin(req => {
hit++;
Expand All @@ -3268,7 +3266,6 @@ describe('beforeLogin hook', () => {
expect(e.message).toBe('banned account');
}
expect(hit).toBe(1);
done();
});

it('should not run beforeLogin with incorrect credentials', async done => {
Expand Down Expand Up @@ -3301,7 +3298,7 @@ describe('beforeLogin hook', () => {
done();
});

it('should trigger afterLogout hook on logout', async done => {
it('should trigger afterLogout hook on logout', async () => {
let userId;
Parse.Cloud.afterLogout(req => {
expect(req.object.className).toEqual('_Session');
Expand All @@ -3311,10 +3308,9 @@ describe('beforeLogin hook', () => {
userId = user.id;
});

const user = await Parse.User.signUp('user', 'pass');
const user = await Parse.User.signUp('user', 'pass', null, {installationId: 'test'});
await Parse.User.logOut();
expect(user.id).toBe(userId);
done();
});

it('does not crash server when throwing in afterLogin hook', async () => {
Expand All @@ -3333,6 +3329,7 @@ describe('beforeLogin hook', () => {
});

it('does not crash server when throwing in afterLogout hook', async () => {
await reconfigureServer({directAccess: false});
const error = new Parse.Error(2000, 'afterLogout error');
const trigger = {
afterLogout() {
Expand All @@ -3347,7 +3344,7 @@ describe('beforeLogin hook', () => {
expect(response).toEqual(error);
});

it_id('5656d6d7-65ef-43d1-8ca6-6942ae3614d5')(it)('should have expected data in request in beforeLogin', async done => {
it_id('5656d6d7-65ef-43d1-8ca6-6942ae3614d5')(it)('should have expected data in request in beforeLogin', async () => {
Parse.Cloud.beforeLogin(req => {
expect(req.object).toBeDefined();
expect(req.user).toBeUndefined();
Expand All @@ -3358,8 +3355,7 @@ describe('beforeLogin hook', () => {
});

await Parse.User.signUp('tupac', 'shakur');
await Parse.User.logIn('tupac', 'shakur');
done();
await Parse.User.logIn('tupac', 'shakur', {installationId: 'test'});
});

it('afterFind should not be triggered when saving an object', async () => {
Expand Down Expand Up @@ -3464,7 +3460,7 @@ describe('afterLogin hook', () => {
done();
});

it_id('e86155c4-62e1-4c6e-ab4a-9ac6c87c60f2')(it)('should have expected data in request in afterLogin', async done => {
it_id('e86155c4-62e1-4c6e-ab4a-9ac6c87c60f2')(it)('should have expected data in request in afterLogin', async () => {
Parse.Cloud.afterLogin(req => {
expect(req.object).toBeDefined();
expect(req.user).toBeDefined();
Expand All @@ -3475,8 +3471,7 @@ describe('afterLogin hook', () => {
});

await Parse.User.signUp('testuser', 'p@ssword');
await Parse.User.logIn('testuser', 'p@ssword');
done();
await Parse.User.logIn('testuser', 'p@ssword', {installationId: 'test'});
});

it('context options should override _context object property when saving a new object', async () => {
Expand Down
4 changes: 4 additions & 0 deletions spec/ParseFile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@ describe('Parse.File testing', () => {

it('rejects all file uploads', async () => {
await reconfigureServer({
directAccess:false,
fileUpload: {
enableForPublic: false,
enableForAnonymousUser: false,
Expand Down Expand Up @@ -1176,6 +1177,7 @@ describe('Parse.File testing', () => {

it('allows file upload only for public', async () => {
await reconfigureServer({
directAccess:false,
fileUpload: {
enableForPublic: true,
enableForAnonymousUser: false,
Expand All @@ -1201,6 +1203,7 @@ describe('Parse.File testing', () => {

it('allows file upload only for anonymous user', async () => {
await reconfigureServer({
directAccess:false,
fileUpload: {
enableForPublic: false,
enableForAnonymousUser: true,
Expand All @@ -1226,6 +1229,7 @@ describe('Parse.File testing', () => {

it('allows file upload only for authenticated user', async () => {
await reconfigureServer({
directAccess:false,
fileUpload: {
enableForPublic: false,
enableForAnonymousUser: false,
Expand Down
2 changes: 1 addition & 1 deletion spec/UserPII.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Personally Identifiable Information', () => {
let user;

beforeEach(async done => {
await reconfigureServer();
await reconfigureServer({directAccess: false});
user = await Parse.User.signUp('tester', 'abc');
user = await Parse.User.logIn(user.get('username'), 'abc');
const acl = new Parse.ACL();
Expand Down
4 changes: 3 additions & 1 deletion spec/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ const reconfigureServer = async (changedConfiguration = {}) => {
});
cache.clear();
parseServer = await ParseServer.startApp(newConfiguration);
Parse.CoreManager.setRESTController(RESTController);
if (!newConfiguration.directAccess) {
Parse.CoreManager.setRESTController(RESTController);
}
parseServer.expressApp.use('/1', err => {
console.error(err);
fail('should not call next');
Expand Down
Loading