-
Notifications
You must be signed in to change notification settings - Fork 51
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
fix: add nil/len guards for RunCommand #126
Conversation
This PR is missing more tests for the InTotoRun function. Right now I am only testing the RunCommand func. We might want to test link creation for an empty CmdArgs parameter as well |
@@ -360,6 +360,23 @@ func TestRunCommand(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestRunCommandErrors(t *testing.T) { |
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.
Can / should we also test by invoking InTotoRun
?
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.
Oh whoops, I missed your comment on the PR.
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.
yes we can. I will add a few more tests for this.
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.
@adityasaky I had a closer look on this. We cannot test InTotoRun for it, because we do not fail if the cmdArgs are empty. If we would fail if cmdArgs is empty we would no longer support link files without commands:
// make sure that we only run RunCommand if cmdArgs is not nil or empty
var byProducts map[string]interface{}
if cmdArgs != nil && len(cmdArgs) != 0 {
byProducts, err = RunCommand(cmdArgs, runDir)
if err != nil {
return linkMb, err
}
}
See line 3 that checks for empty cmdArgs
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.
Reviving this one. I see what you mean but I think it's okay to test that the no command flag works as intended and still results in a link, no?
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.
@shibumi can you take a look? I added a test checking if link metadata is successfully generated. Also caught that a minor difference in byProducts
had crept in.
d7be895
to
37e9e08
Compare
53237ad
to
aa5af7e
Compare
We should add |
Is it even possible to create an in-toto link attestation without a command being run? |
Yes, the field should just be empty. The reference implementation supports it too. Also note that links generates via record always have the command field empty. |
Just to be sure:
The |
aa5af7e
to
5bb106f
Compare
Yes. |
Signed-off-by: Aditya Sirish <aditya@saky.in>
8fbc953
to
9d1c911
Compare
Signed-off-by: Aditya Sirish <aditya@saky.in>
9d1c911
to
53bea4f
Compare
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.
Looks good based on the code.
Please fill in the fields below to submit a pull request. The more
information that is provided, the better.
Fixes issue #: #124
Description of pull request:
Please verify and check that the pull request fulfills the following
requirements: