Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,6 @@ jobs:
- name: Install Node.js dependencies
run: npm install

- name: Install browserify
run: |
if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -ge 1 ]]; then
npm install --save-dev browserify@16
fi

- name: List environment
id: list_env
shell: bash
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/upstream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: upstream

on:
workflow_dispatch:
schedule:
- cron: "33 3 * * 3" # weekly

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: ['latest']
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run upstream
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
},
"scripts": {
"lint": "eslint --plugin markdown --ext js,md .",
"test": "mocha --reporter spec --bail --check-leaks test/",
"test": "mocha --reporter spec --bail --check-leaks test/test.js",
"test-ci": "nyc --reporter=lcov --reporter=text npm test",
"test-cov": "nyc --reporter=html --reporter=text npm test",
"upstream": "mocha --reporter spec --check-leaks test/upstream.js",
"version": "node scripts/version-history.js && git add HISTORY.md"
}
}
42 changes: 42 additions & 0 deletions test/upstream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// NOTE: this is a temporary solution to tell us if future changes to the monkey-patched methods
// could impact this package. Recognizing this is not an ideal solution, we plan to address this when
// we can drop the monkey-patching entirely.
const crypto = require('crypto')
const assert = require('assert')
const http = require('http')
const Socket = require('net').Socket

const req = new http.IncomingMessage(new Socket())
const res = new http.ServerResponse(req)

function getFunctionHash (fn) {
const src = fn.toString().replace(/\s+/g, '') // normalize whitespace
return crypto.createHash('sha256').update(src).digest('hex')
}

const knownWriteHeadHash = '281e0d02084a69893b8c3b8692e3c7c4de2ce22a626217fcf597fa6ddf6955a9'
const knownSetHeaderHash = '2d4f95e92586d28bfd4d3137a8eaacb82b255967d8c26413015c6b56daf0afe7'
const knownAppendHeaderHash = '0deb9f70c3bba63993321cca9281fb4607e2567bed1436b8574c5b86698125a8'
const knownRemoveHeaderHash = '3ad5ccb0a858beb6268f281492bd8d42c9815f5316cc3c4f7f735e142fcd29d9'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add some automation to update these after a change is looked into? Just to make it easier than copy pasting the new value from the failed build?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, should be a straight-forward follow-on.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#32


describe('function verification', function () {
it('should match the known function hash of writeHead', function () {
const currentHash = getFunctionHash(res.writeHead)
assert.strictEqual(currentHash, knownWriteHeadHash, 'writeHead hash has changed')
})

it('should match the known function hash of setHeader', function () {
const currentHash = getFunctionHash(res.setHeader)
assert.strictEqual(currentHash, knownSetHeaderHash, 'setHeader hash has changed')
})

it('should match the known function hash of appendHeader', function () {
const currentHash = getFunctionHash(res.appendHeader)
assert.strictEqual(currentHash, knownAppendHeaderHash, 'appendHeader hash has changed')
})

it('should match the known function hash of removeHeader', function () {
const currentHash = getFunctionHash(res.removeHeader)
assert.strictEqual(currentHash, knownRemoveHeaderHash, 'removeHeader hash has changed')
})
})