tests: Simplify API key reading

Also delete unused imports.
This commit is contained in:
Richard Hansen 2020-10-08 01:37:17 -04:00 committed by John McLear
parent ce0b151159
commit 048bd0f50d
12 changed files with 29 additions and 67 deletions

View file

@ -196,3 +196,7 @@ exports.handle = async function(apiVersion, functionName, fields, req, res)
// call the api function
return api[functionName].apply(this, functionParams);
}
exports.exportedForTestingOnly = {
apiKey: apikey,
};

View file

@ -1,5 +1,6 @@
function m(mod) { return __dirname + '/../../src/' + mod; }
const apiHandler = require(m('node/handler/APIHandler'));
const log4js = require(m('node_modules/log4js'));
const server = require(m('node/server'));
const settings = require(m('node/utils/Settings'));
@ -9,6 +10,7 @@ const webaccess = require(m('node/hooks/express/webaccess'));
const backups = {};
let inited = false;
exports.apiKey = apiHandler.exportedForTestingOnly.apiKey;
exports.agent = null;
exports.baseUrl = null;
exports.httpServer = null;

View file

@ -2,17 +2,13 @@
* Fuzz testing the import endpoint
* Usage: node fuzzImportTest.js
*/
const fs = require('fs');
const common = require('./common');
const settings = require(__dirname+'/loadSettings').loadSettings();
const host = "http://" + settings.ip + ":" + settings.port;
const path = require('path');
const async = require(__dirname+'/../../src/node_modules/async');
const request = require('request');
const froth = require('mocha-froth');
var filePath = path.join(__dirname, '/../../APIKEY.txt');
var apiKey = fs.readFileSync(filePath, {encoding: 'utf-8'});
apiKey = apiKey.replace(/\n$/, "");
const apiKey = common.apiKey;
var apiVersion = 1;
var testPadId = "TEST_fuzz" + makeid();

View file

@ -6,19 +6,14 @@
* and openapi definitions.
*/
const assert = require('assert');
const common = require('../../common');
const supertest = require(__dirname + '/../../../../src/node_modules/supertest');
const fs = require('fs');
const settings = require(__dirname + '/../../../../src/node/utils/Settings');
const api = supertest('http://' + settings.ip + ':' + settings.port);
const path = require('path');
var validateOpenAPI = require(__dirname + '/../../../../src/node_modules/openapi-schema-validation').validate;
var filePath = path.join(__dirname, '../../../../APIKEY.txt');
var apiKey = fs.readFileSync(filePath, { encoding: 'utf-8' });
apiKey = apiKey.replace(/\n$/, '');
const apiKey = common.apiKey;
var apiVersion = 1;
var testPadId = makeid();

View file

@ -4,18 +4,13 @@
* TODO: maybe unify those two files and merge in a single one.
*/
const assert = require('assert');
const common = require('../../common');
const supertest = require(__dirname+'/../../../../src/node_modules/supertest');
const fs = require('fs');
const settings = require(__dirname + '/../../../../src/node/utils/Settings');
const api = supertest('http://'+settings.ip+":"+settings.port);
const path = require('path');
const async = require(__dirname+'/../../../../src/node_modules/async');
var filePath = path.join(__dirname, '../../../../APIKEY.txt');
var apiKey = fs.readFileSync(filePath, {encoding: 'utf-8'});
apiKey = apiKey.replace(/\n$/, "");
const apiKey = common.apiKey;
var apiVersion = 1;
var testPadId = makeid();

View file

@ -1,14 +1,11 @@
var assert = require('assert')
supertest = require(__dirname+'/../../../../src/node_modules/supertest'),
fs = require('fs'),
settings = require(__dirname + '/../../../../src/node/utils/Settings'),
api = supertest('http://'+settings.ip+":"+settings.port),
path = require('path');
function m(mod) { return __dirname + '/../../../../src/' + mod; }
var filePath = path.join(__dirname, '../../../../APIKEY.txt');
const common = require('../../common');
const settings = require(m('node/utils/Settings'));
const supertest = require(m('node_modules/supertest'));
var apiKey = fs.readFileSync(filePath, {encoding: 'utf-8'});
apiKey = apiKey.replace(/\n$/, "");
const api = supertest(`http://${settings.ip}:${settings.port}`);
const apiKey = common.apiKey;
var apiVersion = 1;
var authorID = "";
var padID = makeid();

View file

@ -2,17 +2,13 @@
* Fuzz testing the import endpoint
*/
/*
const fs = require('fs');
const common = require('../../common');
const settings = require(__dirname+'/../../../../tests/container/loadSettings.js').loadSettings();
const host = "http://" + settings.ip + ":" + settings.port;
const path = require('path');
const async = require(__dirname+'/../../../../src/node_modules/async');
const request = require(__dirname+'/../../../../src/node_modules/request');
const froth = require(__dirname+'/../../../../src/node_modules/mocha-froth');
var filePath = path.join(__dirname, '../../../../APIKEY.txt');
var apiKey = fs.readFileSync(filePath, {encoding: 'utf-8'});
apiKey = apiKey.replace(/\n$/, "");
const apiKey = common.apiKey;
var apiVersion = 1;
var testPadId = "TEST_fuzz" + makeid();

View file

@ -5,18 +5,12 @@
* TODO: unify those two files, and merge in a single one.
*/
const assert = require('assert');
const common = require('../../common');
const supertest = require(__dirname+'/../../../../src/node_modules/supertest');
const fs = require('fs');
const settings = require(__dirname+'/../../../../tests/container/loadSettings.js').loadSettings();
const api = supertest('http://'+settings.ip+":"+settings.port);
const path = require('path');
const async = require(__dirname+'/../../../../src/node_modules/async');
var filePath = path.join(__dirname, '../../../../APIKEY.txt');
var apiKey = fs.readFileSync(filePath, {encoding: 'utf-8'});
apiKey = apiKey.replace(/\n$/, "");
const apiKey = common.apiKey;
var apiVersion = 1;
var lastEdited = "";

View file

@ -8,7 +8,6 @@ const superagent = require(__dirname+'/../../../../src/node_modules/superagent')
const fs = require('fs');
const settings = require(__dirname+'/../../../../src/node/utils/Settings');
const padManager = require(__dirname+'/../../../../src/node/db/PadManager');
const path = require('path');
const plugins = require(__dirname+'/../../../../src/static/js/pluginfw/plugin_defs');
const padText = fs.readFileSync("../tests/backend/specs/api/test.txt");
@ -17,11 +16,9 @@ const wordDoc = fs.readFileSync("../tests/backend/specs/api/test.doc");
const wordXDoc = fs.readFileSync("../tests/backend/specs/api/test.docx");
const odtDoc = fs.readFileSync("../tests/backend/specs/api/test.odt");
const pdfDoc = fs.readFileSync("../tests/backend/specs/api/test.pdf");
var filePath = path.join(__dirname, '../../../../APIKEY.txt');
let agent;
var apiKey = fs.readFileSync(filePath, {encoding: 'utf-8'});
apiKey = apiKey.replace(/\n$/, "");
const apiKey = common.apiKey;
var apiVersion = 1;
const testPadId = makeid();
const testPadIdEnc = encodeURIComponent(testPadId);

View file

@ -3,18 +3,12 @@
*
* Section "GLOBAL FUNCTIONS" in src/node/db/API.js
*/
const assert = require('assert');
const common = require('../../common');
const supertest = require(__dirname+'/../../../../src/node_modules/supertest');
const fs = require('fs');
const settings = require(__dirname+'/../../../../src/node/utils/Settings');
const api = supertest('http://'+settings.ip+":"+settings.port);
const path = require('path');
var filePath = path.join(__dirname, '../../../../APIKEY.txt');
var apiKey = fs.readFileSync(filePath, {encoding: 'utf-8'});
apiKey = apiKey.replace(/\n$/, "");
const apiKey = common.apiKey;
var apiVersion = '1.2.14';
describe('Connectivity for instance-level API tests', function() {

View file

@ -5,18 +5,13 @@
* TODO: unify those two files, and merge in a single one.
*/
const assert = require('assert');
const common = require('../../common');
const supertest = require(__dirname+'/../../../../src/node_modules/supertest');
const fs = require('fs');
const settings = require(__dirname + '/../../../../src/node/utils/Settings');
const api = supertest('http://'+settings.ip+":"+settings.port);
const path = require('path');
const async = require(__dirname+'/../../../../src/node_modules/async');
var filePath = path.join(__dirname, '../../../../APIKEY.txt');
var apiKey = fs.readFileSync(filePath, {encoding: 'utf-8'});
apiKey = apiKey.replace(/\n$/, "");
const apiKey = common.apiKey;
var apiVersion = 1;
var testPadId = makeid();
var lastEdited = "";

View file

@ -1,13 +1,10 @@
const assert = require('assert').strict;
const common = require('../../common');
const supertest = require(__dirname + '/../../../../src/node_modules/supertest');
const fs = require('fs');
const settings = require(__dirname + '/../../../../src/node/utils/Settings');
const api = supertest(`http://${settings.ip}:${settings.port}`);
const path = require('path');
const filePath = path.join(__dirname, '../../../../APIKEY.txt');
const apiKey = fs.readFileSync(filePath, {encoding: 'utf-8'}).replace(/\n$/, '');
const apiKey = common.apiKey;
let apiVersion = 1;
let groupID = '';
let authorID = '';