From fb41cb204201c71c4b8e4fda9b42b131057ab4f5 Mon Sep 17 00:00:00 2001 From: Filipe Freire Date: Fri, 22 Nov 2024 11:17:04 +0000 Subject: [PATCH] fix: localhost resolution RFC6761 (#70) * spike: investigate localhost resolution RFC6761 * bump curl to 7.85.0 * fix * pull latest curl-for-windows & bump to 7.86.0 --- .github/workflows/build-and-release.yaml | 4 +- .github/workflows/build-lint-test.yaml | 6 +- deps/curl-for-windows | 2 +- test/curl/localhost.spec.ts | 75 ++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 test/curl/localhost.spec.ts diff --git a/.github/workflows/build-and-release.yaml b/.github/workflows/build-and-release.yaml index 18cf9ef6..4235662f 100644 --- a/.github/workflows/build-and-release.yaml +++ b/.github/workflows/build-and-release.yaml @@ -49,7 +49,7 @@ jobs: - macos-13-xlarge - ubuntu-22.04 libcurl-release: - - 7.79.1 + - 7.86.0 node-libcurl-cpp-std: - c++17 node: @@ -108,7 +108,7 @@ jobs: - macos-13-xlarge - ubuntu-22.04 libcurl-release: - - 7.79.1 + - 7.86.0 node: - 20.16.0 electron-version: diff --git a/.github/workflows/build-lint-test.yaml b/.github/workflows/build-lint-test.yaml index cf4ecdda..31f9451f 100644 --- a/.github/workflows/build-lint-test.yaml +++ b/.github/workflows/build-lint-test.yaml @@ -43,7 +43,7 @@ jobs: - macos-13-xlarge - ubuntu-22.04 libcurl-release: - - 7.79.1 + - 7.86.0 node-libcurl-cpp-std: - c++17 node: @@ -53,7 +53,7 @@ jobs: - os: ubuntu-latest node: 20.16.0 node-libcurl-cpp-std: c++17 - libcurl-release: 7.79.1 + libcurl-release: 7.86.0 run-lint-and-tsc: true env: @@ -141,7 +141,7 @@ jobs: - macos-13-xlarge - ubuntu-22.04 libcurl-release: - - 7.79.1 + - 7.86.0 node: - 20.16.0 electron-version: diff --git a/deps/curl-for-windows b/deps/curl-for-windows index 96c0958c..9e99250b 160000 --- a/deps/curl-for-windows +++ b/deps/curl-for-windows @@ -1 +1 @@ -Subproject commit 96c0958c4db9da1f9779fd4917d38eca120817c2 +Subproject commit 9e99250bc176129b29ef38cebec0c920381f6fb1 diff --git a/test/curl/localhost.spec.ts b/test/curl/localhost.spec.ts new file mode 100644 index 00000000..cca05167 --- /dev/null +++ b/test/curl/localhost.spec.ts @@ -0,0 +1,75 @@ +import 'should' +import { app, host, port, server } from '../helper/server' +import { Curl } from '../../lib' + +let curl: Curl +const urlLocalhost = `http://localhost:${port}/` +const urlTestLocalhost = `http://test.localhost:${port}/` + +describe('DNS Resolution', () => { + before((done) => { + server.listen(port, host, () => done()) + + app.get('/', (req, res) => { + res.send({ message: 'resolved', ip: req.ip }) + }) + }) + + after((done) => { + server.close() + app._router.stack.pop() + done() + }) + + beforeEach(() => { + curl = new Curl() + }) + + afterEach(() => { + curl.close() + }) + + it('should resolve localhost to 127.0.0.1', (done) => { + curl.setOpt('URL', urlLocalhost) + + curl.on('end', (status, data) => { + if (status !== 200) { + throw Error(`Invalid status code: ${status}`) + } + + const result = JSON.parse(data as string) + result.message.should.be.equal('resolved') + result.ip.should.be.equal('::1') + + done() + }) + + curl.on('error', done) + curl.perform() + }) + + it('should resolve test.localhost to 127.0.0.1', (done) => { + // skip this test if windows because it does not support *.localhost on hosts file? + // https://stackoverflow.com/questions/138162/wildcards-in-a-windows-hosts-file/4166967#4166967 + // if (process.platform === 'win32') { + // done() + // return + // } + curl.setOpt('URL', urlTestLocalhost) + + curl.on('end', (status, data) => { + if (status !== 200) { + throw Error(`Invalid status code: ${status}`) + } + + const result = JSON.parse(data as string) + result.message.should.be.equal('resolved') + result.ip.should.be.equal('::1') + + done() + }) + + curl.on('error', done) + curl.perform() + }) +})