Skip to content

Commit

Permalink
fix: update node engines to 18+, CI to test 18, 20, update eslint-con…
Browse files Browse the repository at this point in the history
…fig and eslint errors (#2)

fix: proxy options
  • Loading branch information
shazron committed Jan 8, 2024
1 parent 56ee808 commit 331b652
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node: [14]
node-version: [18]
os: [ubuntu-latest]

steps:
Expand All @@ -29,6 +29,6 @@ jobs:
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_TITLE: 'Node version'
SLACK_MESSAGE: ${{ matrix.node }}
SLACK_MESSAGE: ${{ matrix.node-version }}
SLACK_COLOR: ${{ job.status == 'success' && 'good' || job.status == 'cancelled' && '#808080' || 'danger' }}

9 changes: 4 additions & 5 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [12.x, 14.x]
node-version: [18.x, 20.x]
os: [ubuntu-latest, windows-latest]

steps:
Expand All @@ -34,7 +34,6 @@ jobs:
- run: npm test
- name: upload coverage
if: success()
run: curl -s https://codecov.io/bash | bash
env:
CODECOV_NAME: ${{ runner.os }} node.js ${{ matrix.node-version }}
shell: bash
uses: codecov/codecov-action@v3.1.1
with:
name: ${{ runner.os }} node.js ${{ matrix.node-version }}
2 changes: 1 addition & 1 deletion .github/workflows/on-push-publish-to-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
node-version: 18
- run: npm install
- run: npm test
- uses: JS-DevTools/npm-publish@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/version-bump-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
git config user.email github-actions@github.com
- uses: actions/setup-node@v1
with:
node-version: 14
node-version: 18
- run: |
npm install
npm test
Expand Down
30 changes: 16 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@
"bugs": {
"url": "https://github.com/adobe/aio-lib-test-proxy/issues"
},
"bundleDependencies": false,
"bundleDependencies": [],
"dependencies": {
"express": "^4.17.1",
"@adobe/aio-lib-core-logging": "1.1.0",
"node-fetch": "^2.6.4",
"express": "^4.17.1",
"mockttp": "^2.2.3",
"node-fetch": "^2.6.4",
"syswide-cas": "^5.3.0"
},
"deprecated": false,
"description": "Adobe I/O Lib Test Proxies and Api Servers",
"devDependencies": {
"@adobe/eslint-config-aio-lib-config": "^1.2.0",
"@adobe/eslint-config-aio-lib-config": "^2.0.2",
"babel-runtime": "^6.26.0",
"dotenv": "^8.1.0",
"eol": "^0.9.1",
"eslint": "^6.2.2",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-jest": "^23.6.0",
"eslint-plugin-jsdoc": "^25.0.0",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint": "^8.56.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.6.1",
"eslint-plugin-jsdoc": "^42.0.0",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-standard": "^4.0.0",
"fetch-mock": "^9.0.0",
"http-proxy-agent": "^4.0.1",
"https-proxy-agent": "2.2.4",
"jest": "^25.1.0",
"jest": "^29",
"jest-fetch-mock": "^3.0.1",
"jest-html-reporter": "^3.4.1",
"jest-junit": "^10.0.0",
Expand All @@ -37,7 +38,8 @@
"jsdoc-to-markdown": "^5.0.0",
"query-string": "^7.0.1",
"stdout-stderr": "^0.1.9",
"tsd-jsdoc": "^2.4.0"
"tsd-jsdoc": "^2.4.0",
"typescript": "^5.3.3"
},
"homepage": "https://github.com/adobe/aio-lib-test-proxy",
"license": "Apache-2.0",
Expand All @@ -56,7 +58,7 @@
"version": "1.0.0",
"engineStrict": true,
"engines": {
"node": ">=12.0.0"
"node": ">=18"
},
"files": [
"src"
Expand Down
6 changes: 4 additions & 2 deletions src/api-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const express = require('express')
const mockttp = require('mockttp')
const https = require('https')
const http = require('http')
const HOSTNAME = '127.0.0.1'

/**
* Create a simple API server.
Expand Down Expand Up @@ -50,9 +51,9 @@ async function createApiServer (options = {}) {
if (useSsl) {
const httpsOptions = await mockttp.generateCACertificate()

server = https.createServer(httpsOptions, app).listen(port, 'localhost')
server = https.createServer(httpsOptions, app).listen(port, HOSTNAME)
} else {
server = http.createServer(app).listen(port, 'localhost')
server = http.createServer(app).listen(port, HOSTNAME)
}

return new Promise(resolve => {
Expand All @@ -64,5 +65,6 @@ async function createApiServer (options = {}) {
}

module.exports = {
HOSTNAME,
createApiServer
}
22 changes: 13 additions & 9 deletions test/proxy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ governing permissions and limitations under the License.

const queryString = require('query-string')
const { createHttpsProxy, createHttpProxy } = require('../src/proxy')
const { createApiServer } = require('../src/api-server')
const { createApiServer, HOSTNAME } = require('../src/api-server')
const fetch = require('node-fetch')
const HttpsProxyAgent = require('https-proxy-agent')
const HttpProxyAgent = require('http-proxy-agent')
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('http proxy', () => {
const apiServerAddress = apiServer.address()
const queryObject = { foo: 'bar' }

const testUrl = `${protocol}://localhost:${apiServerAddress.port}/mirror?${queryString.stringify(queryObject)}`
const testUrl = `${protocol}://${HOSTNAME}:${apiServerAddress.port}/mirror?${queryString.stringify(queryObject)}`

const proxyUrl = proxyServer.url
const proxyOpts = urlToHttpOptions(proxyUrl)
Expand All @@ -78,7 +78,7 @@ describe('http proxy', () => {

test('failure', async () => {
// connect to non-existent server port
const testUrl = `${protocol}://localhost:${portNotInUse}/mirror/?foo=bar`
const testUrl = `${protocol}://${HOSTNAME}:${portNotInUse}/mirror/?foo=bar`

const proxyUrl = proxyServer.url
const proxyOpts = urlToHttpOptions(proxyUrl)
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('http proxy', () => {
const proxyOpts = urlToHttpOptions(proxyUrl)
proxyOpts.auth = `${username}:${password}`

const testUrl = `${protocol}://localhost:${apiServerPort}/mirror?${queryString.stringify(queryObject)}`
const testUrl = `${protocol}://${HOSTNAME}:${apiServerPort}/mirror?${queryString.stringify(queryObject)}`
const response = await fetch(testUrl, {
agent: new HttpProxyAgent(proxyOpts),
headers
Expand All @@ -138,7 +138,7 @@ describe('http proxy', () => {
const proxyOpts = urlToHttpOptions(proxyUrl)
proxyOpts.auth = `${username}:${password}`

const testUrl = `${protocol}://localhost:${apiServerPort}/mirror?${queryString.stringify(queryObject)}`
const testUrl = `${protocol}://${HOSTNAME}:${apiServerPort}/mirror?${queryString.stringify(queryObject)}`
const response = await fetch(testUrl, {
agent: new HttpProxyAgent(proxyOpts),
headers
Expand Down Expand Up @@ -170,13 +170,14 @@ describe('https proxy', () => {
const apiServerAddress = apiServer.address()
const queryObject = { foo: 'bar' }

const testUrl = `${protocol}://localhost:${apiServerAddress.port}/mirror?${queryString.stringify(queryObject)}`
const testUrl = `${protocol}://${HOSTNAME}:${apiServerAddress.port}/mirror?${queryString.stringify(queryObject)}`

const proxyUrl = proxyServer.url
const proxyOpts = urlToHttpOptions(proxyUrl)
// the passing on of this property to the underlying implementation only works on https-proxy-agent@2.2.4
// this is only used for unit-tests and passed in the constructor
proxyOpts.rejectUnauthorized = false
proxyOpts.ALPNProtocols = ['http/1.1']

const response = await fetch(testUrl, {
agent: new HttpsProxyAgent(proxyOpts)
Expand All @@ -188,13 +189,14 @@ describe('https proxy', () => {

test('failure', async () => {
// connect to non-existent server port
const testUrl = `${protocol}://localhost:${portNotInUse}/mirror/?foo=bar`
const testUrl = `${protocol}://${HOSTNAME}:${portNotInUse}/mirror/?foo=bar`

const proxyUrl = proxyServer.url
const proxyOpts = urlToHttpOptions(proxyUrl)
// the passing on of this property to the underlying implementation only works on https-proxy-agent@2.2.4
// this is only used for unit-tests and passed in the constructor
proxyOpts.rejectUnauthorized = false
proxyOpts.ALPNProtocols = ['http/1.1']

const response = await fetch(testUrl, {
agent: new HttpsProxyAgent(proxyOpts)
Expand Down Expand Up @@ -230,8 +232,9 @@ describe('https proxy', () => {
// the passing on of this property to the underlying implementation only works on https-proxy-agent@2.2.4
// this is only used for unit-tests and passed in the constructor
proxyOpts.rejectUnauthorized = false
proxyOpts.ALPNProtocols = ['http/1.1']

const testUrl = `${protocol}://localhost:${apiServerPort}/mirror?${queryString.stringify(queryObject)}`
const testUrl = `${protocol}://${HOSTNAME}:${apiServerPort}/mirror?${queryString.stringify(queryObject)}`
const response = await fetch(testUrl, {
agent: new HttpsProxyAgent(proxyOpts),
headers
Expand All @@ -256,8 +259,9 @@ describe('https proxy', () => {
// the passing on of this property to the underlying implementation only works on https-proxy-agent@2.2.4
// this is only used for unit-tests and passed in the constructor
proxyOpts.rejectUnauthorized = false
proxyOpts.ALPNProtocols = ['http/1.1']

const testUrl = `${protocol}://localhost:${apiServerPort}/mirror?${queryString.stringify(queryObject)}`
const testUrl = `${protocol}://${HOSTNAME}:${apiServerPort}/mirror?${queryString.stringify(queryObject)}`
const response = await fetch(testUrl, {
agent: new HttpsProxyAgent(proxyOpts),
headers
Expand Down

0 comments on commit 331b652

Please sign in to comment.