-
Notifications
You must be signed in to change notification settings - Fork 2
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
NEW @W-16360876@ Implemented describeRules() functionality for FlowTest #93
Conversation
5ae8f6f
to
89833b5
Compare
return flowTestRules.map(flowTestRule => { | ||
return { | ||
// The name maps directly over. | ||
name: flowTestRule.query_name, |
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.
The query_name
field has spaces in it, and the query_id
field has periods in it. So I chose to use the one with spaces in it for now. We can have a discussion about what postprocessing might be needed to bring the names more into line with our best practices.
]; | ||
|
||
let stdout: string = ''; | ||
const processStdout = (stdoutMsg: string) => { | ||
stdout += stdoutMsg; | ||
} | ||
await this.pythonCommandExecutor.exec(pythonArgs, processStdout); | ||
return stdout; | ||
return (JSON.parse(stdout) as FlowTestRuleDescriptor[]).sort((a, b) => a.query_name.localeCompare(b.query_name)); |
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.
The sorting is necessary because the output printed to stdout isn't sorted at this time. Robert intends to update it with sorting, and when he does I will change it here too.
packages/code-analyzer-flowtest-engine/src/python/FlowTestCommandWrapper.ts
Show resolved
Hide resolved
...nalyzer-flowtest-engine/test/test-data/goldfiles/FlowTestCommandWrapper.test.ts/catalog.json
Outdated
Show resolved
Hide resolved
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.
I see that code coverage for this flowtest package is no longer 100% like all other packages
code-analyzer-flowtest-engine/src | 100 | 100 | 100 | 100 |
config.ts | 100 | 100 | 100 | 100 |
engine.ts | 100 | 100 | 100 | 100 |
messages.ts | 100 | 100 | 100 | 100 |
plugin.ts | 100 | 100 | 100 | 100 |
code-analyzer-flowtest-engine/src/python | 90.56 | 44.44 | 77.77 | 92.15 |
FlowTestCommandWrapper.ts | 100 | 100 | 100 | 100 |
PythonCommandExecutor.ts | 78.26 | 28.57 | 70 | 80.95 | 35-45
PythonVersionIdentifier.ts | 100 | 100 | 80 | 100 |
If possible, can we either add in code coverage for anything to be submitted or add in the ignore comments where code coverage isn't easily able to be covered?
Or will these be hit when the run method is implemented?
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.
Improved: Now I see
------------------------------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
------------------------------------------|---------|----------|---------|---------|-------------------
PythonVersionIdentifier.ts | 100 | 100 | 80 | 100 |
Maybe there is 1 function that isn't fully hit.
@@ -23,24 +24,60 @@ export class FlowTestEngine extends Engine { | |||
|
|||
public async describeRules(_describeOptions: DescribeOptions): Promise<RuleDescription[]> { |
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.
The describe command should be looking at the workspace if it is provided to see if the workspace even contains relevant files (in this case, flow based xml files). If there is a workspace and there are no relevant files, then no rules should be returned. That is, we shouldn't be doing any work if there are no flow files in the workspace.
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.
It looks like the extensions the FlowTest tool looks for are .flow-meta.xml
and .flow
. So I'll make the plugin look for those too.
this.emitRunRulesProgressEvent(100); | ||
return { | ||
violations: [] | ||
}; | ||
} | ||
|
||
private convertFlowTestRulesToCodeAnalyzerRules(flowTestRules: FlowTestRuleDescriptor[]): RuleDescription[] { |
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.
Nitpick: Can these private methods instead be functions?
Also maybe call this function toRuleDescription(flowTestRule: FlowTestRuleDiscriptor)
and then simply make your line 29 to be
const ruleDescriptions: RuleDescription[] = flowTestRules.map(toRuleDescription);
packages/code-analyzer-flowtest-engine/src/python/FlowTestCommandWrapper.ts
Outdated
Show resolved
Hide resolved
return []; | ||
const flowTestRules: FlowTestRuleDescriptor[] = await this.commandWrapper.getFlowTestRuleDescriptions(); | ||
this.emitDescribeRulesProgressEvent(75); | ||
const convertedRules = flowTestRules.map(r => toRuleDescription(r)); |
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.
Since it is now a function (and not tied to a class instance), I believe you could have also just done flowTestRules.map(toRuleDescription)
function toRuleDescription(flowTestRule: FlowTestRuleDescriptor): RuleDescription { | ||
return { | ||
// The name maps directly over. | ||
name: flowTestRule.query_name, |
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.
It looks like in the catalog.goldfile.json that an example query_name is Flow: SystemModeWithSharing recordUpdates data
and here it looks like we are using this as the rule name. This does not seem good to me.
Robert closed the Enhancement Request for rules having shorter names (see https://git.soma.salesforce.com/SecurityTools/FlowSecurityLinter/issues/39) ... but it looks like he maintained spaces and colons in the names. For example I see
query_name = f"Flow Security: User access to {elem_type} {check_labels_val} in mode {run_mode}"
got turned into
query_name = f"Flow: {run_mode} {elem_type} {check_labels_val}"
which is still too long.
So either we need to go back to him and make these names even shorter without spaces and colons, or we'll need to create a mapping on our end (either fixed or dynamic).
For example on our end we could probably just remove the prefix "Flow: " and then convert all spaces to dashes for now or something. So instead of
Flow: SystemModeWithSharing recordUpdates data
maybe the name could for now just be SystemModeWithSharing-recordUpdates-data
But I created https://git.soma.salesforce.com/SecurityTools/FlowSecurityLinter/issues/47 to ask that we may receive better names.
7b8eed0
to
d2ceb4c
Compare
0b5373f
to
ca3c4f6
Compare
const workspaceFiles: string[] = await describeOptions.workspace.getExpandedFiles(); | ||
// If a workspace is provided but it contains no flow files, then return no rules. | ||
if (!workspaceFiles.some(fileIsFlowFile)) { | ||
this.emitLogEvent(LogLevel.Fine, 'Workspace contains no Flow files; returning no rules'); |
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.
This seems relevant to possible user debugging... so maybe make this to LogLevel.Debug instead of LogLevel.Fine.
This PR does the following: