diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9806c99..2d3ecbc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/upstream.yml b/.github/workflows/upstream.yml new file mode 100644 index 0000000..9f6c1ec --- /dev/null +++ b/.github/workflows/upstream.yml @@ -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 diff --git a/package.json b/package.json index 03fb940..6a0316e 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/test/upstream.js b/test/upstream.js new file mode 100644 index 0000000..e997a45 --- /dev/null +++ b/test/upstream.js @@ -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' + +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') + }) +})