Skip to content

Commit 175ab21

Browse files
ctcpipwesleytoddjonchurch
authored
👷 add upstream change detection (#31)
* 👷 add upstream change detection * add test note Co-authored-by: Wes Todd <wes@wesleytodd.com> * remove push from workflow; was only needed to get the new workflow to run before merging Co-authored-by: Jon Church <me@jonchurch.com> --------- Co-authored-by: Wes Todd <wes@wesleytodd.com> Co-authored-by: Jon Church <me@jonchurch.com>
1 parent ce0b2c8 commit 175ab21

File tree

4 files changed

+69
-7
lines changed

4 files changed

+69
-7
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,6 @@ jobs:
186186
- name: Install Node.js dependencies
187187
run: npm install
188188

189-
- name: Install browserify
190-
run: |
191-
if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -ge 1 ]]; then
192-
npm install --save-dev browserify@16
193-
fi
194-
195189
- name: List environment
196190
id: list_env
197191
shell: bash

.github/workflows/upstream.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: upstream
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "33 3 * * 3" # weekly
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
node-version: ['latest']
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Use Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
- run: npm install
25+
- run: npm run upstream

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@
3434
},
3535
"scripts": {
3636
"lint": "eslint --plugin markdown --ext js,md .",
37-
"test": "mocha --reporter spec --bail --check-leaks test/",
37+
"test": "mocha --reporter spec --bail --check-leaks test/test.js",
3838
"test-ci": "nyc --reporter=lcov --reporter=text npm test",
3939
"test-cov": "nyc --reporter=html --reporter=text npm test",
40+
"upstream": "mocha --reporter spec --check-leaks test/upstream.js",
4041
"version": "node scripts/version-history.js && git add HISTORY.md"
4142
}
4243
}

test/upstream.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// NOTE: this is a temporary solution to tell us if future changes to the monkey-patched methods
2+
// could impact this package. Recognizing this is not an ideal solution, we plan to address this when
3+
// we can drop the monkey-patching entirely.
4+
const crypto = require('crypto')
5+
const assert = require('assert')
6+
const http = require('http')
7+
const Socket = require('net').Socket
8+
9+
const req = new http.IncomingMessage(new Socket())
10+
const res = new http.ServerResponse(req)
11+
12+
function getFunctionHash (fn) {
13+
const src = fn.toString().replace(/\s+/g, '') // normalize whitespace
14+
return crypto.createHash('sha256').update(src).digest('hex')
15+
}
16+
17+
const knownWriteHeadHash = '281e0d02084a69893b8c3b8692e3c7c4de2ce22a626217fcf597fa6ddf6955a9'
18+
const knownSetHeaderHash = '2d4f95e92586d28bfd4d3137a8eaacb82b255967d8c26413015c6b56daf0afe7'
19+
const knownAppendHeaderHash = '0deb9f70c3bba63993321cca9281fb4607e2567bed1436b8574c5b86698125a8'
20+
const knownRemoveHeaderHash = '3ad5ccb0a858beb6268f281492bd8d42c9815f5316cc3c4f7f735e142fcd29d9'
21+
22+
describe('function verification', function () {
23+
it('should match the known function hash of writeHead', function () {
24+
const currentHash = getFunctionHash(res.writeHead)
25+
assert.strictEqual(currentHash, knownWriteHeadHash, 'writeHead hash has changed')
26+
})
27+
28+
it('should match the known function hash of setHeader', function () {
29+
const currentHash = getFunctionHash(res.setHeader)
30+
assert.strictEqual(currentHash, knownSetHeaderHash, 'setHeader hash has changed')
31+
})
32+
33+
it('should match the known function hash of appendHeader', function () {
34+
const currentHash = getFunctionHash(res.appendHeader)
35+
assert.strictEqual(currentHash, knownAppendHeaderHash, 'appendHeader hash has changed')
36+
})
37+
38+
it('should match the known function hash of removeHeader', function () {
39+
const currentHash = getFunctionHash(res.removeHeader)
40+
assert.strictEqual(currentHash, knownRemoveHeaderHash, 'removeHeader hash has changed')
41+
})
42+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy