From 4a9b79af09fe64624931de2911ca51acd1b0e40f Mon Sep 17 00:00:00 2001 From: Fritz Ray Date: Thu, 26 Sep 2024 15:22:53 -0700 Subject: [PATCH] Fixing tests. --- cypressWebpack/plugins/index.js | 7 ++++++- docker/cypress | 2 +- docker/cypressHttps | 2 +- package.json | 12 ++++++------ src/test/EcAesCtr.test.js | 14 ++++++++++---- src/test/EcAesCtrAsync.test.js | 14 ++++++++++---- src/test/EcAesCtrAsyncWorker.test.js | 14 ++++++++++---- src/test/EcCrypto.test.js | 14 ++++++++++---- src/test/EcFrameworkGraph.test.js | 14 ++++++++++---- src/test/EcIdentityManager.test.js | 14 ++++++++++---- src/test/EcRepository.test.js | 14 ++++++++++---- src/test/EcRsaOaep.test.js | 14 ++++++++++---- src/test/EcRsaOaepAsync.test.js | 14 ++++++++++---- src/test/EcRsaOaepAsyncWorker.test.js | 10 ++++++++-- 14 files changed, 112 insertions(+), 47 deletions(-) diff --git a/cypressWebpack/plugins/index.js b/cypressWebpack/plugins/index.js index 4940df90..612f1cac 100644 --- a/cypressWebpack/plugins/index.js +++ b/cypressWebpack/plugins/index.js @@ -13,6 +13,7 @@ // the project's config changing) const webpackPreprocessor = require('@cypress/webpack-preprocessor') const NodePolyfillPlugin = require("node-polyfill-webpack-plugin") +const webpack = require('webpack'); /** * @type {Cypress.PluginConfig} @@ -24,7 +25,11 @@ module.exports = (on, config) => { on('file:preprocessor', webpackPreprocessor({ webpackOptions: { - plugins: [ new NodePolyfillPlugin() ], + plugins: [new NodePolyfillPlugin(), + new webpack.ProvidePlugin({ + process: 'process/browser', + }), + ], externals: { "http2-wrapper": "http2", "node:dns":"commonjs node:dns" diff --git a/docker/cypress b/docker/cypress index 3852c133..530ee187 100644 --- a/docker/cypress +++ b/docker/cypress @@ -15,4 +15,4 @@ COPY cypressWebpack.config.js cypressWebpack.config.js COPY cypressBrowserify.config.js cypressBrowserify.config.js COPY cypressVite cypressVite COPY cypressVite.config.js cypressVite.config.js -ENTRYPOINT cypress run -e CASS_LOOPBACK=${CASS_LOOPBACK} --config-file cypressWebpack.config.js --browser edge && cypress run -e CASS_LOOPBACK=${CASS_LOOPBACK} --config-file cypressWebpack.config.js --browser chrome && cypress run -e CASS_LOOPBACK=${CASS_LOOPBACK} --config-file cypressWebpack.config.js \ No newline at end of file +ENTRYPOINT cypress run --config-file cypressWebpack.config.js --browser edge -e CASS_LOOPBACK=${CASS_LOOPBACK} && cypress run --config-file cypressWebpack.config.js --browser chrome -e CASS_LOOPBACK=${CASS_LOOPBACK} && cypress run --config-file cypressWebpack.config.js -e CASS_LOOPBACK=${CASS_LOOPBACK} \ No newline at end of file diff --git a/docker/cypressHttps b/docker/cypressHttps index 34a6b867..724dc521 100644 --- a/docker/cypressHttps +++ b/docker/cypressHttps @@ -13,4 +13,4 @@ COPY cypressWebpack cypressWebpack COPY cypressBrowserify cypressBrowserify COPY cypressWebpack.config.js cypressWebpack.config.js COPY cypressBrowserify.config.js cypressBrowserify.config.js -ENTRYPOINT cypress run -e CASS_LOOPBACK=${CASS_LOOPBACK} --config-file cypressWebpack.config.js --browser edge && cypress run -e CASS_LOOPBACK=${CASS_LOOPBACK} --config-file cypressWebpack.config.js --browser chrome && cypress run -e CASS_LOOPBACK=${CASS_LOOPBACK} --config-file cypressWebpack.config.js \ No newline at end of file +ENTRYPOINT cypress run --config-file cypressWebpack.config.js --browser edge -e CASS_LOOPBACK=${CASS_LOOPBACK} && cypress run --config-file cypressWebpack.config.js --browser chrome -e CASS_LOOPBACK=${CASS_LOOPBACK} && cypress run --config-file cypressWebpack.config.js -e CASS_LOOPBACK=${CASS_LOOPBACK} \ No newline at end of file diff --git a/package.json b/package.json index cd1267b5..0e649079 100644 --- a/package.json +++ b/package.json @@ -10,17 +10,17 @@ "multitest": "concurrently --kill-others --kill-others-on-fail \"npm run test15\" \"npm run test14\" \"npm run test13\" \"npm run test12\"", "testCassTest": "npm run testkill && docker run -d --network cass-net --name cass-test -p80:80 -e CASS_LOOPBACK cass-test && wait-on http://localhost/api/ping && npm run testNode18 && npm run testNode18Fips && npm run testNode16 && npm run testNode15 && npm run testNode14 && npm run testNode13 && npm run testNode12 && npm run testCypressEdge && npm run testCypress && npm run testkill", "testDevHttps": "npm run testkill && docker run -d --network cass-net --name cass-test -p443:80 -e CASS_LOOPBACK -e HTTPS=true cassproject/cass:dev && wait-on https://localhost/api/ping && npm run testNode18HttpsFips && npm run testNode18Https && npm run testNode16Https && npm run testNode15Https && npm run testNode14Https && npm run testNode13Https && npm run testNode12Https && npm run testCypressEdgeHttps && npm run testCypressHttps", - "test15HttpsFips": "export CASS_LOOPBACK=https://cass-testsf15/api/|| set CASS_LOOPBACK=https://cass-testsf15/api/&& npm run testkill && docker run -d --network cass-net --name cass-testsf15 -p443:443 -e CASS_LOOPBACK -e HTTPS=true cassproject/cass:1.5.65 && wait-on https://localhost/api/ping && concurrently --kill-others-on-fail \"npm run testCypressHttps\" \"npm run testNode20Https\" \"npm run testNode20HttpsFips\" \"npm run testNode20HttpsForceFips\" \"npm run testNode18Https\" \"npm run testNode18HttpsFips\" \"npm run testNode16Https\" && npm run testkill", - "test15Https11Fips": "export CASS_LOOPBACK=https://cass-testsf1115/api/|| set CASS_LOOPBACK=https://cass-testsf1115/api/&& npm run testkill && docker run -d --network cass-net --name cass-testsf1115 -p443:443 -e CASS_LOOPBACK -e HTTPS=true -e HTTP2=false cassproject/cass:1.5.65 && wait-on https://localhost/api/ping && concurrently --kill-others-on-fail \"npm run testCypressHttps\" \"npm run testNode20Https\" \"npm run testNode20HttpsFips\" \"npm run testNode20HttpsForceFips\" \"npm run testNode18Https\" \"npm run testNode18HttpsFips\" \"npm run testNode16Https\" && npm run testkill", - "test15Https": "export CASS_LOOPBACK=https://cass-tests15/api/|| set CASS_LOOPBACK=https://cass-tests15/api/&& npm run testkill && docker run -d --network cass-net --name cass-tests15 -p443:443 -e CASS_LOOPBACK -e HTTPS=true cassproject/cass:1.5.65 && wait-on https://localhost/api/ping && concurrently --kill-others-on-fail \"npm run testCypressHttps\" \"npm run testNode20Https\" \"npm run testNode20HttpsFips\" \"npm run testNode18Https\" \"npm run testNode18HttpsFips\" \"npm run testNode16Https\" && npm run testkill", - "test15Https11": "export CASS_LOOPBACK=https://cass-tests1115/api/|| set CASS_LOOPBACK=https://cass-tests1115/api/&& npm run testkill && docker run -d --network cass-net --name cass-tests1115 -p443:443 -e CASS_LOOPBACK -e HTTPS=true -e HTTP2=false cassproject/cass:1.5.65 && wait-on https://localhost/api/ping && concurrently --kill-others-on-fail \"npm run testCypressHttps\" \"npm run testNode20Https\" \"npm run testNode20HttpsFips\" \"npm run testNode18Https\" \"npm run testNode18HttpsFips\" \"npm run testNode16Https\" && npm run testkill", - "test15Fips": "export CASS_LOOPBACK=http://cass-testf15/api/|| set CASS_LOOPBACK=http://cass-testf15/api/&& npm run testkillf15 && docker run -d --network cass-net -e CASS_LOOPBACK --name cass-testf15 -p80:80 cassproject/cass:1.5.65 && wait-on http://localhost/api/ping && concurrently --kill-others-on-fail \"npm run testCypress\" \"npm run testNode20\" \"npm run testNode20Fips\" \"npm run testNode20ForceFips\" \"npm run testNode18\" \"npm run testNode18Fips\" \"npm run testNode16\" && npm run testkill15", + "test15HttpsFips": "export CASS_LOOPBACK=https://cass-testsf15/api/|| set CASS_LOOPBACK=https://cass-testsf15/api/&& npm run testkillsf15 && docker run -d --network cass-net --name cass-testsf15 -p446:443 -e CASS_LOOPBACK -e HTTPS=true cassproject/cass:1.5.65 && wait-on https://localhost:446/api/ping && concurrently --kill-others-on-fail \"npm run testCypressHttps\" \"npm run testNode20Https\" \"npm run testNode20HttpsFips\" \"npm run testNode20HttpsForceFips\" \"npm run testNode18Https\" \"npm run testNode18HttpsFips\" \"npm run testNode16Https\" && npm run testkillsf15", + "test15Https11Fips": "export CASS_LOOPBACK=https://cass-testsf1115/api/|| set CASS_LOOPBACK=https://cass-testsf1115/api/&& npm run testkillsf1115 && docker run -d --network cass-net --name cass-testsf1115 -p447:443 -e CASS_LOOPBACK -e HTTPS=true -e HTTP2=false cassproject/cass:1.5.65 && wait-on https://localhost:447/api/ping && concurrently --kill-others-on-fail \"npm run testCypressHttps\" \"npm run testNode20Https\" \"npm run testNode20HttpsFips\" \"npm run testNode20HttpsForceFips\" \"npm run testNode18Https\" \"npm run testNode18HttpsFips\" \"npm run testNode16Https\" && npm run testkillsf1115", + "test15Https": "export CASS_LOOPBACK=https://cass-tests15/api/|| set CASS_LOOPBACK=https://cass-tests15/api/&& npm run testkills15 && docker run -d --network cass-net --name cass-tests15 -p444:443 -e CASS_LOOPBACK -e HTTPS=true cassproject/cass:1.5.65 && wait-on https://localhost:444/api/ping && concurrently --kill-others-on-fail \"npm run testCypressHttps\" \"npm run testNode20Https\" \"npm run testNode20HttpsFips\" \"npm run testNode18Https\" \"npm run testNode18HttpsFips\" \"npm run testNode16Https\" && npm run testkills15", + "test15Https11": "export CASS_LOOPBACK=https://cass-tests1115/api/|| set CASS_LOOPBACK=https://cass-tests1115/api/&& npm run testkills1115 && docker run -d --network cass-net --name cass-tests1115 -p443:443 -e CASS_LOOPBACK -e HTTPS=true -e HTTP2=false cassproject/cass:1.5.65 && wait-on https://localhost/api/ping && concurrently --kill-others-on-fail \"npm run testCypressHttps\" \"npm run testNode20Https\" \"npm run testNode20HttpsFips\" \"npm run testNode18Https\" \"npm run testNode18HttpsFips\" \"npm run testNode16Https\" && npm run tests1115", + "test15Fips": "export CASS_LOOPBACK=http://cass-testf15/api/|| set CASS_LOOPBACK=http://cass-testf15/api/&& npm run testkillf15 && docker run -d --network cass-net -e CASS_LOOPBACK --name cass-testf15 -p81:80 cassproject/cass:1.5.65 && wait-on http://localhost:81/api/ping && concurrently --kill-others-on-fail \"npm run testCypress\" \"npm run testNode20\" \"npm run testNode20Fips\" \"npm run testNode20ForceFips\" \"npm run testNode18\" \"npm run testNode18Fips\" \"npm run testNode16\" && npm run testkillf15", "test15": "export CASS_LOOPBACK=http://cass-test15/api/|| set CASS_LOOPBACK=http://cass-test15/api/&& npm run testkill15 && docker run -d --network cass-net -e CASS_LOOPBACK --name cass-test15 -p80:80 cassproject/cass:1.5.65 && wait-on http://localhost/api/ping && concurrently --kill-others-on-fail \"npm run testCypress\" \"npm run testNode20\" \"npm run testNode20Fips\" \"npm run testNode18\" \"npm run testNode18Fips\" \"npm run testNode16\" && npm run testkill15", "test14": "npm run testkill14 && docker run -d --network cass-net -e CASS_LOOPBACK --name cass-test14 -p80:80 cassproject/cass:1.4.4 && wait-on http://localhost/api/ping && concurrently --kill-others-on-fail \"npm run testCypress\" \"npm run testNode16\" && npm run testkill14", "test13": "npm run testkill13 && docker run -d --network cass-net -e CASS_LOOPBACK --name cass-test13 -p80:80 cassproject/cass:1.3.18 && wait-on http://localhost/api/ping && concurrently --kill-others-on-fail \"npm run testCypress\" \"npm run testNode16\" && npm run testkill13", "test12": "npm run testkill12 && docker run -d --network cass-net -e CASS_LOOPBACK --name cass-test12 -p80:80 cassproject/cass:1.2.44 && wait-on http://localhost/api/ping && concurrently --kill-others-on-fail \"npm run testCypress\" \"npm run testNode16\" && npm run testkill12", "testkillsf15": "docker kill cass-testsf15 | exit 0 && docker rm cass-testsf15 | exit 0 && docker network create cass-net | exit 0", - "testkillsf1115": "docker kill cass-testsf1115 | exit 0 && docker rm cass-testsf1115 | exit 0 && docker network create cass-net | exit 0", + "testkillsf1115": "(docker kill cass-testsf1115 | exit 0) && (docker rm cass-testsf1115 | exit 0) && docker network create cass-net | exit 0", "testkills15": "docker kill cass-tests15 | exit 0 && docker rm cass-tests15 | exit 0 && docker network create cass-net | exit 0", "testkills1115": "docker kill cass-tests1115 | exit 0 && docker rm cass-tests1115 | exit 0 && docker network create cass-net | exit 0", "testkillf15": "docker kill cass-testf15 | exit 0 && docker rm cass-testf15 | exit 0 && docker network create cass-net | exit 0", diff --git a/src/test/EcAesCtr.test.js b/src/test/EcAesCtr.test.js index b74c133a..c977d165 100644 --- a/src/test/EcAesCtr.test.js +++ b/src/test/EcAesCtr.test.js @@ -3,13 +3,19 @@ const EcAes = require("../com/eduworks/ec/crypto/EcAes"); const EcAesCtr = require("../com/eduworks/ec/crypto/EcAesCtr"); const EcCrypto = require("../com/eduworks/ec/crypto/EcCrypto"); -let hrtime = function() { +let hrtime = function () { try { - return [Math.round(performance.now()/1000), performance.now() * 1000]; + return [Math.round(performance.now() / 1000), performance.now() * 1000]; } catch (e) { - // Eat quietly. + try { + if (typeof process !== 'undefined') + return process.hrtime(); + return [new Date().getTime(), new Date().getTime() * 1000]; + } + catch (ex) { + return [new Date().getTime(), new Date().getTime() * 1000]; + } } - return process.hrtime(); }; let should = chai.should(); diff --git a/src/test/EcAesCtrAsync.test.js b/src/test/EcAesCtrAsync.test.js index 96438762..8e2cdadd 100644 --- a/src/test/EcAesCtrAsync.test.js +++ b/src/test/EcAesCtrAsync.test.js @@ -6,13 +6,19 @@ let EcAes = require("../com/eduworks/ec/crypto/EcAes.js"); let EcCrypto = require("../com/eduworks/ec/crypto/EcCrypto.js"); let chai = require("chai"); -let hrtime = function() { +let hrtime = function () { try { - return [Math.round(performance.now()/1000), performance.now() * 1000]; + return [Math.round(performance.now() / 1000), performance.now() * 1000]; } catch (e) { - // Eat quietly. + try { + if (typeof process !== 'undefined') + return process.hrtime(); + return [new Date().getTime(), new Date().getTime() * 1000]; + } + catch (ex) { + return [new Date().getTime(), new Date().getTime() * 1000]; + } } - return process.hrtime(); }; let should = chai.should(); diff --git a/src/test/EcAesCtrAsyncWorker.test.js b/src/test/EcAesCtrAsyncWorker.test.js index 5e1e31ca..2d473f30 100644 --- a/src/test/EcAesCtrAsyncWorker.test.js +++ b/src/test/EcAesCtrAsyncWorker.test.js @@ -5,13 +5,19 @@ let EcAes = require("../com/eduworks/ec/crypto/EcAes.js"); let EcCrypto = require("../com/eduworks/ec/crypto/EcCrypto.js"); let chai = require("chai"); -let hrtime = function() { +let hrtime = function () { try { - return [Math.round(performance.now()/1000), performance.now() * 1000]; + return [Math.round(performance.now() / 1000), performance.now() * 1000]; } catch (e) { - // Eat quietly. + try { + if (typeof process !== 'undefined') + return process.hrtime(); + return [new Date().getTime(), new Date().getTime() * 1000]; + } + catch (ex) { + return [new Date().getTime(), new Date().getTime() * 1000]; + } } - return process.hrtime(); }; let should = chai.should(); diff --git a/src/test/EcCrypto.test.js b/src/test/EcCrypto.test.js index fbef9b8d..9b10c8ba 100644 --- a/src/test/EcCrypto.test.js +++ b/src/test/EcCrypto.test.js @@ -9,13 +9,19 @@ try { console.log("Webcrypto not available. Tests will fail. Please upgrade, if possible, to Node 16. Non-test mode will fallback to slower cryptograpy methods.: " + err); } -let hrtime = function() { +let hrtime = function () { try { - return [Math.round(performance.now()/1000), performance.now() * 1000]; + return [Math.round(performance.now() / 1000), performance.now() * 1000]; } catch (e) { - // Eat quietly. + try { + if (typeof process !== 'undefined') + return process.hrtime(); + return [new Date().getTime(), new Date().getTime() * 1000]; + } + catch (ex) { + return [new Date().getTime(), new Date().getTime() * 1000]; + } } - return process.hrtime(); }; let should = chai.should(); diff --git a/src/test/EcFrameworkGraph.test.js b/src/test/EcFrameworkGraph.test.js index 0f2b4f17..05e016d1 100644 --- a/src/test/EcFrameworkGraph.test.js +++ b/src/test/EcFrameworkGraph.test.js @@ -13,13 +13,19 @@ const EcFramework = require("../org/cass/competency/EcFramework"); const EcIdentity = require("../org/cassproject/ebac/identity/EcIdentity"); const EcFrameworkGraph = require("../com/eduworks/ec/graph/EcFrameworkGraph"); -let hrtime = function() { +let hrtime = function () { try { - return [Math.round(performance.now()/1000), performance.now() * 1000]; + return [Math.round(performance.now() / 1000), performance.now() * 1000]; } catch (e) { - // Eat quietly. + try { + if (typeof process !== 'undefined') + return process.hrtime(); + return [new Date().getTime(), new Date().getTime() * 1000]; + } + catch (ex) { + return [new Date().getTime(), new Date().getTime() * 1000]; + } } - return process.hrtime(); }; let should = chai.should(); diff --git a/src/test/EcIdentityManager.test.js b/src/test/EcIdentityManager.test.js index e15fb627..5c3386a3 100644 --- a/src/test/EcIdentityManager.test.js +++ b/src/test/EcIdentityManager.test.js @@ -2,13 +2,19 @@ const chai = require("chai"); const EcRsaOaepAsyncWorker = require("../com/eduworks/ec/crypto/EcRsaOaepAsyncWorker"); const EcPpkFacade = require("../com/eduworks/ec/crypto/EcPpkFacade"); -let hrtime = function() { +let hrtime = function () { try { - return [Math.round(performance.now()/1000), performance.now() * 1000]; + return [Math.round(performance.now() / 1000), performance.now() * 1000]; } catch (e) { - // Eat quietly. + try { + if (typeof process !== 'undefined') + return process.hrtime(); + return [new Date().getTime(), new Date().getTime() * 1000]; + } + catch (ex) { + return [new Date().getTime(), new Date().getTime() * 1000]; + } } - return process.hrtime(); }; let should = chai.should(); diff --git a/src/test/EcRepository.test.js b/src/test/EcRepository.test.js index 3c968185..8caa12f6 100644 --- a/src/test/EcRepository.test.js +++ b/src/test/EcRepository.test.js @@ -14,13 +14,19 @@ const EcIdentityManager = require('../org/cassproject/ebac/identity/EcIdentityMa const EcIdentity = require('../org/cassproject/ebac/identity/EcIdentity.js'); const EcPpk = require('../com/eduworks/ec/crypto/EcPpk.js'); -let hrtime = function() { +let hrtime = function () { try { - return [Math.round(performance.now()/1000), performance.now() * 1000]; + return [Math.round(performance.now() / 1000), performance.now() * 1000]; } catch (e) { - // Eat quietly. + try { + if (typeof process !== 'undefined') + return process.hrtime(); + return [new Date().getTime(), new Date().getTime() * 1000]; + } + catch (ex) { + return [new Date().getTime(), new Date().getTime() * 1000]; + } } - return process.hrtime(); }; let should = chai.should(); diff --git a/src/test/EcRsaOaep.test.js b/src/test/EcRsaOaep.test.js index 8ca77907..714c33fc 100644 --- a/src/test/EcRsaOaep.test.js +++ b/src/test/EcRsaOaep.test.js @@ -4,13 +4,19 @@ const EcAes = require("../com/eduworks/ec/crypto/EcAes"); const EcCrypto = require("../com/eduworks/ec/crypto/EcCrypto"); const EcPpk = require("../com/eduworks/ec/crypto/EcPpk"); -let hrtime = function() { +let hrtime = function () { try { - return [Math.round(performance.now()/1000), performance.now() * 1000]; + return [Math.round(performance.now() / 1000), performance.now() * 1000]; } catch (e) { - // Eat quietly. + try { + if (typeof process !== 'undefined') + return process.hrtime(); + return [new Date().getTime(), new Date().getTime() * 1000]; + } + catch (ex) { + return [new Date().getTime(), new Date().getTime() * 1000]; + } } - return process.hrtime(); }; let should = chai.should(); diff --git a/src/test/EcRsaOaepAsync.test.js b/src/test/EcRsaOaepAsync.test.js index df097911..0ede22de 100644 --- a/src/test/EcRsaOaepAsync.test.js +++ b/src/test/EcRsaOaepAsync.test.js @@ -5,13 +5,19 @@ let EcCrypto = require("../com/eduworks/ec/crypto/EcCrypto.js"); let EcPpk = require("../com/eduworks/ec/crypto/EcPpk.js"); let chai = require("chai"); -let hrtime = function() { +let hrtime = function () { try { - return [Math.round(performance.now()/1000), performance.now() * 1000]; + return [Math.round(performance.now() / 1000), performance.now() * 1000]; } catch (e) { - // Eat quietly. + try { + if (typeof process !== 'undefined') + return process.hrtime(); + return [new Date().getTime(), new Date().getTime() * 1000]; + } + catch (ex) { + return [new Date().getTime(), new Date().getTime() * 1000]; + } } - return process.hrtime(); }; let should = chai.should(); diff --git a/src/test/EcRsaOaepAsyncWorker.test.js b/src/test/EcRsaOaepAsyncWorker.test.js index 77c50b55..5e1fbb91 100644 --- a/src/test/EcRsaOaepAsyncWorker.test.js +++ b/src/test/EcRsaOaepAsyncWorker.test.js @@ -9,9 +9,15 @@ let hrtime = function () { try { return [Math.round(performance.now() / 1000), performance.now() * 1000]; } catch (e) { - // Eat quietly. + try { + if (typeof process !== 'undefined') + return process.hrtime(); + return [new Date().getTime(), new Date().getTime() * 1000]; + } + catch (ex) { + return [new Date().getTime(), new Date().getTime() * 1000]; + } } - return process.hrtime(); }; let should = chai.should();