Remove request and request-promise from dev dependencies (#5077)
* removes from emailverificationtoken spec * updates winston * Updates ValidationAndPasswordsReset * Use local request in schemas * Removes request in rest.spec * Removes request from PushRouter0 * removes request from public API * removes request from index.spec * Removes request form parse.push spec * removes request from ParseInstallation spec * Removes from ParseHooks * removes request from ParseGlobalConfig.spec * Removes request from ParseAPI.spec.js * removes request from LogsRouter * removes in features * Filters undefined headers instead of crashing * Removes request from ParseUser spec * Removes usage of request in ParseFile.spec.js * Removes request from AuthAdapters.js * removes request-promise from ParseGeoPoint.spec * Removes request-promise from ParseQuery spec * remove request-promise from UserPII * removes request-promise from EnableExpressErrorHandler * Updates RevocableSessionUpgrade spec * Update RestQuery * Removes read preferenceOptionM * ensure we forward auth from URL * use request in CloudCode.spec.js * Removes request-promise from JobSchedule.spec * Removes rp from VerifyUserPassword.spec.js * Removes rp from PasswordPolicy spec * Removes rp from ParsePolygon spec * Removes rp from fullTextSearch spec * Removes rp from PArseQuery.Aggregate * Ensure we properly forward errors * Removes request and request-promise
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const request = require('request');
|
||||
const request = require('../lib/request');
|
||||
const Config = require('../lib/Config');
|
||||
const defaultColumns = require('../lib/Controllers/SchemaController')
|
||||
.defaultColumns;
|
||||
@@ -143,6 +143,7 @@ describe('AuthenticationProviders', function() {
|
||||
};
|
||||
|
||||
const options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
@@ -152,17 +153,23 @@ describe('AuthenticationProviders', function() {
|
||||
},
|
||||
url: 'http://localhost:8378/1/users',
|
||||
body: jsonBody,
|
||||
json: true,
|
||||
};
|
||||
|
||||
return new Promise(resolve => {
|
||||
request.post(options, (err, res, body) => {
|
||||
resolve({ err, res, body });
|
||||
return request(options)
|
||||
.then(response => {
|
||||
if (callback) {
|
||||
callback(err, res, body);
|
||||
callback(null, response, response.data);
|
||||
}
|
||||
return {
|
||||
res: response,
|
||||
body: response.data,
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
if (callback) {
|
||||
callback(error);
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
it('should create user with REST API', done => {
|
||||
@@ -226,9 +233,9 @@ describe('AuthenticationProviders', function() {
|
||||
.then(user => {
|
||||
return createOAuthUserWithSessionToken(user.getSessionToken());
|
||||
})
|
||||
.then(({ body }) => {
|
||||
expect(body.code).toBe(208);
|
||||
expect(body.error).toBe('this auth is already used');
|
||||
.then(fail, ({ data }) => {
|
||||
expect(data.code).toBe(208);
|
||||
expect(data.error).toBe('this auth is already used');
|
||||
done();
|
||||
})
|
||||
.catch(done.fail);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
const Parse = require('parse/node');
|
||||
const rp = require('request-promise');
|
||||
const request = require('../lib/request');
|
||||
const InMemoryCacheAdapter = require('../lib/Adapters/Cache/InMemoryCacheAdapter')
|
||||
.InMemoryCacheAdapter;
|
||||
|
||||
@@ -880,26 +880,23 @@ describe('Cloud Code', () => {
|
||||
})
|
||||
.then(user => {
|
||||
session1 = user.getSessionToken();
|
||||
return rp({
|
||||
uri: 'http://localhost:8378/1/login?username=test&password=moon-y',
|
||||
json: true,
|
||||
return request({
|
||||
url: 'http://localhost:8378/1/login?username=test&password=moon-y',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(body => {
|
||||
session2 = body.sessionToken;
|
||||
|
||||
.then(response => {
|
||||
session2 = response.data.sessionToken;
|
||||
//Ensure both session tokens are in the cache
|
||||
return Parse.Cloud.run('checkStaleUser');
|
||||
return Parse.Cloud.run('checkStaleUser', { sessionToken: session2 });
|
||||
})
|
||||
.then(() =>
|
||||
rp({
|
||||
request({
|
||||
method: 'POST',
|
||||
uri: 'http://localhost:8378/1/functions/checkStaleUser',
|
||||
json: true,
|
||||
url: 'http://localhost:8378/1/functions/checkStaleUser',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
@@ -922,10 +919,9 @@ describe('Cloud Code', () => {
|
||||
return user.save();
|
||||
})
|
||||
.then(() =>
|
||||
rp({
|
||||
request({
|
||||
method: 'POST',
|
||||
uri: 'http://localhost:8378/1/functions/checkStaleUser',
|
||||
json: true,
|
||||
url: 'http://localhost:8378/1/functions/checkStaleUser',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
@@ -933,11 +929,11 @@ describe('Cloud Code', () => {
|
||||
},
|
||||
})
|
||||
)
|
||||
.then(body => {
|
||||
expect(body.result).toEqual('second data');
|
||||
.then(response => {
|
||||
expect(response.data.result).toEqual('second data');
|
||||
done();
|
||||
})
|
||||
.catch(done.fail);
|
||||
.catch(e => done.fail(e));
|
||||
});
|
||||
|
||||
it('trivial beforeSave should not affect fetched pointers (regression test for #1238)', done => {
|
||||
@@ -1196,7 +1192,8 @@ describe('Cloud Code', () => {
|
||||
Parse.Cloud.job('myJob', () => {});
|
||||
}).not.toThrow();
|
||||
|
||||
rp.post({
|
||||
request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/jobs/myJob',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
@@ -1218,7 +1215,8 @@ describe('Cloud Code', () => {
|
||||
Parse.Cloud.job('myJob', () => {});
|
||||
}).not.toThrow();
|
||||
|
||||
rp.post({
|
||||
request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/jobs/myJob',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
@@ -1230,7 +1228,7 @@ describe('Cloud Code', () => {
|
||||
done();
|
||||
},
|
||||
err => {
|
||||
expect(err.statusCode).toBe(403);
|
||||
expect(err.status).toBe(403);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@@ -1248,7 +1246,8 @@ describe('Cloud Code', () => {
|
||||
});
|
||||
}).not.toThrow();
|
||||
|
||||
rp.post({
|
||||
request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/jobs/myJob',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
@@ -1275,7 +1274,8 @@ describe('Cloud Code', () => {
|
||||
});
|
||||
}).not.toThrow();
|
||||
|
||||
rp.post({
|
||||
request({
|
||||
method: 'POST',
|
||||
url: `http://${Parse.applicationId}:${
|
||||
Parse.masterKey
|
||||
}@localhost:8378/1/jobs/myJob`,
|
||||
@@ -1317,7 +1317,8 @@ describe('Cloud Code', () => {
|
||||
return promise;
|
||||
});
|
||||
|
||||
rp.post({
|
||||
request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/jobs/myJob',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
@@ -1351,7 +1352,8 @@ describe('Cloud Code', () => {
|
||||
return promise;
|
||||
});
|
||||
|
||||
rp.post({
|
||||
request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/jobs/myJob',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
@@ -1580,7 +1582,7 @@ describe('beforeFind hooks', () => {
|
||||
return Parse.Query.or(req.query, otherQuery);
|
||||
});
|
||||
|
||||
rp.get({
|
||||
request({
|
||||
url: 'http://localhost:8378/1/classes/MyObject',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
@@ -1639,15 +1641,16 @@ describe('beforeFind hooks', () => {
|
||||
const obj = new Parse.Object('MyObject');
|
||||
obj.set('secretField', 'SSID');
|
||||
obj.save().then(function() {
|
||||
rp({
|
||||
request({
|
||||
method: 'GET',
|
||||
uri: 'http://localhost:8378/1/classes/MyObject/' + obj.id,
|
||||
url: 'http://localhost:8378/1/classes/MyObject/' + obj.id,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
json: true,
|
||||
}).then(body => {
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(body.secretField).toEqual('SSID');
|
||||
expect(hook.method).toHaveBeenCalled();
|
||||
done();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const request = require('request');
|
||||
const requestp = require('request-promise');
|
||||
const Config = require('../lib/Config');
|
||||
const request = require('../lib/request');
|
||||
|
||||
describe('Email Verification Token Expiration: ', () => {
|
||||
it('show the invalid verification link page, if the user clicks on the verify email link after the email verify token expires', done => {
|
||||
@@ -32,20 +31,18 @@ describe('Email Verification Token Expiration: ', () => {
|
||||
// wait for 1 second - simulate user behavior to some extent
|
||||
setTimeout(() => {
|
||||
expect(sendEmailOptions).not.toBeUndefined();
|
||||
console.log(sendEmailOptions.link);
|
||||
|
||||
request.get(
|
||||
sendEmailOptions.link,
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link.html?username=testEmailVerifyTokenValidity&appId=test'
|
||||
);
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
url: sendEmailOptions.link,
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link.html?username=testEmailVerifyTokenValidity&appId=test'
|
||||
);
|
||||
done();
|
||||
});
|
||||
}, 1000);
|
||||
})
|
||||
.catch(err => {
|
||||
@@ -82,25 +79,22 @@ describe('Email Verification Token Expiration: ', () => {
|
||||
setTimeout(() => {
|
||||
expect(sendEmailOptions).not.toBeUndefined();
|
||||
|
||||
request.get(
|
||||
sendEmailOptions.link,
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
user
|
||||
.fetch()
|
||||
.then(() => {
|
||||
expect(user.get('emailVerified')).toEqual(false);
|
||||
done();
|
||||
})
|
||||
.catch(() => {
|
||||
jfail(error);
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
request({
|
||||
url: sendEmailOptions.link,
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
user
|
||||
.fetch()
|
||||
.then(() => {
|
||||
expect(user.get('emailVerified')).toEqual(false);
|
||||
done();
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}, 1000);
|
||||
})
|
||||
.catch(error => {
|
||||
@@ -133,19 +127,16 @@ describe('Email Verification Token Expiration: ', () => {
|
||||
return user.signUp();
|
||||
})
|
||||
.then(() => {
|
||||
request.get(
|
||||
sendEmailOptions.link,
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/verify_email_success.html?username=testEmailVerifyTokenValidity'
|
||||
);
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
url: sendEmailOptions.link,
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/verify_email_success.html?username=testEmailVerifyTokenValidity'
|
||||
);
|
||||
done();
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
@@ -177,25 +168,22 @@ describe('Email Verification Token Expiration: ', () => {
|
||||
return user.signUp();
|
||||
})
|
||||
.then(() => {
|
||||
request.get(
|
||||
sendEmailOptions.link,
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
user
|
||||
.fetch()
|
||||
.then(() => {
|
||||
expect(user.get('emailVerified')).toEqual(true);
|
||||
done();
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
request({
|
||||
url: sendEmailOptions.link,
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
user
|
||||
.fetch()
|
||||
.then(() => {
|
||||
expect(user.get('emailVerified')).toEqual(true);
|
||||
done();
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
@@ -227,25 +215,22 @@ describe('Email Verification Token Expiration: ', () => {
|
||||
return user.signUp();
|
||||
})
|
||||
.then(() => {
|
||||
request.get(
|
||||
sendEmailOptions.link,
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
Parse.User.logIn('testEmailVerifyTokenValidity', 'expiringToken')
|
||||
.then(user => {
|
||||
expect(typeof user).toBe('object');
|
||||
expect(user.get('emailVerified')).toBe(true);
|
||||
done();
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
request({
|
||||
url: sendEmailOptions.link,
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
Parse.User.logIn('testEmailVerifyTokenValidity', 'expiringToken')
|
||||
.then(user => {
|
||||
expect(typeof user).toBe('object');
|
||||
expect(user.get('emailVerified')).toBe(true);
|
||||
done();
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
@@ -322,37 +307,34 @@ describe('Email Verification Token Expiration: ', () => {
|
||||
return user.signUp();
|
||||
})
|
||||
.then(() => {
|
||||
request.get(
|
||||
sendEmailOptions.link,
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
const config = Config.get('test');
|
||||
return config.database
|
||||
.find('_User', {
|
||||
username: 'unsets_email_verify_token_expires_at',
|
||||
})
|
||||
.then(results => {
|
||||
expect(results.length).toBe(1);
|
||||
return results[0];
|
||||
})
|
||||
.then(user => {
|
||||
expect(typeof user).toBe('object');
|
||||
expect(user.emailVerified).toEqual(true);
|
||||
expect(typeof user._email_verify_token).toBe('undefined');
|
||||
expect(typeof user._email_verify_token_expires_at).toBe(
|
||||
'undefined'
|
||||
);
|
||||
done();
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
request({
|
||||
url: sendEmailOptions.link,
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
const config = Config.get('test');
|
||||
return config.database
|
||||
.find('_User', {
|
||||
username: 'unsets_email_verify_token_expires_at',
|
||||
})
|
||||
.then(results => {
|
||||
expect(results.length).toBe(1);
|
||||
return results[0];
|
||||
})
|
||||
.then(user => {
|
||||
expect(typeof user).toBe('object');
|
||||
expect(user.emailVerified).toEqual(true);
|
||||
expect(typeof user._email_verify_token).toBe('undefined');
|
||||
expect(typeof user._email_verify_token_expires_at).toBe(
|
||||
'undefined'
|
||||
);
|
||||
done();
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
@@ -386,14 +368,12 @@ describe('Email Verification Token Expiration: ', () => {
|
||||
return user.signUp();
|
||||
})
|
||||
.then(() => {
|
||||
return new Promise((resolve, reject) => {
|
||||
request
|
||||
.get(sendEmailOptions.link, { followRedirect: false })
|
||||
.on('error', error => reject(error))
|
||||
.on('response', response => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
resolve(user.fetch());
|
||||
});
|
||||
return request({
|
||||
url: sendEmailOptions.link,
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
return user.fetch();
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
@@ -403,19 +383,16 @@ describe('Email Verification Token Expiration: ', () => {
|
||||
return reconfigureServer(serverConfig);
|
||||
})
|
||||
.then(() => {
|
||||
request.get(
|
||||
sendEmailOptions.link,
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/verify_email_success.html?username=testEmailVerifyTokenValidity'
|
||||
);
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
url: sendEmailOptions.link,
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/verify_email_success.html?username=testEmailVerifyTokenValidity'
|
||||
);
|
||||
done();
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
@@ -459,19 +436,16 @@ describe('Email Verification Token Expiration: ', () => {
|
||||
return reconfigureServer(serverConfig);
|
||||
})
|
||||
.then(() => {
|
||||
request.get(
|
||||
sendEmailOptions.link,
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link.html?username=testEmailVerifyTokenValidity&appId=test'
|
||||
);
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
url: sendEmailOptions.link,
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link.html?username=testEmailVerifyTokenValidity&appId=test'
|
||||
);
|
||||
done();
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
@@ -590,22 +564,21 @@ describe('Email Verification Token Expiration: ', () => {
|
||||
|
||||
expect(sendVerificationEmailCallCount).toBe(1);
|
||||
|
||||
return requestp.post({
|
||||
uri: 'http://localhost:8378/1/verificationEmailRequest',
|
||||
return request({
|
||||
url: 'http://localhost:8378/1/verificationEmailRequest',
|
||||
method: 'POST',
|
||||
body: {
|
||||
email: 'user@parse.com',
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
json: true,
|
||||
resolveWithFullResponse: true,
|
||||
simple: false, // this promise is only rejected if the call itself failed
|
||||
});
|
||||
})
|
||||
.then(response => {
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.status).toBe(200);
|
||||
expect(sendVerificationEmailCallCount).toBe(2);
|
||||
expect(sendEmailOptions).toBeDefined();
|
||||
|
||||
@@ -660,36 +633,31 @@ describe('Email Verification Token Expiration: ', () => {
|
||||
return user.signUp();
|
||||
})
|
||||
.then(() => {
|
||||
return requestp
|
||||
.get({
|
||||
url: sendEmailOptions.link,
|
||||
followRedirect: false,
|
||||
resolveWithFullResponse: true,
|
||||
simple: false,
|
||||
})
|
||||
.then(response => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
});
|
||||
return request({
|
||||
url: sendEmailOptions.link,
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
expect(sendVerificationEmailCallCount).toBe(1);
|
||||
|
||||
return requestp
|
||||
.post({
|
||||
uri: 'http://localhost:8378/1/verificationEmailRequest',
|
||||
body: {
|
||||
email: 'user@parse.com',
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
json: true,
|
||||
resolveWithFullResponse: true,
|
||||
simple: false, // this promise is only rejected if the call itself failed
|
||||
})
|
||||
return request({
|
||||
url: 'http://localhost:8378/1/verificationEmailRequest',
|
||||
method: 'POST',
|
||||
body: {
|
||||
email: 'user@parse.com',
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
})
|
||||
.then(fail, res => res)
|
||||
.then(response => {
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.status).toBe(400);
|
||||
expect(sendVerificationEmailCallCount).toBe(1);
|
||||
done();
|
||||
});
|
||||
@@ -719,22 +687,22 @@ describe('Email Verification Token Expiration: ', () => {
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
})
|
||||
.then(() => {
|
||||
return requestp
|
||||
.post({
|
||||
uri: 'http://localhost:8378/1/verificationEmailRequest',
|
||||
body: {
|
||||
email: 'user@parse.com',
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
json: true,
|
||||
resolveWithFullResponse: true,
|
||||
simple: false,
|
||||
})
|
||||
return request({
|
||||
url: 'http://localhost:8378/1/verificationEmailRequest',
|
||||
method: 'POST',
|
||||
body: {
|
||||
email: 'user@parse.com',
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
})
|
||||
.then(fail)
|
||||
.catch(response => response)
|
||||
.then(response => {
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.status).toBe(400);
|
||||
expect(sendVerificationEmailCallCount).toBe(0);
|
||||
expect(sendEmailOptions).not.toBeDefined();
|
||||
done();
|
||||
@@ -765,27 +733,25 @@ describe('Email Verification Token Expiration: ', () => {
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
})
|
||||
.then(() => {
|
||||
request.post(
|
||||
{
|
||||
uri: 'http://localhost:8378/1/verificationEmailRequest',
|
||||
body: {},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
json: true,
|
||||
resolveWithFullResponse: true,
|
||||
simple: false,
|
||||
request({
|
||||
url: 'http://localhost:8378/1/verificationEmailRequest',
|
||||
method: 'POST',
|
||||
body: {},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
(err, response) => {
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.body.code).toBe(Parse.Error.EMAIL_MISSING);
|
||||
expect(response.body.error).toBe('you must provide an email');
|
||||
})
|
||||
.then(fail, response => response)
|
||||
.then(response => {
|
||||
expect(response.status).toBe(400);
|
||||
expect(response.data.code).toBe(Parse.Error.EMAIL_MISSING);
|
||||
expect(response.data.error).toBe('you must provide an email');
|
||||
expect(sendVerificationEmailCallCount).toBe(0);
|
||||
expect(sendEmailOptions).not.toBeDefined();
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
@@ -812,29 +778,27 @@ describe('Email Verification Token Expiration: ', () => {
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
})
|
||||
.then(() => {
|
||||
request.post(
|
||||
{
|
||||
uri: 'http://localhost:8378/1/verificationEmailRequest',
|
||||
body: { email: 3 },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
json: true,
|
||||
resolveWithFullResponse: true,
|
||||
simple: false,
|
||||
request({
|
||||
url: 'http://localhost:8378/1/verificationEmailRequest',
|
||||
method: 'POST',
|
||||
body: { email: 3 },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
(err, response) => {
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.body.code).toBe(Parse.Error.INVALID_EMAIL_ADDRESS);
|
||||
expect(response.body.error).toBe(
|
||||
})
|
||||
.then(fail, res => res)
|
||||
.then(response => {
|
||||
expect(response.status).toBe(400);
|
||||
expect(response.data.code).toBe(Parse.Error.INVALID_EMAIL_ADDRESS);
|
||||
expect(response.data.error).toBe(
|
||||
'you must provide a valid email string'
|
||||
);
|
||||
expect(sendVerificationEmailCallCount).toBe(0);
|
||||
expect(sendEmailOptions).not.toBeDefined();
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
@@ -911,44 +875,38 @@ describe('Email Verification Token Expiration: ', () => {
|
||||
return user.signUp();
|
||||
})
|
||||
.then(() => {
|
||||
request.get(
|
||||
sendEmailOptions.link,
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
Parse.User.logIn('testEmailVerifyTokenValidity', 'expiringToken')
|
||||
.then(user => {
|
||||
expect(typeof user).toBe('object');
|
||||
expect(user.get('emailVerified')).toBe(true);
|
||||
request({
|
||||
url: sendEmailOptions.link,
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
Parse.User.logIn('testEmailVerifyTokenValidity', 'expiringToken')
|
||||
.then(user => {
|
||||
expect(typeof user).toBe('object');
|
||||
expect(user.get('emailVerified')).toBe(true);
|
||||
|
||||
user.set('email', 'newEmail@parse.com');
|
||||
return user.save();
|
||||
})
|
||||
.then(() => user.fetch())
|
||||
.then(user => {
|
||||
expect(typeof user).toBe('object');
|
||||
expect(user.get('email')).toBe('newEmail@parse.com');
|
||||
expect(user.get('emailVerified')).toBe(false);
|
||||
user.set('email', 'newEmail@parse.com');
|
||||
return user.save();
|
||||
})
|
||||
.then(() => user.fetch())
|
||||
.then(user => {
|
||||
expect(typeof user).toBe('object');
|
||||
expect(user.get('email')).toBe('newEmail@parse.com');
|
||||
expect(user.get('emailVerified')).toBe(false);
|
||||
|
||||
request.get(
|
||||
sendEmailOptions.link,
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
done();
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
request({
|
||||
url: sendEmailOptions.link,
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const ParseServer = require('../lib/index');
|
||||
const express = require('express');
|
||||
const rp = require('request-promise');
|
||||
const request = require('../lib/request');
|
||||
|
||||
describe('Enable express error handler', () => {
|
||||
it('should call the default handler in case of error, like updating a non existing object', done => {
|
||||
@@ -30,22 +30,21 @@ describe('Enable express error handler', () => {
|
||||
lastError = err;
|
||||
});
|
||||
|
||||
rp({
|
||||
request({
|
||||
method: 'PUT',
|
||||
uri: serverUrl + '/classes/AnyClass/nonExistingId',
|
||||
url: serverUrl + '/classes/AnyClass/nonExistingId',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': appId,
|
||||
'X-Parse-Master-Key': masterKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: { someField: 'blablabla' },
|
||||
json: true,
|
||||
})
|
||||
.then(() => {
|
||||
fail('Should throw error');
|
||||
})
|
||||
.catch(e => {
|
||||
expect(e).toBeDefined();
|
||||
const reqError = e.error;
|
||||
.catch(response => {
|
||||
const reqError = response.data;
|
||||
expect(reqError).toBeDefined();
|
||||
expect(lastError).toBeDefined();
|
||||
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
const rp = require('request-promise');
|
||||
const request = require('../lib/request');
|
||||
|
||||
const defaultHeaders = {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Rest-API-Key': 'rest',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
const masterKeyHeaders = {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Rest-API-Key': 'rest',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
const defaultOptions = {
|
||||
headers: defaultHeaders,
|
||||
@@ -43,58 +46,75 @@ describe('JobSchedule', () => {
|
||||
});
|
||||
|
||||
it('should reject access when not using masterKey (/jobs)', done => {
|
||||
rp.get(Parse.serverURL + '/cloud_code/jobs', defaultOptions).then(
|
||||
done.fail,
|
||||
() => done()
|
||||
);
|
||||
request(
|
||||
Object.assign(
|
||||
{ url: Parse.serverURL + '/cloud_code/jobs' },
|
||||
defaultOptions
|
||||
)
|
||||
).then(done.fail, () => done());
|
||||
});
|
||||
|
||||
it('should reject access when not using masterKey (/jobs/data)', done => {
|
||||
rp.get(Parse.serverURL + '/cloud_code/jobs/data', defaultOptions).then(
|
||||
done.fail,
|
||||
() => done()
|
||||
);
|
||||
request(
|
||||
Object.assign(
|
||||
{ url: Parse.serverURL + '/cloud_code/jobs/data' },
|
||||
defaultOptions
|
||||
)
|
||||
).then(done.fail, () => done());
|
||||
});
|
||||
|
||||
it('should reject access when not using masterKey (PUT /jobs/id)', done => {
|
||||
rp.put(Parse.serverURL + '/cloud_code/jobs/jobId', defaultOptions).then(
|
||||
done.fail,
|
||||
() => done()
|
||||
);
|
||||
request(
|
||||
Object.assign(
|
||||
{ method: 'PUT', url: Parse.serverURL + '/cloud_code/jobs/jobId' },
|
||||
defaultOptions
|
||||
)
|
||||
).then(done.fail, () => done());
|
||||
});
|
||||
|
||||
it('should reject access when not using masterKey (DELETE /jobs/id)', done => {
|
||||
rp.del(Parse.serverURL + '/cloud_code/jobs/jobId', defaultOptions).then(
|
||||
done.fail,
|
||||
() => done()
|
||||
);
|
||||
request(
|
||||
Object.assign(
|
||||
{ method: 'DELETE', url: Parse.serverURL + '/cloud_code/jobs/jobId' },
|
||||
defaultOptions
|
||||
)
|
||||
).then(done.fail, () => done());
|
||||
});
|
||||
|
||||
it('should allow access when using masterKey (GET /jobs)', done => {
|
||||
rp.get(Parse.serverURL + '/cloud_code/jobs', masterKeyOptions).then(
|
||||
done,
|
||||
done.fail
|
||||
);
|
||||
request(
|
||||
Object.assign(
|
||||
{ url: Parse.serverURL + '/cloud_code/jobs' },
|
||||
masterKeyOptions
|
||||
)
|
||||
).then(done, done.fail);
|
||||
});
|
||||
|
||||
it('should create a job schedule', done => {
|
||||
Parse.Cloud.job('job', () => {});
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/cloud_code/jobs',
|
||||
body: {
|
||||
job_schedule: {
|
||||
jobName: 'job',
|
||||
},
|
||||
},
|
||||
});
|
||||
rp.post(Parse.serverURL + '/cloud_code/jobs', options)
|
||||
request(options)
|
||||
.then(res => {
|
||||
expect(res.objectId).not.toBeUndefined();
|
||||
expect(res.data.objectId).not.toBeUndefined();
|
||||
})
|
||||
.then(() => {
|
||||
return rp.get(Parse.serverURL + '/cloud_code/jobs', masterKeyOptions);
|
||||
return request(
|
||||
Object.assign(
|
||||
{ url: Parse.serverURL + '/cloud_code/jobs' },
|
||||
masterKeyOptions
|
||||
)
|
||||
);
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.length).toBe(1);
|
||||
expect(res.data.length).toBe(1);
|
||||
})
|
||||
.then(done)
|
||||
.catch(done.fail);
|
||||
@@ -102,13 +122,15 @@ describe('JobSchedule', () => {
|
||||
|
||||
it('should fail creating a job with an invalid name', done => {
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
url: Parse.serverURL + '/cloud_code/jobs',
|
||||
method: 'POST',
|
||||
body: {
|
||||
job_schedule: {
|
||||
jobName: 'job',
|
||||
},
|
||||
},
|
||||
});
|
||||
rp.post(Parse.serverURL + '/cloud_code/jobs', options)
|
||||
request(options)
|
||||
.then(done.fail)
|
||||
.catch(() => done());
|
||||
});
|
||||
@@ -117,18 +139,21 @@ describe('JobSchedule', () => {
|
||||
Parse.Cloud.job('job1', () => {});
|
||||
Parse.Cloud.job('job2', () => {});
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/cloud_code/jobs',
|
||||
body: {
|
||||
job_schedule: {
|
||||
jobName: 'job1',
|
||||
},
|
||||
},
|
||||
});
|
||||
rp.post(Parse.serverURL + '/cloud_code/jobs', options)
|
||||
request(options)
|
||||
.then(res => {
|
||||
expect(res.objectId).not.toBeUndefined();
|
||||
return rp.put(
|
||||
Parse.serverURL + '/cloud_code/jobs/' + res.objectId,
|
||||
expect(res.data.objectId).not.toBeUndefined();
|
||||
return request(
|
||||
Object.assign(options, {
|
||||
url: Parse.serverURL + '/cloud_code/jobs/' + res.data.objectId,
|
||||
method: 'PUT',
|
||||
body: {
|
||||
job_schedule: {
|
||||
jobName: 'job2',
|
||||
@@ -138,11 +163,15 @@ describe('JobSchedule', () => {
|
||||
);
|
||||
})
|
||||
.then(() => {
|
||||
return rp.get(Parse.serverURL + '/cloud_code/jobs', masterKeyOptions);
|
||||
return request(
|
||||
Object.assign({}, masterKeyOptions, {
|
||||
url: Parse.serverURL + '/cloud_code/jobs',
|
||||
})
|
||||
);
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.length).toBe(1);
|
||||
expect(res[0].jobName).toBe('job2');
|
||||
expect(res.data.length).toBe(1);
|
||||
expect(res.data[0].jobName).toBe('job2');
|
||||
})
|
||||
.then(done)
|
||||
.catch(done.fail);
|
||||
@@ -151,18 +180,21 @@ describe('JobSchedule', () => {
|
||||
it('should fail updating a job with an invalid name', done => {
|
||||
Parse.Cloud.job('job1', () => {});
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/cloud_code/jobs',
|
||||
body: {
|
||||
job_schedule: {
|
||||
jobName: 'job1',
|
||||
},
|
||||
},
|
||||
});
|
||||
rp.post(Parse.serverURL + '/cloud_code/jobs', options)
|
||||
request(options)
|
||||
.then(res => {
|
||||
expect(res.objectId).not.toBeUndefined();
|
||||
return rp.put(
|
||||
Parse.serverURL + '/cloud_code/jobs/' + res.objectId,
|
||||
expect(res.data.objectId).not.toBeUndefined();
|
||||
return request(
|
||||
Object.assign(options, {
|
||||
method: 'PUT',
|
||||
url: Parse.serverURL + '/cloud_code/jobs/' + res.data.objectId,
|
||||
body: {
|
||||
job_schedule: {
|
||||
jobName: 'job2',
|
||||
@@ -178,25 +210,39 @@ describe('JobSchedule', () => {
|
||||
it('should destroy a job', done => {
|
||||
Parse.Cloud.job('job', () => {});
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/cloud_code/jobs',
|
||||
body: {
|
||||
job_schedule: {
|
||||
jobName: 'job',
|
||||
},
|
||||
},
|
||||
});
|
||||
rp.post(Parse.serverURL + '/cloud_code/jobs', options)
|
||||
request(options)
|
||||
.then(res => {
|
||||
expect(res.objectId).not.toBeUndefined();
|
||||
return rp.del(
|
||||
Parse.serverURL + '/cloud_code/jobs/' + res.objectId,
|
||||
masterKeyOptions
|
||||
expect(res.data.objectId).not.toBeUndefined();
|
||||
return request(
|
||||
Object.assign(
|
||||
{
|
||||
method: 'DELETE',
|
||||
url: Parse.serverURL + '/cloud_code/jobs/' + res.data.objectId,
|
||||
},
|
||||
masterKeyOptions
|
||||
)
|
||||
);
|
||||
})
|
||||
.then(() => {
|
||||
return rp.get(Parse.serverURL + '/cloud_code/jobs', masterKeyOptions);
|
||||
return request(
|
||||
Object.assign(
|
||||
{
|
||||
url: Parse.serverURL + '/cloud_code/jobs',
|
||||
},
|
||||
masterKeyOptions
|
||||
)
|
||||
);
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.length).toBe(0);
|
||||
expect(res.data.length).toBe(0);
|
||||
})
|
||||
.then(done)
|
||||
.catch(done.fail);
|
||||
@@ -206,29 +252,35 @@ describe('JobSchedule', () => {
|
||||
Parse.Cloud.job('job1', () => {});
|
||||
Parse.Cloud.job('job2', () => {});
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/cloud_code/jobs',
|
||||
body: {
|
||||
job_schedule: {
|
||||
jobName: 'job1',
|
||||
},
|
||||
},
|
||||
});
|
||||
rp.post(Parse.serverURL + '/cloud_code/jobs', options)
|
||||
.then(res => {
|
||||
request(options)
|
||||
.then(response => {
|
||||
const res = response.data;
|
||||
expect(res.objectId).not.toBeUndefined();
|
||||
})
|
||||
.then(() => {
|
||||
return rp.get(
|
||||
Parse.serverURL + '/cloud_code/jobs/data',
|
||||
masterKeyOptions
|
||||
return request(
|
||||
Object.assign(
|
||||
{ url: Parse.serverURL + '/cloud_code/jobs/data' },
|
||||
masterKeyOptions
|
||||
)
|
||||
);
|
||||
})
|
||||
.then(res => {
|
||||
.then(response => {
|
||||
const res = response.data;
|
||||
expect(res.in_use).toEqual(['job1']);
|
||||
expect(res.jobs).toContain('job1');
|
||||
expect(res.jobs).toContain('job2');
|
||||
expect(res.jobs.length).toBe(2);
|
||||
})
|
||||
.then(done)
|
||||
.catch(done.fail);
|
||||
.catch(e => done.fail(e.data));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const request = require('request');
|
||||
const request = require('../lib/request');
|
||||
const LogsRouter = require('../lib/Routers/LogsRouter').LogsRouter;
|
||||
const LoggerController = require('../lib/Controllers/LoggerController')
|
||||
.LoggerController;
|
||||
@@ -51,21 +51,18 @@ describe('LogsRouter', () => {
|
||||
});
|
||||
|
||||
it('can check invalid master key of request', done => {
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/scriptlog',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
request({
|
||||
url: 'http://localhost:8378/1/scriptlog',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(response.statusCode).toEqual(403);
|
||||
expect(body.error).toEqual('unauthorized: master key is required');
|
||||
done();
|
||||
}
|
||||
);
|
||||
}).then(fail, response => {
|
||||
const body = response.data;
|
||||
expect(response.status).toEqual(403);
|
||||
expect(body.error).toEqual('unauthorized: master key is required');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
const headers = {
|
||||
@@ -81,33 +78,29 @@ describe('LogsRouter', () => {
|
||||
reconfigureServer({
|
||||
verbose: true,
|
||||
}).then(function() {
|
||||
request.get(
|
||||
{
|
||||
headers: headers,
|
||||
url:
|
||||
'http://localhost:8378/1/login?username=test&password=simplepass.com',
|
||||
},
|
||||
() => {
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/scriptlog?size=4&level=verbose',
|
||||
json: true,
|
||||
headers: headers,
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(response.statusCode).toEqual(200);
|
||||
// 4th entry is our actual GET request
|
||||
expect(body[2].url).toEqual(
|
||||
'/1/login?username=test&password=********'
|
||||
);
|
||||
expect(body[2].message).toEqual(
|
||||
'REQUEST for [GET] /1/login?username=test&password=********: {}'
|
||||
);
|
||||
done();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
request({
|
||||
headers: headers,
|
||||
url:
|
||||
'http://localhost:8378/1/login?username=test&password=simplepass.com',
|
||||
})
|
||||
.catch(() => {})
|
||||
.then(() => {
|
||||
request({
|
||||
url: 'http://localhost:8378/1/scriptlog?size=4&level=verbose',
|
||||
headers: headers,
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(response.status).toEqual(200);
|
||||
// 4th entry is our actual GET request
|
||||
expect(body[2].url).toEqual(
|
||||
'/1/login?username=test&password=********'
|
||||
);
|
||||
expect(body[2].message).toEqual(
|
||||
'REQUEST for [GET] /1/login?username=test&password=********: {}'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -117,23 +110,22 @@ describe('LogsRouter', () => {
|
||||
it('does scrub complex passwords on GET login', done => {
|
||||
reconfigureServer({
|
||||
verbose: true,
|
||||
}).then(function() {
|
||||
request.get(
|
||||
{
|
||||
})
|
||||
.then(function() {
|
||||
return request({
|
||||
headers: headers,
|
||||
// using urlencoded password, 'simple @,/?:&=+$#pass.com'
|
||||
url:
|
||||
'http://localhost:8378/1/login?username=test&password=simple%20%40%2C%2F%3F%3A%26%3D%2B%24%23pass.com',
|
||||
},
|
||||
() => {
|
||||
request.get(
|
||||
{
|
||||
})
|
||||
.catch(() => {})
|
||||
.then(() => {
|
||||
return request({
|
||||
url: 'http://localhost:8378/1/scriptlog?size=4&level=verbose',
|
||||
json: true,
|
||||
headers: headers,
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(response.statusCode).toEqual(200);
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(response.status).toEqual(200);
|
||||
// 4th entry is our actual GET request
|
||||
expect(body[2].url).toEqual(
|
||||
'/1/login?username=test&password=********'
|
||||
@@ -142,11 +134,10 @@ describe('LogsRouter', () => {
|
||||
'REQUEST for [GET] /1/login?username=test&password=********: {}'
|
||||
);
|
||||
done();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -156,34 +147,31 @@ describe('LogsRouter', () => {
|
||||
reconfigureServer({
|
||||
verbose: true,
|
||||
}).then(function() {
|
||||
request.post(
|
||||
{
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/login',
|
||||
data: {
|
||||
username: 'test',
|
||||
password: 'simplepass.com',
|
||||
},
|
||||
request({
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/login',
|
||||
body: {
|
||||
username: 'test',
|
||||
password: 'simplepass.com',
|
||||
},
|
||||
() => {
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/scriptlog?size=4&level=verbose',
|
||||
json: true,
|
||||
headers: headers,
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(response.statusCode).toEqual(200);
|
||||
// 4th entry is our actual GET request
|
||||
expect(body[2].url).toEqual('/1/login');
|
||||
expect(body[2].message).toEqual(
|
||||
'REQUEST for [POST] /1/login: {}'
|
||||
);
|
||||
done();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch(() => {})
|
||||
.then(() => {
|
||||
request({
|
||||
url: 'http://localhost:8378/1/scriptlog?size=4&level=verbose',
|
||||
headers: headers,
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(response.status).toEqual(200);
|
||||
// 4th entry is our actual GET request
|
||||
expect(body[2].url).toEqual('/1/login');
|
||||
expect(body[2].message).toEqual(
|
||||
'REQUEST for [POST] /1/login: {\n "username": "test",\n "password": "********"\n}'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const request = require('request');
|
||||
const request = require('../lib/request');
|
||||
|
||||
const delayPromise = delay => {
|
||||
return new Promise(resolve => {
|
||||
@@ -153,19 +153,16 @@ describe('Parse.Push', () => {
|
||||
)
|
||||
.then(() => delayPromise(500))
|
||||
.then(() => {
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/classes/_PushStatus',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
},
|
||||
request({
|
||||
url: 'http://localhost:8378/1/classes/_PushStatus',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(body.error).toEqual('unauthorized');
|
||||
done();
|
||||
}
|
||||
);
|
||||
}).then(fail, response => {
|
||||
expect(response.data.error).toEqual('unauthorized');
|
||||
done();
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
jfail(err);
|
||||
@@ -191,28 +188,26 @@ describe('Parse.Push', () => {
|
||||
)
|
||||
.then(() => delayPromise(500)) // put a delay as we keep writing
|
||||
.then(() => {
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/classes/_PushStatus',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
request({
|
||||
url: 'http://localhost:8378/1/classes/_PushStatus',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
(error, response, body) => {
|
||||
try {
|
||||
expect(body.results.length).toEqual(1);
|
||||
expect(body.results[0].query).toEqual('{"deviceType":"ios"}');
|
||||
expect(body.results[0].payload).toEqual(
|
||||
'{"badge":"increment","alert":"Hello world!"}'
|
||||
);
|
||||
} catch (e) {
|
||||
jfail(e);
|
||||
}
|
||||
done();
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
try {
|
||||
expect(body.results.length).toEqual(1);
|
||||
expect(body.results[0].query).toEqual('{"deviceType":"ios"}');
|
||||
expect(body.results[0].payload).toEqual(
|
||||
'{"badge":"increment","alert":"Hello world!"}'
|
||||
);
|
||||
} catch (e) {
|
||||
jfail(e);
|
||||
}
|
||||
);
|
||||
done();
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
jfail(err);
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
// It would probably be better to refactor them into different files.
|
||||
'use strict';
|
||||
|
||||
const request = require('request');
|
||||
const rp = require('request-promise');
|
||||
const request = require('../lib/request');
|
||||
const Parse = require('parse/node');
|
||||
const Config = require('../lib/Config');
|
||||
const SchemaController = require('../lib/Controllers/SchemaController');
|
||||
@@ -92,44 +91,44 @@ describe('miscellaneous', function() {
|
||||
it('fail to create a duplicate username', async () => {
|
||||
let numFailed = 0;
|
||||
let numCreated = 0;
|
||||
const p1 = rp
|
||||
.post(Parse.serverURL + '/users', {
|
||||
json: {
|
||||
password: 'asdf',
|
||||
username: 'u1',
|
||||
email: 'dupe@dupe.dupe',
|
||||
},
|
||||
headers,
|
||||
})
|
||||
.then(
|
||||
() => {
|
||||
numCreated++;
|
||||
expect(numCreated).toEqual(1);
|
||||
},
|
||||
({ error }) => {
|
||||
numFailed++;
|
||||
expect(error.code).toEqual(Parse.Error.USERNAME_TAKEN);
|
||||
}
|
||||
);
|
||||
const p1 = request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/users',
|
||||
body: {
|
||||
password: 'asdf',
|
||||
username: 'u1',
|
||||
email: 'dupe@dupe.dupe',
|
||||
},
|
||||
headers,
|
||||
}).then(
|
||||
() => {
|
||||
numCreated++;
|
||||
expect(numCreated).toEqual(1);
|
||||
},
|
||||
response => {
|
||||
numFailed++;
|
||||
expect(response.data.code).toEqual(Parse.Error.USERNAME_TAKEN);
|
||||
}
|
||||
);
|
||||
|
||||
const p2 = rp
|
||||
.post(Parse.serverURL + '/users', {
|
||||
json: {
|
||||
password: 'otherpassword',
|
||||
username: 'u1',
|
||||
email: 'email@other.email',
|
||||
},
|
||||
headers,
|
||||
})
|
||||
.then(
|
||||
() => {
|
||||
numCreated++;
|
||||
},
|
||||
({ error }) => {
|
||||
numFailed++;
|
||||
expect(error.code).toEqual(Parse.Error.USERNAME_TAKEN);
|
||||
}
|
||||
);
|
||||
const p2 = request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/users',
|
||||
body: {
|
||||
password: 'otherpassword',
|
||||
username: 'u1',
|
||||
email: 'email@other.email',
|
||||
},
|
||||
headers,
|
||||
}).then(
|
||||
() => {
|
||||
numCreated++;
|
||||
},
|
||||
({ data }) => {
|
||||
numFailed++;
|
||||
expect(data.code).toEqual(Parse.Error.USERNAME_TAKEN);
|
||||
}
|
||||
);
|
||||
|
||||
await Promise.all([p1, p2]);
|
||||
expect(numFailed).toEqual(1);
|
||||
@@ -139,45 +138,45 @@ describe('miscellaneous', function() {
|
||||
it('ensure that email is uniquely indexed', async () => {
|
||||
let numFailed = 0;
|
||||
let numCreated = 0;
|
||||
const p1 = rp
|
||||
.post(Parse.serverURL + '/users', {
|
||||
json: {
|
||||
password: 'asdf',
|
||||
username: 'u1',
|
||||
email: 'dupe@dupe.dupe',
|
||||
},
|
||||
headers,
|
||||
})
|
||||
.then(
|
||||
() => {
|
||||
numCreated++;
|
||||
expect(numCreated).toEqual(1);
|
||||
},
|
||||
({ error }) => {
|
||||
numFailed++;
|
||||
expect(error.code).toEqual(Parse.Error.EMAIL_TAKEN);
|
||||
}
|
||||
);
|
||||
const p1 = request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/users',
|
||||
body: {
|
||||
password: 'asdf',
|
||||
username: 'u1',
|
||||
email: 'dupe@dupe.dupe',
|
||||
},
|
||||
headers,
|
||||
}).then(
|
||||
() => {
|
||||
numCreated++;
|
||||
expect(numCreated).toEqual(1);
|
||||
},
|
||||
({ data }) => {
|
||||
numFailed++;
|
||||
expect(data.code).toEqual(Parse.Error.EMAIL_TAKEN);
|
||||
}
|
||||
);
|
||||
|
||||
const p2 = rp
|
||||
.post(Parse.serverURL + '/users', {
|
||||
json: {
|
||||
password: 'asdf',
|
||||
username: 'u2',
|
||||
email: 'dupe@dupe.dupe',
|
||||
},
|
||||
headers,
|
||||
})
|
||||
.then(
|
||||
() => {
|
||||
numCreated++;
|
||||
expect(numCreated).toEqual(1);
|
||||
},
|
||||
({ error }) => {
|
||||
numFailed++;
|
||||
expect(error.code).toEqual(Parse.Error.EMAIL_TAKEN);
|
||||
}
|
||||
);
|
||||
const p2 = request({
|
||||
url: Parse.serverURL + '/users',
|
||||
method: 'POST',
|
||||
body: {
|
||||
password: 'asdf',
|
||||
username: 'u2',
|
||||
email: 'dupe@dupe.dupe',
|
||||
},
|
||||
headers,
|
||||
}).then(
|
||||
() => {
|
||||
numCreated++;
|
||||
expect(numCreated).toEqual(1);
|
||||
},
|
||||
({ data }) => {
|
||||
numFailed++;
|
||||
expect(data.code).toEqual(Parse.Error.EMAIL_TAKEN);
|
||||
}
|
||||
);
|
||||
|
||||
await Promise.all([p1, p2]);
|
||||
expect(numFailed).toEqual(1);
|
||||
@@ -962,51 +961,46 @@ describe('miscellaneous', function() {
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
'X-Parse-Installation-Id': 'yolo',
|
||||
};
|
||||
request.put(
|
||||
{
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/GameScore/' + obj.id,
|
||||
body: JSON.stringify({
|
||||
a: 'b',
|
||||
c: { __op: 'Increment', amount: 2 },
|
||||
d: { __op: 'Add', objects: ['2'] },
|
||||
e: { __op: 'AddUnique', objects: ['1', '2'] },
|
||||
f: { __op: 'Remove', objects: ['2'] },
|
||||
selfThing: {
|
||||
__type: 'Pointer',
|
||||
className: 'GameScore',
|
||||
objectId: obj.id,
|
||||
},
|
||||
}),
|
||||
},
|
||||
(error, response, body) => {
|
||||
try {
|
||||
body = JSON.parse(body);
|
||||
expect(body.a).toBeUndefined();
|
||||
expect(body.c).toEqual(3); // 2+1
|
||||
expect(body.d.length).toBe(2);
|
||||
expect(body.d.indexOf('1') > -1).toBe(true);
|
||||
expect(body.d.indexOf('2') > -1).toBe(true);
|
||||
expect(body.e.length).toBe(2);
|
||||
expect(body.e.indexOf('1') > -1).toBe(true);
|
||||
expect(body.e.indexOf('2') > -1).toBe(true);
|
||||
expect(body.f.length).toBe(1);
|
||||
expect(body.f.indexOf('1') > -1).toBe(true);
|
||||
// return nothing on other self
|
||||
expect(body.selfThing).toBeUndefined();
|
||||
// updatedAt is always set
|
||||
expect(body.updatedAt).not.toBeUndefined();
|
||||
} catch (e) {
|
||||
jfail(e);
|
||||
}
|
||||
done();
|
||||
request({
|
||||
method: 'PUT',
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/GameScore/' + obj.id,
|
||||
body: JSON.stringify({
|
||||
a: 'b',
|
||||
c: { __op: 'Increment', amount: 2 },
|
||||
d: { __op: 'Add', objects: ['2'] },
|
||||
e: { __op: 'AddUnique', objects: ['1', '2'] },
|
||||
f: { __op: 'Remove', objects: ['2'] },
|
||||
selfThing: {
|
||||
__type: 'Pointer',
|
||||
className: 'GameScore',
|
||||
objectId: obj.id,
|
||||
},
|
||||
}),
|
||||
}).then(response => {
|
||||
try {
|
||||
const body = response.data;
|
||||
expect(body.a).toBeUndefined();
|
||||
expect(body.c).toEqual(3); // 2+1
|
||||
expect(body.d.length).toBe(2);
|
||||
expect(body.d.indexOf('1') > -1).toBe(true);
|
||||
expect(body.d.indexOf('2') > -1).toBe(true);
|
||||
expect(body.e.length).toBe(2);
|
||||
expect(body.e.indexOf('1') > -1).toBe(true);
|
||||
expect(body.e.indexOf('2') > -1).toBe(true);
|
||||
expect(body.f.length).toBe(1);
|
||||
expect(body.f.indexOf('1') > -1).toBe(true);
|
||||
// return nothing on other self
|
||||
expect(body.selfThing).toBeUndefined();
|
||||
// updatedAt is always set
|
||||
expect(body.updatedAt).not.toBeUndefined();
|
||||
} catch (e) {
|
||||
fail(e);
|
||||
}
|
||||
);
|
||||
done();
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
fail('Should not fail');
|
||||
done();
|
||||
});
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('test cloud function error handling', done => {
|
||||
@@ -1082,18 +1076,15 @@ describe('miscellaneous', function() {
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
'X-Parse-Installation-Id': 'yolo',
|
||||
};
|
||||
request.post(
|
||||
{
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/GameScore',
|
||||
body: JSON.stringify({ a: 'b' }),
|
||||
},
|
||||
error => {
|
||||
expect(error).toBe(null);
|
||||
expect(triggerTime).toEqual(2);
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/GameScore',
|
||||
body: JSON.stringify({ a: 'b' }),
|
||||
}).then(() => {
|
||||
expect(triggerTime).toEqual(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('test beforeDelete/afterDelete get installationId', function(done) {
|
||||
@@ -1115,29 +1106,22 @@ describe('miscellaneous', function() {
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
'X-Parse-Installation-Id': 'yolo',
|
||||
};
|
||||
request.post(
|
||||
{
|
||||
request({
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/GameScore',
|
||||
body: JSON.stringify({ a: 'b' }),
|
||||
}).then(response => {
|
||||
request({
|
||||
method: 'DELETE',
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/GameScore',
|
||||
body: JSON.stringify({ a: 'b' }),
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(error).toBe(null);
|
||||
request.del(
|
||||
{
|
||||
headers: headers,
|
||||
url:
|
||||
'http://localhost:8378/1/classes/GameScore/' +
|
||||
JSON.parse(body).objectId,
|
||||
},
|
||||
error => {
|
||||
expect(error).toBe(null);
|
||||
expect(triggerTime).toEqual(2);
|
||||
done();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
url:
|
||||
'http://localhost:8378/1/classes/GameScore/' + response.data.objectId,
|
||||
}).then(() => {
|
||||
expect(triggerTime).toEqual(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('test beforeDelete with locked down ACL', async () => {
|
||||
@@ -1167,26 +1151,23 @@ describe('miscellaneous', function() {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
};
|
||||
request.post(
|
||||
{
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/functions/echoParams', //?option=1&other=2
|
||||
qs: {
|
||||
option: 1,
|
||||
other: 2,
|
||||
},
|
||||
body: '{"foo":"bar", "other": 1}',
|
||||
request({
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/functions/echoParams', //?option=1&other=2
|
||||
qs: {
|
||||
option: 1,
|
||||
other: 2,
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(error).toBe(null);
|
||||
const res = JSON.parse(body).result;
|
||||
expect(res.option).toEqual('1');
|
||||
// Make sure query string params override body params
|
||||
expect(res.other).toEqual('2');
|
||||
expect(res.foo).toEqual('bar');
|
||||
done();
|
||||
}
|
||||
);
|
||||
body: '{"foo":"bar", "other": 1}',
|
||||
}).then(response => {
|
||||
const res = response.data.result;
|
||||
expect(res.option).toEqual('1');
|
||||
// Make sure query string params override body params
|
||||
expect(res.other).toEqual('2');
|
||||
expect(res.foo).toEqual('bar');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('test cloud function parameter validation', done => {
|
||||
@@ -1258,18 +1239,14 @@ describe('miscellaneous', function() {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Client-Key': 'notclient',
|
||||
};
|
||||
request.get(
|
||||
{
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(error).toBe(null);
|
||||
const b = JSON.parse(body);
|
||||
expect(b.error).toEqual('unauthorized');
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
}).then(fail, response => {
|
||||
const b = response.data;
|
||||
expect(b.error).toEqual('unauthorized');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('fails on invalid windows key', done => {
|
||||
@@ -1278,18 +1255,14 @@ describe('miscellaneous', function() {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Windows-Key': 'notwindows',
|
||||
};
|
||||
request.get(
|
||||
{
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(error).toBe(null);
|
||||
const b = JSON.parse(body);
|
||||
expect(b.error).toEqual('unauthorized');
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
}).then(fail, response => {
|
||||
const b = response.data;
|
||||
expect(b.error).toEqual('unauthorized');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('fails on invalid javascript key', done => {
|
||||
@@ -1298,18 +1271,14 @@ describe('miscellaneous', function() {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'notjavascript',
|
||||
};
|
||||
request.get(
|
||||
{
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(error).toBe(null);
|
||||
const b = JSON.parse(body);
|
||||
expect(b.error).toEqual('unauthorized');
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
}).then(fail, response => {
|
||||
const b = response.data;
|
||||
expect(b.error).toEqual('unauthorized');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('fails on invalid rest api key', done => {
|
||||
@@ -1318,18 +1287,14 @@ describe('miscellaneous', function() {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'notrest',
|
||||
};
|
||||
request.get(
|
||||
{
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(error).toBe(null);
|
||||
const b = JSON.parse(body);
|
||||
expect(b.error).toEqual('unauthorized');
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
}).then(fail, response => {
|
||||
const b = response.data;
|
||||
expect(b.error).toEqual('unauthorized');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('fails on invalid function', done => {
|
||||
@@ -1360,16 +1325,15 @@ describe('miscellaneous', function() {
|
||||
};
|
||||
const requestOptions = {
|
||||
headers: headers,
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/installations',
|
||||
body: JSON.stringify(data),
|
||||
};
|
||||
request.post(requestOptions, (error, response, body) => {
|
||||
expect(error).toBe(null);
|
||||
const b = JSON.parse(body);
|
||||
request(requestOptions).then(response => {
|
||||
const b = response.data;
|
||||
expect(typeof b.objectId).toEqual('string');
|
||||
request.post(requestOptions, (error, response, body) => {
|
||||
expect(error).toBe(null);
|
||||
const b = JSON.parse(body);
|
||||
request(requestOptions).then(response => {
|
||||
const b = response.data;
|
||||
expect(typeof b.updatedAt).toEqual('string');
|
||||
done();
|
||||
});
|
||||
@@ -1388,16 +1352,15 @@ describe('miscellaneous', function() {
|
||||
authData: {},
|
||||
};
|
||||
const requestOptions = {
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/users',
|
||||
body: JSON.stringify(data),
|
||||
};
|
||||
request.post(requestOptions, error => {
|
||||
expect(error).toBe(null);
|
||||
request(requestOptions).then(() => {
|
||||
requestOptions.url = 'http://localhost:8378/1/login';
|
||||
request.get(requestOptions, (error, response, body) => {
|
||||
expect(error).toBe(null);
|
||||
const b = JSON.parse(body);
|
||||
request(requestOptions).then(response => {
|
||||
const b = response.data;
|
||||
expect(typeof b['sessionToken']).toEqual('string');
|
||||
done();
|
||||
});
|
||||
@@ -1423,7 +1386,8 @@ describe('miscellaneous', function() {
|
||||
url: 'http://localhost:8378/1/classes/AnObject',
|
||||
json: true,
|
||||
};
|
||||
request.get(requestOptions, (err, res, body) => {
|
||||
request(requestOptions).then(res => {
|
||||
const body = res.data;
|
||||
expect(body.results.length).toBe(1);
|
||||
const result = body.results[0];
|
||||
expect(result.related).toEqual({
|
||||
@@ -1461,16 +1425,9 @@ describe('miscellaneous', function() {
|
||||
},
|
||||
},
|
||||
url: 'http://localhost:8378/1/classes/AnObject/' + object.id,
|
||||
method: 'PUT',
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
request.put(options, (err, res, body) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(body);
|
||||
}
|
||||
});
|
||||
});
|
||||
return request(options).then(res => res.data);
|
||||
}
|
||||
|
||||
object
|
||||
@@ -1492,29 +1449,27 @@ describe('miscellaneous', function() {
|
||||
const object = new Parse.Object('AnObject');
|
||||
object.set('a', 'b');
|
||||
object.save().then(() => {
|
||||
request.post(
|
||||
{
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
url: 'http://localhost:8378/1/classes/AnObject',
|
||||
body: {
|
||||
_method: 'GET',
|
||||
_ApplicationId: 'test',
|
||||
_JavaScriptKey: 'test',
|
||||
_ClientVersion: 'js1.8.3',
|
||||
_InstallationId: 'iid',
|
||||
_RevocableSession: '1',
|
||||
},
|
||||
json: true,
|
||||
request({
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
url: 'http://localhost:8378/1/classes/AnObject',
|
||||
body: {
|
||||
_method: 'GET',
|
||||
_ApplicationId: 'test',
|
||||
_JavaScriptKey: 'test',
|
||||
_ClientVersion: 'js1.8.3',
|
||||
_InstallationId: 'iid',
|
||||
_RevocableSession: '1',
|
||||
},
|
||||
(err, res, body) => {
|
||||
expect(body.error).toBeUndefined();
|
||||
expect(body.results).not.toBeUndefined();
|
||||
expect(body.results.length).toBe(1);
|
||||
const result = body.results[0];
|
||||
expect(result.a).toBe('b');
|
||||
done();
|
||||
}
|
||||
);
|
||||
}).then(res => {
|
||||
const body = res.data;
|
||||
expect(body.error).toBeUndefined();
|
||||
expect(body.results).not.toBeUndefined();
|
||||
expect(body.results.length).toBe(1);
|
||||
const result = body.results[0];
|
||||
expect(result.a).toBe('b');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1654,21 +1609,17 @@ describe('miscellaneous', function() {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
};
|
||||
request.del(
|
||||
{
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/purge/TestObject',
|
||||
json: true,
|
||||
},
|
||||
err => {
|
||||
expect(err).toBe(null);
|
||||
const query = new Parse.Query(TestObject);
|
||||
return query.count().then(count => {
|
||||
expect(count).toBe(0);
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
request({
|
||||
method: 'DELETE',
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/purge/TestObject',
|
||||
}).then(() => {
|
||||
const query = new Parse.Query(TestObject);
|
||||
return query.count().then(count => {
|
||||
expect(count).toBe(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1678,17 +1629,18 @@ describe('miscellaneous', function() {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
};
|
||||
rp({
|
||||
request({
|
||||
method: 'DELETE',
|
||||
headers: headers,
|
||||
uri: 'http://localhost:8378/1/purge/TestObject',
|
||||
json: true,
|
||||
url: 'http://localhost:8378/1/purge/TestObject',
|
||||
})
|
||||
.then(() => {
|
||||
fail('Should not succeed');
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.error).toEqual('unauthorized: master key is required');
|
||||
.catch(response => {
|
||||
expect(response.data.error).toEqual(
|
||||
'unauthorized: master key is required'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -1739,10 +1691,10 @@ describe('miscellaneous', function() {
|
||||
})
|
||||
.then(x => {
|
||||
expect(x.length).toEqual(1);
|
||||
return rp({
|
||||
return request({
|
||||
method: 'DELETE',
|
||||
headers: headers,
|
||||
uri: 'http://localhost:8378/1/purge/_Role',
|
||||
url: 'http://localhost:8378/1/purge/_Role',
|
||||
json: true,
|
||||
});
|
||||
})
|
||||
@@ -1789,20 +1741,20 @@ describe('miscellaneous', function() {
|
||||
done();
|
||||
},
|
||||
() => {
|
||||
return rp({
|
||||
return request({
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
uri: 'http://localhost:8378/1/schemas/MyObject',
|
||||
url: 'http://localhost:8378/1/schemas/MyObject',
|
||||
json: true,
|
||||
});
|
||||
}
|
||||
)
|
||||
.then(
|
||||
res => {
|
||||
const fields = res.fields;
|
||||
const fields = res.data.fields;
|
||||
expect(fields.secret).toBeUndefined();
|
||||
done();
|
||||
},
|
||||
@@ -1819,11 +1771,12 @@ describe_only_db('mongo')('legacy _acl', () => {
|
||||
const headers = {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
rp({
|
||||
request({
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
uri: 'http://localhost:8378/1/classes/Report',
|
||||
url: 'http://localhost:8378/1/classes/Report',
|
||||
body: {
|
||||
ACL: {},
|
||||
name: 'My Report',
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
// This is a port of the test suite:
|
||||
// hungry/js/test/parse_geo_point_test.js
|
||||
|
||||
const rp = require('request-promise');
|
||||
const request = require('../lib/request');
|
||||
const TestObject = Parse.Object.extend('TestObject');
|
||||
|
||||
describe('Parse.GeoPoint testing', () => {
|
||||
@@ -381,17 +381,19 @@ describe('Parse.GeoPoint testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
expect(resp.data.results.length).toBe(2);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
@@ -418,17 +420,19 @@ describe('Parse.GeoPoint testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
expect(resp.data.results.length).toBe(2);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
@@ -453,17 +457,19 @@ describe('Parse.GeoPoint testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
expect(resp.data.results.length).toBe(2);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
@@ -485,12 +491,14 @@ describe('Parse.GeoPoint testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
@@ -499,7 +507,7 @@ describe('Parse.GeoPoint testing', () => {
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
expect(err.data.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -521,12 +529,14 @@ describe('Parse.GeoPoint testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
@@ -535,7 +545,7 @@ describe('Parse.GeoPoint testing', () => {
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(1);
|
||||
expect(err.data.code).toEqual(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -553,12 +563,14 @@ describe('Parse.GeoPoint testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
@@ -567,7 +579,7 @@ describe('Parse.GeoPoint testing', () => {
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
expect(err.data.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -585,12 +597,14 @@ describe('Parse.GeoPoint testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
@@ -599,7 +613,7 @@ describe('Parse.GeoPoint testing', () => {
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
expect(err.data.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -621,12 +635,14 @@ describe('Parse.GeoPoint testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
@@ -635,7 +651,7 @@ describe('Parse.GeoPoint testing', () => {
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(1);
|
||||
expect(err.data.code).toEqual(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -657,12 +673,14 @@ describe('Parse.GeoPoint testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
@@ -671,7 +689,7 @@ describe('Parse.GeoPoint testing', () => {
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(1);
|
||||
expect(err.data.code).toEqual(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -689,12 +707,14 @@ describe('Parse.GeoPoint testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
@@ -703,7 +723,7 @@ describe('Parse.GeoPoint testing', () => {
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(107);
|
||||
expect(err.data.code).toEqual(107);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const request = require('request');
|
||||
const request = require('../lib/request');
|
||||
const Config = require('../lib/Config');
|
||||
|
||||
describe('a GlobalConfig', () => {
|
||||
@@ -31,154 +31,134 @@ describe('a GlobalConfig', () => {
|
||||
});
|
||||
});
|
||||
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
};
|
||||
|
||||
it('can be retrieved', done => {
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/config',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
},
|
||||
(error, response, body) => {
|
||||
try {
|
||||
expect(response.statusCode).toEqual(200);
|
||||
expect(body.params.companies).toEqual(['US', 'DK']);
|
||||
} catch (e) {
|
||||
jfail(e);
|
||||
}
|
||||
done();
|
||||
request({
|
||||
url: 'http://localhost:8378/1/config',
|
||||
json: true,
|
||||
headers,
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
try {
|
||||
expect(response.status).toEqual(200);
|
||||
expect(body.params.companies).toEqual(['US', 'DK']);
|
||||
} catch (e) {
|
||||
jfail(e);
|
||||
}
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can be updated when a master key exists', done => {
|
||||
request.put(
|
||||
{
|
||||
url: 'http://localhost:8378/1/config',
|
||||
json: true,
|
||||
body: { params: { companies: ['US', 'DK', 'SE'] } },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(response.statusCode).toEqual(200);
|
||||
expect(body.result).toEqual(true);
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
method: 'PUT',
|
||||
url: 'http://localhost:8378/1/config',
|
||||
json: true,
|
||||
body: { params: { companies: ['US', 'DK', 'SE'] } },
|
||||
headers,
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(response.status).toEqual(200);
|
||||
expect(body.result).toEqual(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can add and retrive files', done => {
|
||||
request.put(
|
||||
{
|
||||
url: 'http://localhost:8378/1/config',
|
||||
json: true,
|
||||
body: {
|
||||
params: { file: { __type: 'File', name: 'name', url: 'http://url' } },
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
request({
|
||||
method: 'PUT',
|
||||
url: 'http://localhost:8378/1/config',
|
||||
json: true,
|
||||
body: {
|
||||
params: { file: { __type: 'File', name: 'name', url: 'http://url' } },
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(response.statusCode).toEqual(200);
|
||||
expect(body.result).toEqual(true);
|
||||
Parse.Config.get().then(res => {
|
||||
const file = res.get('file');
|
||||
expect(file.name()).toBe('name');
|
||||
expect(file.url()).toBe('http://url');
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
headers,
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(response.status).toEqual(200);
|
||||
expect(body.result).toEqual(true);
|
||||
Parse.Config.get().then(res => {
|
||||
const file = res.get('file');
|
||||
expect(file.name()).toBe('name');
|
||||
expect(file.url()).toBe('http://url');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('can add and retrive Geopoints', done => {
|
||||
const geopoint = new Parse.GeoPoint(10, -20);
|
||||
request.put(
|
||||
{
|
||||
url: 'http://localhost:8378/1/config',
|
||||
json: true,
|
||||
body: { params: { point: geopoint.toJSON() } },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(response.statusCode).toEqual(200);
|
||||
expect(body.result).toEqual(true);
|
||||
Parse.Config.get().then(res => {
|
||||
const point = res.get('point');
|
||||
expect(point.latitude).toBe(10);
|
||||
expect(point.longitude).toBe(-20);
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
request({
|
||||
method: 'PUT',
|
||||
url: 'http://localhost:8378/1/config',
|
||||
json: true,
|
||||
body: { params: { point: geopoint.toJSON() } },
|
||||
headers,
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(response.status).toEqual(200);
|
||||
expect(body.result).toEqual(true);
|
||||
Parse.Config.get().then(res => {
|
||||
const point = res.get('point');
|
||||
expect(point.latitude).toBe(10);
|
||||
expect(point.longitude).toBe(-20);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('properly handles delete op', done => {
|
||||
request.put(
|
||||
{
|
||||
request({
|
||||
method: 'PUT',
|
||||
url: 'http://localhost:8378/1/config',
|
||||
json: true,
|
||||
body: { params: { companies: { __op: 'Delete' }, foo: 'bar' } },
|
||||
headers,
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(response.status).toEqual(200);
|
||||
expect(body.result).toEqual(true);
|
||||
request({
|
||||
url: 'http://localhost:8378/1/config',
|
||||
json: true,
|
||||
body: { params: { companies: { __op: 'Delete' }, foo: 'bar' } },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(response.statusCode).toEqual(200);
|
||||
expect(body.result).toEqual(true);
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/config',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
},
|
||||
(error, response, body) => {
|
||||
try {
|
||||
expect(response.statusCode).toEqual(200);
|
||||
expect(body.params.companies).toBeUndefined();
|
||||
expect(body.params.foo).toBe('bar');
|
||||
expect(Object.keys(body.params).length).toBe(1);
|
||||
} catch (e) {
|
||||
jfail(e);
|
||||
}
|
||||
done();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
headers,
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
try {
|
||||
expect(response.status).toEqual(200);
|
||||
expect(body.params.companies).toBeUndefined();
|
||||
expect(body.params.foo).toBe('bar');
|
||||
expect(Object.keys(body.params).length).toBe(1);
|
||||
} catch (e) {
|
||||
jfail(e);
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('fail to update if master key is missing', done => {
|
||||
request.put(
|
||||
{
|
||||
url: 'http://localhost:8378/1/config',
|
||||
json: true,
|
||||
body: { params: { companies: [] } },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
request({
|
||||
method: 'PUT',
|
||||
url: 'http://localhost:8378/1/config',
|
||||
json: true,
|
||||
body: { params: { companies: [] } },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(response.statusCode).toEqual(403);
|
||||
expect(body.error).toEqual('unauthorized: master key is required');
|
||||
done();
|
||||
}
|
||||
);
|
||||
}).then(fail, response => {
|
||||
const body = response.data;
|
||||
expect(response.status).toEqual(403);
|
||||
expect(body.error).toEqual('unauthorized: master key is required');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('failed getting config when it is missing', done => {
|
||||
@@ -190,21 +170,16 @@ describe('a GlobalConfig', () => {
|
||||
{ objectId: '1' }
|
||||
)
|
||||
.then(() => {
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/config',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(response.statusCode).toEqual(200);
|
||||
expect(body.params).toEqual({});
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
url: 'http://localhost:8378/1/config',
|
||||
json: true,
|
||||
headers,
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(response.status).toEqual(200);
|
||||
expect(body.params).toEqual({});
|
||||
done();
|
||||
});
|
||||
})
|
||||
.catch(e => {
|
||||
jfail(e);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
/* global describe, it, expect, fail, Parse */
|
||||
const request = require('request');
|
||||
const request = require('../lib/request');
|
||||
const triggers = require('../lib/triggers');
|
||||
const HooksController = require('../lib/Controllers/HooksController').default;
|
||||
const express = require('express');
|
||||
@@ -177,24 +177,21 @@ describe('Hooks', () => {
|
||||
});
|
||||
|
||||
it('should fail to register hooks without Master Key', done => {
|
||||
request.post(
|
||||
Parse.serverURL + '/hooks/functions',
|
||||
{
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-REST-API-Key': Parse.restKey,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
url: 'http://hello.word',
|
||||
functionName: 'SomeFunction',
|
||||
}),
|
||||
request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/hooks/functions',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
},
|
||||
(err, res, body) => {
|
||||
body = JSON.parse(body);
|
||||
expect(body.error).toBe('unauthorized');
|
||||
done();
|
||||
}
|
||||
);
|
||||
body: JSON.stringify({
|
||||
url: 'http://hello.word',
|
||||
functionName: 'SomeFunction',
|
||||
}),
|
||||
}).then(fail, response => {
|
||||
const body = response.data;
|
||||
expect(body.error).toBe('unauthorized');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail trying to create two times the same function', done => {
|
||||
@@ -367,22 +364,20 @@ describe('Hooks', () => {
|
||||
});
|
||||
|
||||
it('should fail trying to create a malformed function (REST)', done => {
|
||||
request.post(
|
||||
Parse.serverURL + '/hooks/functions',
|
||||
{
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': Parse.masterKey,
|
||||
},
|
||||
body: JSON.stringify({ functionName: 'SomeFunction' }),
|
||||
request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/hooks/functions',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': Parse.masterKey,
|
||||
},
|
||||
(err, res, body) => {
|
||||
body = JSON.parse(body);
|
||||
expect(body.error).toBe('invalid hook declaration');
|
||||
expect(body.code).toBe(143);
|
||||
done();
|
||||
}
|
||||
);
|
||||
body: JSON.stringify({ functionName: 'SomeFunction' }),
|
||||
}).then(fail, response => {
|
||||
const body = response.data;
|
||||
expect(body.error).toBe('invalid hook declaration');
|
||||
expect(body.code).toBe(143);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should create hooks and properly preload them', done => {
|
||||
|
||||
@@ -6,7 +6,7 @@ const auth = require('../lib/Auth');
|
||||
const Config = require('../lib/Config');
|
||||
const Parse = require('parse/node').Parse;
|
||||
const rest = require('../lib/rest');
|
||||
const request = require('request');
|
||||
const request = require('../lib/request');
|
||||
|
||||
let config;
|
||||
let database;
|
||||
@@ -1223,19 +1223,16 @@ describe('Installations', () => {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
};
|
||||
request.get(
|
||||
{
|
||||
headers: headers,
|
||||
url:
|
||||
'http://localhost:8378/1/installations/' +
|
||||
createResult.response.objectId,
|
||||
json: true,
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(body.objectId).toEqual(createResult.response.objectId);
|
||||
done();
|
||||
}
|
||||
);
|
||||
return request({
|
||||
headers: headers,
|
||||
url:
|
||||
'http://localhost:8378/1/installations/' +
|
||||
createResult.response.objectId,
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(body.objectId).toEqual(createResult.response.objectId);
|
||||
done();
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
@@ -1259,21 +1256,20 @@ describe('Installations', () => {
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
'X-Parse-Installation-Id': installId,
|
||||
};
|
||||
request.post(
|
||||
{
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/_Installation',
|
||||
json: true,
|
||||
body: {
|
||||
date: new Date(),
|
||||
},
|
||||
request({
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/_Installation',
|
||||
json: true,
|
||||
body: {
|
||||
date: new Date(),
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(body.updatedAt).not.toBeUndefined();
|
||||
done();
|
||||
}
|
||||
);
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(response.status).toBe(200);
|
||||
expect(body.updatedAt).not.toBeUndefined();
|
||||
done();
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
|
||||
@@ -3,10 +3,11 @@ const MongoStorageAdapter = require('../lib/Adapters/Storage/Mongo/MongoStorageA
|
||||
.default;
|
||||
const mongoURI =
|
||||
'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase';
|
||||
const rp = require('request-promise');
|
||||
const request = require('../lib/request');
|
||||
const defaultHeaders = {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Rest-API-Key': 'rest',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
describe('Parse.Polygon testing', () => {
|
||||
@@ -174,17 +175,19 @@ describe('Parse.Polygon testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
expect(resp.data.results.length).toBe(2);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
@@ -208,17 +211,19 @@ describe('Parse.Polygon testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
expect(resp.data.results.length).toBe(2);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
@@ -247,17 +252,19 @@ describe('Parse.Polygon testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(1);
|
||||
expect(resp.data.results.length).toBe(1);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
@@ -276,9 +283,10 @@ describe('Parse.Polygon testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
@@ -302,9 +310,10 @@ describe('Parse.Polygon testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
@@ -339,9 +348,10 @@ describe_only_db('mongo')('Parse.Polygon testing', () => {
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
json: {
|
||||
body: {
|
||||
_method: 'POST',
|
||||
location,
|
||||
polygon,
|
||||
@@ -351,16 +361,19 @@ describe_only_db('mongo')('Parse.Polygon testing', () => {
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
return rp.post({
|
||||
url: `http://localhost:8378/1/classes/TestObject/${resp.objectId}`,
|
||||
json: { _method: 'GET' },
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: `http://localhost:8378/1/classes/TestObject/${
|
||||
resp.data.objectId
|
||||
}`,
|
||||
body: { _method: 'GET' },
|
||||
headers: defaultHeaders,
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
equal(resp.location, location);
|
||||
equal(resp.polygon, polygon);
|
||||
equal(resp.polygon2, polygon);
|
||||
equal(resp.data.location, location);
|
||||
equal(resp.data.polygon, polygon);
|
||||
equal(resp.data.polygon2, polygon);
|
||||
return databaseAdapter.getIndexes('TestObject');
|
||||
})
|
||||
.then(indexes => {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
'use strict';
|
||||
const Parse = require('parse/node');
|
||||
const rp = require('request-promise');
|
||||
const request = require('../lib/request');
|
||||
|
||||
const masterKeyHeaders = {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Rest-API-Key': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
const masterKeyOptions = {
|
||||
@@ -53,6 +54,19 @@ const loadTestData = () => {
|
||||
return Parse.Object.saveAll([obj1, obj2, obj3, obj4]);
|
||||
};
|
||||
|
||||
const get = function(url, options) {
|
||||
options.qs = options.body;
|
||||
delete options.body;
|
||||
Object.keys(options.qs).forEach(key => {
|
||||
options.qs[key] = JSON.stringify(options.qs[key]);
|
||||
});
|
||||
return request(Object.assign({}, { url }, options))
|
||||
.then(response => response.data)
|
||||
.catch(response => {
|
||||
throw { error: response.data };
|
||||
});
|
||||
};
|
||||
|
||||
describe('Parse.Query Aggregate testing', () => {
|
||||
beforeEach(done => {
|
||||
loadTestData().then(done, done);
|
||||
@@ -74,7 +88,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
unknown: {},
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options).catch(error => {
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options).catch(error => {
|
||||
expect(error.error.code).toEqual(Parse.Error.INVALID_QUERY);
|
||||
done();
|
||||
});
|
||||
@@ -86,7 +100,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
group: { _id: null },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options).catch(error => {
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options).catch(error => {
|
||||
expect(error.error.code).toEqual(Parse.Error.INVALID_QUERY);
|
||||
done();
|
||||
});
|
||||
@@ -98,7 +112,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
group: {},
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options).catch(error => {
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options).catch(error => {
|
||||
expect(error.error.code).toEqual(Parse.Error.INVALID_QUERY);
|
||||
done();
|
||||
});
|
||||
@@ -110,7 +124,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
group: { objectId: '$name' },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(3);
|
||||
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
|
||||
@@ -132,10 +146,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
const resp = await rp.get(
|
||||
Parse.serverURL + '/aggregate/TestObject',
|
||||
options
|
||||
);
|
||||
const resp = await get(Parse.serverURL + '/aggregate/TestObject', options);
|
||||
expect(resp.results.length).toBe(3);
|
||||
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
|
||||
expect(resp.results[1].hasOwnProperty('objectId')).toBe(true);
|
||||
@@ -429,7 +440,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
group: { objectId: null, total: { $sum: '$score' } },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
|
||||
expect(resp.results[0].objectId).toBe(null);
|
||||
@@ -445,7 +456,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
group: { objectId: null, total: { $sum: 1 } },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
|
||||
expect(resp.results[0].objectId).toBe(null);
|
||||
@@ -461,7 +472,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
group: { objectId: null, minScore: { $min: '$score' } },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
|
||||
expect(resp.results[0].objectId).toBe(null);
|
||||
@@ -477,7 +488,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
group: { objectId: null, maxScore: { $max: '$score' } },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
|
||||
expect(resp.results[0].objectId).toBe(null);
|
||||
@@ -493,7 +504,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
group: { objectId: null, avgScore: { $avg: '$score' } },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results[0].hasOwnProperty('objectId')).toBe(true);
|
||||
expect(resp.results[0].objectId).toBe(null);
|
||||
@@ -509,7 +520,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
limit: 2,
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
done();
|
||||
@@ -523,7 +534,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
sort: { name: 1 },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(4);
|
||||
expect(resp.results[0].name).toBe('bar');
|
||||
@@ -541,7 +552,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
sort: { name: -1 },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(4);
|
||||
expect(resp.results[0].name).toBe('foo');
|
||||
@@ -559,7 +570,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
skip: 2,
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
done();
|
||||
@@ -594,7 +605,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
match: { score: { $gt: 15 } },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(1);
|
||||
expect(resp.results[0].score).toBe(20);
|
||||
@@ -609,7 +620,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
match: { score: { $gt: 5, $lt: 15 } },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(3);
|
||||
expect(resp.results[0].score).toBe(10);
|
||||
@@ -626,7 +637,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
match: { score: { $gt: 5, $lt: 15 }, views: { $gt: 850, $lt: 1000 } },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(1);
|
||||
expect(resp.results[0].score).toBe(10);
|
||||
@@ -642,7 +653,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
match: { score: { $gt: 5, $lt: 15 }, views: 900 },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(1);
|
||||
expect(resp.results[0].score).toBe(10);
|
||||
@@ -663,7 +674,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
// Match score { $gt: 15, $lt: 25 }
|
||||
@@ -847,7 +858,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
project: { name: 1 },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
resp.results.forEach(result => {
|
||||
expect(result.objectId).not.toBe(undefined);
|
||||
@@ -867,7 +878,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
project: { name: 1, score: 1, sender: 1 },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
resp.results.forEach(result => {
|
||||
expect(result.objectId).not.toBe(undefined);
|
||||
@@ -911,7 +922,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
group: { objectId: '$score', score: { $sum: '$score' } },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
resp.results.forEach(result => {
|
||||
@@ -938,7 +949,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
group: { objectId: null, total: { $sum: '$score' } },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/UnknownClass', options)
|
||||
get(Parse.serverURL + '/aggregate/UnknownClass', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(0);
|
||||
done();
|
||||
@@ -952,7 +963,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
group: { objectId: null, total: { $sum: '$unknownfield' } },
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/UnknownClass', options)
|
||||
get(Parse.serverURL + '/aggregate/UnknownClass', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(0);
|
||||
done();
|
||||
@@ -964,7 +975,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: { distinct: 'score' },
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
expect(resp.results.includes(10)).toBe(true);
|
||||
@@ -983,7 +994,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results[0]).toBe(10);
|
||||
done();
|
||||
@@ -998,7 +1009,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
where: JSON.stringify({ name: 'bar' }),
|
||||
},
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results[0]).toBe(10);
|
||||
done();
|
||||
@@ -1010,7 +1021,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: { distinct: 'sender.group' },
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
expect(resp.results.includes('A')).toBe(true);
|
||||
@@ -1047,7 +1058,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: { distinct: 'unknown' },
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/UnknownClass', options)
|
||||
get(Parse.serverURL + '/aggregate/UnknownClass', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(0);
|
||||
done();
|
||||
@@ -1063,7 +1074,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
obj
|
||||
.save()
|
||||
.then(() => {
|
||||
return rp.get(Parse.serverURL + '/aggregate/TestObject', options);
|
||||
return get(Parse.serverURL + '/aggregate/TestObject', options);
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(0);
|
||||
@@ -1076,7 +1087,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: { distinct: 'size' },
|
||||
});
|
||||
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
get(Parse.serverURL + '/aggregate/TestObject', options)
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(3);
|
||||
expect(resp.results.includes('S')).toBe(true);
|
||||
@@ -1106,7 +1117,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
return user2.signUp();
|
||||
})
|
||||
.then(() => {
|
||||
return rp.get(Parse.serverURL + '/aggregate/_User', options);
|
||||
return get(Parse.serverURL + '/aggregate/_User', options);
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toEqual(1);
|
||||
@@ -1137,7 +1148,7 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
user
|
||||
.signUp()
|
||||
.then(function() {
|
||||
return rp.get(Parse.serverURL + '/aggregate/_User', options);
|
||||
return get(Parse.serverURL + '/aggregate/_User', options);
|
||||
})
|
||||
.then(function(resp) {
|
||||
expect(resp.results.length).toBe(1);
|
||||
@@ -1177,39 +1188,41 @@ describe('Parse.Query Aggregate testing', () => {
|
||||
const obj3 = new TestObject({ pointer: pointer3, name: 'World' });
|
||||
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: [
|
||||
{
|
||||
match: { name: 'Hello' },
|
||||
},
|
||||
{
|
||||
// Transform className$objectId to objectId and store in new field tempPointer
|
||||
project: {
|
||||
tempPointer: { $substr: ['$_p_pointer', 11, -1] }, // Remove TestObject$
|
||||
body: {
|
||||
pipeline: [
|
||||
{
|
||||
match: { name: 'Hello' },
|
||||
},
|
||||
},
|
||||
{
|
||||
// Left Join, replace objectId stored in tempPointer with an actual object
|
||||
lookup: {
|
||||
from: 'test_TestObject',
|
||||
localField: 'tempPointer',
|
||||
foreignField: '_id',
|
||||
as: 'tempPointer',
|
||||
{
|
||||
// Transform className$objectId to objectId and store in new field tempPointer
|
||||
project: {
|
||||
tempPointer: { $substr: ['$_p_pointer', 11, -1] }, // Remove TestObject$
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
// lookup returns an array, Deconstructs an array field to objects
|
||||
unwind: {
|
||||
path: '$tempPointer',
|
||||
{
|
||||
// Left Join, replace objectId stored in tempPointer with an actual object
|
||||
lookup: {
|
||||
from: 'test_TestObject',
|
||||
localField: 'tempPointer',
|
||||
foreignField: '_id',
|
||||
as: 'tempPointer',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
match: { 'tempPointer.value': 2 },
|
||||
},
|
||||
],
|
||||
{
|
||||
// lookup returns an array, Deconstructs an array field to objects
|
||||
unwind: {
|
||||
path: '$tempPointer',
|
||||
},
|
||||
},
|
||||
{
|
||||
match: { 'tempPointer.value': 2 },
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
Parse.Object.saveAll([pointer1, pointer2, pointer3, obj1, obj2, obj3])
|
||||
.then(() => {
|
||||
return rp.get(Parse.serverURL + '/aggregate/TestObject', options);
|
||||
return get(Parse.serverURL + '/aggregate/TestObject', options);
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toEqual(1);
|
||||
|
||||
@@ -9,7 +9,7 @@ const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/Postgre
|
||||
const postgresURI =
|
||||
'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
|
||||
const Parse = require('parse/node');
|
||||
const rp = require('request-promise');
|
||||
const request = require('../lib/request');
|
||||
let databaseAdapter;
|
||||
|
||||
const fullTextHelper = () => {
|
||||
@@ -48,15 +48,16 @@ const fullTextHelper = () => {
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
databaseAdapter,
|
||||
}).then(() => {
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/batch',
|
||||
body: {
|
||||
requests,
|
||||
},
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -75,19 +76,24 @@ describe('Parse.Query Full Text Search testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(3);
|
||||
done();
|
||||
}, done.fail);
|
||||
.then(
|
||||
resp => {
|
||||
expect(resp.data.results.length).toBe(3);
|
||||
done();
|
||||
},
|
||||
e => done.fail(e)
|
||||
);
|
||||
});
|
||||
|
||||
it('fullTextSearch: $search, sort', done => {
|
||||
@@ -104,16 +110,19 @@ describe('Parse.Query Full Text Search testing', () => {
|
||||
};
|
||||
const order = '$score';
|
||||
const keys = '$score';
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
json: { where, order, keys, _method: 'GET' },
|
||||
body: { where, order, keys, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
.then(response => {
|
||||
const resp = response.data;
|
||||
expect(resp.results.length).toBe(3);
|
||||
expect(resp.results[0].score);
|
||||
expect(resp.results[1].score);
|
||||
@@ -135,17 +144,19 @@ describe('Parse.Query Full Text Search testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
expect(resp.data.results.length).toBe(2);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
@@ -163,17 +174,19 @@ describe('Parse.Query Full Text Search testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(1);
|
||||
expect(resp.data.results.length).toBe(1);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
@@ -188,12 +201,14 @@ describe('Parse.Query Full Text Search testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
@@ -202,7 +217,7 @@ describe('Parse.Query Full Text Search testing', () => {
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
expect(err.data.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -220,12 +235,14 @@ describe('Parse.Query Full Text Search testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
@@ -234,7 +251,7 @@ describe('Parse.Query Full Text Search testing', () => {
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
expect(err.data.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -252,12 +269,14 @@ describe('Parse.Query Full Text Search testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
@@ -266,7 +285,7 @@ describe('Parse.Query Full Text Search testing', () => {
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
expect(err.data.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -284,12 +303,14 @@ describe('Parse.Query Full Text Search testing', () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
@@ -298,7 +319,7 @@ describe('Parse.Query Full Text Search testing', () => {
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
expect(err.data.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -336,43 +357,43 @@ describe_only_db('mongo')(
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toEqual(3);
|
||||
expect(resp.data.results.length).toEqual(3);
|
||||
return databaseAdapter.getIndexes('TestObject');
|
||||
})
|
||||
.then(indexes => {
|
||||
expect(indexes.length).toEqual(2);
|
||||
rp.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/schemas/TestObject',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
json: true,
|
||||
request({
|
||||
url: 'http://localhost:8378/1/schemas/TestObject',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(body.indexes._id_).toBeDefined();
|
||||
expect(body.indexes._id_._id).toEqual(1);
|
||||
expect(body.indexes.subject_text_comment_text).toBeDefined();
|
||||
expect(body.indexes.subject_text_comment_text.subject).toEqual(
|
||||
'text'
|
||||
);
|
||||
expect(body.indexes.subject_text_comment_text.comment).toEqual(
|
||||
'text'
|
||||
);
|
||||
done();
|
||||
}
|
||||
);
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(body.indexes._id_).toBeDefined();
|
||||
expect(body.indexes._id_._id).toEqual(1);
|
||||
expect(body.indexes.subject_text_comment_text).toBeDefined();
|
||||
expect(body.indexes.subject_text_comment_text.subject).toEqual(
|
||||
'text'
|
||||
);
|
||||
expect(body.indexes.subject_text_comment_text.comment).toEqual(
|
||||
'text'
|
||||
);
|
||||
done();
|
||||
});
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
@@ -387,13 +408,14 @@ describe_only_db('mongo')(
|
||||
})
|
||||
.then(indexes => {
|
||||
expect(indexes.length).toEqual(1);
|
||||
return rp.put({
|
||||
return request({
|
||||
method: 'PUT',
|
||||
url: 'http://localhost:8378/1/schemas/TestObject',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: {
|
||||
indexes: {
|
||||
@@ -416,39 +438,39 @@ describe_only_db('mongo')(
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toEqual(3);
|
||||
expect(resp.data.results.length).toEqual(3);
|
||||
return databaseAdapter.getIndexes('TestObject');
|
||||
})
|
||||
.then(indexes => {
|
||||
expect(indexes.length).toEqual(2);
|
||||
rp.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/schemas/TestObject',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
json: true,
|
||||
request({
|
||||
url: 'http://localhost:8378/1/schemas/TestObject',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(body.indexes._id_).toBeDefined();
|
||||
expect(body.indexes._id_._id).toEqual(1);
|
||||
expect(body.indexes.text_test).toBeDefined();
|
||||
expect(body.indexes.text_test.subject).toEqual('text');
|
||||
expect(body.indexes.text_test.comment).toEqual('text');
|
||||
done();
|
||||
}
|
||||
);
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(body.indexes._id_).toBeDefined();
|
||||
expect(body.indexes._id_._id).toEqual(1);
|
||||
expect(body.indexes.text_test).toBeDefined();
|
||||
expect(body.indexes.text_test.subject).toEqual('text');
|
||||
expect(body.indexes.text_test.comment).toEqual('text');
|
||||
done();
|
||||
});
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
@@ -466,17 +488,19 @@ describe_only_db('mongo')(
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
expect(resp.data.results.length).toBe(2);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
@@ -494,17 +518,19 @@ describe_only_db('mongo')(
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(1);
|
||||
expect(resp.data.results.length).toBe(1);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
@@ -527,12 +553,14 @@ describe_only_db('postgres')(
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
@@ -545,7 +573,7 @@ describe_only_db('postgres')(
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
expect(err.data.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -563,12 +591,14 @@ describe_only_db('postgres')(
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
@@ -577,7 +607,7 @@ describe_only_db('postgres')(
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
expect(err.data.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,17 +5,17 @@
|
||||
'use strict';
|
||||
|
||||
const Parse = require('parse/node');
|
||||
const rp = require('request-promise');
|
||||
const request = require('../lib/request');
|
||||
|
||||
const masterKeyHeaders = {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Rest-API-Key': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
const masterKeyOptions = {
|
||||
headers: masterKeyHeaders,
|
||||
json: true,
|
||||
};
|
||||
|
||||
describe('Parse.Query testing', () => {
|
||||
@@ -540,65 +540,70 @@ describe('Parse.Query testing', () => {
|
||||
Parse.Object.saveAll(objectList).then(results => {
|
||||
equal(objectList.length, results.length);
|
||||
|
||||
return require('request-promise')
|
||||
.get({
|
||||
url: Parse.serverURL + '/classes/Object',
|
||||
json: {
|
||||
where: {
|
||||
strings: {
|
||||
$all: [
|
||||
{ $regex: '^\\Qthe\\E' },
|
||||
{ $regex: '^\\Qfox\\E' },
|
||||
{ $regex: '^\\Qlazy\\E' },
|
||||
],
|
||||
},
|
||||
return request({
|
||||
url: Parse.serverURL + '/classes/Object',
|
||||
qs: {
|
||||
where: JSON.stringify({
|
||||
strings: {
|
||||
$all: [
|
||||
{ $regex: '^\\Qthe\\E' },
|
||||
{ $regex: '^\\Qfox\\E' },
|
||||
{ $regex: '^\\Qlazy\\E' },
|
||||
],
|
||||
},
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
},
|
||||
})
|
||||
.then(function(results) {
|
||||
}),
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
})
|
||||
.then(function(response) {
|
||||
const results = response.data;
|
||||
equal(results.results.length, 1);
|
||||
arrayContains(results.results, object);
|
||||
|
||||
return require('request-promise').get({
|
||||
return request({
|
||||
url: Parse.serverURL + '/classes/Object',
|
||||
json: {
|
||||
where: {
|
||||
qs: {
|
||||
where: JSON.stringify({
|
||||
strings: {
|
||||
$all: [{ $regex: '^\\Qthe\\E' }, { $regex: '^\\Qlazy\\E' }],
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(function(results) {
|
||||
.then(function(response) {
|
||||
const results = response.data;
|
||||
equal(results.results.length, 2);
|
||||
arrayContains(results.results, object);
|
||||
arrayContains(results.results, object3);
|
||||
|
||||
return require('request-promise').get({
|
||||
return request({
|
||||
url: Parse.serverURL + '/classes/Object',
|
||||
json: {
|
||||
where: {
|
||||
qs: {
|
||||
where: JSON.stringify({
|
||||
strings: {
|
||||
$all: [{ $regex: '^\\Qhe\\E' }, { $regex: '^\\Qlazy\\E' }],
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(function(results) {
|
||||
.then(function(response) {
|
||||
const results = response.data;
|
||||
equal(results.results.length, 0);
|
||||
|
||||
done();
|
||||
@@ -615,10 +620,10 @@ describe('Parse.Query testing', () => {
|
||||
.then(() => {
|
||||
equal(object.isNew(), false);
|
||||
|
||||
return require('request-promise').get({
|
||||
return request({
|
||||
url: Parse.serverURL + '/classes/Object',
|
||||
json: {
|
||||
where: {
|
||||
qs: {
|
||||
where: JSON.stringify({
|
||||
strings: {
|
||||
$all: [
|
||||
{ $regex: '^\\Qthe\\E' },
|
||||
@@ -627,20 +632,18 @@ describe('Parse.Query testing', () => {
|
||||
{ $unknown: /unknown/ },
|
||||
],
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(
|
||||
function() {},
|
||||
function() {
|
||||
done();
|
||||
}
|
||||
);
|
||||
.then(done.fail, function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('containsAllStartingWith empty array values should return empty results', done => {
|
||||
@@ -652,23 +655,25 @@ describe('Parse.Query testing', () => {
|
||||
.then(() => {
|
||||
equal(object.isNew(), false);
|
||||
|
||||
return require('request-promise').get({
|
||||
return request({
|
||||
url: Parse.serverURL + '/classes/Object',
|
||||
json: {
|
||||
where: {
|
||||
qs: {
|
||||
where: JSON.stringify({
|
||||
strings: {
|
||||
$all: [],
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(
|
||||
function(results) {
|
||||
function(response) {
|
||||
const results = response.data;
|
||||
equal(results.results.length, 0);
|
||||
done();
|
||||
},
|
||||
@@ -685,23 +690,25 @@ describe('Parse.Query testing', () => {
|
||||
.then(() => {
|
||||
equal(object.isNew(), false);
|
||||
|
||||
return require('request-promise').get({
|
||||
return request({
|
||||
url: Parse.serverURL + '/classes/Object',
|
||||
json: {
|
||||
where: {
|
||||
qs: {
|
||||
where: JSON.stringify({
|
||||
strings: {
|
||||
$all: [{}],
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(
|
||||
function(results) {
|
||||
function(response) {
|
||||
const results = response.data;
|
||||
equal(results.results.length, 0);
|
||||
done();
|
||||
},
|
||||
@@ -723,23 +730,25 @@ describe('Parse.Query testing', () => {
|
||||
.then(results => {
|
||||
equal(objectList.length, results.length);
|
||||
|
||||
return require('request-promise').get({
|
||||
return request({
|
||||
url: Parse.serverURL + '/classes/Object',
|
||||
json: {
|
||||
where: {
|
||||
qs: {
|
||||
where: JSON.stringify({
|
||||
strings: {
|
||||
$all: [{ $regex: '^\\Qlazy\\E' }],
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(
|
||||
function(results) {
|
||||
function(response) {
|
||||
const results = response.data;
|
||||
equal(results.results.length, 2);
|
||||
done();
|
||||
},
|
||||
@@ -756,14 +765,14 @@ describe('Parse.Query testing', () => {
|
||||
.then(() => {
|
||||
equal(object.isNew(), false);
|
||||
|
||||
return require('request-promise').get({
|
||||
return request({
|
||||
url: Parse.serverURL + '/classes/Object',
|
||||
json: {
|
||||
where: {
|
||||
qs: {
|
||||
where: JSON.stringify({
|
||||
strings: {
|
||||
$all: [{ $unknown: '^\\Qlazy\\E' }],
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
@@ -772,7 +781,8 @@ describe('Parse.Query testing', () => {
|
||||
});
|
||||
})
|
||||
.then(
|
||||
function(results) {
|
||||
function(response) {
|
||||
const results = response.data;
|
||||
equal(results.results.length, 0);
|
||||
done();
|
||||
},
|
||||
@@ -810,22 +820,24 @@ describe('Parse.Query testing', () => {
|
||||
const pointers = objects.map(object => object.toPointer());
|
||||
|
||||
// Return all Parent where all parent.objects are contained in objects
|
||||
return rp.get({
|
||||
return request({
|
||||
url: Parse.serverURL + '/classes/Parent',
|
||||
json: {
|
||||
where: {
|
||||
qs: {
|
||||
where: JSON.stringify({
|
||||
objects: {
|
||||
$containedBy: pointers,
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(results => {
|
||||
.then(response => {
|
||||
const results = response.data;
|
||||
expect(results.results[0].objectId).not.toBeUndefined();
|
||||
expect(results.results[0].objectId).toBe(parent3.id);
|
||||
expect(results.results.length).toBe(1);
|
||||
@@ -835,8 +847,10 @@ describe('Parse.Query testing', () => {
|
||||
|
||||
it('containedBy number array', done => {
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: {
|
||||
where: { numbers: { $containedBy: [1, 2, 3, 4, 5, 6, 7, 8, 9] } },
|
||||
qs: {
|
||||
where: JSON.stringify({
|
||||
numbers: { $containedBy: [1, 2, 3, 4, 5, 6, 7, 8, 9] },
|
||||
}),
|
||||
},
|
||||
});
|
||||
const obj1 = new TestObject({ numbers: [0, 1, 2] });
|
||||
@@ -844,9 +858,15 @@ describe('Parse.Query testing', () => {
|
||||
const obj3 = new TestObject({ numbers: [1, 2, 3, 4] });
|
||||
Parse.Object.saveAll([obj1, obj2, obj3])
|
||||
.then(() => {
|
||||
return rp.get(Parse.serverURL + '/classes/TestObject', options);
|
||||
return request(
|
||||
Object.assign(
|
||||
{ url: Parse.serverURL + '/classes/TestObject' },
|
||||
options
|
||||
)
|
||||
);
|
||||
})
|
||||
.then(results => {
|
||||
.then(response => {
|
||||
const results = response.data;
|
||||
expect(results.results[0].objectId).not.toBeUndefined();
|
||||
expect(results.results[0].objectId).toBe(obj3.id);
|
||||
expect(results.results.length).toBe(1);
|
||||
@@ -856,8 +876,8 @@ describe('Parse.Query testing', () => {
|
||||
|
||||
it('containedBy empty array', done => {
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: {
|
||||
where: { numbers: { $containedBy: [] } },
|
||||
qs: {
|
||||
where: JSON.stringify({ numbers: { $containedBy: [] } }),
|
||||
},
|
||||
});
|
||||
const obj1 = new TestObject({ numbers: [0, 1, 2] });
|
||||
@@ -865,9 +885,15 @@ describe('Parse.Query testing', () => {
|
||||
const obj3 = new TestObject({ numbers: [1, 2, 3, 4] });
|
||||
Parse.Object.saveAll([obj1, obj2, obj3])
|
||||
.then(() => {
|
||||
return rp.get(Parse.serverURL + '/classes/TestObject', options);
|
||||
return request(
|
||||
Object.assign(
|
||||
{ url: Parse.serverURL + '/classes/TestObject' },
|
||||
options
|
||||
)
|
||||
);
|
||||
})
|
||||
.then(results => {
|
||||
.then(response => {
|
||||
const results = response.data;
|
||||
expect(results.results.length).toBe(0);
|
||||
done();
|
||||
});
|
||||
@@ -875,20 +901,25 @@ describe('Parse.Query testing', () => {
|
||||
|
||||
it('containedBy invalid query', done => {
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: {
|
||||
where: { objects: { $containedBy: 1234 } },
|
||||
qs: {
|
||||
where: JSON.stringify({ objects: { $containedBy: 1234 } }),
|
||||
},
|
||||
});
|
||||
const obj = new TestObject();
|
||||
obj
|
||||
.save()
|
||||
.then(() => {
|
||||
return rp.get(Parse.serverURL + '/classes/TestObject', options);
|
||||
return request(
|
||||
Object.assign(
|
||||
{ url: Parse.serverURL + '/classes/TestObject' },
|
||||
options
|
||||
)
|
||||
);
|
||||
})
|
||||
.then(done.fail)
|
||||
.catch(error => {
|
||||
equal(error.error.code, Parse.Error.INVALID_JSON);
|
||||
equal(error.error.error, 'bad $containedBy: should be an array');
|
||||
.catch(response => {
|
||||
equal(response.data.code, Parse.Error.INVALID_JSON);
|
||||
equal(response.data.error, 'bad $containedBy: should be an array');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -1186,15 +1217,17 @@ describe('Parse.Query testing', () => {
|
||||
|
||||
it('where $eq false queries (rest)', done => {
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: {
|
||||
where: { field: { $eq: false } },
|
||||
qs: {
|
||||
where: JSON.stringify({ field: { $eq: false } }),
|
||||
},
|
||||
});
|
||||
const obj1 = new TestObject({ field: false });
|
||||
const obj2 = new TestObject({ field: true });
|
||||
Parse.Object.saveAll([obj1, obj2]).then(() => {
|
||||
rp.get(Parse.serverURL + '/classes/TestObject', options).then(resp => {
|
||||
equal(resp.results.length, 1);
|
||||
request(
|
||||
Object.assign({ url: Parse.serverURL + '/classes/TestObject' }, options)
|
||||
).then(resp => {
|
||||
equal(resp.data.results.length, 1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -1202,15 +1235,17 @@ describe('Parse.Query testing', () => {
|
||||
|
||||
it('where $eq null queries (rest)', done => {
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: {
|
||||
where: { field: { $eq: null } },
|
||||
qs: {
|
||||
where: JSON.stringify({ field: { $eq: null } }),
|
||||
},
|
||||
});
|
||||
const obj1 = new TestObject({ field: false });
|
||||
const obj2 = new TestObject({ field: null });
|
||||
Parse.Object.saveAll([obj1, obj2]).then(() => {
|
||||
rp.get(Parse.serverURL + '/classes/TestObject', options).then(resp => {
|
||||
equal(resp.results.length, 1);
|
||||
return request(
|
||||
Object.assign({ url: Parse.serverURL + '/classes/TestObject' }, options)
|
||||
).then(resp => {
|
||||
equal(resp.data.results.length, 1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -2698,21 +2733,27 @@ describe('Parse.Query testing', () => {
|
||||
const highValue = 5;
|
||||
const lowValue = 3;
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: {
|
||||
where: {
|
||||
qs: {
|
||||
where: JSON.stringify({
|
||||
$nor: [
|
||||
{ rating: { $gt: highValue } },
|
||||
{ rating: { $lte: lowValue } },
|
||||
],
|
||||
},
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
Parse.Object.saveAll(objects)
|
||||
.then(() => {
|
||||
return rp.get(Parse.serverURL + '/classes/TestObject', options);
|
||||
return request(
|
||||
Object.assign(
|
||||
{ url: Parse.serverURL + '/classes/TestObject' },
|
||||
options
|
||||
)
|
||||
);
|
||||
})
|
||||
.then(results => {
|
||||
.then(response => {
|
||||
const results = response.data;
|
||||
expect(results.results.length).toBe(highValue - lowValue);
|
||||
expect(
|
||||
results.results.every(
|
||||
@@ -2725,38 +2766,48 @@ describe('Parse.Query testing', () => {
|
||||
|
||||
it('$nor invalid query - empty array', done => {
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: {
|
||||
where: { $nor: [] },
|
||||
qs: {
|
||||
where: JSON.stringify({ $nor: [] }),
|
||||
},
|
||||
});
|
||||
const obj = new TestObject();
|
||||
obj
|
||||
.save()
|
||||
.then(() => {
|
||||
return rp.get(Parse.serverURL + '/classes/TestObject', options);
|
||||
return request(
|
||||
Object.assign(
|
||||
{ url: Parse.serverURL + '/classes/TestObject' },
|
||||
options
|
||||
)
|
||||
);
|
||||
})
|
||||
.then(done.fail)
|
||||
.catch(error => {
|
||||
equal(error.error.code, Parse.Error.INVALID_QUERY);
|
||||
.catch(response => {
|
||||
equal(response.data.code, Parse.Error.INVALID_QUERY);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('$nor invalid query - wrong type', done => {
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: {
|
||||
where: { $nor: 1337 },
|
||||
qs: {
|
||||
where: JSON.stringify({ $nor: 1337 }),
|
||||
},
|
||||
});
|
||||
const obj = new TestObject();
|
||||
obj
|
||||
.save()
|
||||
.then(() => {
|
||||
return rp.get(Parse.serverURL + '/classes/TestObject', options);
|
||||
return request(
|
||||
Object.assign(
|
||||
{ url: Parse.serverURL + '/classes/TestObject' },
|
||||
options
|
||||
)
|
||||
);
|
||||
})
|
||||
.then(done.fail)
|
||||
.catch(error => {
|
||||
equal(error.error.code, Parse.Error.INVALID_QUERY);
|
||||
.catch(response => {
|
||||
equal(response.data.code, Parse.Error.INVALID_QUERY);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -3892,13 +3943,15 @@ describe('Parse.Query testing', () => {
|
||||
const parent = new Container({ child1, child2, child3 });
|
||||
await Parse.Object.saveAll([parent, child1, child2, child3]);
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: {
|
||||
where: { objectId: parent.id },
|
||||
qs: {
|
||||
where: JSON.stringify({ objectId: parent.id }),
|
||||
include: '*',
|
||||
},
|
||||
});
|
||||
const resp = await rp.get(Parse.serverURL + '/classes/Container', options);
|
||||
const result = resp.results[0];
|
||||
const resp = await request(
|
||||
Object.assign({ url: Parse.serverURL + '/classes/Container' }, options)
|
||||
);
|
||||
const result = resp.data.results[0];
|
||||
equal(result.child1.foo, 'bar');
|
||||
equal(result.child2.foo, 'baz');
|
||||
equal(result.child3.foo, 'bad');
|
||||
@@ -3914,13 +3967,15 @@ describe('Parse.Query testing', () => {
|
||||
const parent = new Container({ child1, child2, child3 });
|
||||
await Parse.Object.saveAll([parent, child1, child2, child3]);
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: {
|
||||
where: { objectId: parent.id },
|
||||
qs: {
|
||||
where: JSON.stringify({ objectId: parent.id }),
|
||||
include: 'child2,*',
|
||||
},
|
||||
});
|
||||
const resp = await rp.get(Parse.serverURL + '/classes/Container', options);
|
||||
const result = resp.results[0];
|
||||
const resp = await request(
|
||||
Object.assign({ url: Parse.serverURL + '/classes/Container' }, options)
|
||||
);
|
||||
const result = resp.data.results[0];
|
||||
equal(result.child1.foo, 'bar');
|
||||
equal(result.child2.foo, 'baz');
|
||||
equal(result.child3.foo, 'bad');
|
||||
@@ -3937,15 +3992,20 @@ describe('Parse.Query testing', () => {
|
||||
Parse.Object.saveAll([parent, child1, child2, child3])
|
||||
.then(() => {
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: {
|
||||
where: { objectId: parent.id },
|
||||
qs: {
|
||||
where: JSON.stringify({ objectId: parent.id }),
|
||||
includeAll: true,
|
||||
},
|
||||
});
|
||||
return rp.get(Parse.serverURL + '/classes/Container', options);
|
||||
return request(
|
||||
Object.assign(
|
||||
{ url: Parse.serverURL + '/classes/Container' },
|
||||
options
|
||||
)
|
||||
);
|
||||
})
|
||||
.then(resp => {
|
||||
const result = resp.results[0];
|
||||
const result = resp.data.results[0];
|
||||
equal(result.child1.foo, 'bar');
|
||||
equal(result.child2.foo, 'baz');
|
||||
equal(result.child3.foo, 'bad');
|
||||
@@ -3983,17 +4043,23 @@ describe('Parse.Query testing', () => {
|
||||
return Foobar.save();
|
||||
})
|
||||
.then(savedFoobar => {
|
||||
const options = Object.assign({}, masterKeyOptions, {
|
||||
body: {
|
||||
where: { objectId: savedFoobar.id },
|
||||
includeAll: true,
|
||||
keys: 'fizz,barBaz.key,barBaz.bazoo.some',
|
||||
const options = Object.assign(
|
||||
{
|
||||
url: Parse.serverURL + '/classes/Foobar',
|
||||
},
|
||||
});
|
||||
return rp.get(Parse.serverURL + '/classes/Foobar', options);
|
||||
masterKeyOptions,
|
||||
{
|
||||
qs: {
|
||||
where: JSON.stringify({ objectId: savedFoobar.id }),
|
||||
includeAll: true,
|
||||
keys: 'fizz,barBaz.key,barBaz.bazoo.some',
|
||||
},
|
||||
}
|
||||
);
|
||||
return request(options);
|
||||
})
|
||||
.then(resp => {
|
||||
const result = resp.results[0];
|
||||
const result = resp.data.results[0];
|
||||
equal(result.group.clan, 'wu');
|
||||
equal(result.foo, undefined);
|
||||
equal(result.fizz, 'buzz');
|
||||
@@ -4002,7 +4068,8 @@ describe('Parse.Query testing', () => {
|
||||
equal(result.barBaz.bazoo.some, 'thing');
|
||||
equal(result.barBaz.bazoo.otherSome, undefined);
|
||||
done();
|
||||
});
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('select nested keys 2 level without include (issue #3185)', function(done) {
|
||||
@@ -4109,19 +4176,25 @@ describe('Parse.Query testing', () => {
|
||||
__type: 'Pointer',
|
||||
},
|
||||
};
|
||||
return require('request-promise').post({
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/classes/Game',
|
||||
json: { where, _method: 'GET' },
|
||||
body: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(response => {
|
||||
expect(response.results.length).toBe(1);
|
||||
done();
|
||||
}, done.fail);
|
||||
.then(
|
||||
response => {
|
||||
const results = response.data;
|
||||
expect(results.results.length).toBe(1);
|
||||
done();
|
||||
},
|
||||
res => done.fail(res.data)
|
||||
);
|
||||
});
|
||||
|
||||
it('should not interfere with has when using select on field with undefined value #3999', done => {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const requestp = require('request-promise');
|
||||
const request = require('../lib/request');
|
||||
|
||||
describe('Password Policy: ', () => {
|
||||
it('should show the invalid link page if the user clicks on the password reset link after the token expires', done => {
|
||||
@@ -39,16 +39,15 @@ describe('Password Policy: ', () => {
|
||||
setTimeout(() => {
|
||||
expect(sendEmailOptions).not.toBeUndefined();
|
||||
|
||||
requestp
|
||||
.get({
|
||||
uri: sendEmailOptions.link,
|
||||
followRedirect: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
request({
|
||||
url: sendEmailOptions.link,
|
||||
followRedirects: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
.then(response => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/invalid_link.html'
|
||||
);
|
||||
done();
|
||||
@@ -100,17 +99,16 @@ describe('Password Policy: ', () => {
|
||||
setTimeout(() => {
|
||||
expect(sendEmailOptions).not.toBeUndefined();
|
||||
|
||||
requestp
|
||||
.get({
|
||||
uri: sendEmailOptions.link,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
followRedirect: false,
|
||||
})
|
||||
request({
|
||||
url: sendEmailOptions.link,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
followRedirects: false,
|
||||
})
|
||||
.then(response => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.status).toEqual(302);
|
||||
const re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=[a-zA-Z0-9]+\&id=test\&username=testResetTokenValidity/;
|
||||
expect(response.body.match(re)).not.toBe(null);
|
||||
expect(response.text.match(re)).not.toBe(null);
|
||||
done();
|
||||
})
|
||||
.catch(error => {
|
||||
@@ -546,17 +544,16 @@ describe('Password Policy: ', () => {
|
||||
const emailAdapter = {
|
||||
sendVerificationEmail: () => Promise.resolve(),
|
||||
sendPasswordResetEmail: options => {
|
||||
requestp
|
||||
.get({
|
||||
uri: options.link,
|
||||
followRedirect: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
request({
|
||||
url: options.link,
|
||||
followRedirects: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
.then(response => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.status).toEqual(302);
|
||||
const re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=([a-zA-Z0-9]+)\&id=test\&username=user1/;
|
||||
const match = response.body.match(re);
|
||||
const match = response.text.match(re);
|
||||
if (!match) {
|
||||
fail('should have a token');
|
||||
done();
|
||||
@@ -564,20 +561,20 @@ describe('Password Policy: ', () => {
|
||||
}
|
||||
const token = match[1];
|
||||
|
||||
requestp
|
||||
.post({
|
||||
uri: 'http://localhost:8378/1/apps/test/request_password_reset',
|
||||
body: `new_password=has2init&token=${token}&username=user1`,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
followRedirect: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/apps/test/request_password_reset',
|
||||
body: `new_password=has2init&token=${token}&username=user1`,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
followRedirects: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
.then(response => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/password_reset_success.html?username=user1'
|
||||
);
|
||||
|
||||
@@ -639,17 +636,16 @@ describe('Password Policy: ', () => {
|
||||
const emailAdapter = {
|
||||
sendVerificationEmail: () => Promise.resolve(),
|
||||
sendPasswordResetEmail: options => {
|
||||
requestp
|
||||
.get({
|
||||
uri: options.link,
|
||||
followRedirect: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
request({
|
||||
url: options.link,
|
||||
followRedirects: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
.then(response => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.status).toEqual(302);
|
||||
const re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=([a-zA-Z0-9]+)\&id=test\&username=user1/;
|
||||
const match = response.body.match(re);
|
||||
const match = response.text.match(re);
|
||||
if (!match) {
|
||||
fail('should have a token');
|
||||
done();
|
||||
@@ -657,20 +653,20 @@ describe('Password Policy: ', () => {
|
||||
}
|
||||
const token = match[1];
|
||||
|
||||
requestp
|
||||
.post({
|
||||
uri: 'http://localhost:8378/1/apps/test/request_password_reset',
|
||||
body: `new_password=hasnodigit&token=${token}&username=user1`,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
followRedirect: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/apps/test/request_password_reset',
|
||||
body: `new_password=hasnodigit&token=${token}&username=user1`,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
followRedirects: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
.then(response => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
`Found. Redirecting to http://localhost:8378/1/apps/choose_password?username=user1&token=${token}&id=test&error=Password%20does%20not%20meet%20the%20Password%20Policy%20requirements.&app=passwordPolicy`
|
||||
);
|
||||
|
||||
@@ -826,17 +822,16 @@ describe('Password Policy: ', () => {
|
||||
const emailAdapter = {
|
||||
sendVerificationEmail: () => Promise.resolve(),
|
||||
sendPasswordResetEmail: options => {
|
||||
requestp
|
||||
.get({
|
||||
uri: options.link,
|
||||
followRedirect: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
request({
|
||||
url: options.link,
|
||||
followRedirects: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
.then(response => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.status).toEqual(302);
|
||||
const re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=([a-zA-Z0-9]+)\&id=test\&username=user1/;
|
||||
const match = response.body.match(re);
|
||||
const match = response.text.match(re);
|
||||
if (!match) {
|
||||
fail('should have a token');
|
||||
done();
|
||||
@@ -844,20 +839,20 @@ describe('Password Policy: ', () => {
|
||||
}
|
||||
const token = match[1];
|
||||
|
||||
requestp
|
||||
.post({
|
||||
uri: 'http://localhost:8378/1/apps/test/request_password_reset',
|
||||
body: `new_password=xuser12&token=${token}&username=user1`,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
followRedirect: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/apps/test/request_password_reset',
|
||||
body: `new_password=xuser12&token=${token}&username=user1`,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
followRedirects: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
.then(response => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
`Found. Redirecting to http://localhost:8378/1/apps/choose_password?username=user1&token=${token}&id=test&error=Password%20does%20not%20meet%20the%20Password%20Policy%20requirements.&app=passwordPolicy`
|
||||
);
|
||||
|
||||
@@ -919,17 +914,16 @@ describe('Password Policy: ', () => {
|
||||
const emailAdapter = {
|
||||
sendVerificationEmail: () => Promise.resolve(),
|
||||
sendPasswordResetEmail: options => {
|
||||
requestp
|
||||
.get({
|
||||
uri: options.link,
|
||||
followRedirect: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
request({
|
||||
url: options.link,
|
||||
followRedirects: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
.then(response => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.status).toEqual(302);
|
||||
const re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=([a-zA-Z0-9]+)\&id=test\&username=user1/;
|
||||
const match = response.body.match(re);
|
||||
const match = response.text.match(re);
|
||||
if (!match) {
|
||||
fail('should have a token');
|
||||
done();
|
||||
@@ -937,20 +931,20 @@ describe('Password Policy: ', () => {
|
||||
}
|
||||
const token = match[1];
|
||||
|
||||
requestp
|
||||
.post({
|
||||
uri: 'http://localhost:8378/1/apps/test/request_password_reset',
|
||||
body: `new_password=uuser11&token=${token}&username=user1`,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
followRedirect: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/apps/test/request_password_reset',
|
||||
body: `new_password=uuser11&token=${token}&username=user1`,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
followRedirects: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
.then(response => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/password_reset_success.html?username=user1'
|
||||
);
|
||||
|
||||
@@ -1192,17 +1186,16 @@ describe('Password Policy: ', () => {
|
||||
const emailAdapter = {
|
||||
sendVerificationEmail: () => Promise.resolve(),
|
||||
sendPasswordResetEmail: options => {
|
||||
requestp
|
||||
.get({
|
||||
uri: options.link,
|
||||
followRedirect: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
request({
|
||||
url: options.link,
|
||||
followRedirects: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
.then(response => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.status).toEqual(302);
|
||||
const re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=([a-zA-Z0-9]+)\&id=test\&username=user1/;
|
||||
const match = response.body.match(re);
|
||||
const match = response.text.match(re);
|
||||
if (!match) {
|
||||
fail('should have a token');
|
||||
done();
|
||||
@@ -1210,20 +1203,20 @@ describe('Password Policy: ', () => {
|
||||
}
|
||||
const token = match[1];
|
||||
|
||||
requestp
|
||||
.post({
|
||||
uri: 'http://localhost:8378/1/apps/test/request_password_reset',
|
||||
body: `new_password=uuser11&token=${token}&username=user1`,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
followRedirect: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/apps/test/request_password_reset',
|
||||
body: `new_password=uuser11&token=${token}&username=user1`,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
followRedirects: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
.then(response => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/password_reset_success.html?username=user1'
|
||||
);
|
||||
|
||||
@@ -1358,17 +1351,14 @@ describe('Password Policy: ', () => {
|
||||
const emailAdapter = {
|
||||
sendVerificationEmail: () => Promise.resolve(),
|
||||
sendPasswordResetEmail: options => {
|
||||
requestp
|
||||
.get({
|
||||
uri: options.link,
|
||||
followRedirect: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
request({
|
||||
url: options.link,
|
||||
followRedirects: false,
|
||||
})
|
||||
.then(response => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.status).toEqual(302);
|
||||
const re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=([a-zA-Z0-9]+)\&id=test\&username=user1/;
|
||||
const match = response.body.match(re);
|
||||
const match = response.text.match(re);
|
||||
if (!match) {
|
||||
fail('should have a token');
|
||||
return Promise.reject('Invalid password link');
|
||||
@@ -1376,39 +1366,32 @@ describe('Password Policy: ', () => {
|
||||
return Promise.resolve(match[1]); // token
|
||||
})
|
||||
.then(token => {
|
||||
return new Promise((resolve, reject) => {
|
||||
requestp
|
||||
.post({
|
||||
uri:
|
||||
'http://localhost:8378/1/apps/test/request_password_reset',
|
||||
body: `new_password=user1&token=${token}&username=user1`,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
followRedirect: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
})
|
||||
.then(response => {
|
||||
resolve([response, token]);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/apps/test/request_password_reset',
|
||||
body: `new_password=user1&token=${token}&username=user1`,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
followRedirects: false,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
}).then(response => {
|
||||
return [response, token];
|
||||
});
|
||||
})
|
||||
.then(data => {
|
||||
const response = data[0];
|
||||
const token = data[1];
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
`Found. Redirecting to http://localhost:8378/1/apps/choose_password?username=user1&token=${token}&id=test&error=New%20password%20should%20not%20be%20the%20same%20as%20last%201%20passwords.&app=passwordPolicy`
|
||||
);
|
||||
done();
|
||||
return Promise.resolve();
|
||||
})
|
||||
.catch(error => {
|
||||
jfail(error);
|
||||
fail(error);
|
||||
fail('Repeat password test failed');
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
const request = require('request');
|
||||
const req = require('../lib/request');
|
||||
|
||||
const request = function(url, callback) {
|
||||
return req({
|
||||
url,
|
||||
}).then(response => callback(null, response), err => callback(err, err));
|
||||
};
|
||||
|
||||
describe('public API', () => {
|
||||
it('should get invalid_link.html', done => {
|
||||
request(
|
||||
'http://localhost:8378/1/apps/invalid_link.html',
|
||||
(err, httpResponse) => {
|
||||
expect(httpResponse.statusCode).toBe(200);
|
||||
expect(httpResponse.status).toBe(200);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@@ -19,7 +25,7 @@ describe('public API', () => {
|
||||
request(
|
||||
'http://localhost:8378/1/apps/choose_password?id=test',
|
||||
(err, httpResponse) => {
|
||||
expect(httpResponse.statusCode).toBe(200);
|
||||
expect(httpResponse.status).toBe(200);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@@ -30,7 +36,7 @@ describe('public API', () => {
|
||||
request(
|
||||
'http://localhost:8378/1/apps/verify_email_success.html',
|
||||
(err, httpResponse) => {
|
||||
expect(httpResponse.statusCode).toBe(200);
|
||||
expect(httpResponse.status).toBe(200);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@@ -40,7 +46,7 @@ describe('public API', () => {
|
||||
request(
|
||||
'http://localhost:8378/1/apps/password_reset_success.html',
|
||||
(err, httpResponse) => {
|
||||
expect(httpResponse.statusCode).toBe(200);
|
||||
expect(httpResponse.status).toBe(200);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@@ -55,7 +61,7 @@ describe('public API without publicServerURL', () => {
|
||||
request(
|
||||
'http://localhost:8378/1/apps/test/verify_email',
|
||||
(err, httpResponse) => {
|
||||
expect(httpResponse.statusCode).toBe(404);
|
||||
expect(httpResponse.status).toBe(404);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@@ -65,7 +71,7 @@ describe('public API without publicServerURL', () => {
|
||||
request(
|
||||
'http://localhost:8378/1/apps/choose_password?id=test',
|
||||
(err, httpResponse) => {
|
||||
expect(httpResponse.statusCode).toBe(404);
|
||||
expect(httpResponse.status).toBe(404);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@@ -75,7 +81,7 @@ describe('public API without publicServerURL', () => {
|
||||
request(
|
||||
'http://localhost:8378/1/apps/test/request_password_reset',
|
||||
(err, httpResponse) => {
|
||||
expect(httpResponse.statusCode).toBe(404);
|
||||
expect(httpResponse.status).toBe(404);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@@ -91,7 +97,7 @@ describe('public API supplied with invalid application id', () => {
|
||||
request(
|
||||
'http://localhost:8378/1/apps/invalid/verify_email',
|
||||
(err, httpResponse) => {
|
||||
expect(httpResponse.statusCode).toBe(403);
|
||||
expect(httpResponse.status).toBe(403);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@@ -101,7 +107,7 @@ describe('public API supplied with invalid application id', () => {
|
||||
request(
|
||||
'http://localhost:8378/1/apps/choose_password?id=invalid',
|
||||
(err, httpResponse) => {
|
||||
expect(httpResponse.statusCode).toBe(403);
|
||||
expect(httpResponse.status).toBe(403);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@@ -111,27 +117,27 @@ describe('public API supplied with invalid application id', () => {
|
||||
request(
|
||||
'http://localhost:8378/1/apps/invalid/request_password_reset',
|
||||
(err, httpResponse) => {
|
||||
expect(httpResponse.statusCode).toBe(403);
|
||||
expect(httpResponse.status).toBe(403);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should get 403 on post of request_password_reset', done => {
|
||||
request.post(
|
||||
'http://localhost:8378/1/apps/invalid/request_password_reset',
|
||||
(err, httpResponse) => {
|
||||
expect(httpResponse.statusCode).toBe(403);
|
||||
done();
|
||||
}
|
||||
);
|
||||
req({
|
||||
url: 'http://localhost:8378/1/apps/invalid/request_password_reset',
|
||||
method: 'POST',
|
||||
}).then(done.fail, httpResponse => {
|
||||
expect(httpResponse.status).toBe(403);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get 403 on resendVerificationEmail', done => {
|
||||
request(
|
||||
'http://localhost:8378/1/apps/invalid/resend_verification_email',
|
||||
(err, httpResponse) => {
|
||||
expect(httpResponse.statusCode).toBe(403);
|
||||
expect(httpResponse.status).toBe(403);
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const PushRouter = require('../lib/Routers/PushRouter').PushRouter;
|
||||
const request = require('request');
|
||||
const request = require('../lib/request');
|
||||
|
||||
describe('PushRouter', () => {
|
||||
it('can get query condition when channels is set', done => {
|
||||
@@ -68,27 +68,24 @@ describe('PushRouter', () => {
|
||||
});
|
||||
|
||||
it('sends a push through REST', done => {
|
||||
request.post(
|
||||
{
|
||||
url: Parse.serverURL + '/push',
|
||||
json: true,
|
||||
body: {
|
||||
channels: {
|
||||
$in: ['Giants', 'Mets'],
|
||||
},
|
||||
},
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': Parse.masterKey,
|
||||
request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/push',
|
||||
body: {
|
||||
channels: {
|
||||
$in: ['Giants', 'Mets'],
|
||||
},
|
||||
},
|
||||
function(err, res, body) {
|
||||
expect(res.headers['x-parse-push-status-id']).not.toBe(undefined);
|
||||
expect(res.headers['x-parse-push-status-id'].length).toBe(10);
|
||||
expect(res.headers['']);
|
||||
expect(body.result).toBe(true);
|
||||
done();
|
||||
}
|
||||
);
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': Parse.masterKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}).then(res => {
|
||||
expect(res.headers['x-parse-push-status-id']).not.toBe(undefined);
|
||||
expect(res.headers['x-parse-push-status-id'].length).toBe(10);
|
||||
expect(res.data.result).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
const Parse = require('parse/node');
|
||||
const ReadPreference = require('mongodb').ReadPreference;
|
||||
const rp = require('request-promise');
|
||||
const request = require('../lib/request');
|
||||
const Config = require('../lib/Config');
|
||||
|
||||
describe_only_db('mongo')('Read preference option', () => {
|
||||
@@ -420,15 +420,16 @@ describe_only_db('mongo')('Read preference option', () => {
|
||||
req.readPreference = 'SECONDARY';
|
||||
});
|
||||
|
||||
rp({
|
||||
request({
|
||||
method: 'GET',
|
||||
uri: 'http://localhost:8378/1/classes/MyObject/' + obj0.id,
|
||||
url: 'http://localhost:8378/1/classes/MyObject/' + obj0.id,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
json: true,
|
||||
}).then(body => {
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(body.boolKey).toBe(false);
|
||||
|
||||
let myObjectReadPreference = null;
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
const auth = require('../lib/Auth');
|
||||
const Config = require('../lib/Config');
|
||||
const rest = require('../lib/rest');
|
||||
const request = require('../lib/request');
|
||||
|
||||
const querystring = require('querystring');
|
||||
const rp = require('request-promise');
|
||||
|
||||
let config;
|
||||
let database;
|
||||
@@ -221,40 +221,34 @@ describe('rest query', () => {
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
};
|
||||
|
||||
const p0 = rp
|
||||
.get({
|
||||
headers: headers,
|
||||
url:
|
||||
'http://localhost:8378/1/classes/TestParameterEncode?' +
|
||||
querystring
|
||||
.stringify({
|
||||
where: '{"foo":{"$ne": "baz"}}',
|
||||
limit: 1,
|
||||
})
|
||||
.replace('=', '%3D'),
|
||||
})
|
||||
.then(fail, response => {
|
||||
const error = response.error;
|
||||
const b = JSON.parse(error);
|
||||
expect(b.code).toEqual(Parse.Error.INVALID_QUERY);
|
||||
});
|
||||
const p0 = request({
|
||||
headers: headers,
|
||||
url:
|
||||
'http://localhost:8378/1/classes/TestParameterEncode?' +
|
||||
querystring
|
||||
.stringify({
|
||||
where: '{"foo":{"$ne": "baz"}}',
|
||||
limit: 1,
|
||||
})
|
||||
.replace('=', '%3D'),
|
||||
}).then(fail, response => {
|
||||
const error = response.data;
|
||||
expect(error.code).toEqual(Parse.Error.INVALID_QUERY);
|
||||
});
|
||||
|
||||
const p1 = rp
|
||||
.get({
|
||||
headers: headers,
|
||||
url:
|
||||
'http://localhost:8378/1/classes/TestParameterEncode?' +
|
||||
querystring
|
||||
.stringify({
|
||||
limit: 1,
|
||||
})
|
||||
.replace('=', '%3D'),
|
||||
})
|
||||
.then(fail, response => {
|
||||
const error = response.error;
|
||||
const b = JSON.parse(error);
|
||||
expect(b.code).toEqual(Parse.Error.INVALID_QUERY);
|
||||
});
|
||||
const p1 = request({
|
||||
headers: headers,
|
||||
url:
|
||||
'http://localhost:8378/1/classes/TestParameterEncode?' +
|
||||
querystring
|
||||
.stringify({
|
||||
limit: 1,
|
||||
})
|
||||
.replace('=', '%3D'),
|
||||
}).then(fail, response => {
|
||||
const error = response.data;
|
||||
expect(error.code).toEqual(Parse.Error.INVALID_QUERY);
|
||||
});
|
||||
return Promise.all([p0, p1]);
|
||||
})
|
||||
.then(done)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const Config = require('../lib/Config');
|
||||
const sessionToken = 'legacySessionToken';
|
||||
const rp = require('request-promise');
|
||||
const request = require('../lib/request');
|
||||
const Parse = require('parse/node');
|
||||
|
||||
function createUser() {
|
||||
@@ -92,24 +92,24 @@ describe_only_db('mongo')('revocable sessions', () => {
|
||||
});
|
||||
|
||||
it('should not upgrade bad legacy session token', done => {
|
||||
rp.post({
|
||||
request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/upgradeToRevocableSession',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Rest-API-Key': 'rest',
|
||||
'X-Parse-Session-Token': 'badSessionToken',
|
||||
},
|
||||
json: true,
|
||||
})
|
||||
.then(
|
||||
() => {
|
||||
fail('should not be able to upgrade a bad token');
|
||||
},
|
||||
response => {
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.error).not.toBeUndefined();
|
||||
expect(response.error.code).toBe(Parse.Error.INVALID_SESSION_TOKEN);
|
||||
expect(response.error.error).toEqual('invalid legacy session token');
|
||||
expect(response.status).toBe(400);
|
||||
expect(response.data).not.toBeUndefined();
|
||||
expect(response.data.code).toBe(Parse.Error.INVALID_SESSION_TOKEN);
|
||||
expect(response.data.error).toEqual('invalid legacy session token');
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
@@ -118,23 +118,23 @@ describe_only_db('mongo')('revocable sessions', () => {
|
||||
});
|
||||
|
||||
it('should not crash without session token #2720', done => {
|
||||
rp.post({
|
||||
request({
|
||||
method: 'POST',
|
||||
url: Parse.serverURL + '/upgradeToRevocableSession',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Rest-API-Key': 'rest',
|
||||
},
|
||||
json: true,
|
||||
})
|
||||
.then(
|
||||
() => {
|
||||
fail('should not be able to upgrade a bad token');
|
||||
},
|
||||
response => {
|
||||
expect(response.statusCode).toBe(404);
|
||||
expect(response.error).not.toBeUndefined();
|
||||
expect(response.error.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
|
||||
expect(response.error.error).toEqual('invalid session');
|
||||
expect(response.status).toBe(404);
|
||||
expect(response.data).not.toBeUndefined();
|
||||
expect(response.data.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
|
||||
expect(response.data.error).toEqual('invalid session');
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const Parse = require('parse/node');
|
||||
const request = require('request-promise');
|
||||
const request = require('../lib/request');
|
||||
|
||||
// const Config = require('../lib/Config');
|
||||
|
||||
@@ -143,132 +143,130 @@ describe('Personally Identifiable Information', () => {
|
||||
});
|
||||
|
||||
it('should not get PII via REST', done => {
|
||||
request
|
||||
.get({
|
||||
url: 'http://localhost:8378/1/classes/_User',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
},
|
||||
})
|
||||
request({
|
||||
url: 'http://localhost:8378/1/classes/_User',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
},
|
||||
})
|
||||
.then(
|
||||
result => {
|
||||
response => {
|
||||
const result = response.data;
|
||||
const fetchedUser = result.results[0];
|
||||
expect(fetchedUser.zip).toBe(ZIP);
|
||||
expect(fetchedUser.email).toBe(undefined);
|
||||
},
|
||||
e => console.error('error', e.message)
|
||||
)
|
||||
.done(() => done());
|
||||
.then(done)
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('should get PII via REST with self credentials', done => {
|
||||
request
|
||||
.get({
|
||||
url: 'http://localhost:8378/1/classes/_User',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
'X-Parse-Session-Token': user.getSessionToken(),
|
||||
},
|
||||
})
|
||||
request({
|
||||
url: 'http://localhost:8378/1/classes/_User',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
'X-Parse-Session-Token': user.getSessionToken(),
|
||||
},
|
||||
})
|
||||
.then(
|
||||
result => {
|
||||
response => {
|
||||
const result = response.data;
|
||||
const fetchedUser = result.results[0];
|
||||
expect(fetchedUser.zip).toBe(ZIP);
|
||||
expect(fetchedUser.email).toBe(EMAIL);
|
||||
},
|
||||
e => console.error('error', e.message)
|
||||
)
|
||||
.done(() => done());
|
||||
.then(done);
|
||||
});
|
||||
|
||||
it('should get PII via REST using master key', done => {
|
||||
request
|
||||
.get({
|
||||
url: 'http://localhost:8378/1/classes/_User',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
})
|
||||
request({
|
||||
url: 'http://localhost:8378/1/classes/_User',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
})
|
||||
.then(
|
||||
result => {
|
||||
response => {
|
||||
const result = response.data;
|
||||
const fetchedUser = result.results[0];
|
||||
expect(fetchedUser.zip).toBe(ZIP);
|
||||
expect(fetchedUser.email).toBe(EMAIL);
|
||||
},
|
||||
e => console.error('error', e.message)
|
||||
)
|
||||
.done(() => done());
|
||||
.then(() => done());
|
||||
});
|
||||
|
||||
it('should not get PII via REST by ID', done => {
|
||||
request
|
||||
.get({
|
||||
url: `http://localhost:8378/1/classes/_User/${user.id}`,
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
},
|
||||
})
|
||||
request({
|
||||
url: `http://localhost:8378/1/classes/_User/${user.id}`,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
},
|
||||
})
|
||||
.then(
|
||||
result => {
|
||||
const fetchedUser = result;
|
||||
response => {
|
||||
const fetchedUser = response.data;
|
||||
expect(fetchedUser.zip).toBe(ZIP);
|
||||
expect(fetchedUser.email).toBe(undefined);
|
||||
},
|
||||
e => console.error('error', e.message)
|
||||
e => done.fail(e)
|
||||
)
|
||||
.done(() => done());
|
||||
.then(() => done());
|
||||
});
|
||||
|
||||
it('should get PII via REST by ID with self credentials', done => {
|
||||
request
|
||||
.get({
|
||||
url: `http://localhost:8378/1/classes/_User/${user.id}`,
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
'X-Parse-Session-Token': user.getSessionToken(),
|
||||
},
|
||||
})
|
||||
request({
|
||||
url: `http://localhost:8378/1/classes/_User/${user.id}`,
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
'X-Parse-Session-Token': user.getSessionToken(),
|
||||
},
|
||||
})
|
||||
.then(
|
||||
result => {
|
||||
response => {
|
||||
const result = response.data;
|
||||
const fetchedUser = result;
|
||||
expect(fetchedUser.zip).toBe(ZIP);
|
||||
expect(fetchedUser.email).toBe(EMAIL);
|
||||
},
|
||||
e => console.error('error', e.message)
|
||||
)
|
||||
.done(() => done());
|
||||
.then(() => done());
|
||||
});
|
||||
|
||||
it('should get PII via REST by ID with master key', done => {
|
||||
request
|
||||
.get({
|
||||
url: `http://localhost:8378/1/classes/_User/${user.id}`,
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
})
|
||||
request({
|
||||
url: `http://localhost:8378/1/classes/_User/${user.id}`,
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
})
|
||||
.then(
|
||||
result => {
|
||||
response => {
|
||||
const result = response.data;
|
||||
const fetchedUser = result;
|
||||
expect(fetchedUser.zip).toBe(ZIP);
|
||||
expect(fetchedUser.email).toBe(EMAIL);
|
||||
},
|
||||
e => console.error('error', e.message)
|
||||
)
|
||||
.done(() => done());
|
||||
.then(() => done());
|
||||
});
|
||||
|
||||
describe('with configured sensitive fields', () => {
|
||||
@@ -317,14 +315,11 @@ describe('Personally Identifiable Information', () => {
|
||||
userObj.id = user.id;
|
||||
userObj
|
||||
.fetch({ useMasterKey: true })
|
||||
.then(
|
||||
fetchedUser => {
|
||||
expect(fetchedUser.get('email')).toBe(EMAIL);
|
||||
expect(fetchedUser.get('zip')).toBe(ZIP);
|
||||
expect(fetchedUser.get('ssn')).toBe(SSN);
|
||||
},
|
||||
e => console.error('error', e)
|
||||
)
|
||||
.then(fetchedUser => {
|
||||
expect(fetchedUser.get('email')).toBe(EMAIL);
|
||||
expect(fetchedUser.get('zip')).toBe(ZIP);
|
||||
expect(fetchedUser.get('ssn')).toBe(SSN);
|
||||
}, done.fail)
|
||||
.then(done)
|
||||
.catch(done.fail);
|
||||
});
|
||||
@@ -397,138 +392,131 @@ describe('Personally Identifiable Information', () => {
|
||||
});
|
||||
|
||||
it('should not get PII via REST', done => {
|
||||
request
|
||||
.get({
|
||||
url: 'http://localhost:8378/1/classes/_User',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
},
|
||||
})
|
||||
.then(
|
||||
result => {
|
||||
const fetchedUser = result.results[0];
|
||||
expect(fetchedUser.zip).toBe(undefined);
|
||||
expect(fetchedUser.ssn).toBe(undefined);
|
||||
expect(fetchedUser.email).toBe(undefined);
|
||||
},
|
||||
e => console.error('error', e.message)
|
||||
)
|
||||
request({
|
||||
url: 'http://localhost:8378/1/classes/_User',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
},
|
||||
})
|
||||
.then(response => {
|
||||
const result = response.data;
|
||||
const fetchedUser = result.results[0];
|
||||
expect(fetchedUser.zip).toBe(undefined);
|
||||
expect(fetchedUser.ssn).toBe(undefined);
|
||||
expect(fetchedUser.email).toBe(undefined);
|
||||
}, done.fail)
|
||||
.then(done)
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('should get PII via REST with self credentials', done => {
|
||||
request
|
||||
.get({
|
||||
url: 'http://localhost:8378/1/classes/_User',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
'X-Parse-Session-Token': user.getSessionToken(),
|
||||
},
|
||||
})
|
||||
request({
|
||||
url: 'http://localhost:8378/1/classes/_User',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
'X-Parse-Session-Token': user.getSessionToken(),
|
||||
},
|
||||
})
|
||||
.then(
|
||||
result => {
|
||||
response => {
|
||||
const result = response.data;
|
||||
const fetchedUser = result.results[0];
|
||||
expect(fetchedUser.zip).toBe(ZIP);
|
||||
expect(fetchedUser.email).toBe(EMAIL);
|
||||
expect(fetchedUser.ssn).toBe(SSN);
|
||||
},
|
||||
e => console.error('error', e.message)
|
||||
() => {}
|
||||
)
|
||||
.then(done)
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('should get PII via REST using master key', done => {
|
||||
request
|
||||
.get({
|
||||
url: 'http://localhost:8378/1/classes/_User',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
})
|
||||
request({
|
||||
url: 'http://localhost:8378/1/classes/_User',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
})
|
||||
.then(
|
||||
result => {
|
||||
response => {
|
||||
const result = response.data;
|
||||
const fetchedUser = result.results[0];
|
||||
expect(fetchedUser.zip).toBe(ZIP);
|
||||
expect(fetchedUser.email).toBe(EMAIL);
|
||||
expect(fetchedUser.ssn).toBe(SSN);
|
||||
},
|
||||
e => console.error('error', e.message)
|
||||
e => done.fail(e.data)
|
||||
)
|
||||
.then(done)
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('should not get PII via REST by ID', done => {
|
||||
request
|
||||
.get({
|
||||
url: `http://localhost:8378/1/classes/_User/${user.id}`,
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
},
|
||||
})
|
||||
request({
|
||||
url: `http://localhost:8378/1/classes/_User/${user.id}`,
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
},
|
||||
})
|
||||
.then(
|
||||
result => {
|
||||
const fetchedUser = result;
|
||||
response => {
|
||||
const fetchedUser = response.data;
|
||||
expect(fetchedUser.zip).toBe(undefined);
|
||||
expect(fetchedUser.email).toBe(undefined);
|
||||
},
|
||||
e => console.error('error', e.message)
|
||||
e => done.fail(e.data)
|
||||
)
|
||||
.then(done)
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('should get PII via REST by ID with self credentials', done => {
|
||||
request
|
||||
.get({
|
||||
url: `http://localhost:8378/1/classes/_User/${user.id}`,
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
'X-Parse-Session-Token': user.getSessionToken(),
|
||||
},
|
||||
})
|
||||
request({
|
||||
url: `http://localhost:8378/1/classes/_User/${user.id}`,
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
'X-Parse-Session-Token': user.getSessionToken(),
|
||||
},
|
||||
})
|
||||
.then(
|
||||
result => {
|
||||
const fetchedUser = result;
|
||||
response => {
|
||||
const fetchedUser = response.data;
|
||||
expect(fetchedUser.zip).toBe(ZIP);
|
||||
expect(fetchedUser.email).toBe(EMAIL);
|
||||
},
|
||||
e => console.error('error', e.message)
|
||||
() => {}
|
||||
)
|
||||
.then(done)
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('should get PII via REST by ID with master key', done => {
|
||||
request
|
||||
.get({
|
||||
url: `http://localhost:8378/1/classes/_User/${user.id}`,
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
})
|
||||
request({
|
||||
url: `http://localhost:8378/1/classes/_User/${user.id}`,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Javascript-Key': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
})
|
||||
.then(
|
||||
result => {
|
||||
response => {
|
||||
const result = response.data;
|
||||
const fetchedUser = result;
|
||||
expect(fetchedUser.zip).toBe(ZIP);
|
||||
expect(fetchedUser.email).toBe(EMAIL);
|
||||
},
|
||||
e => console.error('error', e.message)
|
||||
e => done.fail(e.data)
|
||||
)
|
||||
.then(done)
|
||||
.catch(done.fail);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const MockEmailAdapterWithOptions = require('./MockEmailAdapterWithOptions');
|
||||
const request = require('request');
|
||||
const request = require('../lib/request');
|
||||
const Config = require('../lib/Config');
|
||||
|
||||
describe('Custom Pages, Email Verification, Password Reset', () => {
|
||||
@@ -273,46 +273,43 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
|
||||
})
|
||||
.then(() => {
|
||||
expect(sendEmailOptions).not.toBeUndefined();
|
||||
request.get(
|
||||
sendEmailOptions.link,
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/verify_email_success.html?username=user'
|
||||
);
|
||||
user
|
||||
.fetch()
|
||||
.then(
|
||||
() => {
|
||||
expect(user.get('emailVerified')).toEqual(true);
|
||||
request({
|
||||
url: sendEmailOptions.link,
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/verify_email_success.html?username=user'
|
||||
);
|
||||
user
|
||||
.fetch()
|
||||
.then(
|
||||
() => {
|
||||
expect(user.get('emailVerified')).toEqual(true);
|
||||
|
||||
Parse.User.logIn('user', 'other-password').then(
|
||||
user => {
|
||||
expect(typeof user).toBe('object');
|
||||
expect(user.get('emailVerified')).toBe(true);
|
||||
done();
|
||||
},
|
||||
() => {
|
||||
fail('login should have succeeded');
|
||||
done();
|
||||
}
|
||||
);
|
||||
},
|
||||
err => {
|
||||
jfail(err);
|
||||
fail('this should not fail');
|
||||
done();
|
||||
}
|
||||
)
|
||||
.catch(err => {
|
||||
Parse.User.logIn('user', 'other-password').then(
|
||||
user => {
|
||||
expect(typeof user).toBe('object');
|
||||
expect(user.get('emailVerified')).toBe(true);
|
||||
done();
|
||||
},
|
||||
() => {
|
||||
fail('login should have succeeded');
|
||||
done();
|
||||
}
|
||||
);
|
||||
},
|
||||
err => {
|
||||
jfail(err);
|
||||
fail('this should not fail');
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
.catch(err => {
|
||||
jfail(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -375,8 +372,7 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
|
||||
Parse.User.requestPasswordReset('testInvalidConfig@parse.com')
|
||||
)
|
||||
.then(
|
||||
result => {
|
||||
console.log(result);
|
||||
() => {
|
||||
fail('sending password reset email should not have succeeded');
|
||||
done();
|
||||
},
|
||||
@@ -414,8 +410,7 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
|
||||
Parse.User.requestPasswordReset('testInvalidConfig@parse.com')
|
||||
)
|
||||
.then(
|
||||
result => {
|
||||
console.log(result);
|
||||
() => {
|
||||
fail('sending password reset email should not have succeeded');
|
||||
done();
|
||||
},
|
||||
@@ -450,8 +445,7 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
|
||||
Parse.User.requestPasswordReset('testInvalidConfig@parse.com')
|
||||
)
|
||||
.then(
|
||||
result => {
|
||||
console.log(result);
|
||||
() => {
|
||||
fail('sending password reset email should not have succeeded');
|
||||
done();
|
||||
},
|
||||
@@ -624,35 +618,32 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
|
||||
})
|
||||
.then(() => {
|
||||
expect(sendEmailOptions).not.toBeUndefined();
|
||||
request.get(
|
||||
sendEmailOptions.link,
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/verify_email_success.html?username=user'
|
||||
);
|
||||
user
|
||||
.fetch()
|
||||
.then(
|
||||
() => {
|
||||
expect(user.get('emailVerified')).toEqual(true);
|
||||
done();
|
||||
},
|
||||
err => {
|
||||
jfail(err);
|
||||
fail('this should not fail');
|
||||
done();
|
||||
}
|
||||
)
|
||||
.catch(err => {
|
||||
jfail(err);
|
||||
request({
|
||||
url: sendEmailOptions.link,
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/verify_email_success.html?username=user'
|
||||
);
|
||||
user
|
||||
.fetch()
|
||||
.then(
|
||||
() => {
|
||||
expect(user.get('emailVerified')).toEqual(true);
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
},
|
||||
err => {
|
||||
jfail(err);
|
||||
fail('this should not fail');
|
||||
done();
|
||||
}
|
||||
)
|
||||
.catch(err => {
|
||||
jfail(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -667,19 +658,16 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
|
||||
},
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
}).then(() => {
|
||||
request.get(
|
||||
'http://localhost:8378/1/apps/test/verify_email',
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/invalid_link.html'
|
||||
);
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
url: 'http://localhost:8378/1/apps/test/verify_email',
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/invalid_link.html'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -694,19 +682,17 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
|
||||
},
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
}).then(() => {
|
||||
request.get(
|
||||
'http://localhost:8378/1/apps/test/verify_email?token=asdfasdf&username=sadfasga',
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link.html?username=sadfasga&appId=test'
|
||||
);
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
url:
|
||||
'http://localhost:8378/1/apps/test/verify_email?token=asdfasdf&username=sadfasga',
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link.html?username=sadfasga&appId=test'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -721,22 +707,20 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
|
||||
},
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
}).then(() => {
|
||||
request.post(
|
||||
'http://localhost:8378/1/apps/test/resend_verification_email',
|
||||
{
|
||||
followRedirect: false,
|
||||
form: {
|
||||
username: 'sadfasga',
|
||||
},
|
||||
request({
|
||||
url: 'http://localhost:8378/1/apps/test/resend_verification_email',
|
||||
method: 'POST',
|
||||
followRedirects: false,
|
||||
body: {
|
||||
username: 'sadfasga',
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/link_send_fail.html'
|
||||
);
|
||||
done();
|
||||
}
|
||||
);
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/link_send_fail.html'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -744,22 +728,20 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
|
||||
const user = new Parse.User();
|
||||
const emailAdapter = {
|
||||
sendVerificationEmail: () => {
|
||||
request.get(
|
||||
'http://localhost:8378/1/apps/test/verify_email?token=invalid&username=zxcv',
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link.html?username=zxcv&appId=test'
|
||||
);
|
||||
user.fetch().then(() => {
|
||||
expect(user.get('emailVerified')).toEqual(false);
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
request({
|
||||
url:
|
||||
'http://localhost:8378/1/apps/test/verify_email?token=invalid&username=zxcv',
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/invalid_verification_link.html?username=zxcv&appId=test'
|
||||
);
|
||||
user.fetch().then(() => {
|
||||
expect(user.get('emailVerified')).toEqual(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
},
|
||||
sendPasswordResetEmail: () => Promise.resolve(),
|
||||
sendMail: () => {},
|
||||
@@ -788,23 +770,15 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
|
||||
const emailAdapter = {
|
||||
sendVerificationEmail: () => Promise.resolve(),
|
||||
sendPasswordResetEmail: options => {
|
||||
request.get(
|
||||
options.link,
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
if (error) {
|
||||
jfail(error);
|
||||
fail('Failed to get the reset link');
|
||||
return;
|
||||
}
|
||||
expect(response.statusCode).toEqual(302);
|
||||
const re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=[a-zA-Z0-9]+\&id=test\&username=zxcv%2Bzxcv/;
|
||||
expect(response.body.match(re)).not.toBe(null);
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
url: options.link,
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
const re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=[a-zA-Z0-9]+\&id=test\&username=zxcv%2Bzxcv/;
|
||||
expect(response.text.match(re)).not.toBe(null);
|
||||
done();
|
||||
});
|
||||
},
|
||||
sendMail: () => {},
|
||||
};
|
||||
@@ -840,19 +814,17 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
|
||||
},
|
||||
publicServerURL: 'http://localhost:8378/1',
|
||||
}).then(() => {
|
||||
request.get(
|
||||
'http://localhost:8378/1/apps/test/request_password_reset?token=asdfasdf&username=sadfasga',
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/invalid_link.html'
|
||||
);
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
url:
|
||||
'http://localhost:8378/1/apps/test/request_password_reset?token=asdfasdf&username=sadfasga',
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/invalid_link.html'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -861,76 +833,59 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
|
||||
const emailAdapter = {
|
||||
sendVerificationEmail: () => Promise.resolve(),
|
||||
sendPasswordResetEmail: options => {
|
||||
request.get(
|
||||
options.link,
|
||||
{
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
if (error) {
|
||||
jfail(error);
|
||||
fail('Failed to get the reset link');
|
||||
return;
|
||||
}
|
||||
expect(response.statusCode).toEqual(302);
|
||||
const re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=([a-zA-Z0-9]+)\&id=test\&username=zxcv/;
|
||||
const match = response.body.match(re);
|
||||
if (!match) {
|
||||
fail('should have a token');
|
||||
done();
|
||||
return;
|
||||
}
|
||||
const token = match[1];
|
||||
request({
|
||||
url: options.link,
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
const re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=([a-zA-Z0-9]+)\&id=test\&username=zxcv/;
|
||||
const match = response.text.match(re);
|
||||
if (!match) {
|
||||
fail('should have a token');
|
||||
done();
|
||||
return;
|
||||
}
|
||||
const token = match[1];
|
||||
|
||||
request.post(
|
||||
{
|
||||
url: 'http://localhost:8378/1/apps/test/request_password_reset',
|
||||
body: `new_password=hello&token=${token}&username=zxcv`,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
followRedirect: false,
|
||||
},
|
||||
(error, response) => {
|
||||
if (error) {
|
||||
jfail(error);
|
||||
fail('Failed to POST request password reset');
|
||||
return;
|
||||
}
|
||||
expect(response.statusCode).toEqual(302);
|
||||
expect(response.body).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/password_reset_success.html?username=zxcv'
|
||||
);
|
||||
request({
|
||||
url: 'http://localhost:8378/1/apps/test/request_password_reset',
|
||||
method: 'POST',
|
||||
body: { new_password: 'hello', token, username: 'zxcv' },
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
followRedirects: false,
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(302);
|
||||
expect(response.text).toEqual(
|
||||
'Found. Redirecting to http://localhost:8378/1/apps/password_reset_success.html?username=zxcv'
|
||||
);
|
||||
|
||||
Parse.User.logIn('zxcv', 'hello').then(
|
||||
function() {
|
||||
const config = Config.get('test');
|
||||
config.database.adapter
|
||||
.find(
|
||||
'_User',
|
||||
{ fields: {} },
|
||||
{ username: 'zxcv' },
|
||||
{ limit: 1 }
|
||||
)
|
||||
.then(results => {
|
||||
// _perishable_token should be unset after reset password
|
||||
expect(results.length).toEqual(1);
|
||||
expect(results[0]['_perishable_token']).toEqual(
|
||||
undefined
|
||||
);
|
||||
done();
|
||||
});
|
||||
},
|
||||
err => {
|
||||
jfail(err);
|
||||
fail('should login with new password');
|
||||
Parse.User.logIn('zxcv', 'hello').then(
|
||||
function() {
|
||||
const config = Config.get('test');
|
||||
config.database.adapter
|
||||
.find(
|
||||
'_User',
|
||||
{ fields: {} },
|
||||
{ username: 'zxcv' },
|
||||
{ limit: 1 }
|
||||
)
|
||||
.then(results => {
|
||||
// _perishable_token should be unset after reset password
|
||||
expect(results.length).toEqual(1);
|
||||
expect(results[0]['_perishable_token']).toEqual(undefined);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
err => {
|
||||
jfail(err);
|
||||
fail('should login with new password');
|
||||
done();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
},
|
||||
sendMail: () => {},
|
||||
};
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
const rp = require('request-promise');
|
||||
const request = require('../lib/request');
|
||||
const MockEmailAdapterWithOptions = require('./MockEmailAdapterWithOptions');
|
||||
|
||||
const verifyPassword = function(login, password, isEmail = false) {
|
||||
const body = !isEmail
|
||||
? { username: login, password }
|
||||
: { email: login, password };
|
||||
return rp
|
||||
.get({
|
||||
url: Parse.serverURL + '/verifyPassword',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
body,
|
||||
json: true,
|
||||
})
|
||||
return request({
|
||||
url: Parse.serverURL + '/verifyPassword',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
qs: body,
|
||||
})
|
||||
.then(res => res)
|
||||
.catch(err => err);
|
||||
};
|
||||
@@ -65,7 +63,7 @@ describe('Verify User Password', () => {
|
||||
})
|
||||
.then(() => {
|
||||
expect(user.getACL().getPublicReadAccess()).toBe(false);
|
||||
return rp.get({
|
||||
return request({
|
||||
url: Parse.serverURL + '/verifyPassword',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
@@ -82,8 +80,8 @@ describe('Verify User Password', () => {
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.statusCode).toBe(404);
|
||||
expect(err.error).toMatch(
|
||||
expect(err.status).toBe(404);
|
||||
expect(err.text).toMatch(
|
||||
'{"code":101,"error":"Invalid username/password."}'
|
||||
);
|
||||
done();
|
||||
@@ -98,7 +96,7 @@ describe('Verify User Password', () => {
|
||||
email: 'my@user.com',
|
||||
})
|
||||
.then(() => {
|
||||
return rp.get({
|
||||
return request({
|
||||
url: Parse.serverURL + '/verifyPassword',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
@@ -115,8 +113,8 @@ describe('Verify User Password', () => {
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.statusCode).toBe(400);
|
||||
expect(err.error).toMatch(
|
||||
expect(err.status).toBe(400);
|
||||
expect(err.text).toMatch(
|
||||
'{"code":200,"error":"username/email is required."}'
|
||||
);
|
||||
done();
|
||||
@@ -131,7 +129,7 @@ describe('Verify User Password', () => {
|
||||
email: 'my@user.com',
|
||||
})
|
||||
.then(() => {
|
||||
return rp.get({
|
||||
return request({
|
||||
url: Parse.serverURL + '/verifyPassword',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
@@ -148,8 +146,8 @@ describe('Verify User Password', () => {
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.statusCode).toBe(400);
|
||||
expect(err.error).toMatch(
|
||||
expect(err.status).toBe(400);
|
||||
expect(err.text).toMatch(
|
||||
'{"code":200,"error":"username/email is required."}'
|
||||
);
|
||||
done();
|
||||
@@ -167,8 +165,8 @@ describe('Verify User Password', () => {
|
||||
return verifyPassword('', 'mypass');
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.statusCode).toBe(400);
|
||||
expect(JSON.stringify(res.error)).toMatch(
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.text).toMatch(
|
||||
'{"code":200,"error":"username/email is required."}'
|
||||
);
|
||||
done();
|
||||
@@ -190,8 +188,8 @@ describe('Verify User Password', () => {
|
||||
return verifyPassword('', 'mypass', true);
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.statusCode).toBe(400);
|
||||
expect(JSON.stringify(res.error)).toMatch(
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.text).toMatch(
|
||||
'{"code":200,"error":"username/email is required."}'
|
||||
);
|
||||
done();
|
||||
@@ -213,8 +211,8 @@ describe('Verify User Password', () => {
|
||||
return verifyPassword('testuser', '');
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.statusCode).toBe(400);
|
||||
expect(JSON.stringify(res.error)).toMatch(
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.text).toMatch(
|
||||
'{"code":201,"error":"password is required."}'
|
||||
);
|
||||
done();
|
||||
@@ -236,8 +234,8 @@ describe('Verify User Password', () => {
|
||||
return verifyPassword('testuser', 'wrong password');
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.statusCode).toBe(404);
|
||||
expect(JSON.stringify(res.error)).toMatch(
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.text).toMatch(
|
||||
'{"code":101,"error":"Invalid username/password."}'
|
||||
);
|
||||
done();
|
||||
@@ -259,8 +257,8 @@ describe('Verify User Password', () => {
|
||||
return verifyPassword('my@user.com', 'wrong password', true);
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.statusCode).toBe(404);
|
||||
expect(JSON.stringify(res.error)).toMatch(
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.text).toMatch(
|
||||
'{"code":101,"error":"Invalid username/password."}'
|
||||
);
|
||||
done();
|
||||
@@ -282,8 +280,8 @@ describe('Verify User Password', () => {
|
||||
return verifyPassword(123, 'mypass');
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.statusCode).toBe(404);
|
||||
expect(JSON.stringify(res.error)).toMatch(
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.text).toMatch(
|
||||
'{"code":101,"error":"Invalid username/password."}'
|
||||
);
|
||||
done();
|
||||
@@ -305,8 +303,8 @@ describe('Verify User Password', () => {
|
||||
return verifyPassword(123, 'mypass', true);
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.statusCode).toBe(404);
|
||||
expect(JSON.stringify(res.error)).toMatch(
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.text).toMatch(
|
||||
'{"code":101,"error":"Invalid username/password."}'
|
||||
);
|
||||
done();
|
||||
@@ -328,8 +326,8 @@ describe('Verify User Password', () => {
|
||||
return verifyPassword('my@user.com', 123, true);
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.statusCode).toBe(404);
|
||||
expect(JSON.stringify(res.error)).toMatch(
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.text).toMatch(
|
||||
'{"code":101,"error":"Invalid username/password."}'
|
||||
);
|
||||
done();
|
||||
@@ -342,8 +340,8 @@ describe('Verify User Password', () => {
|
||||
it('fails to verify password when username cannot be found REST API', done => {
|
||||
verifyPassword('mytestuser', 'mypass')
|
||||
.then(res => {
|
||||
expect(res.statusCode).toBe(404);
|
||||
expect(JSON.stringify(res.error)).toMatch(
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.text).toMatch(
|
||||
'{"code":101,"error":"Invalid username/password."}'
|
||||
);
|
||||
done();
|
||||
@@ -356,8 +354,8 @@ describe('Verify User Password', () => {
|
||||
it('fails to verify password when email cannot be found REST API', done => {
|
||||
verifyPassword('my@user.com', 'mypass', true)
|
||||
.then(res => {
|
||||
expect(res.statusCode).toBe(404);
|
||||
expect(JSON.stringify(res.error)).toMatch(
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.text).toMatch(
|
||||
'{"code":101,"error":"Invalid username/password."}'
|
||||
);
|
||||
done();
|
||||
@@ -391,8 +389,8 @@ describe('Verify User Password', () => {
|
||||
return verifyPassword('unverified-email@user.com', 'mypass', true);
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.statusCode).toBe(400);
|
||||
expect(JSON.stringify(res.error)).toMatch(
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.text).toMatch(
|
||||
'{"code":205,"error":"User email is not verified."}'
|
||||
);
|
||||
done();
|
||||
@@ -451,24 +449,24 @@ describe('Verify User Password', () => {
|
||||
email: 'my@user.com',
|
||||
})
|
||||
.then(() => {
|
||||
return rp
|
||||
.get({
|
||||
url: Parse.serverURL + '/verifyPassword',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
body: {
|
||||
username: 'testuser',
|
||||
email: 'my@user.com',
|
||||
password: 'mypass',
|
||||
},
|
||||
json: true,
|
||||
})
|
||||
return request({
|
||||
url: Parse.serverURL + '/verifyPassword',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
qs: {
|
||||
username: 'testuser',
|
||||
email: 'my@user.com',
|
||||
password: 'mypass',
|
||||
},
|
||||
json: true,
|
||||
})
|
||||
.then(res => res)
|
||||
.catch(err => err);
|
||||
})
|
||||
.then(res => {
|
||||
.then(response => {
|
||||
const res = response.data;
|
||||
expect(typeof res).toBe('object');
|
||||
expect(typeof res['objectId']).toEqual('string');
|
||||
expect(res.hasOwnProperty('sessionToken')).toEqual(false);
|
||||
@@ -491,7 +489,8 @@ describe('Verify User Password', () => {
|
||||
.then(() => {
|
||||
return verifyPassword('testuser', 'mypass');
|
||||
})
|
||||
.then(res => {
|
||||
.then(response => {
|
||||
const res = response.data;
|
||||
expect(typeof res).toBe('object');
|
||||
expect(typeof res['objectId']).toEqual('string');
|
||||
expect(res.hasOwnProperty('sessionToken')).toEqual(false);
|
||||
@@ -510,7 +509,8 @@ describe('Verify User Password', () => {
|
||||
.then(() => {
|
||||
return verifyPassword('my@user.com', 'mypass', true);
|
||||
})
|
||||
.then(res => {
|
||||
.then(response => {
|
||||
const res = response.data;
|
||||
expect(typeof res).toBe('object');
|
||||
expect(typeof res['objectId']).toEqual('string');
|
||||
expect(res.hasOwnProperty('sessionToken')).toEqual(false);
|
||||
@@ -527,7 +527,7 @@ describe('Verify User Password', () => {
|
||||
email: 'my@user.com',
|
||||
})
|
||||
.then(() => {
|
||||
return rp.get({
|
||||
return request({
|
||||
url: Parse.serverURL + '/verifyPassword',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
@@ -539,7 +539,8 @@ describe('Verify User Password', () => {
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(res => {
|
||||
.then(response => {
|
||||
const res = response.text;
|
||||
expect(typeof res).toBe('string');
|
||||
const body = JSON.parse(res);
|
||||
expect(typeof body['objectId']).toEqual('string');
|
||||
@@ -557,7 +558,7 @@ describe('Verify User Password', () => {
|
||||
email: 'my@user.com',
|
||||
})
|
||||
.then(() => {
|
||||
return rp.get({
|
||||
return request({
|
||||
url: Parse.serverURL + '/verifyPassword',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
@@ -569,7 +570,8 @@ describe('Verify User Password', () => {
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(res => {
|
||||
.then(response => {
|
||||
const res = response.text;
|
||||
expect(typeof res).toBe('string');
|
||||
const body = JSON.parse(res);
|
||||
expect(typeof body['objectId']).toEqual('string');
|
||||
@@ -597,7 +599,8 @@ describe('Verify User Password', () => {
|
||||
.then(() => {
|
||||
return verifyPassword('email@user.com', 'mypass1');
|
||||
})
|
||||
.then(res => {
|
||||
.then(response => {
|
||||
const res = response.data;
|
||||
expect(typeof res).toBe('object');
|
||||
expect(typeof res['objectId']).toEqual('string');
|
||||
expect(res.hasOwnProperty('sessionToken')).toEqual(false);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
const WinstonLoggerAdapter = require('../lib/Adapters/Logger/WinstonLoggerAdapter')
|
||||
.WinstonLoggerAdapter;
|
||||
const request = require('request');
|
||||
const request = require('../lib/request');
|
||||
|
||||
describe('info logs', () => {
|
||||
it('Verify INFO logs', done => {
|
||||
@@ -84,27 +84,24 @@ describe('verbose logs', () => {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
};
|
||||
request.get(
|
||||
{
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/login?username=test&password=moon-y',
|
||||
},
|
||||
() => {
|
||||
const winstonLoggerAdapter = new WinstonLoggerAdapter();
|
||||
return winstonLoggerAdapter
|
||||
.query({
|
||||
from: new Date(Date.now() - 500),
|
||||
size: 100,
|
||||
level: 'verbose',
|
||||
})
|
||||
.then(results => {
|
||||
const logString = JSON.stringify(results);
|
||||
expect(logString.match(/\*\*\*\*\*\*\*\*/g).length).not.toBe(0);
|
||||
expect(logString.match(/moon-y/g)).toBe(null);
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
request({
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/login?username=test&password=moon-y',
|
||||
}).then(() => {
|
||||
const winstonLoggerAdapter = new WinstonLoggerAdapter();
|
||||
return winstonLoggerAdapter
|
||||
.query({
|
||||
from: new Date(Date.now() - 500),
|
||||
size: 100,
|
||||
level: 'verbose',
|
||||
})
|
||||
.then(results => {
|
||||
const logString = JSON.stringify(results);
|
||||
expect(logString.match(/\*\*\*\*\*\*\*\*/g).length).not.toBe(0);
|
||||
expect(logString.match(/moon-y/g)).toBe(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
fail(JSON.stringify(err));
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
const request = require('request');
|
||||
const request = require('../lib/request');
|
||||
|
||||
describe('features', () => {
|
||||
it('requires the master key to get features', done => {
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/serverInfo',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
request({
|
||||
url: 'http://localhost:8378/1/serverInfo',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(response.statusCode).toEqual(403);
|
||||
expect(body.error).toEqual('unauthorized: master key is required');
|
||||
done();
|
||||
}
|
||||
);
|
||||
}).then(fail, response => {
|
||||
expect(response.status).toEqual(403);
|
||||
expect(response.data.error).toEqual(
|
||||
'unauthorized: master key is required'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
const request = require('request');
|
||||
const request = require('../lib/request');
|
||||
const parseServerPackage = require('../package.json');
|
||||
const MockEmailAdapterWithOptions = require('./MockEmailAdapterWithOptions');
|
||||
const ParseServer = require('../lib/index');
|
||||
@@ -28,38 +28,32 @@ describe('server', () => {
|
||||
|
||||
it('support http basic authentication with masterkey', done => {
|
||||
reconfigureServer({ appId: 'test' }).then(() => {
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
headers: {
|
||||
Authorization:
|
||||
'Basic ' + new Buffer('test:' + 'test').toString('base64'),
|
||||
},
|
||||
request({
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
headers: {
|
||||
Authorization:
|
||||
'Basic ' + new Buffer('test:' + 'test').toString('base64'),
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(200);
|
||||
done();
|
||||
}
|
||||
);
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('support http basic authentication with javascriptKey', done => {
|
||||
reconfigureServer({ appId: 'test' }).then(() => {
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
headers: {
|
||||
Authorization:
|
||||
'Basic ' +
|
||||
new Buffer('test:javascript-key=' + 'test').toString('base64'),
|
||||
},
|
||||
request({
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
headers: {
|
||||
Authorization:
|
||||
'Basic ' +
|
||||
new Buffer('test:javascript-key=' + 'test').toString('base64'),
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toEqual(200);
|
||||
done();
|
||||
}
|
||||
);
|
||||
}).then(response => {
|
||||
expect(response.status).toEqual(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -70,23 +64,21 @@ describe('server', () => {
|
||||
}),
|
||||
}).catch(() => {
|
||||
//Need to use rest api because saving via JS SDK results in fail() not getting called
|
||||
request.post(
|
||||
{
|
||||
url: 'http://localhost:8378/1/classes/NewClass',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
body: {},
|
||||
json: true,
|
||||
request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/NewClass',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(response.statusCode).toEqual(500);
|
||||
expect(body.code).toEqual(1);
|
||||
expect(body.message).toEqual('Internal server error.');
|
||||
reconfigureServer().then(done, done);
|
||||
}
|
||||
);
|
||||
body: {},
|
||||
}).then(fail, response => {
|
||||
expect(response.status).toEqual(500);
|
||||
const body = response.data;
|
||||
expect(body.code).toEqual(1);
|
||||
expect(body.message).toEqual('Internal server error.');
|
||||
reconfigureServer().then(done, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -169,20 +161,17 @@ describe('server', () => {
|
||||
});
|
||||
|
||||
it('can report the server version', done => {
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/serverInfo',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
json: true,
|
||||
request({
|
||||
url: 'http://localhost:8378/1/serverInfo',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(body.parseServerVersion).toEqual(parseServerPackage.version);
|
||||
done();
|
||||
}
|
||||
);
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(body.parseServerVersion).toEqual(parseServerPackage.version);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can properly sets the push support', done => {
|
||||
@@ -190,21 +179,19 @@ describe('server', () => {
|
||||
const config = Config.get('test');
|
||||
expect(config.hasPushSupport).toEqual(true);
|
||||
expect(config.hasPushScheduledSupport).toEqual(false);
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/serverInfo',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
json: true,
|
||||
request({
|
||||
url: 'http://localhost:8378/1/serverInfo',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(body.features.push.immediatePush).toEqual(true);
|
||||
expect(body.features.push.scheduledPush).toEqual(false);
|
||||
done();
|
||||
}
|
||||
);
|
||||
json: true,
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(body.features.push.immediatePush).toEqual(true);
|
||||
expect(body.features.push.scheduledPush).toEqual(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can properly sets the push support when not configured', done => {
|
||||
@@ -215,21 +202,19 @@ describe('server', () => {
|
||||
const config = Config.get('test');
|
||||
expect(config.hasPushSupport).toEqual(false);
|
||||
expect(config.hasPushScheduledSupport).toEqual(false);
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/serverInfo',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
json: true,
|
||||
request({
|
||||
url: 'http://localhost:8378/1/serverInfo',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(body.features.push.immediatePush).toEqual(false);
|
||||
expect(body.features.push.scheduledPush).toEqual(false);
|
||||
done();
|
||||
}
|
||||
);
|
||||
json: true,
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(body.features.push.immediatePush).toEqual(false);
|
||||
expect(body.features.push.scheduledPush).toEqual(false);
|
||||
done();
|
||||
});
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
@@ -247,21 +232,19 @@ describe('server', () => {
|
||||
const config = Config.get('test');
|
||||
expect(config.hasPushSupport).toEqual(true);
|
||||
expect(config.hasPushScheduledSupport).toEqual(false);
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/serverInfo',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
json: true,
|
||||
request({
|
||||
url: 'http://localhost:8378/1/serverInfo',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(body.features.push.immediatePush).toEqual(true);
|
||||
expect(body.features.push.scheduledPush).toEqual(false);
|
||||
done();
|
||||
}
|
||||
);
|
||||
json: true,
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(body.features.push.immediatePush).toEqual(true);
|
||||
expect(body.features.push.scheduledPush).toEqual(false);
|
||||
done();
|
||||
});
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
@@ -280,35 +263,30 @@ describe('server', () => {
|
||||
const config = Config.get('test');
|
||||
expect(config.hasPushSupport).toEqual(true);
|
||||
expect(config.hasPushScheduledSupport).toEqual(true);
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/serverInfo',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
json: true,
|
||||
request({
|
||||
url: 'http://localhost:8378/1/serverInfo',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(body.features.push.immediatePush).toEqual(true);
|
||||
expect(body.features.push.scheduledPush).toEqual(true);
|
||||
done();
|
||||
}
|
||||
);
|
||||
json: true,
|
||||
}).then(response => {
|
||||
const body = response.data;
|
||||
expect(body.features.push.immediatePush).toEqual(true);
|
||||
expect(body.features.push.scheduledPush).toEqual(true);
|
||||
done();
|
||||
});
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('can respond 200 on path health', done => {
|
||||
request.get(
|
||||
{
|
||||
url: 'http://localhost:8378/1/health',
|
||||
},
|
||||
(error, response) => {
|
||||
expect(response.statusCode).toBe(200);
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
url: 'http://localhost:8378/1/health',
|
||||
}).then(response => {
|
||||
expect(response.status).toBe(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can create a parse-server v1', done => {
|
||||
@@ -525,7 +503,7 @@ describe('server', () => {
|
||||
middleware: 'spec/support/CustomMiddleware',
|
||||
})
|
||||
.then(() => {
|
||||
return request.get('http://localhost:8378/1', (err, res) => {
|
||||
return request({ url: 'http://localhost:8378/1' }).then(fail, res => {
|
||||
// Just check that the middleware set the header
|
||||
expect(res.headers['x-yolo']).toBe('1');
|
||||
done();
|
||||
|
||||
@@ -5,8 +5,7 @@ const Config = require('../lib/Config');
|
||||
const Parse = require('parse/node').Parse;
|
||||
const rest = require('../lib/rest');
|
||||
const RestWrite = require('../lib/RestWrite');
|
||||
const request = require('request');
|
||||
const rp = require('request-promise');
|
||||
const request = require('../lib/request');
|
||||
|
||||
let config;
|
||||
let database;
|
||||
@@ -152,11 +151,7 @@ describe('rest create', () => {
|
||||
expect(mob.subdoc.wu).toBe('clan');
|
||||
done();
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
fail();
|
||||
done();
|
||||
});
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('handles create on non-existent class when disabled client class creation', done => {
|
||||
@@ -436,26 +431,24 @@ describe('rest create', () => {
|
||||
|
||||
it('cannot set objectId', done => {
|
||||
const headers = {
|
||||
'Content-Type': 'application/octet-stream',
|
||||
'Content-Type': 'application/json',
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
};
|
||||
request.post(
|
||||
{
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
body: JSON.stringify({
|
||||
foo: 'bar',
|
||||
objectId: 'hello',
|
||||
}),
|
||||
},
|
||||
(error, response, body) => {
|
||||
const b = JSON.parse(body);
|
||||
expect(b.code).toEqual(105);
|
||||
expect(b.error).toEqual('objectId is an invalid field name.');
|
||||
done();
|
||||
}
|
||||
);
|
||||
request({
|
||||
headers: headers,
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/classes/TestObject',
|
||||
body: JSON.stringify({
|
||||
foo: 'bar',
|
||||
objectId: 'hello',
|
||||
}),
|
||||
}).then(fail, response => {
|
||||
const b = response.data;
|
||||
expect(b.code).toEqual(105);
|
||||
expect(b.error).toEqual('objectId is an invalid field name.');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('test default session length', done => {
|
||||
@@ -589,9 +582,6 @@ describe('rest create', () => {
|
||||
.then(() => {
|
||||
return rest.create(config, auth.nobody(config), '_PushStatus', {});
|
||||
})
|
||||
.then(r => {
|
||||
console.log(r);
|
||||
})
|
||||
.catch(error => {
|
||||
expect(error.code).toEqual(119);
|
||||
done();
|
||||
@@ -605,64 +595,66 @@ describe('rest create', () => {
|
||||
currentUser = user;
|
||||
const sessionToken = user.getSessionToken();
|
||||
const headers = {
|
||||
'Content-Type': 'application/octet-stream',
|
||||
'Content-Type': 'application/json',
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
'X-Parse-Session-Token': sessionToken,
|
||||
};
|
||||
let sessionId;
|
||||
return rp
|
||||
.get({
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/sessions/me',
|
||||
json: true,
|
||||
})
|
||||
.then(body => {
|
||||
sessionId = body.objectId;
|
||||
return rp.put({
|
||||
return request({
|
||||
headers: headers,
|
||||
url: 'http://localhost:8378/1/sessions/me',
|
||||
})
|
||||
.then(response => {
|
||||
sessionId = response.data.objectId;
|
||||
return request({
|
||||
headers,
|
||||
method: 'PUT',
|
||||
url: 'http://localhost:8378/1/sessions/' + sessionId,
|
||||
json: {
|
||||
body: {
|
||||
installationId: 'yolo',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(done.fail, res => {
|
||||
expect(res.statusCode).toBe(400);
|
||||
expect(res.error.code).toBe(105);
|
||||
return rp.put({
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.data.code).toBe(105);
|
||||
return request({
|
||||
headers,
|
||||
method: 'PUT',
|
||||
url: 'http://localhost:8378/1/sessions/' + sessionId,
|
||||
json: {
|
||||
body: {
|
||||
sessionToken: 'yolo',
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(done.fail, res => {
|
||||
expect(res.statusCode).toBe(400);
|
||||
expect(res.error.code).toBe(105);
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.data.code).toBe(105);
|
||||
return Parse.User.signUp('other', 'user');
|
||||
})
|
||||
.then(otherUser => {
|
||||
const user = new Parse.User();
|
||||
user.id = otherUser.id;
|
||||
return rp.put({
|
||||
return request({
|
||||
headers,
|
||||
method: 'PUT',
|
||||
url: 'http://localhost:8378/1/sessions/' + sessionId,
|
||||
json: {
|
||||
body: {
|
||||
user: Parse._encode(user),
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(done.fail, res => {
|
||||
expect(res.statusCode).toBe(400);
|
||||
expect(res.error.code).toBe(105);
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.data.code).toBe(105);
|
||||
const user = new Parse.User();
|
||||
user.id = currentUser.id;
|
||||
return rp.put({
|
||||
return request({
|
||||
headers,
|
||||
method: 'PUT',
|
||||
url: 'http://localhost:8378/1/sessions/' + sessionId,
|
||||
json: {
|
||||
body: {
|
||||
user: Parse._encode(user),
|
||||
},
|
||||
});
|
||||
@@ -683,18 +675,19 @@ describe('rest create', () => {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-REST-API-Key': 'rest',
|
||||
'X-Parse-Session-Token': sessionToken,
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
return rp.post({
|
||||
return request({
|
||||
headers,
|
||||
method: 'POST',
|
||||
url: 'http://localhost:8378/1/sessions',
|
||||
json: true,
|
||||
body: {
|
||||
user: { __type: 'Pointer', className: '_User', objectId: 'fakeId' },
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(body => {
|
||||
if (body.user.objectId === currentUser.id) {
|
||||
.then(response => {
|
||||
if (response.data.user.objectId === currentUser.id) {
|
||||
return done();
|
||||
} else {
|
||||
return done.fail();
|
||||
@@ -763,18 +756,21 @@ describe('read-only masterKey', () => {
|
||||
readOnlyMasterKey: 'yolo-read-only',
|
||||
})
|
||||
.then(() => {
|
||||
return rp.post(`${Parse.serverURL}/classes/MyYolo`, {
|
||||
return request({
|
||||
url: `${Parse.serverURL}/classes/MyYolo`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': 'yolo-read-only',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
json: { foo: 'bar' },
|
||||
body: { foo: 'bar' },
|
||||
});
|
||||
})
|
||||
.then(done.fail)
|
||||
.catch(res => {
|
||||
expect(res.error.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||
expect(res.error.error).toBe(
|
||||
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||
expect(res.data.error).toBe(
|
||||
"read-only masterKey isn't allowed to perform the create operation."
|
||||
);
|
||||
done();
|
||||
@@ -808,18 +804,20 @@ describe('read-only masterKey', () => {
|
||||
});
|
||||
|
||||
it('should throw when trying to create schema', done => {
|
||||
return rp
|
||||
.post(`${Parse.serverURL}/schemas`, {
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': 'read-only-test',
|
||||
},
|
||||
json: {},
|
||||
})
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: `${Parse.serverURL}/schemas`,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': 'read-only-test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
json: {},
|
||||
})
|
||||
.then(done.fail)
|
||||
.catch(res => {
|
||||
expect(res.error.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||
expect(res.error.error).toBe(
|
||||
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||
expect(res.data.error).toBe(
|
||||
"read-only masterKey isn't allowed to create a schema."
|
||||
);
|
||||
done();
|
||||
@@ -827,18 +825,20 @@ describe('read-only masterKey', () => {
|
||||
});
|
||||
|
||||
it('should throw when trying to create schema with a name', done => {
|
||||
return rp
|
||||
.post(`${Parse.serverURL}/schemas/MyClass`, {
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': 'read-only-test',
|
||||
},
|
||||
json: {},
|
||||
})
|
||||
return request({
|
||||
url: `${Parse.serverURL}/schemas/MyClass`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': 'read-only-test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
json: {},
|
||||
})
|
||||
.then(done.fail)
|
||||
.catch(res => {
|
||||
expect(res.error.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||
expect(res.error.error).toBe(
|
||||
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||
expect(res.data.error).toBe(
|
||||
"read-only masterKey isn't allowed to create a schema."
|
||||
);
|
||||
done();
|
||||
@@ -846,18 +846,20 @@ describe('read-only masterKey', () => {
|
||||
});
|
||||
|
||||
it('should throw when trying to update schema', done => {
|
||||
return rp
|
||||
.put(`${Parse.serverURL}/schemas/MyClass`, {
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': 'read-only-test',
|
||||
},
|
||||
json: {},
|
||||
})
|
||||
return request({
|
||||
url: `${Parse.serverURL}/schemas/MyClass`,
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': 'read-only-test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
json: {},
|
||||
})
|
||||
.then(done.fail)
|
||||
.catch(res => {
|
||||
expect(res.error.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||
expect(res.error.error).toBe(
|
||||
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||
expect(res.data.error).toBe(
|
||||
"read-only masterKey isn't allowed to update a schema."
|
||||
);
|
||||
done();
|
||||
@@ -865,18 +867,20 @@ describe('read-only masterKey', () => {
|
||||
});
|
||||
|
||||
it('should throw when trying to delete schema', done => {
|
||||
return rp
|
||||
.del(`${Parse.serverURL}/schemas/MyClass`, {
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': 'read-only-test',
|
||||
},
|
||||
json: {},
|
||||
})
|
||||
return request({
|
||||
url: `${Parse.serverURL}/schemas/MyClass`,
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': 'read-only-test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
json: {},
|
||||
})
|
||||
.then(done.fail)
|
||||
.catch(res => {
|
||||
expect(res.error.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||
expect(res.error.error).toBe(
|
||||
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||
expect(res.data.error).toBe(
|
||||
"read-only masterKey isn't allowed to delete a schema."
|
||||
);
|
||||
done();
|
||||
@@ -884,18 +888,20 @@ describe('read-only masterKey', () => {
|
||||
});
|
||||
|
||||
it('should throw when trying to update the global config', done => {
|
||||
return rp
|
||||
.put(`${Parse.serverURL}/config`, {
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': 'read-only-test',
|
||||
},
|
||||
json: {},
|
||||
})
|
||||
return request({
|
||||
url: `${Parse.serverURL}/config`,
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': 'read-only-test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
json: {},
|
||||
})
|
||||
.then(done.fail)
|
||||
.catch(res => {
|
||||
expect(res.error.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||
expect(res.error.error).toBe(
|
||||
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||
expect(res.data.error).toBe(
|
||||
"read-only masterKey isn't allowed to update the config."
|
||||
);
|
||||
done();
|
||||
@@ -903,18 +909,20 @@ describe('read-only masterKey', () => {
|
||||
});
|
||||
|
||||
it('should throw when trying to send push', done => {
|
||||
return rp
|
||||
.post(`${Parse.serverURL}/push`, {
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': 'read-only-test',
|
||||
},
|
||||
json: {},
|
||||
})
|
||||
return request({
|
||||
url: `${Parse.serverURL}/push`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Master-Key': 'read-only-test',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
json: {},
|
||||
})
|
||||
.then(done.fail)
|
||||
.catch(res => {
|
||||
expect(res.error.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||
expect(res.error.error).toBe(
|
||||
expect(res.data.code).toBe(Parse.Error.OPERATION_FORBIDDEN);
|
||||
expect(res.data.error).toBe(
|
||||
"read-only masterKey isn't allowed to send push notifications."
|
||||
);
|
||||
done();
|
||||
|
||||
3219
spec/schemas.spec.js
3219
spec/schemas.spec.js
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user