Replace VariantAnalysisQueryLanguage -> QueryLanguage

This commit is contained in:
Elena Tanasoiu
2023-02-13 19:32:27 +00:00
parent 73838ffc6c
commit aabeba067a
9 changed files with 24 additions and 56 deletions

View File

@@ -3,16 +3,7 @@ import { dump } from "js-yaml";
import { join } from "path";
import { Uri, workspace } from "vscode";
import { CodeQLCliServer } from "./cli";
export type QueryLanguage =
| "csharp"
| "cpp"
| "go"
| "java"
| "javascript"
| "python"
| "ruby"
| "swift";
import { QueryLanguage } from "./types/query-language";
export class QlPackGenerator {
private readonly qlpackName: string;

View File

@@ -1,28 +1,19 @@
import { QueryLanguage } from "../../types/query-language";
import { Repository, RepositoryWithMetadata } from "./repository";
export interface VariantAnalysisSubmissionRequest {
action_repo_ref: string;
language: VariantAnalysisQueryLanguage;
language: QueryLanguage;
query_pack: string;
repositories?: string[];
repository_lists?: string[];
repository_owners?: string[];
}
export type VariantAnalysisQueryLanguage =
| "csharp"
| "cpp"
| "go"
| "java"
| "javascript"
| "python"
| "ruby"
| "swift";
export interface VariantAnalysis {
id: number;
controller_repo: Repository;
query_language: VariantAnalysisQueryLanguage;
query_language: QueryLanguage;
query_pack_url: string;
created_at: string;
updated_at: string;

View File

@@ -1,5 +1,6 @@
import { Repository, RepositoryWithMetadata } from "./repository";
import { AnalysisAlert, AnalysisRawResults } from "./analysis-result";
import { QueryLanguage } from "../../types/query-language";
export interface VariantAnalysis {
id: number;
@@ -7,7 +8,7 @@ export interface VariantAnalysis {
query: {
name: string;
filePath: string;
language: VariantAnalysisQueryLanguage;
language: QueryLanguage;
text: string;
};
databases: {
@@ -26,23 +27,10 @@ export interface VariantAnalysis {
skippedRepos?: VariantAnalysisSkippedRepositories;
}
export enum VariantAnalysisQueryLanguage {
CSharp = "csharp",
Cpp = "cpp",
Go = "go",
Java = "java",
Javascript = "javascript",
Python = "python",
Ruby = "ruby",
Swift = "swift",
}
export function parseVariantAnalysisQueryLanguage(
language: string,
): VariantAnalysisQueryLanguage | undefined {
return Object.values(VariantAnalysisQueryLanguage).find(
(x) => x === language,
);
): QueryLanguage | undefined {
return Object.values(QueryLanguage).find((x) => x === language);
}
export enum VariantAnalysisStatus {
@@ -148,7 +136,7 @@ export interface VariantAnalysisSubmission {
query: {
name: string;
filePath: string;
language: VariantAnalysisQueryLanguage;
language: QueryLanguage;
text: string;
// Base64 encoded query pack.

View File

@@ -5,7 +5,7 @@ import {
VariantAnalysisSkippedRepositories,
VariantAnalysisStatus,
} from "../../../../src/variant-analysis/gh-api/variant-analysis";
import { VariantAnalysisQueryLanguage } from "../../../../src/variant-analysis/shared/variant-analysis";
import { QueryLanguage } from "../../../../src/types/query-language";
import { createMockScannedRepos } from "./scanned-repositories";
import { createMockSkippedRepos } from "./skipped-repositories";
import { createMockRepository } from "./repository";
@@ -23,7 +23,7 @@ export function createMockApiResponse(
full_name: "github/pickles",
private: false,
},
query_language: VariantAnalysisQueryLanguage.Javascript,
query_language: QueryLanguage.Javascript,
query_pack_url: "https://example.com/foo",
created_at: faker.date.recent().toISOString(),
updated_at: faker.date.recent().toISOString(),

View File

@@ -1,8 +1,6 @@
import { faker } from "@faker-js/faker";
import {
VariantAnalysisQueryLanguage,
VariantAnalysisSubmission,
} from "../../../../src/variant-analysis/shared/variant-analysis";
import { VariantAnalysisSubmission } from "../../../../src/variant-analysis/shared/variant-analysis";
import { QueryLanguage } from "../../../../src/types/query-language";
export function createMockSubmission(): VariantAnalysisSubmission {
return {
@@ -12,7 +10,7 @@ export function createMockSubmission(): VariantAnalysisSubmission {
query: {
name: "query-name",
filePath: "query-file-path",
language: VariantAnalysisQueryLanguage.Javascript,
language: QueryLanguage.Javascript,
text: "query-text",
pack: "base64-encoded-string",
},

View File

@@ -1,7 +1,6 @@
import { faker } from "@faker-js/faker";
import {
VariantAnalysis,
VariantAnalysisQueryLanguage,
VariantAnalysisScannedRepository,
VariantAnalysisSkippedRepositories,
VariantAnalysisStatus,
@@ -9,6 +8,7 @@ import {
import { createMockScannedRepos } from "./scanned-repositories";
import { createMockSkippedRepos } from "./skipped-repositories";
import { createMockRepository } from "./repository";
import { QueryLanguage } from "../../../../src/types/query-language";
export function createMockVariantAnalysis({
status = VariantAnalysisStatus.InProgress,
@@ -32,7 +32,7 @@ export function createMockVariantAnalysis({
query: {
name: "a-query-name",
filePath: "a-query-file-path",
language: VariantAnalysisQueryLanguage.Javascript,
language: QueryLanguage.Javascript,
text: "a-query-text",
},
databases: {

View File

@@ -1,7 +1,6 @@
import {
VariantAnalysis,
parseVariantAnalysisQueryLanguage,
VariantAnalysisQueryLanguage,
VariantAnalysisStatus,
isVariantAnalysisComplete,
VariantAnalysisRepoStatus,
@@ -9,11 +8,12 @@ import {
} from "../../src/variant-analysis/shared/variant-analysis";
import { createMockScannedRepo } from "../factories/variant-analysis/shared/scanned-repositories";
import { createMockVariantAnalysis } from "../factories/variant-analysis/shared/variant-analysis";
import { QueryLanguage } from "../../src/types/query-language";
describe("parseVariantAnalysisQueryLanguage", () => {
it("parses a valid language", () => {
expect(parseVariantAnalysisQueryLanguage("javascript")).toBe(
VariantAnalysisQueryLanguage.Javascript,
QueryLanguage.Javascript,
);
});

View File

@@ -6,11 +6,11 @@ import {
MarkdownFile,
} from "../../../src/variant-analysis/markdown-generation";
import {
VariantAnalysisQueryLanguage,
VariantAnalysisRepoStatus,
VariantAnalysisScannedRepository,
VariantAnalysisScannedRepositoryResult,
} from "../../../src/variant-analysis/shared/variant-analysis";
import { QueryLanguage } from "../../../src/types/query-language";
import {
AnalysisAlert,
AnalysisRawResults,
@@ -32,7 +32,7 @@ describe(generateVariantAnalysisMarkdown.name, () => {
filePath:
"c:\\git-repo\\vscode-codeql-starter\\ql\\javascript\\ql\\src\\Security\\CWE-078\\ShellCommandInjectionFromEnvironment.ql",
text: '/**\n * @name Shell command built from environment values\n * @description Building a shell command string with values from the enclosing\n * environment may cause subtle bugs or vulnerabilities.\n * @kind path-problem\n * @problem.severity warning\n * @security-severity 6.3\n * @precision high\n * @id js/shell-command-injection-from-environment\n * @tags correctness\n * security\n * external/cwe/cwe-078\n * external/cwe/cwe-088\n */\n\nimport javascript\nimport DataFlow::PathGraph\nimport semmle.javascript.security.dataflow.ShellCommandInjectionFromEnvironmentQuery\n\nfrom\n Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink, DataFlow::Node highlight,\n Source sourceNode\nwhere\n sourceNode = source.getNode() and\n cfg.hasFlowPath(source, sink) and\n if cfg.isSinkWithHighlight(sink.getNode(), _)\n then cfg.isSinkWithHighlight(sink.getNode(), highlight)\n else highlight = sink.getNode()\nselect highlight, source, sink, "This shell command depends on an uncontrolled $@.", sourceNode,\n sourceNode.getSourceType()\n',
language: VariantAnalysisQueryLanguage.Javascript,
language: QueryLanguage.Javascript,
},
},
getResults(pathProblemAnalysesResults),
@@ -56,7 +56,7 @@ describe(generateVariantAnalysisMarkdown.name, () => {
filePath:
"c:\\git-repo\\vscode-codeql-starter\\ql\\javascript\\ql\\src\\Performance\\ReDoS.ql",
text: '/**\n * @name Inefficient regular expression\n * @description A regular expression that requires exponential time to match certain inputs\n * can be a performance bottleneck, and may be vulnerable to denial-of-service\n * attacks.\n * @kind problem\n * @problem.severity error\n * @security-severity 7.5\n * @precision high\n * @id js/redos\n * @tags security\n * external/cwe/cwe-1333\n * external/cwe/cwe-730\n * external/cwe/cwe-400\n */\n\nimport javascript\nimport semmle.javascript.security.performance.ReDoSUtil\nimport semmle.javascript.security.performance.ExponentialBackTracking\n\nfrom RegExpTerm t, string pump, State s, string prefixMsg\nwhere hasReDoSResult(t, pump, s, prefixMsg)\nselect t,\n "This part of the regular expression may cause exponential backtracking on strings " + prefixMsg +\n "containing many repetitions of \'" + pump + "\'."\n',
language: VariantAnalysisQueryLanguage.Javascript,
language: QueryLanguage.Javascript,
},
},
getResults(problemAnalysesResults),
@@ -79,7 +79,7 @@ describe(generateVariantAnalysisMarkdown.name, () => {
name: "Contradictory guard nodes",
filePath: "c:\\Users\\foo\\bar\\quick-query.ql",
text: '/**\n * @name Contradictory guard nodes\n * \n * @description Snippet from "UselessComparisonTest.ql"\n */\n\nimport javascript\n\n/**\n * Holds if there are any contradictory guard nodes in `container`.\n *\n * We use this to restrict reachability analysis to a small set of containers.\n */\npredicate hasContradictoryGuardNodes(StmtContainer container) {\n exists(ConditionGuardNode guard |\n RangeAnalysis::isContradictoryGuardNode(guard) and\n container = guard.getContainer()\n )\n}\n\nfrom StmtContainer c\nwhere hasContradictoryGuardNodes(c)\nselect c, c.getNumLines()',
language: VariantAnalysisQueryLanguage.Javascript,
language: QueryLanguage.Javascript,
},
},
getResults(rawResultsAnalysesResults),

View File

@@ -1,7 +1,6 @@
import { faker } from "@faker-js/faker";
import { VariantAnalysisScannedRepository as ApiVariantAnalysisScannedRepository } from "../../../src/variant-analysis/gh-api/variant-analysis";
import {
VariantAnalysisQueryLanguage,
VariantAnalysisScannedRepository,
VariantAnalysisRepoStatus,
} from "../../../src/variant-analysis/shared/variant-analysis";
@@ -18,6 +17,7 @@ import { createMockSkippedRepos } from "../../factories/variant-analysis/gh-api/
import { createMockApiResponse } from "../../factories/variant-analysis/gh-api/variant-analysis-api-response";
import { createMockSubmission } from "../../factories/variant-analysis/shared/variant-analysis-submission";
import { createMockVariantAnalysisRepoTask } from "../../factories/variant-analysis/gh-api/variant-analysis-repo-task";
import { QueryLanguage } from "../../../src/types/query-language";
describe(processVariantAnalysis.name, () => {
const scannedRepos = createMockScannedRepos();
@@ -48,7 +48,7 @@ describe(processVariantAnalysis.name, () => {
},
query: {
filePath: "query-file-path",
language: VariantAnalysisQueryLanguage.Javascript,
language: QueryLanguage.Javascript,
name: "query-name",
text: mockSubmission.query.text,
},