Skip to content

Commit

Permalink
fix: Allow IPv6 (if supported)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aviad Hahami committed Jun 30, 2020
1 parent d8dddaf commit 75d39d2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -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",
Expand Down
19 changes: 7 additions & 12 deletions 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';
Expand All @@ -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');
Expand Down Expand Up @@ -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;
}
}
1 change: 0 additions & 1 deletion 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';
Expand Down

0 comments on commit 75d39d2

Please sign in to comment.