Skip to content
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-15884203@: Implement the retire-js engine #23

Merged
merged 7 commits into from
Jun 14, 2024

Conversation

stephen-carter-at-sf
Copy link
Collaborator

No description provided.

Comment on lines 18 to 22
"@types/tmp": "^0.2.6",
"isbinaryfile": "^5.0.2",
"node-stream-zip": "^1.15.0",
"retire": "^5.0.0",
"tmp": "^0.2.3"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed that all these third party libraries (which we used before) have all already been approved.

this.retireJsExecutor = retireJsExecutor ? retireJsExecutor : new AdvancedRetireJsExecutor(emitLogEventFcn);
}

getName(): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some places you call this method and in other places, you directly use the RetireJsEngine.NAME. Is that intentional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getName is the only way the core module gets the engine name. The only other place I call getName here in this project is when testing that getName returns the expected name. Otherwise, I only use the constant. This indeed is intentional. In those other instances where I use the constant, I don't have an instance of the engine in order to call getName anyway.

/**
* Expands a list of files and/or folders to be a list of all contained files, including the files found in subfolders
*/
export function expandToListAllFiles(absoluteFileOrFolderPaths: string[]): string[] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: What does this method do that using globby and glob('**/**') wouldn't do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function receives the list of files and folders that it gets from core. For example:
if the user passes to the cli ['some/relativeFile.js', 'some/relative/folder', 'some/relative/folder/someFileInTheFolder.js'] then core automatically removes dudundant entries, and makes the paths absolute:
['/full/path/some/relativeFile.js', '/full/path/some/relative/folder']

and then the engine gets this list.

Now retire js needs to walk through the list of all files... so this expandToListAllFiles will then convert things to

['/full/path/some/relativeFile.js', '/full/path/some/relative/folder/subFolder/someFile.js', '/full/path/some/relative/folder/anotherFile.html', ...., '/full/path/some/relative/folder/yetAnotherFile.zip']

for example.

globby just expands globs. Also, i'd like to not bring in unnecessary tools to do operations that are simple. Using a hammer all the time can get messy.

The algorithm I'm using here is a very common path algorithm for finding all files under a directory.

*/
export function isZipFile(file: string) {
const buf: Buffer = fs.readFileSync(file);
/* istanbul ignore next */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being excluded?

Copy link
Collaborator Author

@stephen-carter-at-sf stephen-carter-at-sf Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any time we have literally no way to hit a branch of code because of some crazy edge case, it's nice to make this known to the code coverage utility.

/* istanbul ignore next */
is how you basically say, ignore the next line for code coverage checking here.

It seems there are many edge cases that is-zip covers... but our zip files only hit a few of these branches. But it leaving code as is since our users might have some random file that hits these other branches.

});

it('When validate is called, then nothing happens since it currently is a no-op', () => {
engine.validate();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test actually verifying that nothing is happening? Or is it just for coverage?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our validate method here is a no-op. Making sure that at least the core module can call it without things blowing up. So it is both for coverage, but also as a sanity check that when the core module calls it - it won't break anything.

/**
* AdvancedRetireJsExecutor - An advanced strategy of calling retire that does a lot more work to catch more vulnerabilities
*
* This executor examines all specifies files and makes a copy of all text based files into a temporary folder, renaming
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something we introduced in 5.x or is this the same strategy currently followed by sfdx-scanner?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is exactly what our current strategy with 4.x is. This is what makes our retire-js engine more complicated... because we have to do all this advanced stuff.

@stephen-carter-at-sf stephen-carter-at-sf merged commit 8dc1023 into dev Jun 14, 2024
5 checks passed
@stephen-carter-at-sf stephen-carter-at-sf deleted the d/W-15884203 branch June 14, 2024 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants