|
@@ -0,0 +1,26 @@
|
|
|
|
|
+const fs = require('fs');
|
|
|
|
|
+const vm = require('vm');
|
|
|
|
|
+const assert = require('assert');
|
|
|
|
|
+
|
|
|
|
|
+const libraryPath = 'src/main/resources/static/mjs/mjs.min.js';
|
|
|
|
|
+const source = fs.readFileSync(libraryPath, 'utf8');
|
|
|
|
|
+const signatureModule = source.slice(source.indexOf('// ZTNA signature helper'));
|
|
|
|
|
+const sandbox = { mjs: {} };
|
|
|
|
|
+
|
|
|
|
|
+vm.runInNewContext(signatureModule, sandbox, { filename: libraryPath });
|
|
|
|
|
+
|
|
|
|
|
+assert.strictEqual(typeof sandbox.mjs.sign, 'function');
|
|
|
|
|
+assert.strictEqual(
|
|
|
|
|
+ sandbox.mjs.sign('testAccessKeyId', 'testAccessKeySecret', 'gateway.example.com:8443', '', 1714268844854),
|
|
|
|
|
+ 'NJxwxDOUcz+DDQ9XhzHflgz2gxOVC2RcKBXXySWm+dA='
|
|
|
|
|
+);
|
|
|
|
|
+assert.throws(
|
|
|
|
|
+ () => sandbox.mjs.sign('', 'testAccessKeySecret', 'gateway.example.com:8443', '', 1714268844854),
|
|
|
|
|
+ /accessKeyId is required/
|
|
|
|
|
+);
|
|
|
|
|
+assert.throws(
|
|
|
|
|
+ () => sandbox.mjs.sign('testAccessKeyId', '', 'gateway.example.com:8443', '', 1714268844854),
|
|
|
|
|
+ /accessKeySecret is required/
|
|
|
|
|
+);
|
|
|
|
|
+
|
|
|
|
|
+console.log('mjs.sign signature test passed');
|