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 TestRemovePath being flagged as a possible virus #3411

Merged

Conversation

cmacknz
Copy link
Member

@cmacknz cmacknz commented Sep 13, 2023

My suspicion is this test gets flagged as malware because it writes code to disk and then compiles it by executing go build itself. This does seem like something malware could do, so I changed this to use the same build strategy the fake component uses. The mage build:testBinary target must be used to build the binaries before the test can run, which is a dependency of mage unitTest.

@mergify
Copy link
Contributor

mergify bot commented Sep 13, 2023

This pull request does not have a backport label. Could you fix it @cmacknz? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit

NOTE: backport-skip has been added to this pull request.

@elasticmachine
Copy link
Contributor

elasticmachine commented Sep 13, 2023

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-09-14T02:20:52.315+0000

  • Duration: 28 min 11 sec

Test stats 🧪

Test Results
Failed 0
Passed 6301
Skipped 59
Total 6360

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages.

  • run integration tests : Run the Elastic Agent Integration tests.

  • run end-to-end tests : Generate the packages and run the E2E Tests.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@elasticmachine
Copy link
Contributor

elasticmachine commented Sep 13, 2023

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 98.78% (81/82) 👍
Files 66.327% (195/294) 👍
Classes 65.751% (359/546) 👍
Methods 52.76% (1128/2138) 👍
Lines 38.246% (12812/33499) 👍 0.018
Conditionals 100.0% (0/0) 💚

@cmacknz cmacknz force-pushed the fix-windows-uninstall-test-malware-detection branch from 2c8009e to c9afc2d Compare September 13, 2023 22:09
@cmacknz
Copy link
Member Author

cmacknz commented Sep 13, 2023

/test

@cmacknz cmacknz changed the title Do not generate and compile blocking exe automatically. Fix TestRemovePath being flagged as a possible virus Sep 13, 2023
@cmacknz cmacknz added the Team:Elastic-Agent Label for the Agent team label Sep 14, 2023
@cmacknz
Copy link
Member Author

cmacknz commented Sep 14, 2023

Taking out of draft, got one successful run. Will run the tests a few times before merging to confirm. I expect test may still be flaky for other reasons, I just want to eliminate the virus scanning false positive with these changes.

@cmacknz cmacknz marked this pull request as ready for review September 14, 2023 00:01
@cmacknz cmacknz requested a review from a team as a code owner September 14, 2023 00:01
@cmacknz cmacknz requested review from AndersonQ and pchila September 14, 2023 00:01
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent (Team:Elastic-Agent)

Copy link
Contributor

@ycombinator ycombinator left a comment

Choose a reason for hiding this comment

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

LGTM.

@cmacknz cmacknz force-pushed the fix-windows-uninstall-test-malware-detection branch from c9afc2d to 0b42ffc Compare September 14, 2023 01:00
@cmacknz cmacknz added the backport-v8.10.0 Automated backport with mergify label Sep 14, 2023
@mergify mergify bot removed the backport-skip label Sep 14, 2023
@cmacknz cmacknz enabled auto-merge (squash) September 14, 2023 01:01
Comment on lines 53 to 54
err = RemovePath(dir)
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't these lines still be there? Isn't RemovePath the function being tested?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes they should whoops

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 did this far too quickly the first time, thanks for catching this.

@cmacknz cmacknz disabled auto-merge September 14, 2023 01:02
@cmacknz
Copy link
Member Author

cmacknz commented Sep 14, 2023

=== RUN   TestRemovePath
    uninstall_windows_test.go:43: 
        	Error Trace:	C:/Users/jenkins/workspace/_agent_elastic-agent-mbp_PR-3411/src/github.com/elastic/elastic-agent/internal/pkg/agent/install/uninstall_windows_test.go:43
        	Error:      	Received unexpected error:
        	            	fork/exec C:\Users\jenkins\AppData\Local\Temp\TestRemovePath532456694\001\subdir\testblocking.exe: Operation did not complete successfully because the file contains a virus or potentially unwanted software.
        	Test:       	TestRemovePath
--- FAIL: TestRemovePath (2.95s)

Ugh

@elastic-sonarqube
Copy link

SonarQube Quality Gate

Quality Gate failed

Failed condition 0.0% 0.0% Coverage on New Code (is less than 40%)

See analysis details on SonarQube

@cmacknz
Copy link
Member Author

cmacknz commented Sep 14, 2023

Merging, let's see if this problem comes back after some more test runs on other branches and adjust from there.

@cmacknz cmacknz merged commit 72ce0fe into elastic:main Sep 14, 2023
7 of 11 checks passed
@cmacknz cmacknz deleted the fix-windows-uninstall-test-malware-detection branch September 14, 2023 13:39
mergify bot pushed a commit that referenced this pull request Sep 14, 2023
* Do not generate and compile blocking exe automatically.

* Copy the test binary to a tmp subdir so the test actually works.

* Stop exec-ing from Temp.

(cherry picked from commit 72ce0fe)
cmacknz added a commit that referenced this pull request Sep 14, 2023
* Do not generate and compile blocking exe automatically.

* Copy the test binary to a tmp subdir so the test actually works.

* Stop exec-ing from Temp.

(cherry picked from commit 72ce0fe)

Co-authored-by: Craig MacKenzie <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.10.0 Automated backport with mergify skip-changelog Team:Elastic-Agent Label for the Agent team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants