2017-10-17 11:49:28 -07:00
|
|
|
'use strict';
|
|
|
|
|
/* Tests for ParseServer.js */
|
|
|
|
|
const express = require('express');
|
2020-10-25 15:06:58 -05:00
|
|
|
const MongoStorageAdapter = require('../lib/Adapters/Storage/Mongo/MongoStorageAdapter').default;
|
2018-09-01 13:58:06 -04:00
|
|
|
const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/PostgresStorageAdapter')
|
|
|
|
|
.default;
|
2018-07-02 23:30:14 -04:00
|
|
|
const ParseServer = require('../lib/ParseServer').default;
|
2019-05-14 11:34:51 -07:00
|
|
|
const path = require('path');
|
|
|
|
|
const { spawn } = require('child_process');
|
2017-10-17 11:49:28 -07:00
|
|
|
|
|
|
|
|
describe('Server Url Checks', () => {
|
2018-06-29 17:09:51 -04:00
|
|
|
let server;
|
2018-09-01 13:58:06 -04:00
|
|
|
beforeAll(done => {
|
2018-06-29 17:09:51 -04:00
|
|
|
const app = express();
|
2020-10-25 15:06:58 -05:00
|
|
|
app.get('/health', function (req, res) {
|
2018-06-29 17:09:51 -04:00
|
|
|
res.json({
|
2018-09-01 13:58:06 -04:00
|
|
|
status: 'ok',
|
2018-06-29 17:09:51 -04:00
|
|
|
});
|
2017-11-03 08:51:46 -07:00
|
|
|
});
|
2018-06-29 17:09:51 -04:00
|
|
|
server = app.listen(13376, undefined, done);
|
|
|
|
|
});
|
|
|
|
|
|
2018-09-01 13:58:06 -04:00
|
|
|
afterAll(done => {
|
2018-06-29 17:09:51 -04:00
|
|
|
server.close(done);
|
2017-10-17 11:49:28 -07:00
|
|
|
});
|
|
|
|
|
|
2018-09-01 13:58:06 -04:00
|
|
|
it('validate good server url', done => {
|
2017-10-17 11:49:28 -07:00
|
|
|
Parse.serverURL = 'http://localhost:13376';
|
2020-10-25 15:06:58 -05:00
|
|
|
ParseServer.verifyServerUrl(function (result) {
|
2018-09-01 13:58:06 -04:00
|
|
|
if (!result) {
|
2017-10-17 11:49:28 -07:00
|
|
|
done.fail('Did not pass valid url');
|
|
|
|
|
}
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-09-01 13:58:06 -04:00
|
|
|
it('mark bad server url', done => {
|
2019-12-03 18:21:12 -06:00
|
|
|
spyOn(console, 'warn').and.callFake(() => {});
|
2017-10-17 11:49:28 -07:00
|
|
|
Parse.serverURL = 'notavalidurl';
|
2020-10-25 15:06:58 -05:00
|
|
|
ParseServer.verifyServerUrl(function (result) {
|
2018-09-01 13:58:06 -04:00
|
|
|
if (result) {
|
2017-10-17 11:49:28 -07:00
|
|
|
done.fail('Did not mark invalid url');
|
|
|
|
|
}
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-11-19 04:20:19 +08:00
|
|
|
|
2019-12-06 18:00:27 -06:00
|
|
|
xit('handleShutdown, close connection', done => {
|
2020-10-25 15:06:58 -05:00
|
|
|
const mongoURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase';
|
|
|
|
|
const postgresURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
|
2017-11-19 04:20:19 +08:00
|
|
|
let databaseAdapter;
|
|
|
|
|
if (process.env.PARSE_SERVER_TEST_DB === 'postgres') {
|
|
|
|
|
databaseAdapter = new PostgresStorageAdapter({
|
|
|
|
|
uri: process.env.PARSE_SERVER_TEST_DATABASE_URI || postgresURI,
|
|
|
|
|
collectionPrefix: 'test_',
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
databaseAdapter = new MongoStorageAdapter({
|
|
|
|
|
uri: mongoURI,
|
|
|
|
|
collectionPrefix: 'test_',
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-08-19 00:25:52 -05:00
|
|
|
let close = false;
|
2018-09-01 13:58:06 -04:00
|
|
|
const newConfiguration = Object.assign({}, defaultConfiguration, {
|
|
|
|
|
databaseAdapter,
|
2019-05-14 11:34:51 -07:00
|
|
|
serverStartComplete: () => {
|
2019-08-19 00:35:06 -07:00
|
|
|
let promise = Promise.resolve();
|
|
|
|
|
if (process.env.PARSE_SERVER_TEST_DB !== 'postgres') {
|
|
|
|
|
promise = parseServer.config.filesController.adapter._connect();
|
|
|
|
|
}
|
|
|
|
|
promise.then(() => {
|
|
|
|
|
parseServer.handleShutdown();
|
|
|
|
|
parseServer.server.close(err => {
|
|
|
|
|
if (err) {
|
|
|
|
|
done.fail('Close Server Error');
|
|
|
|
|
}
|
|
|
|
|
reconfigureServer({}).then(() => {
|
|
|
|
|
expect(close).toBe(true);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2019-05-09 09:12:30 -07:00
|
|
|
});
|
2017-11-19 04:20:19 +08:00
|
|
|
});
|
2019-05-09 09:12:30 -07:00
|
|
|
},
|
2019-08-19 00:25:52 -05:00
|
|
|
serverCloseComplete: () => {
|
|
|
|
|
close = true;
|
|
|
|
|
},
|
2017-11-19 04:20:19 +08:00
|
|
|
});
|
2019-05-09 09:12:30 -07:00
|
|
|
const parseServer = ParseServer.start(newConfiguration);
|
2017-11-19 04:20:19 +08:00
|
|
|
});
|
2019-05-14 11:34:51 -07:00
|
|
|
|
|
|
|
|
it('does not have unhandled promise rejection in the case of load error', done => {
|
2020-10-25 15:06:58 -05:00
|
|
|
const parseServerProcess = spawn(path.resolve(__dirname, './support/FailingServer.js'));
|
2019-05-14 11:34:51 -07:00
|
|
|
let stdout;
|
|
|
|
|
let stderr;
|
|
|
|
|
parseServerProcess.stdout.on('data', data => {
|
|
|
|
|
stdout = data.toString();
|
|
|
|
|
});
|
|
|
|
|
parseServerProcess.stderr.on('data', data => {
|
|
|
|
|
stderr = data.toString();
|
|
|
|
|
});
|
|
|
|
|
parseServerProcess.on('close', code => {
|
|
|
|
|
expect(code).toEqual(1);
|
|
|
|
|
expect(stdout).toBeUndefined();
|
2020-02-08 04:49:43 +00:00
|
|
|
expect(stderr).toContain('MongoServerSelectionError');
|
2019-05-14 11:34:51 -07:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-10-17 11:49:28 -07:00
|
|
|
});
|