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

feat: fixed in key in binaries output #317

Merged
merged 1 commit into from Jan 1, 2019

Conversation

karniwl
Copy link
Contributor

@karniwl karniwl commented Dec 30, 2018

  • Ready for review
  • Follows CONTRIBUTING rules
  • Reviewed by Snyk internal team

What does this PR do?

Adds a Fixed in version key in binaries/output, using npm semver rules.
Refactors formatting issues logic.

How should this be manually tested?

Run snyk test --docker node:5.10.1 for example to see the fixed versions of found vulnerabilities.

Screenshots

image

@karniwl karniwl self-assigned this Dec 30, 2018
function createFixedInText(versionRangeList, pkgVersion) {
let fixedVersion = '';
if (!pkgVersion && versionRangeList &&
versionRangeList.length && /^<\S+$/.test(versionRangeList[0])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This if clause is a bit difficult to read, how do you feel about extracting it to a function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's a bit of an overkill to extract it to a function as the meaning (if you know it of course... :) ) is pretty straightforward. I'll change it up and extract to a variable instead and let me know what you think

@@ -314,7 +320,7 @@ function displayResult(res, options) {
remediationInfo: vuln.metadata.type !== 'license'
? createRemediationText(vuln, packageManager)
: '',
fixedIn: options.docker ? createFixedInText(vuln) : '',
fixedIn: options.docker ? createFixedInText(vuln.list[0].semver.vulnerable, version) : '',
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand there's special meaning to the first index of the vuln.list, perhaps we could store it in a variable? (same for versionRangeList[0] and versionList[1])

src/cli/commands/test.js Outdated Show resolved Hide resolved
src/cli/commands/test.js Outdated Show resolved Hide resolved
src/cli/commands/test.js Show resolved Hide resolved
if (!pkgVersion) {
if (versionRangeList &&
versionRangeList.length &&
(lesserThan.test(versionRangeList[0]))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the changes! Can we also store versionRangeList[0] in a variable? I don't understand the significance of the first index (I guess it's ordered and we need the first item?) :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there isn't a special meaning, it's not ordered, we actually have only one item in the list in that case. I added a comment explaining it

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this warrants a comment, variable fits nice (alleviates us from the need to use the index twice and documents there's just a single item in the list)

}
} else {
for (const versionRange of versionRangeList) {
if (semver.valid(pkgVersion) && semver.satisfies(pkgVersion, versionRange)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (semver.valid(pkgVersion) && semver.satisfies(pkgVersion, versionRange)) {
if (!semver.valid(pkgVersion) || !semver.satisfies(pkgVersion, versionRange)) {
continue;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is much less readable than the current condition, we want to find the version range that matches our package version, imo it makes more sense to show what we are looking for, not what we're NOT looking for

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it's a style opinion - you're choice :)

src/cli/commands/test.js Outdated Show resolved Hide resolved
src/cli/commands/test.js Show resolved Hide resolved
vulnOutput.fixedIn +
vulnOutput.extraInfo
);
var nonBinariesSortedGroupedVulns = sortedGroupedVulns.filter(function (vuln) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var nonBinariesSortedGroupedVulns = sortedGroupedVulns.filter(function (vuln) {
var sortedGroupedVulns = sortedGroupedVulns.filter(function (vuln) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not change the all code to be docker related :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's the name I first gave and it caused a bug that wasted too much time because that's a variable name we already declared and changing it deletes all binaries vulns from it and then when filtering by upstream package manager we get an empty result...
I can change the order of the lines but that's too error-prone imo, I'll think of another solution but you're welcome to offer one as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem I'm thinking about is a developer that has no idea about what's binary is, so nonBinariesSortedGroupedVulns might be a bit confusing for him

src/cli/commands/test.js Outdated Show resolved Hide resolved
src/cli/commands/test.js Outdated Show resolved Hide resolved
src/cli/commands/test.js Outdated Show resolved Hide resolved
src/cli/commands/test.js Outdated Show resolved Hide resolved
test/acceptance/cli.acceptance.test.ts Show resolved Hide resolved
src/cli/commands/test.js Outdated Show resolved Hide resolved
@karniwl karniwl force-pushed the feat/support-docker-binaries branch from 1984ea9 to 80daaf5 Compare January 1, 2019 10:23
@karniwl karniwl merged commit bb31229 into master Jan 1, 2019
@karniwl karniwl deleted the feat/support-docker-binaries branch January 1, 2019 10:30
@snyksec
Copy link

snyksec commented Jan 1, 2019

🎉 This PR is included in version 1.120.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants