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

fix: add nil/len guards for RunCommand #126

Merged
merged 3 commits into from
Oct 19, 2022

Conversation

shibumi
Copy link
Collaborator

@shibumi shibumi commented Sep 11, 2021

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
:

  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

@shibumi
Copy link
Collaborator Author

shibumi commented Sep 11, 2021

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

@shibumi shibumi marked this pull request as draft September 11, 2021 15:04
@shibumi shibumi requested a review from adityasaky September 11, 2021 15:04
@@ -360,6 +360,23 @@ func TestRunCommand(t *testing.T) {
}
}

func TestRunCommandErrors(t *testing.T) {
Copy link
Member

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?

Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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

Copy link
Member

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?

Copy link
Member

@adityasaky adityasaky Oct 13, 2022

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.

@shibumi shibumi marked this pull request as ready for review October 17, 2021 18:19
@shibumi shibumi force-pushed the shibumi/fix-124 branch 2 times, most recently from 53237ad to aa5af7e Compare October 17, 2021 18:29
@adityasaky
Copy link
Member

We should add -x / --no-command to the CLI to indicate no commands.

@shibumi
Copy link
Collaborator Author

shibumi commented Oct 17, 2021

We should add -x / --no-command to the CLI to indicate no commands.

Is it even possible to create an in-toto link attestation without a command being run?

@adityasaky
Copy link
Member

adityasaky commented Oct 17, 2021

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.

@shibumi
Copy link
Collaborator Author

shibumi commented Oct 17, 2021

Just to be sure:

We should add -x / --no-command to the CLI to indicate no commands.

The -x flag is for the subcommand run, right?

@adityasaky
Copy link
Member

Just to be sure:

We should add -x / --no-command to the CLI to indicate no commands.

The -x flag is for the subcommand run, right?

Yes.

Signed-off-by: Aditya Sirish <aditya@saky.in>
@adityasaky
Copy link
Member

@shibumi @pxp928 I think this is good to go, please take a look. If we merge this in, we can soon cut a release I think.

Copy link
Member

@pxp928 pxp928 left a 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.

@adityasaky adityasaky merged commit ec59903 into in-toto:master Oct 19, 2022
@shibumi shibumi deleted the shibumi/fix-124 branch October 20, 2022 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants