-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new data flow paths view (empty) #2172
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
extensions/ql-vscode/src/variant-analysis/data-flow-paths-view.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { ExtensionContext, ViewColumn } from "vscode"; | ||
import { AbstractWebview, WebviewPanelConfig } from "../abstract-webview"; | ||
import { assertNever } from "../pure/helpers-pure"; | ||
import { telemetryListener } from "../telemetry"; | ||
import { | ||
FromDataFlowPathsMessage, | ||
ToDataFlowPathsMessage, | ||
} from "../pure/interface-types"; | ||
import { DataFlowPaths } from "./shared/data-flow-paths"; | ||
import { showAndLogExceptionWithTelemetry } from "../helpers"; | ||
import { redactableError } from "../pure/errors"; | ||
|
||
export class DataFlowPathsView extends AbstractWebview< | ||
ToDataFlowPathsMessage, | ||
FromDataFlowPathsMessage | ||
> { | ||
public static readonly viewType = "codeQL.dataFlowPaths"; | ||
|
||
public constructor(ctx: ExtensionContext) { | ||
super(ctx); | ||
} | ||
|
||
public async showDataFlows(dataFlowPaths: DataFlowPaths) { | ||
const panel = await this.getPanel(); | ||
panel.reveal(undefined, true); | ||
|
||
await this.waitForPanelLoaded(); | ||
|
||
await this.postMessage({ | ||
t: "setDataFlowPaths", | ||
dataFlowPaths, | ||
}); | ||
} | ||
|
||
protected async getPanelConfig(): Promise<WebviewPanelConfig> { | ||
return { | ||
viewId: DataFlowPathsView.viewType, | ||
title: "Data Flow Paths", | ||
charisk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
viewColumn: ViewColumn.Active, | ||
preserveFocus: true, | ||
view: "data-flow-paths", | ||
}; | ||
} | ||
|
||
protected onPanelDispose(): void { | ||
// Nothing to dispose | ||
} | ||
|
||
protected async onMessage(msg: FromDataFlowPathsMessage): Promise<void> { | ||
switch (msg.t) { | ||
case "viewLoaded": | ||
this.onWebViewLoaded(); | ||
break; | ||
case "telemetry": | ||
telemetryListener?.sendUIInteraction(msg.action); | ||
break; | ||
case "unhandledError": | ||
void showAndLogExceptionWithTelemetry( | ||
redactableError( | ||
msg.error, | ||
)`Unhandled error in data flow paths view: ${msg.error.message}`, | ||
); | ||
break; | ||
default: | ||
assertNever(msg); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
extensions/ql-vscode/src/variant-analysis/shared/data-flow-paths.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { AnalysisMessage, CodeFlow, ResultSeverity } from "./analysis-result"; | ||
|
||
export interface DataFlowPaths { | ||
codeFlows: CodeFlow[]; | ||
ruleDescription: string; | ||
message: AnalysisMessage; | ||
severity: ResultSeverity; | ||
} |
48 changes: 48 additions & 0 deletions
48
extensions/ql-vscode/src/view/data-flow-paths/DataFlowPathsView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as React from "react"; | ||
import { useEffect, useState } from "react"; | ||
import { ToDataFlowPathsMessage } from "../../pure/interface-types"; | ||
import { DataFlowPaths } from "../../variant-analysis/shared/data-flow-paths"; | ||
|
||
export type DataFlowPathsViewProps = { | ||
dataFlowPaths?: DataFlowPaths; | ||
}; | ||
|
||
export function DataFlowPathsView({ | ||
dataFlowPaths: initialDataFlowPaths, | ||
}: DataFlowPathsViewProps): JSX.Element { | ||
const [dataFlowPaths, setDataFlowPaths] = useState<DataFlowPaths | undefined>( | ||
initialDataFlowPaths, | ||
); | ||
|
||
useEffect(() => { | ||
const listener = (evt: MessageEvent) => { | ||
if (evt.origin === window.origin) { | ||
const msg: ToDataFlowPathsMessage = evt.data; | ||
if (msg.t === "setDataFlowPaths") { | ||
setDataFlowPaths(msg.dataFlowPaths); | ||
} | ||
} else { | ||
// sanitize origin | ||
const origin = evt.origin.replace(/\n|\r/g, ""); | ||
console.error(`Invalid event origin ${origin}`); | ||
} | ||
}; | ||
window.addEventListener("message", listener); | ||
|
||
return () => { | ||
window.removeEventListener("message", listener); | ||
}; | ||
}, []); | ||
|
||
if (!dataFlowPaths) { | ||
return <>Loading data flow paths</>; | ||
} | ||
|
||
// For now, just render the data flows as JSON. | ||
return ( | ||
<> | ||
Loaded | ||
<pre>{JSON.stringify(dataFlowPaths)}</pre> | ||
</> | ||
); | ||
} |
24 changes: 24 additions & 0 deletions
24
extensions/ql-vscode/src/view/data-flow-paths/__tests__/DataFlowPathsView.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as React from "react"; | ||
import { render as reactRender, screen } from "@testing-library/react"; | ||
import { | ||
DataFlowPathsView, | ||
DataFlowPathsViewProps, | ||
} from "../DataFlowPathsView"; | ||
import { createMockDataFlowPaths } from "../../../../test/factories/variant-analysis/shared/data-flow-paths"; | ||
|
||
describe(DataFlowPathsView.name, () => { | ||
const render = (props: Partial<DataFlowPathsViewProps>) => | ||
reactRender(<DataFlowPathsView {...props} />); | ||
|
||
it("renders a loading data flow paths view", () => { | ||
render({}); | ||
|
||
expect(screen.getByText("Loading data flow paths")).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders a data flow paths view", () => { | ||
render({ dataFlowPaths: createMockDataFlowPaths() }); | ||
|
||
expect(screen.getByText("Loaded")).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as React from "react"; | ||
import { WebviewDefinition } from "../webview-definition"; | ||
import { DataFlowPathsView } from "./DataFlowPathsView"; | ||
|
||
const definition: WebviewDefinition = { | ||
component: <DataFlowPathsView />, | ||
}; | ||
|
||
export default definition; |
106 changes: 106 additions & 0 deletions
106
extensions/ql-vscode/test/factories/variant-analysis/shared/data-flow-paths.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { CodeFlow } from "../../../../src/variant-analysis/shared/analysis-result"; | ||
import { DataFlowPaths } from "../../../../src/variant-analysis/shared/data-flow-paths"; | ||
|
||
export function createMockDataFlowPaths(): DataFlowPaths { | ||
const codeFlows: CodeFlow[] = [ | ||
{ | ||
threadFlows: [ | ||
{ | ||
fileLink: { | ||
fileLinkPrefix: | ||
"https://github.com/PowerShell/PowerShell/blob/450d884668ca477c6581ce597958f021fac30bff", | ||
filePath: | ||
"src/System.Management.Automation/help/UpdatableHelpSystem.cs", | ||
}, | ||
codeSnippet: { | ||
startLine: 1260, | ||
endLine: 1260, | ||
text: " string extractPath = Path.Combine(destination, entry.FullName);", | ||
}, | ||
highlightedRegion: { | ||
startLine: 1260, | ||
startColumn: 72, | ||
endLine: 1260, | ||
endColumn: 86, | ||
}, | ||
message: { | ||
tokens: [ | ||
{ | ||
t: "text", | ||
text: "access to property FullName : String", | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
fileLink: { | ||
fileLinkPrefix: | ||
"https://github.com/PowerShell/PowerShell/blob/450d884668ca477c6581ce597958f021fac30bff", | ||
filePath: | ||
"src/System.Management.Automation/help/UpdatableHelpSystem.cs", | ||
}, | ||
codeSnippet: { | ||
startLine: 1260, | ||
endLine: 1260, | ||
text: " string extractPath = Path.Combine(destination, entry.FullName);", | ||
}, | ||
highlightedRegion: { | ||
startLine: 1260, | ||
startColumn: 46, | ||
endLine: 1260, | ||
endColumn: 87, | ||
}, | ||
message: { | ||
tokens: [ | ||
{ | ||
t: "text", | ||
text: "call to method Combine : String", | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
fileLink: { | ||
fileLinkPrefix: | ||
"https://github.com/PowerShell/PowerShell/blob/450d884668ca477c6581ce597958f021fac30bff", | ||
filePath: | ||
"src/System.Management.Automation/help/UpdatableHelpSystem.cs", | ||
}, | ||
codeSnippet: { | ||
startLine: 1261, | ||
endLine: 1261, | ||
text: " entry.ExtractToFile(extractPath);", | ||
}, | ||
highlightedRegion: { | ||
startLine: 1261, | ||
startColumn: 45, | ||
endLine: 1261, | ||
endColumn: 56, | ||
}, | ||
message: { | ||
tokens: [ | ||
{ | ||
t: "text", | ||
text: "access to local variable extractPath", | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
return { | ||
codeFlows, | ||
ruleDescription: "ZipSlip vulnerability", | ||
message: { | ||
tokens: [ | ||
{ | ||
t: "text", | ||
text: "This zip file may have a dangerous path", | ||
}, | ||
], | ||
}, | ||
severity: "Warning", | ||
}; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should opening this view also be added as an activation event?
It might not be necessary to add it since it can only be opened if another CodeQL view is already open, but perhaps it would be good for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I'm not sure. This view won't persist - it will be lost if you restart VS Code and you'd have to click on "Show paths" again. So why would it go in the activation events? Or have I misunderstood what this is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Activation events are also used for opening a non-persisted view, so it would also be an activation event if you opened the view from somewhere else. However, as I mentioned I don't believe it's necessary for this view to be an activation event because another view will always have to be loaded already before you can open this one. However, all of our current views are in the activation events, even those that currently also have that behaviour (like
onWebviewPanel:resultsView
), so I think it would be good to add it for consistency.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems odd to just do it for consistency but that's perhaps a tech-debt issue. Updated.