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

Update samples commit, refresh test data, fix refresh-test-data on macOS #508

Merged
merged 7 commits into from
Oct 8, 2024

Conversation

egibs
Copy link
Member

@egibs egibs commented Oct 8, 2024

Closes: #503, #505

This PR updates the samples commit to the latest ref and fixes .xz archive extraction where some archives contain archives. If this is the case, we'll decompress the .xz file and then extract the resulting archive via tar xJvf.

I also fixed the test data refresh on macOS by re-adding -n1 to the final xargs command.

It's likely that we'll see some JSON test failures so those will need to be resolved before this can merge.

@egibs egibs requested a review from tstromberg October 8, 2024 16:52
mv $(OUT_DIR) $(basename $(OUT_DIR))

prepare-samples: out/samples-$(SAMPLES_COMMIT)
cp -a test_data/. $(basename $(OUT_DIR))

.PHONY: test
test: prepare-samples
go test $(shell go list ./... | grep -Ev "samples|test_data")
Copy link
Member Author

Choose a reason for hiding this comment

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

This was excluding the out/samples-... directories. Oddly enough, the test_data directory was still being run when I updated this to `grep -Ev "^samples$|test_data" so I updated this to the valid two directories with tests.

@@ -108,21 +108,21 @@ addq ${malcontent} --format=simple \
for f in $(find "${test_data}" -name "*.simple"); do
prog=$(echo $f | sed -e s#"${test_data}/"## -e s#\.simple\$##)
if [[ -f "${prog}" ]]; then
addq ${malcontent} --format=simple -o "${f}" analyze "${prog}"
addq ${malcontent} --format=simple --ignore-tags=harmless -o "${f}" analyze "${prog}"
Copy link
Member Author

Choose a reason for hiding this comment

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

I added these flags to match the test mc configuration.

@@ -17,6 +17,18 @@
"rpath"
],
"Behaviors": [
{
Copy link
Member Author

Choose a reason for hiding this comment

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

There seems to be some ordering oscillation going on here and it changes from run to run.

@@ -27,6 +27,8 @@ func (r JSON) File(_ context.Context, _ *malcontent.FileReport) error {
}

func (r JSON) Full(_ context.Context, rep *malcontent.Report) error {
// Drop the applied filters
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't display this for any other renderer (though it's still set in the report) and it was causing weird diffs when testing JSON output.

@@ -552,6 +553,11 @@ func Generate(ctx context.Context, path string, mrs yara.MatchRules, c malconten
fr.RiskScore = overallRiskScore
fr.RiskLevel = RiskLevels[fr.RiskScore]

// Ensure that the behaviors are consistently sorted by ID
Copy link
Member Author

@egibs egibs Oct 8, 2024

Choose a reason for hiding this comment

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

We rebuild the Behaviors slice from a map when working on overrides, so that's why we were seeing ordering issues. I can probably do this in handleOverrides but this ensures that the sorting happens right before we return the report.

@egibs egibs force-pushed the update-samples branch 2 times, most recently from 470f8f6 to fd5cf04 Compare October 8, 2024 17:53
@egibs
Copy link
Member Author

egibs commented Oct 8, 2024

Opened chainguard-dev/malcontent-samples#11 to fix the remaining tests (incorrect directory name is causing issues).

if [ "$(shell uname)" = "Darwin" ]; then \
tar xJvf "$$temp_path" -C $$(dirname "$$temp_path"); \
elif [ "$(shell uname)" = "Linux" ]; then \
tar xvf "$$temp_path" -C $$(dirname "$$temp_path"); \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Linux should support tar xJvf too?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was getting tar: short read errors when using it for some reason (at least in Wolfi).

Makefile Outdated Show resolved Hide resolved
@egibs egibs marked this pull request as ready for review October 8, 2024 19:07
@egibs egibs merged commit f578607 into chainguard-dev:main Oct 8, 2024
6 checks passed
@egibs egibs deleted the update-samples branch October 8, 2024 19:22
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.

make refresh-sample-testdata does not refresh non-diff files on macOS
2 participants