From 8122d96ee15bf2c829894cc91aa058e0bc4677c4 Mon Sep 17 00:00:00 2001 From: Szymon Marczak <36894700+szmarczak@users.noreply.github.com> Date: Wed, 3 Nov 2021 14:14:27 +0100 Subject: [PATCH] Fix IP tests --- test/http.ts | 6 ++++-- test/https.ts | 5 ++--- test/promise.ts | 2 +- test/stream.ts | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/test/http.ts b/test/http.ts index 0d757cd1b..772e0b544 100644 --- a/test/http.ts +++ b/test/http.ts @@ -2,7 +2,7 @@ import process from 'process'; import {Buffer} from 'buffer'; import {STATUS_CODES, Agent} from 'http'; import os from 'os'; -import {isIPv4, isIPv6} from 'net'; +import {isIPv4, isIPv6, isIP} from 'net'; import test from 'ava'; import {Handler} from 'express'; import nock from 'nock'; @@ -305,7 +305,9 @@ test('DNS auto', withServer, async (t, server, got) => { dnsLookupIpVersion: undefined, }); - t.true(isIPv4(response.body)); + const version = isIP(response.body); + + t.true(version === 4 || version === 6); }); test('DNS IPv4', withServer, async (t, server, got) => { diff --git a/test/https.ts b/test/https.ts index 0de8f9d06..122e1a5df 100644 --- a/test/https.ts +++ b/test/https.ts @@ -414,9 +414,8 @@ test('invalid key passphrase', withHttpsServer(), async (t, server, got) => { }, }); - await t.throwsAsync(request, { - code: 'ERR_OSSL_EVP_BAD_DECRYPT', - }); + const {code}: NodeJS.ErrnoException = await t.throwsAsync(request); + t.true(code === 'ERR_OSSL_BAD_DECRYPT' || code === 'ERR_OSSL_EVP_BAD_DECRYPT'); }); test('client certificate PFX', withHttpsServer(), async (t, server, got) => { diff --git a/test/promise.ts b/test/promise.ts index d0041ca55..da72d98c0 100644 --- a/test/promise.ts +++ b/test/promise.ts @@ -26,7 +26,7 @@ test('emits response event as promise', withServer, async (t, server, got) => { t.true(response instanceof IncomingMessage); t.false(response.readable); t.is(response.statusCode, 200); - t.is(response.ip, '127.0.0.1'); + t.true(response.ip === '127.0.0.1' || response.ip === '::1'); }); }); diff --git a/test/stream.ts b/test/stream.ts index bacf042ad..782cda54d 100644 --- a/test/stream.ts +++ b/test/stream.ts @@ -354,7 +354,7 @@ test('works with pipeline', async t => { got.stream.put('http://localhost:7777'), ), { instanceOf: RequestError, - message: 'connect ECONNREFUSED 127.0.0.1:7777', + message: /^connect ECONNREFUSED (127\.0\.0\.1|::1):7777$/, }); });