From d9d20160d6ef382768f417392f74879e125b71d0 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 28 Sep 2021 20:56:08 -1000 Subject: [PATCH] LavaMoat Node update and various small enhancements (#12239) * lavamoat - update lavamoat-node and relevant policy + two handy patches * test/e2e - add timeout known to be flaky * lavamoat-viz - rename npm script --- .circleci/scripts/create-lavamoat-viz.sh | 2 +- lavamoat/node/policy.json | 201 ------------------- package.json | 4 +- patches/abort-controller+3.0.0.patch | 18 ++ patches/regenerator-runtime+0.13.7.patch | 11 +- test/e2e/tests/contract-interactions.spec.js | 3 +- yarn.lock | 30 ++- 7 files changed, 58 insertions(+), 211 deletions(-) create mode 100644 patches/abort-controller+3.0.0.patch diff --git a/.circleci/scripts/create-lavamoat-viz.sh b/.circleci/scripts/create-lavamoat-viz.sh index 53e520f27..db1dc3979 100755 --- a/.circleci/scripts/create-lavamoat-viz.sh +++ b/.circleci/scripts/create-lavamoat-viz.sh @@ -11,7 +11,7 @@ BUILD_DEST="./build-artifacts/build-viz/" mkdir -p "${BUILD_DEST}" # generate lavamoat debug config -yarn lavamoat:debug +yarn lavamoat:debug:build # generate viz npx lavamoat-viz --dest "${BUILD_DEST}" \ No newline at end of file diff --git a/lavamoat/node/policy.json b/lavamoat/node/policy.json index 7497e459b..c3acbd59d 100644 --- a/lavamoat/node/policy.json +++ b/lavamoat/node/policy.json @@ -1008,16 +1008,6 @@ "buffer-equal": true } }, - "are-we-there-yet": { - "builtin": { - "events.EventEmitter": true, - "util.inherits": true - }, - "packages": { - "delegates": true, - "readable-stream": true - } - }, "arr-diff": { "packages": { "arr-flatten": true, @@ -1377,7 +1367,6 @@ "anymatch": true, "async-each": true, "braces": true, - "fsevents": true, "glob-parent": true, "inherits": true, "is-binary-path": true, @@ -1629,16 +1618,6 @@ "through2": true } }, - "detect-libc": { - "builtin": { - "child_process.spawnSync": true, - "fs.readdirSync": true, - "os.platform": true - }, - "globals": { - "process.env": true - } - }, "detective": { "packages": { "acorn-node": true, @@ -2175,45 +2154,6 @@ "process.version": true } }, - "fsevents": { - "builtin": { - "events.EventEmitter": true, - "fs.stat": true, - "path.join": true, - "util.inherits": true - }, - "globals": { - "__dirname": true, - "process.nextTick": true, - "process.platform": true, - "setImmediate": true - }, - "native": true, - "packages": { - "node-pre-gyp": true - } - }, - "gauge": { - "builtin": { - "util.format": true - }, - "globals": { - "clearInterval": true, - "process": true, - "setImmediate": true, - "setInterval": true - }, - "packages": { - "aproba": true, - "console-control-strings": true, - "has-unicode": true, - "object-assign": true, - "signal-exit": true, - "string-width": true, - "strip-ansi": true, - "wide-align": true - } - }, "get-assigned-identifiers": { "builtin": { "assert.equal": true @@ -2575,16 +2515,6 @@ "process.argv": true } }, - "has-unicode": { - "builtin": { - "os.type": true - }, - "globals": { - "process.env.LANG": true, - "process.env.LC_ALL": true, - "process.env.LC_CTYPE": true - } - }, "has-value": { "packages": { "get-value": true, @@ -2738,11 +2668,6 @@ "is-plain-object": true } }, - "is-fullwidth-code-point": { - "packages": { - "number-is-nan": true - } - }, "is-glob": { "packages": { "is-extglob": true @@ -3138,56 +3063,6 @@ "setTimeout": true } }, - "node-pre-gyp": { - "builtin": { - "events.EventEmitter": true, - "fs.existsSync": true, - "fs.readFileSync": true, - "fs.renameSync": true, - "path.dirname": true, - "path.existsSync": true, - "path.join": true, - "path.resolve": true, - "url.parse": true, - "url.resolve": true, - "util.inherits": true - }, - "globals": { - "__dirname": true, - "console.log": true, - "process.arch": true, - "process.cwd": true, - "process.env": true, - "process.platform": true, - "process.version.substr": true, - "process.versions": true - }, - "packages": { - "detect-libc": true, - "nopt": true, - "npmlog": true, - "rimraf": true, - "semver": true - } - }, - "nopt": { - "builtin": { - "path": true, - "stream.Stream": true, - "url": true - }, - "globals": { - "console": true, - "process.argv": true, - "process.env.DEBUG_NOPT": true, - "process.env.NOPT_DEBUG": true, - "process.platform": true - }, - "packages": { - "abbrev": true, - "osenv": true - } - }, "normalize-path": { "packages": { "remove-trailing-separator": true @@ -3203,22 +3078,6 @@ "once": true } }, - "npmlog": { - "builtin": { - "events.EventEmitter": true, - "util": true - }, - "globals": { - "process.nextTick": true, - "process.stderr": true - }, - "packages": { - "are-we-there-yet": true, - "console-control-strings": true, - "gauge": true, - "set-blocking": true - } - }, "object-copy": { "packages": { "copy-descriptor": true, @@ -3285,54 +3144,6 @@ "readable-stream": true } }, - "os-homedir": { - "builtin": { - "os.homedir": true - }, - "globals": { - "process.env": true, - "process.getuid": true, - "process.platform": true - } - }, - "os-tmpdir": { - "globals": { - "process.env.SystemRoot": true, - "process.env.TEMP": true, - "process.env.TMP": true, - "process.env.TMPDIR": true, - "process.env.windir": true, - "process.platform": true - } - }, - "osenv": { - "builtin": { - "child_process.exec": true, - "path": true - }, - "globals": { - "process.env.COMPUTERNAME": true, - "process.env.ComSpec": true, - "process.env.EDITOR": true, - "process.env.HOSTNAME": true, - "process.env.PATH": true, - "process.env.PROMPT": true, - "process.env.PS1": true, - "process.env.Path": true, - "process.env.SHELL": true, - "process.env.USER": true, - "process.env.USERDOMAIN": true, - "process.env.USERNAME": true, - "process.env.VISUAL": true, - "process.env.path": true, - "process.nextTick": true, - "process.platform": true - }, - "packages": { - "os-homedir": true, - "os-tmpdir": true - } - }, "parent-module": { "packages": { "callsites": true @@ -3915,12 +3726,6 @@ "process": true } }, - "set-blocking": { - "globals": { - "process.stderr": true, - "process.stdout": true - } - }, "set-value": { "packages": { "extend-shallow": true, @@ -4122,7 +3927,6 @@ }, "string-width": { "packages": { - "code-point-at": true, "emoji-regex": true, "is-fullwidth-code-point": true, "strip-ansi": true @@ -4699,11 +4503,6 @@ "isexe": true } }, - "wide-align": { - "packages": { - "string-width": true - } - }, "write": { "builtin": { "fs.createWriteStream": true, diff --git a/package.json b/package.json index 3096ec6fd..bfb493184 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "update-changelog": "auto-changelog update", "generate:migration": "./development/generate-migration.sh", "lavamoat:auto": "lavamoat ./development/build/index.js --writeAutoPolicy", - "lavamoat:debug": "lavamoat ./development/build/index.js --writeAutoPolicyDebug" + "lavamoat:debug:build": "lavamoat ./development/build/index.js --writeAutoPolicyDebug" }, "resolutions": { "**/regenerator-runtime": "^0.13.7", @@ -287,7 +287,7 @@ "jest": "^26.6.3", "jsdom": "^11.2.0", "koa": "^2.7.0", - "lavamoat": "^5.3.1", + "lavamoat": "^5.3.4", "lavamoat-viz": "^6.0.9", "lockfile-lint": "^4.0.0", "loose-envify": "^1.4.0", diff --git a/patches/abort-controller+3.0.0.patch b/patches/abort-controller+3.0.0.patch new file mode 100644 index 000000000..2210446d2 --- /dev/null +++ b/patches/abort-controller+3.0.0.patch @@ -0,0 +1,18 @@ +diff --git a/node_modules/abort-controller/browser.js b/node_modules/abort-controller/browser.js +index b0c5ec3..c8c8018 100644 +--- a/node_modules/abort-controller/browser.js ++++ b/node_modules/abort-controller/browser.js +@@ -2,12 +2,7 @@ + "use strict" + + /*eslint-disable @mysticatea/prettier */ +-const { AbortController, AbortSignal } = +- typeof self !== "undefined" ? self : +- typeof window !== "undefined" ? window : +- /* otherwise */ undefined ++const { AbortController } = globalThis; + /*eslint-enable @mysticatea/prettier */ + + module.exports = AbortController +-module.exports.AbortSignal = AbortSignal +-module.exports.default = AbortController diff --git a/patches/regenerator-runtime+0.13.7.patch b/patches/regenerator-runtime+0.13.7.patch index 1710d779a..778bc62ca 100644 --- a/patches/regenerator-runtime+0.13.7.patch +++ b/patches/regenerator-runtime+0.13.7.patch @@ -1,5 +1,5 @@ diff --git a/node_modules/regenerator-runtime/runtime.js b/node_modules/regenerator-runtime/runtime.js -index 547b8c6..c53a471 100644 +index 547b8c6..885626e 100644 --- a/node_modules/regenerator-runtime/runtime.js +++ b/node_modules/regenerator-runtime/runtime.js @@ -5,7 +5,7 @@ @@ -65,3 +65,12 @@ index 547b8c6..c53a471 100644 function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; +@@ -733,7 +734,7 @@ var runtime = (function (exports) { + )); + + try { +- regeneratorRuntime = runtime; ++ globalThis.regeneratorRuntime = runtime; + } catch (accidentalStrictMode) { + // This module should not be running in strict mode, so the above + // assignment should always work unless something is misconfigured. Just diff --git a/test/e2e/tests/contract-interactions.spec.js b/test/e2e/tests/contract-interactions.spec.js index e94c18f0a..c4e0537c5 100644 --- a/test/e2e/tests/contract-interactions.spec.js +++ b/test/e2e/tests/contract-interactions.spec.js @@ -1,5 +1,5 @@ const { strict: assert } = require('assert'); -const { withFixtures } = require('../helpers'); +const { withFixtures, regularDelayMs } = require('../helpers'); describe('Deploy contract and call contract methods', function () { let windowHandles; @@ -91,6 +91,7 @@ describe('Deploy contract and call contract methods', function () { 'MetaMask Notification', windowHandles, ); + await driver.delay(regularDelayMs); await driver.clickElement({ text: 'Confirm', tag: 'button' }); await driver.waitUntilXWindowHandles(2); await driver.switchToWindow(extension); diff --git a/yarn.lock b/yarn.lock index 6aaf4069e..3828c4441 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17418,6 +17418,17 @@ lavamoat-core@^10.0.1: merge-deep "^3.0.2" resolve "^1.15.1" +lavamoat-core@^11.0.0: + version "11.0.0" + resolved "https://registry.yarnpkg.com/lavamoat-core/-/lavamoat-core-11.0.0.tgz#d1decbabae0429149fb7bbeb7f8a74fa054dbdf9" + integrity sha512-D/ULw8cbQ+0Rr/2IT38XedH8CWZsfIy0WThJHLjPbxwdPuHasFw9GHs88vjYv7a6UJ1uac8x5mhyOlbGoOJcIw== + dependencies: + fromentries "^1.2.0" + json-stable-stringify "^1.0.1" + lavamoat-tofu "^6.0.0" + merge-deep "^3.0.2" + resolve "^1.15.1" + lavamoat-tofu@^5.1.3: version "5.1.3" resolved "https://registry.yarnpkg.com/lavamoat-tofu/-/lavamoat-tofu-5.1.3.tgz#8e89a7ac206f3b2dc9c8ea52ecfd4f92f90285ae" @@ -17426,6 +17437,14 @@ lavamoat-tofu@^5.1.3: "@babel/parser" "^7.10.1" "@babel/traverse" "^7.10.1" +lavamoat-tofu@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/lavamoat-tofu/-/lavamoat-tofu-6.0.0.tgz#26d37c14864eb98df247195c5419a3a762ef650b" + integrity sha512-tgXf+/lplow/Ao2cOsbQ4ZqTuKBLwNnSSjPFIiGAHAM6xs+c+jEr60UAqOflyBg94VOE47G6o8zYZOAylZpUrw== + dependencies: + "@babel/parser" "^7.10.1" + "@babel/traverse" "^7.10.1" + lavamoat-viz@^6.0.9: version "6.0.9" resolved "https://registry.yarnpkg.com/lavamoat-viz/-/lavamoat-viz-6.0.9.tgz#ddec64becdf62448f7d0ea57c5258246ee14304c" @@ -17438,16 +17457,17 @@ lavamoat-viz@^6.0.9: serve-handler "^6.1.3" yargs "^16.0.0" -lavamoat@^5.3.1: - version "5.3.1" - resolved "https://registry.yarnpkg.com/lavamoat/-/lavamoat-5.3.1.tgz#66f140210f406c69ec58f18ebcd827b52e3a3276" - integrity sha512-XXMDX7dV2lKEymlC3+rAAWp7/j1Qe+j2lgyRMvg1xI2Vux24iW837grHDIyx1qs7LOhu5F98Z772z7jmGjBjfg== +lavamoat@^5.3.4: + version "5.3.4" + resolved "https://registry.yarnpkg.com/lavamoat/-/lavamoat-5.3.4.tgz#cf0778a5fc8b2bc14bce79d46dc730df3d8c21ad" + integrity sha512-0p7B8+6Hs/WGlkBaVQl6RGdAlYd0pL6eFTh6/Oc3kdyi4wVc2Fz5vFOJqrZi8XkvjMuCLln7udYbiCapr74yZQ== dependencies: "@babel/code-frame" "^7.10.4" + "@babel/highlight" "^7.10.4" bindings "^1.5.0" htmlescape "^1.1.1" json-stable-stringify "^1.0.1" - lavamoat-core "^10.0.1" + lavamoat-core "^11.0.0" lavamoat-tofu "^5.1.3" node-gyp-build "^4.2.3" object.fromentries "^2.0.2"