test: FIPS does not setup bind mounts#4566
Draft
angelcerveraroldan wants to merge 2 commits into
Draft
Conversation
Add a helper function that checks that a commands stdout does not contain a substring.
On RHEL10, fips-mode-setup was removed. If the FIPS dracut module doesn't call update-crypto-policies directly, the fips-crypto-policies dracut module falls back to setting up read-only bind mounts over /etc/crypto-policies, leading to issues. Add a test assertion to verify that /etc/crypto-policies is configured on-disk and not via bind mounts, ensuring the fix[1] in rhel-coreos-config is working correctly. [1] coreos/rhel-coreos-config#259
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a new helper method AssertCmdOutputDoesNotContain to TestCluster and utilizes it in the FIPS test to verify that there are no mounts over crypto-policies. A review comment suggests improving the helper's failure message by including the command output and using %q formatting for better debuggability.
Comment on lines
+212
to
+220
| // AssertCmdOutputDoesNotContain runs cmd via SSH and panics if stdout contains unexpected | ||
| func (t *TestCluster) AssertCmdOutputDoesNotContain(m platform.Machine, cmd string, unexpected string) { | ||
| t.LogJournal(m, "+ "+cmd) | ||
| outputBuf := t.MustSSH(m, cmd) | ||
| output := string(outputBuf) | ||
| if strings.Contains(output, unexpected) { | ||
| t.Fatalf("cmd %s unexpectedly contained %s", cmd, unexpected) | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
To improve debuggability when a test assertion fails, it is highly recommended to include the actual command output in the failure message. Additionally, using %q instead of %s for the command and unexpected string arguments is a Go best practice to clearly demarcate them (especially if they contain spaces or special characters).
func (t *TestCluster) AssertCmdOutputDoesNotContain(m platform.Machine, cmd string, unexpected string) {
t.LogJournal(m, "+ "+cmd)
outputBuf := t.MustSSH(m, cmd)
output := string(outputBuf)
if strings.Contains(output, unexpected) {
t.Fatalf("cmd %q unexpectedly contained %q; output:\n%s", cmd, unexpected, output)
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On RHEL10, fips-mode-setup was removed. If the FIPS dracut module
doesn't call update-crypto-policies directly, the fips-crypto-policies
dracut module falls back to setting up read-only bind mounts over
/etc/crypto-policies, leading to issues.
Add a test assertion to verify that /etc/crypto-policies is configured
on-disk and not via bind mounts, ensuring the fix[1] in
rhel-coreos-config is working correctly.
[1] coreos/rhel-coreos-config#259