Skip to content

Commit

Permalink
fix: getIpFamily not detecting IPv6 support (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
michelkaporin authored Jan 3, 2022
1 parent e50e6f4 commit 9b436fa
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const NETWORK_ERRORS = {
ECONNRESET: ErrorCodes.connectionRefused,
ENETUNREACH: ErrorCodes.connectionRefused,
ENOTFOUND: ErrorCodes.dnsNotFound,
EADDRNOTAVAIL: ErrorCodes.dnsNotFound, // happens when DNS cannot resolve the IPv6
};

export const DEFAULT_ERROR_MESSAGES: { [P in ErrorCodes]: string } = {
Expand Down
7 changes: 5 additions & 2 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ErrorCodes, GenericErrorTypes, DEFAULT_ERROR_MESSAGES, MAX_RETRY_ATTEMP

import { BundleFiles, SupportedFiles } from './interfaces/files.interface';
import { AnalysisResult } from './interfaces/analysis-result.interface';
import { makeRequest, Payload } from './needle';
import { FailedResponse, makeRequest, Payload } from './needle';
import { AnalysisOptions, AnalysisContext } from './interfaces/analysis-options.interface';

type ResultSuccess<T> = { type: 'success'; value: T };
Expand Down Expand Up @@ -99,7 +99,10 @@ export async function getIpFamily(authHost: string): Promise<IpFamily> {
},
0,
);
return res.success ? family : undefined;

const ipv6Incompatible = (<FailedResponse>res).errorCode === ErrorCodes.dnsNotFound;

return ipv6Incompatible ? undefined : family;
}

type CheckSessionErrorCodes = GenericErrorTypes | ErrorCodes.unauthorizedUser | ErrorCodes.loginInProgress;
Expand Down
2 changes: 1 addition & 1 deletion src/needle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface SuccessResponse<T> {
success: true;
body: T;
}
type FailedResponse = {
export type FailedResponse = {
success: false;
errorCode: number;
};
Expand Down
2 changes: 1 addition & 1 deletion tests/analysis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ describe('Functional test of analysis', () => {

const sarifResults = extendedBundle.analysisResults.sarif;

expect(sarifResults.runs[0].tool.driver.rules).toHaveLength(8);
expect(sarifResults.runs[0].tool.driver.rules).toHaveLength(7);
expect(sarifResults.runs[0].results).toHaveLength(15);
const getRes = (path: string) =>
sarifResults.runs[0].results!.find(
Expand Down
5 changes: 5 additions & 0 deletions tests/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('Requests to public API', () => {
'.cc',
'.cjs',
'.cls',
'.config',
'.cpp',
'.cs',
'.cxx',
Expand All @@ -57,6 +58,7 @@ describe('Requests to public API', () => {
'.mjs',
'.php',
'.phtml',
'.pom',
'.py',
'.rb',
'.rhtml',
Expand All @@ -65,6 +67,9 @@ describe('Requests to public API', () => {
'.ts',
'.tsx',
'.vue',
'.wxs',
'.xml',
'.xsd',
'.aspx',
'.ejs',
]),
Expand Down

0 comments on commit 9b436fa

Please sign in to comment.