Skip to content

Commit

Permalink
Merge pull request #448 from snyk/prettier-update
Browse files Browse the repository at this point in the history
build(prettier): update prettier
  • Loading branch information
tommyknows committed Aug 31, 2022
2 parents b012a2c + 9ddd898 commit c922785
Show file tree
Hide file tree
Showing 26 changed files with 164 additions and 128 deletions.
4 changes: 3 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ jobs:
name: Use snyk-main npmjs user
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
- run: npm install
- run: npm run test-jest-windows
- run:
command: npm run test-jest-windows
no_output_timeout: 20m
build:
<<: *defaults
steps:
Expand Down
6 changes: 3 additions & 3 deletions lib/analyzer/applications/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ function findManifestLockPairsInSameDirectory(
}

// assumption: we only care about manifest+lock files if they are in the same directory
function groupFilesByDirectory(
filePathToContent: FilePathToContent,
): { [directoryName: string]: string[] } {
function groupFilesByDirectory(filePathToContent: FilePathToContent): {
[directoryName: string]: string[];
} {
const fileNamesGroupedByDirectory: { [directoryName: string]: string[] } = {};
for (const filePath of Object.keys(filePathToContent)) {
const directory = path.dirname(filePath);
Expand Down
6 changes: 3 additions & 3 deletions lib/analyzer/applications/php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ function findManifestLockPairsInSameDirectory(
}

// assumption: we only care about manifest+lock files if they are in the same directory
function groupFilesByDirectory(
filePathToContent: FilePathToContent,
): { [directoryName: string]: string[] } {
function groupFilesByDirectory(filePathToContent: FilePathToContent): {
[directoryName: string]: string[];
} {
const fileNamesGroupedByDirectory: { [directoryName: string]: string[] } = {};
for (const filePath of Object.keys(filePathToContent)) {
const directory = path.dirname(filePath);
Expand Down
6 changes: 3 additions & 3 deletions lib/analyzer/applications/python/poetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ function findManifestLockPairsInSameDirectory(
}

// assumption: we only care about manifest+lock files if they are in the same directory
function groupFilesByDirectory(
filePathToContent: FilePathToContent,
): { [directoryName: string]: string[] } {
function groupFilesByDirectory(filePathToContent: FilePathToContent): {
[directoryName: string]: string[];
} {
const fileNamesGroupedByDirectory: { [directoryName: string]: string[] } = {};
for (const filePath of Object.keys(filePathToContent)) {
const directory = path.dirname(filePath);
Expand Down
3 changes: 2 additions & 1 deletion lib/analyzer/static-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ export async function analyze(

const binaries = getBinariesHashes(extractedLayers);

const applicationDependenciesScanResults: AppDepsScanResultWithoutTarget[] = [];
const applicationDependenciesScanResults: AppDepsScanResultWithoutTarget[] =
[];

if (appScan) {
const nodeDependenciesScanResults = await nodeFilesToScannedProjects(
Expand Down
3 changes: 2 additions & 1 deletion lib/dockerfile/instruction-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export {

// Naive regex; see tests for cases
// tslint:disable-next-line:max-line-length
const installRegex = /(rpm\s+-i|rpm\s+--install|apk\s+((--update|-u|--no-cache)\s+)*add(\s+(--update|-u|--no-cache))*|apt-get\s+((--assume-yes|--yes|-y)\s+)*install(\s+(--assume-yes|--yes|-y))*|apt\s+((--assume-yes|--yes|-y)\s+)*install|yum\s+install|aptitude\s+install)\s+/;
const installRegex =
/(rpm\s+-i|rpm\s+--install|apk\s+((--update|-u|--no-cache)\s+)*add(\s+(--update|-u|--no-cache))*|apt-get\s+((--assume-yes|--yes|-y)\s+)*install(\s+(--assume-yes|--yes|-y))*|apt\s+((--assume-yes|--yes|-y)\s+)*install|yum\s+install|aptitude\s+install)\s+/;

function getPackagesFromDockerfile(dockerfile: Dockerfile): DockerFilePackages {
const runInstructions = getRunInstructionsFromDockerfile(dockerfile);
Expand Down
3 changes: 1 addition & 2 deletions lib/dockerfile/instruction-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ function updateDockerfileBaseImageName(
return {
contents,
error: {
code:
UpdateDockerfileBaseImageNameErrorCode.DOCKERFILE_GENERATION_FAILED,
code: UpdateDockerfileBaseImageNameErrorCode.DOCKERFILE_GENERATION_FAILED,
},
};
}
Expand Down
14 changes: 8 additions & 6 deletions lib/extractor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ export async function extractImageContent(
rootFsLayers: dockerExtractor.getRootFsLayersFromConfig(
ociArchive.imageConfig,
),
autoDetectedUserInstructions: dockerExtractor.getDetectedLayersInfoFromConfig(
ociArchive.imageConfig,
),
autoDetectedUserInstructions:
dockerExtractor.getDetectedLayersInfoFromConfig(
ociArchive.imageConfig,
),
platform: dockerExtractor.getPlatformFromConfig(ociArchive.imageConfig),
imageLabels: ociArchive.imageConfig.config.Labels,
};
Expand All @@ -57,9 +58,10 @@ export async function extractImageContent(
rootFsLayers: dockerExtractor.getRootFsLayersFromConfig(
dockerArchive.imageConfig,
),
autoDetectedUserInstructions: dockerExtractor.getDetectedLayersInfoFromConfig(
dockerArchive.imageConfig,
),
autoDetectedUserInstructions:
dockerExtractor.getDetectedLayersInfoFromConfig(
dockerArchive.imageConfig,
),
platform: dockerExtractor.getPlatformFromConfig(
dockerArchive.imageConfig,
),
Expand Down
3 changes: 2 additions & 1 deletion lib/inputs/python/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { streamToString } from "../../stream-utils";

const poetryManifestFiles = ["pyproject.toml", "poetry.lock"];
const pipManifestFiles = ["requirements.txt"];
const pythonMetadataFilesRegex = /\/lib\/python.*?\/site-packages\/.*?\.dist-info\/METADATA/;
const pythonMetadataFilesRegex =
/\/lib\/python.*?\/site-packages\/.*?\.dist-info\/METADATA/;

function poetryFilePathMatches(filePath: string): boolean {
const fileName = basename(filePath);
Expand Down
3 changes: 2 additions & 1 deletion lib/python-parser/metadata-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { PythonPackage, PythonRequirement } from "./types";
const PACKAGE_NAME = "Name: ";
const PACKAGE_VERSION = "Version: ";
const PACKAGE_DEPS = "Requires-Dist: ";
const DEP_PARSE_REGEX = /^(?<name>[\w.-]+)(\s?\(?(?<specifier><|<=|!=|==|>=|>|~=|===)(?<version>[\w.]+)\)?)?/;
const DEP_PARSE_REGEX =
/^(?<name>[\w.-]+)(\s?\(?(?<specifier><|<=|!=|==|>=|>|~=|===)(?<version>[\w.]+)\)?)?/;
export function getPackageInfo(fileContent: string): PythonPackage {
const lines = fileContent.split("\n");
let name = "";
Expand Down
3 changes: 2 additions & 1 deletion lib/python-parser/requirements-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { PythonRequirement } from "./types";
// This looks like a crazy regex, but it's long because of the named capture groups
// which make the result easier to read. It essentially breaks each line into name,
// specifier and version, where only the name is mandatory
const VERSION_PARSE_REGEX = /^(?<name>[\w.-]+)((?<specifier><|<=|!=|==|>=|>|~=|===)(?<version>[\w.]*))?/;
const VERSION_PARSE_REGEX =
/^(?<name>[\w.-]+)((?<specifier><|<=|!=|==|>=|>|~=|===)(?<version>[\w.]*))?/;

export function getRequirements(fileContent: string): PythonRequirement[] {
const lines = fileContent.split("\n");
Expand Down
15 changes: 8 additions & 7 deletions lib/response-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ async function buildResponse(
deps,
);

const autoDetectedUserInstructionsFact: facts.AutoDetectedUserInstructionsFact = {
type: "autoDetectedUserInstructions",
data: {
dockerfileLayers: autoDetectedLayers,
dockerfilePackages: autoDetectedPackagesWithChildren!,
},
};
const autoDetectedUserInstructionsFact: facts.AutoDetectedUserInstructionsFact =
{
type: "autoDetectedUserInstructions",
data: {
dockerfileLayers: autoDetectedLayers,
dockerfilePackages: autoDetectedPackagesWithChildren!,
},
};
additionalFacts.push(autoDetectedUserInstructionsFact);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"@types/tmp": "^0.2.0",
"jest": "^26.4.2",
"npm-run-all": "^4.1.5",
"prettier": "^1.19.1",
"prettier": "^2.7.1",
"sinon": "^6",
"tap": "^14.10.8",
"ts-jest": "^26.4.0",
Expand Down
6 changes: 2 additions & 4 deletions test/lib/analyzer/image-inspector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,8 @@ describe("getImageArchive", () => {
const imageSavePath = path.join(customPath, uuidv4());
const registryPullSpy = jest.spyOn(Docker.prototype, "pull");

const archiveLocation: ArchiveResult = await imageInspector.getImageArchive(
targetImage,
imageSavePath,
);
const archiveLocation: ArchiveResult =
await imageInspector.getImageArchive(targetImage, imageSavePath);

expect(registryPullSpy).not.toHaveBeenCalled();
expect(archiveLocation.path).toEqual(
Expand Down
9 changes: 5 additions & 4 deletions test/lib/dockerfile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,11 @@ describe("readDockerfileAndAnalyse() correctly parses...", () => {
},
},
dockerfileLayers: {
UlVOIGFwayB1cGRhdGUgJiYgYXBrIHVwZ3JhZGUgJiYgYXBrIGFkZCAtLXVwZGF0ZSAtLW5vLWNhY2hlIG5vZGVqcyBiYXNo: {
instruction:
"RUN apk update && apk upgrade && apk add --update --no-cache nodejs bash",
},
UlVOIGFwayB1cGRhdGUgJiYgYXBrIHVwZ3JhZGUgJiYgYXBrIGFkZCAtLXVwZGF0ZSAtLW5vLWNhY2hlIG5vZGVqcyBiYXNo:
{
instruction:
"RUN apk update && apk upgrade && apk add --update --no-cache nodejs bash",
},
},
error: undefined,
},
Expand Down
5 changes: 3 additions & 2 deletions test/lib/extractor/extractor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ describe("extractImageContent", () => {
});

it("extracts red hat repositories information from layers", async () => {
const numOfFoundFiles = Object.keys(extractedContent.extractedLayers)
.length;
const numOfFoundFiles = Object.keys(
extractedContent.extractedLayers,
).length;
expect(numOfFoundFiles).toBe(1);

expect(
Expand Down
9 changes: 5 additions & 4 deletions test/lib/facts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ describe("Facts", () => {
type: "testedFiles",
data: [],
};
const autoDetectedUserInstructionsFact: facts.AutoDetectedUserInstructionsFact = {
type: "autoDetectedUserInstructions",
data: {} as any,
};
const autoDetectedUserInstructionsFact: facts.AutoDetectedUserInstructionsFact =
{
type: "autoDetectedUserInstructions",
data: {} as any,
};
const loadedPackagesFact: facts.LoadedPackagesFact = {
type: "loadedPackages",
data: {} as any,
Expand Down
3 changes: 2 additions & 1 deletion test/matchers/dockerPackageInstallCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ declare global {
}

export function toBeDockerPackageInstallCommand(received, pkgName) {
const installCmdRegex = /^(rpm\s+-i|rpm\s+--install|apk\s+((--update|-u|--no-cache)\s+)*add(\s+(--update|-u|--no-cache))*|apt-get\s+((--assume-yes|--yes|-y)\s+)*install(\s+(--assume-yes|--yes|-y))*|apt\s+((--assume-yes|--yes|-y)\s+)*install|yum\s+install|aptitude\s+install)\s+/;
const installCmdRegex =
/^(rpm\s+-i|rpm\s+--install|apk\s+((--update|-u|--no-cache)\s+)*add(\s+(--update|-u|--no-cache))*|apt-get\s+((--assume-yes|--yes|-y)\s+)*install(\s+(--assume-yes|--yes|-y))*|apt\s+((--assume-yes|--yes|-y)\s+)*install|yum\s+install|aptitude\s+install)\s+/;
const pass =
(installCmdRegex.test(received) &&
received.indexOf(pkgName) > -1 &&
Expand Down
14 changes: 8 additions & 6 deletions test/system/bugs/image-layers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ describe("demonstrates a potential bug with image layers", () => {
path: image,
});

const dockerImageLayers: string[] = dockerPluginResult.scanResults[0].facts.find(
(fact) => fact.type === "imageLayers",
)!.data;
const pullLibraryImageLayers: string[] = pullLibraryPluginResult.scanResults[0].facts.find(
(fact) => fact.type === "imageLayers",
)!.data;
const dockerImageLayers: string[] =
dockerPluginResult.scanResults[0].facts.find(
(fact) => fact.type === "imageLayers",
)!.data;
const pullLibraryImageLayers: string[] =
pullLibraryPluginResult.scanResults[0].facts.find(
(fact) => fact.type === "imageLayers",
)!.data;
expect(dockerImageLayers).toBeDefined();
expect(pullLibraryImageLayers).toBeDefined();

Expand Down
7 changes: 4 additions & 3 deletions test/system/bugs/rpm-transitive-dependencies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ describe("BUG: Dockerfile analysis does not produce transitive dependencies for

expect(pluginResult).toMatchSnapshot();

const dockerfileAnalysis: DockerFileAnalysis = pluginResult.scanResults[0].facts.find(
(fact) => fact.type === "dockerfileAnalysis",
)!.data;
const dockerfileAnalysis: DockerFileAnalysis =
pluginResult.scanResults[0].facts.find(
(fact) => fact.type === "dockerfileAnalysis",
)!.data;
// "BUG: transitive dependency 'kernel-headers' not in 'dockerfilePackages'"
expect(Object.keys(dockerfileAnalysis.dockerfilePackages)).not.toContain(
"kernel-headers",
Expand Down
12 changes: 6 additions & 6 deletions test/system/detected-layers/detected-layers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ describe("auto detected layers are identical to dockerfileAnlaysis layert", () =

const config = JSON.parse(readFileSync(configPath, "utf8"));

const autoDetectedUserInstructions = getDetectedLayersInfoFromConfig(
config,
);
const autoDetectedUserInstructions =
getDetectedLayersInfoFromConfig(config);

expect(Object.keys(dockerfileAnalysis.dockerfilePackages)).toEqual(
Object.keys(autoDetectedUserInstructions.dockerfilePackages),
Expand Down Expand Up @@ -107,9 +106,10 @@ describe("scan results", () => {
path: `docker-archive:${fixturePath}`,
});

const autoDetectedUserInstructions: AutoDetectedUserInstructions = pluginResponse.scanResults[0].facts.find(
(fact) => fact.type === "autoDetectedUserInstructions",
)!.data;
const autoDetectedUserInstructions: AutoDetectedUserInstructions =
pluginResponse.scanResults[0].facts.find(
(fact) => fact.type === "autoDetectedUserInstructions",
)!.data;

const packages = Object.keys(
autoDetectedUserInstructions.dockerfilePackages,
Expand Down
14 changes: 8 additions & 6 deletions test/system/image-type/compressed-archive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ describe("compressed archive scanning", () => {
pluginResult.scanResults.length,
);

const compressedPluginResultDepGraph: DepGraph = compressedPluginResult.scanResults[0].facts.find(
(fact) => fact.type === "depGraph",
)!.data;
const pluginResultDepGraph: DepGraph = pluginResult.scanResults[0].facts.find(
(fact) => fact.type === "depGraph",
)!.data;
const compressedPluginResultDepGraph: DepGraph =
compressedPluginResult.scanResults[0].facts.find(
(fact) => fact.type === "depGraph",
)!.data;
const pluginResultDepGraph: DepGraph =
pluginResult.scanResults[0].facts.find(
(fact) => fact.type === "depGraph",
)!.data;
expect(compressedPluginResultDepGraph.getDepPkgs().sort()).toEqual(
pluginResultDepGraph.getDepPkgs().sort(),
);
Expand Down
35 changes: 20 additions & 15 deletions test/system/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ describe("system tests", () => {
depGraph.pkgManager.name,
);

const dockerfileAnalysis: DockerFileAnalysis = pluginResponse.scanResults[0].facts.find(
(fact) => fact.type === "dockerfileAnalysis",
)!.data;
const dockerfileAnalysis: DockerFileAnalysis =
pluginResponse.scanResults[0].facts.find(
(fact) => fact.type === "dockerfileAnalysis",
)!.data;
expect(dockerfileAnalysis.baseImage).toEqual("buildpack-deps:stretch");
expect(pluginResponse.scanResults[0].target.image).toEqual(
"docker-image|" + imgName,
Expand Down Expand Up @@ -122,9 +123,10 @@ describe("system tests", () => {
const imageId: string = pluginResponse.scanResults[0].facts.find(
(fact) => fact.type === "imageId",
)!.data;
const dockerfileAnalysis: DockerFileAnalysis = pluginResponse.scanResults[0].facts.find(
(fact) => fact.type === "dockerfileAnalysis",
)!.data;
const dockerfileAnalysis: DockerFileAnalysis =
pluginResponse.scanResults[0].facts.find(
(fact) => fact.type === "dockerfileAnalysis",
)!.data;

expect(imageId).toEqual(
"sha256:7f70b30f2cc66b5e23308fb20c6e57dc1ea0c47950cca797831b705177c6b8ce",
Expand Down Expand Up @@ -182,9 +184,10 @@ describe("system tests", () => {
const imageId: string = pluginResponse.scanResults[0].facts.find(
(fact) => fact.type === "imageId",
)!.data;
const dockerfileAnalysis: DockerFileAnalysis = pluginResponse.scanResults[0].facts.find(
(fact) => fact.type === "dockerfileAnalysis",
)!.data;
const dockerfileAnalysis: DockerFileAnalysis =
pluginResponse.scanResults[0].facts.find(
(fact) => fact.type === "dockerfileAnalysis",
)!.data;

expect(imageId).toEqual(
"sha256:ca0b6709748d024a67c502558ea88dc8a1f8a858d380f5ddafa1504126a3b018",
Expand All @@ -202,9 +205,10 @@ describe("system tests", () => {

expect(depGraph.getDepPkgs()).toHaveLength(13);

const manifestFiles: ManifestFile[] = pluginResponse.scanResults[0].facts.find(
(fact) => fact.type === "imageManifestFiles",
)!.data;
const manifestFiles: ManifestFile[] =
pluginResponse.scanResults[0].facts.find(
(fact) => fact.type === "imageManifestFiles",
)!.data;
expect(Array.isArray(manifestFiles)).toBeTruthy();
expect(manifestFiles).toHaveLength(1);

Expand Down Expand Up @@ -243,9 +247,10 @@ describe("system tests", () => {
const imageId: string = pluginResponse.scanResults[0].facts.find(
(fact) => fact.type === "imageId",
)!.data;
const dockerfileAnalysis: DockerFileAnalysis = pluginResponse.scanResults[0].facts.find(
(fact) => fact.type === "dockerfileAnalysis",
)!.data;
const dockerfileAnalysis: DockerFileAnalysis =
pluginResponse.scanResults[0].facts.find(
(fact) => fact.type === "dockerfileAnalysis",
)!.data;

expect(imageId).toEqual(
"sha256:ca0b6709748d024a67c502558ea88dc8a1f8a858d380f5ddafa1504126a3b018",
Expand Down
Loading

0 comments on commit c922785

Please sign in to comment.