2016-01-28 10:58:12 -08:00
|
|
|
// testing-routes.js
|
2018-07-02 23:30:14 -04:00
|
|
|
const AppCache = require('../lib/cache').default;
|
|
|
|
|
const middlewares = require('../lib/middlewares');
|
|
|
|
|
const { ParseServer } = require('../lib/index');
|
|
|
|
|
const { Parse } = require('parse/node');
|
2016-03-10 14:27:00 -08:00
|
|
|
|
2018-02-17 09:55:30 -05:00
|
|
|
const express = require('express'),
|
2018-07-02 23:30:14 -04:00
|
|
|
cryptoUtils = require('../lib/cryptoUtils');
|
2016-01-28 10:58:12 -08:00
|
|
|
|
2018-02-17 09:55:30 -05:00
|
|
|
const router = express.Router();
|
2016-01-28 10:58:12 -08:00
|
|
|
|
|
|
|
|
// creates a unique app in the cache, with a collection prefix
|
|
|
|
|
function createApp(req, res) {
|
2018-02-17 09:55:30 -05:00
|
|
|
const appId = cryptoUtils.randomHexString(32);
|
2016-03-16 19:34:46 -07:00
|
|
|
|
|
|
|
|
ParseServer({
|
2018-09-01 13:58:06 -04:00
|
|
|
databaseURI:
|
|
|
|
|
'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase',
|
2016-03-16 19:34:46 -07:00
|
|
|
appId: appId,
|
|
|
|
|
masterKey: 'master',
|
|
|
|
|
serverURL: Parse.serverURL,
|
2018-09-01 13:58:06 -04:00
|
|
|
collectionPrefix: appId,
|
2016-02-26 20:55:17 -08:00
|
|
|
});
|
2018-02-17 09:55:30 -05:00
|
|
|
const keys = {
|
2018-09-01 13:58:06 -04:00
|
|
|
application_id: appId,
|
|
|
|
|
client_key: 'unused',
|
|
|
|
|
windows_key: 'unused',
|
|
|
|
|
javascript_key: 'unused',
|
|
|
|
|
webhook_key: 'unused',
|
|
|
|
|
rest_api_key: 'unused',
|
|
|
|
|
master_key: 'master',
|
2016-01-28 10:58:12 -08:00
|
|
|
};
|
|
|
|
|
res.status(200).send(keys);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-13 16:45:07 -07:00
|
|
|
// deletes all collections that belong to the app
|
2016-01-28 10:58:12 -08:00
|
|
|
function clearApp(req, res) {
|
|
|
|
|
if (!req.auth.isMaster) {
|
2018-09-01 13:58:06 -04:00
|
|
|
return res.status(401).send({ error: 'unauthorized' });
|
2016-01-28 10:58:12 -08:00
|
|
|
}
|
2016-02-26 21:17:04 -08:00
|
|
|
return req.config.database.deleteEverything().then(() => {
|
2016-01-28 10:58:12 -08:00
|
|
|
res.status(200).send({});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// deletes all collections and drops the app from cache
|
|
|
|
|
function dropApp(req, res) {
|
|
|
|
|
if (!req.auth.isMaster) {
|
2018-09-01 13:58:06 -04:00
|
|
|
return res.status(401).send({ error: 'unauthorized' });
|
2016-01-28 10:58:12 -08:00
|
|
|
}
|
2016-02-26 21:17:04 -08:00
|
|
|
return req.config.database.deleteEverything().then(() => {
|
2016-05-18 12:12:30 +12:00
|
|
|
AppCache.del(req.config.applicationId);
|
2016-01-28 10:58:12 -08:00
|
|
|
res.status(200).send({});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lets just return a success response and see what happens.
|
|
|
|
|
function notImplementedYet(req, res) {
|
|
|
|
|
res.status(200).send({});
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-16 19:34:46 -07:00
|
|
|
router.post('/rest_clear_app', middlewares.handleParseHeaders, clearApp);
|
|
|
|
|
router.post('/rest_block', middlewares.handleParseHeaders, notImplementedYet);
|
2018-09-01 13:58:06 -04:00
|
|
|
router.post(
|
|
|
|
|
'/rest_mock_v8_client',
|
|
|
|
|
middlewares.handleParseHeaders,
|
|
|
|
|
notImplementedYet
|
|
|
|
|
);
|
|
|
|
|
router.post(
|
|
|
|
|
'/rest_unmock_v8_client',
|
|
|
|
|
middlewares.handleParseHeaders,
|
|
|
|
|
notImplementedYet
|
|
|
|
|
);
|
|
|
|
|
router.post(
|
|
|
|
|
'/rest_verify_analytics',
|
|
|
|
|
middlewares.handleParseHeaders,
|
|
|
|
|
notImplementedYet
|
|
|
|
|
);
|
2016-01-28 10:58:12 -08:00
|
|
|
router.post('/rest_create_app', createApp);
|
2016-03-16 19:34:46 -07:00
|
|
|
router.post('/rest_drop_app', middlewares.handleParseHeaders, dropApp);
|
2018-09-01 13:58:06 -04:00
|
|
|
router.post(
|
|
|
|
|
'/rest_configure_app',
|
|
|
|
|
middlewares.handleParseHeaders,
|
|
|
|
|
notImplementedYet
|
|
|
|
|
);
|
2016-01-28 10:58:12 -08:00
|
|
|
|
|
|
|
|
module.exports = {
|
2018-09-01 13:58:06 -04:00
|
|
|
router: router,
|
2016-02-12 02:02:55 +01:00
|
|
|
};
|