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

Issue with skipped violations using CircleCI and JUnit output format #1122

Closed
gchappel opened this issue Jan 21, 2022 · 0 comments · Fixed by #1123
Closed

Issue with skipped violations using CircleCI and JUnit output format #1122

gchappel opened this issue Jan 21, 2022 · 0 comments · Fixed by #1123

Comments

@gchappel
Copy link
Contributor

  • terrascan version: v1.8.0
  • Operating System: Linux

Description

I/we are running Terrascan tests against some Terraform code, but trying to skip one known validation. This is executing through CircleCI, with the output in JUnit XML format and stored for display in the CircleCI webUI using store_test_results

The issue is that skipped violations, when output in JUnit format contain both the skipped element AND still contain a failure element. This appears to be causing CircleCI to show skipped violations as test failures, meaning that:

  • on a successful CircleCI run (where terrascan exits with 0) the Tests tab on the CircleCI build still shows errors where there should be none.
  • on a failed CircleCI run (where terrascan exits with >0) the Tests tab shows all skipped violations as errors, making it difficult to pinpoint what actually needs fixing at first glance. For example if you have 9 known violations with skip tags, and 1 genuine violation, they are all displayed identically as failed tests in the CircleCI UI.

I can't share the Terraform code itself but if required I'm happy to put together a minimal reproduction for this

I believe the issue is:

  • The JUnit spec allows only one of the skipped/failure/error etc elements to exist (because these are all contained within an <xs:choice> element
  • https://github.com/accurics/terrascan/blob/master/pkg/writer/junit_xml.go#L166-L169 says that if something is marked as skipped, it should have both a skipped AND a failure element, which appears to be against this spec
  • CircleCI's JUnit parser is displaying all testcases that have a failure element, without taking the skipped element into account as the use of these two elements together appears to be outside the schema

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
gchappel added a commit to gchappel/terrascan that referenced this issue Jan 21, 2022
This is a potential fix to prevent both `skipped` and `failure` elements on a skipped violation in JUnit output format

Fixes: tenable#1122
gchappel added a commit to gchappel/terrascan that referenced this issue Feb 5, 2022
This is a potential fix to prevent both `skipped` and `failure` elements on a skipped violation in JUnit output format

Fixes: tenable#1122
gchappel added a commit to gchappel/terrascan that referenced this issue Feb 8, 2022
This is a potential fix to prevent both `skipped` and `failure` elements on a skipped violation in JUnit output format

Fixes: tenable#1122
patilpankaj212 pushed a commit that referenced this issue Feb 8, 2022
* Prevent adding both skipped and failure elements

This is a potential fix to prevent both `skipped` and `failure` elements on a skipped violation in JUnit output format

Fixes: #1122

* rebase to fix tests, and remove violation details from skip message
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 a pull request may close this issue.

1 participant