From 75d39d2d3a65446c6343c05651d7c1f9a84f2329 Mon Sep 17 00:00:00 2001 From: Aviad Hahami Date: Mon, 29 Jun 2020 15:54:43 +0300 Subject: [PATCH] fix: Allow IPv6 (if supported) --- package.json | 1 - src/cli/commands/auth/index.ts | 19 +++++++------------ test/system/auth.test.ts | 1 - 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 8cac64fa3e9..3ccf0c8383c 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,6 @@ "debug": "^4.1.1", "diff": "^4.0.1", "glob": "^7.1.3", - "ipaddr.js": "^1.9.1", "needle": "^2.5.0", "open": "^7.0.3", "os-name": "^3.0.0", diff --git a/src/cli/commands/auth/index.ts b/src/cli/commands/auth/index.ts index 8247c62738a..b6ab4413a67 100644 --- a/src/cli/commands/auth/index.ts +++ b/src/cli/commands/auth/index.ts @@ -1,11 +1,8 @@ -import * as dns from 'dns'; import * as url from 'url'; -import * as util from 'util'; import * as open from 'open'; import * as uuid from 'uuid'; import * as Debug from 'debug'; import { Spinner } from 'cli-spinner'; -import { IPv6, parse } from 'ipaddr.js'; import * as snyk from '../../../lib'; import { verifyAPI } from './is-authed'; @@ -21,8 +18,6 @@ import { getQueryParamsAsString } from '../../../lib/query-strings'; export = auth; -const dnsLookupPromise = util.promisify(dns.lookup); - const apiUrl = url.parse(config.API); const authUrl = apiUrl.protocol + '//' + apiUrl.host; const debug = Debug('snyk-auth'); @@ -179,16 +174,16 @@ function errorForFailedAuthAttempt(res, body) { } async function getIpFamily(): Promise<6 | undefined> { - const IPv6Family = 6; - + const family = 6; try { - const { address } = await dnsLookupPromise(apiUrl.hostname!, { - family: IPv6Family, + // Dispatch a FORCED IPv6 request to test client's ISP and network capability + await request({ + url: config.API + '/verify/callback', + family, // family param forces the handler to dispatch a request using IP at "family" version + method: 'post', }); - const res = parse(address) as IPv6; - return !res.isIPv4MappedAddress() ? IPv6Family : undefined; + return family; } catch (e) { - /* IPv6 is not enabled */ return undefined; } } diff --git a/test/system/auth.test.ts b/test/system/auth.test.ts index 5ddb5c86917..7678b1b3fa0 100644 --- a/test/system/auth.test.ts +++ b/test/system/auth.test.ts @@ -1,4 +1,3 @@ -import * as _ from '@snyk/lodash'; import { test } from 'tap'; import * as sinon from 'sinon'; import * as isAuthed from '../../src/cli/commands/auth/is-authed';