-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: patch vuln in web-sdk dev dep @happy-dom/jest-environment (#1519)
Define custom happy-dom jest env for running web-sdk integration tests that force credentials to be passed since tests were failing on node 18 but not 16 or 20 due to obscure reason w/ fetch still being experimental in node 18 :(
- Loading branch information
1 parent
f7c584d
commit 5722497
Showing
3 changed files
with
53 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/client-sdk-web/test/integration/CustomHappyDomEnv.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const HappyDomEnvironment = require('@happy-dom/jest-environment').default; | ||
|
||
class CustomHappyDomEnvironment extends HappyDomEnvironment { | ||
async setup() { | ||
await super.setup(); | ||
|
||
// Grab the prototype once the environment is ready: | ||
const xhrProto = this.global.window.XMLHttpRequest.prototype; | ||
|
||
const originalOpen = xhrProto.open; | ||
xhrProto.open = function (method, url, async, user, password) { | ||
// This line is the main reason we need this custom happy dom env to force | ||
// creds to be passed w/ requests. | ||
// Node18 has some funkiness since fetch wasn't included in core runtime yet. | ||
// It explains why node 16 and 20 worked but not 18 when updating Happy Dom | ||
// a major version due to critical vulnerability warnings. | ||
// | ||
// These issues and prs from AWS dev on their JS sdk clued me into what was happening | ||
// https://github.com/capricorn86/happy-dom/issues/1042 | ||
// https://github.com/aws/aws-sdk-js-v3/pull/6780/files | ||
// | ||
// Note: im overriding 'xhrProto' though not 'fetch' since that is what grpc-web uses | ||
this.withCredentials = true; | ||
return originalOpen.apply(this, arguments); | ||
}; | ||
} | ||
} | ||
|
||
module.exports = CustomHappyDomEnvironment; |