From c940d0599e8ed38b39064658a93424e2381f14a0 Mon Sep 17 00:00:00 2001 From: Brenden Date: Wed, 20 Nov 2024 18:25:06 -0800 Subject: [PATCH] further investigation - no results yet --- src/server/test/web/obviusTest.js | 180 +++++++++++++++--------------- 1 file changed, 91 insertions(+), 89 deletions(-) diff --git a/src/server/test/web/obviusTest.js b/src/server/test/web/obviusTest.js index 00747dcae..68cb47a10 100644 --- a/src/server/test/web/obviusTest.js +++ b/src/server/test/web/obviusTest.js @@ -71,9 +71,9 @@ mocha.describe('Obvius API', () => { //should respond with 406, not acceptable expect(res).to.have.status(406); //should also return expected message - expect(res.text).equals(`
\nRequest must include mode parameter.\n
\n`); + expect(res.text).equals(`
\nRequest must include mode parameter.\n
\n`); }); - mocha.it('should accept status requests', async function () { + mocha.it('should accept status requests', async () => { const conn = testDB.getConnection(); const password = 'password'; const hashedPassword = await bcrypt.hash(password, 10); @@ -85,106 +85,108 @@ mocha.describe('Obvius API', () => { //should respond with 200, success expect(res).to.have.status(200); //should also return expected message - expect(res.text).equals("
\nSUCCESS\n
\n"); + expect(res.text).equals("
\nSUCCESS\n
\n"); }); - mocha.it('should accept valid logfile uploads', async function () { - this.timeout(30000); - + mocha.it('should accept valid logfile uploads', async () => { + //PromiseRejectionHandledWarning originates here const conn = testDB.getConnection(); const password = 'password'; const hashedPassword = await bcrypt.hash(password, 10); const obviusUser = new User(undefined, 'obvius@example.com', hashedPassword, User.role.OBVIUS); await obviusUser.insert(conn); obviusUser.password = password; - const requestMode = 'LOGFILEUPLOAD'; - + const logfileRequestMode = 'LOGFILEUPLOAD'; + const configFileRequestMode = 'CONFIGFILEUPLOAD'; + // Adapted from ../obvius/README.md const logfilePath = 'src/server/test/web/obvius/mb-001.log.gz'; - + const configFilePath = 'src/server/test/web/obvius/mb-001.ini.gz'; + + + //the upload of a logfile is the subject of the test + const res = await chai.request(app) + .post('/api/obvius') + .field('username', obviusUser.username) + .field('password', obviusUser.password) + .field('mode', logfileRequestMode) + .field('serialnumber', 'mb-001') + .attach('files', logfilePath); + + //should respond with 200, success + expect(res).to.have.status(200); + //should also return expected message + expect(res.text).equals("
\nSUCCESS\nLogfile Upload IS PROVISIONAL
\n"); + + }); + mocha.it('should accept valid config file uploads', async () => { + const conn = testDB.getConnection(); + const password = 'password'; + const hashedPassword = await bcrypt.hash(password, 10); + const obviusUser = new User(undefined, 'obvius@example.com', hashedPassword, User.role.OBVIUS); + await obviusUser.insert(conn); + obviusUser.password = password; + const requestMode = 'CONFIGFILEUPLOAD'; + + // Adapted from ../obvius/README.md + const configFilePath = 'src/server/test/web/obvius/mb-001.ini.gz'; + const res = await chai.request(app) - .post('/api/obvius') - .field('username', obviusUser.username) - .field('password', obviusUser.password) - .field('mode', requestMode) - .field('serialnumber', 'mb-001') - .attach('files', logfilePath); - + .post('/api/obvius') + .field('username', obviusUser.username) + .field('password', obviusUser.password) + .field('mode', requestMode) + .field('serialnumber', 'mb-001') + .field('modbusdevice', '1234') + .attach('files', configFilePath); + //should respond with 200, success expect(res).to.have.status(200); //should also return expected message - expect(res.text).equals("
\nSUCCESS\nLogfile Upload IS PROVISIONAL
\n"); - }); - mocha.it('should accept valid config file uploads', async function () { - this.timeout(30000); - - const conn = testDB.getConnection(); - const password = 'password'; - const hashedPassword = await bcrypt.hash(password, 10); - const obviusUser = new User(undefined, 'obvius@example.com', hashedPassword, User.role.OBVIUS); - await obviusUser.insert(conn); - obviusUser.password = password; - const requestMode = 'CONFIGFILEUPLOAD'; - - // Adapted from ../obvius/README.md - const configFilePath = 'src/server/test/web/obvius/mb-001.ini.gz'; - - const res = await chai.request(app) - .post('/api/obvius') - .field('username', obviusUser.username) - .field('password', obviusUser.password) - .field('mode', requestMode) - .field('serialnumber', 'mb-001') - .field('modbusdevice', '1234') - .attach('files', configFilePath); - - //should respond with 200, success - expect(res).to.have.status(200); - //should also return expected message - expect(res.text).equals("
\nSUCCESS\nAcquired config log with (pseudo)filename mb-001-mb-1234.ini.
\n"); - }); - mocha.it('should return accurate config file manifests', async function () { - this.timeout(30000); - - const conn = testDB.getConnection(); - const password = 'password'; - const hashedPassword = await bcrypt.hash(password, 10); - const obviusUser = new User(undefined, 'obvius@example.com', hashedPassword, User.role.OBVIUS); - await obviusUser.insert(conn); - obviusUser.password = password; - const uploadRequestMode = 'CONFIGFILEUPLOAD'; - const manifestRequestMode = 'CONFIGFILEMANIFEST'; - - // Adapted from ../obvius/README.md - const configFilePath = 'src/server/test/web/obvius/mb-001.ini.gz'; - - const upload = await chai.request(app) - .post('/api/obvius') - .field('username', obviusUser.username) - .field('password', obviusUser.password) - .field('mode', uploadRequestMode) - .field('serialnumber', 'mb-001') - .field('modbusdevice', '1234') - .attach('files', configFilePath); - - const res = await chai.request(app) - .post('/api/obvius') - .field('username', obviusUser.username) - .field('password', obviusUser.password) - .field('mode', manifestRequestMode); - - //should respond with 200, success - expect(res).to.have.status(200); - - //get "all" config files to compare to response - const allConfigfiles = await Configfile.getAll(conn); - let response = ''; - for (f of allConfigfiles) { - response += `CONFIGFILE,${f.makeFilename()},${f.hash},${f.created.format('YYYY-MM-DD hh:mm:ss')}`; - } - - //the third line of the response should be the config file - expect(res.text.split("\n")[2]).equals(response); - }); + expect(res.text).equals("
\nSUCCESS\nAcquired config log with (pseudo)filename mb-001-mb-1234.ini.
\n"); + }); + mocha.it('should return accurate config file manifests', async () => { + const conn = testDB.getConnection(); + const password = 'password'; + const hashedPassword = await bcrypt.hash(password, 10); + const obviusUser = new User(undefined, 'obvius@example.com', hashedPassword, User.role.OBVIUS); + await obviusUser.insert(conn); + obviusUser.password = password; + const uploadRequestMode = 'CONFIGFILEUPLOAD'; + const manifestRequestMode = 'CONFIGFILEMANIFEST'; + + // Adapted from ../obvius/README.md + const configFilePath = 'src/server/test/web/obvius/mb-001.ini.gz'; + const upload = await chai.request(app) + .post('/api/obvius') + .field('username', obviusUser.username) + .field('password', obviusUser.password) + .field('mode', uploadRequestMode) + .field('serialnumber', 'mb-001') + .field('modbusdevice', '1234') + .attach('files', configFilePath); + + const res = await chai.request(app) + .post('/api/obvius') + .field('username', obviusUser.username) + .field('password', obviusUser.password) + .field('mode', manifestRequestMode); + + //logfile upload should respond with 200, success + expect(upload).to.have.status(200); + + //logfile request should respond with 200, success + expect(res).to.have.status(200); + + //get "all" config files to compare to response + const allConfigfiles = await Configfile.getAll(conn); + let response = ''; + for (f of allConfigfiles) { + response += `CONFIGFILE,${f.makeFilename()},${f.hash},${f.created.format('YYYY-MM-DD hh:mm:ss')}`; + } + + //the third line of the response should be the config file + expect(res.text.split("\n")[2]).equals(response); + }); }); }); });