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 sarif output to use 'match.details' in result object, instead of 'match.message' #3163

Merged
merged 15 commits into from Mar 24, 2023
Merged

Fix sarif output to use 'match.details' in result object, instead of 'match.message' #3163

merged 15 commits into from Mar 24, 2023

Conversation

4ch1m
Copy link
Contributor

@4ch1m 4ch1m commented Mar 9, 2023

Hi,

the SARIF output (redundantly) uses the match.message for both the rule and the result objects:

rule: dict[str, Any] = {
"id": match.tag,
"name": match.tag,
"shortDescription": {
"text": str(match.message),
},

result: dict[str, Any] = {
"ruleId": match.tag,
"message": {
"text": str(match.message),
},

This isn't correct, since the (general) rule object should contain the (general) message/description, whereas the result object should provide the detailed description.

This would also be in line with the Codeclimate output (see first and last line):

issue["description"] = self.escape(str(match.message))
issue["fingerprint"] = hashlib.sha256(
repr(match).encode("utf-8")
).hexdigest()
issue["location"] = {}
issue["location"]["path"] = self._format_path(match.filename or "")
if match.column:
issue["location"]["positions"] = {}
issue["location"]["positions"]["begin"] = {}
issue["location"]["positions"]["begin"]["line"] = match.linenumber
issue["location"]["positions"]["begin"]["column"] = match.column
else:
issue["location"]["lines"] = {}
issue["location"]["lines"]["begin"] = match.linenumber
if match.details:
issue["content"] = {}
issue["content"]["body"] = match.details

@4ch1m 4ch1m requested review from a team as code owners March 9, 2023 16:26
@4ch1m
Copy link
Contributor Author

4ch1m commented Mar 9, 2023

Hi,
the 'Verify PR label action' fails.
The PR needs an appropriate label.
Is that something the requester can do? Or has this always to be done by the maintainers???

@ssbarnea ssbarnea added the bug label Mar 9, 2023
@ssbarnea
Copy link
Member

ssbarnea commented Mar 9, 2023

Hi, the 'Verify PR label action' fails. The PR needs an appropriate label. Is that something the requester can do? Or has this always to be done by the maintainers???

Don't worry about that, we add it ourselves. If you using specific semantic branch prefixes like fix/, chore/ or feat/ it can be added automatically by the bot.

@ssbarnea ssbarnea changed the title improve/fix sarif output (use 'match.details' in result object, instead of 'match.message') Fix sarif output to use 'match.details' in result object, instead of 'match.message' Mar 9, 2023
@ssbarnea
Copy link
Member

ssbarnea commented Mar 9, 2023

Before merging we need to look a little bit at details because AFAIK, some rules might not have details and if true, it might be a regression in UX for these.

If that is true, we might need to conditionally fallback to message.

@4ch1m
Copy link
Contributor Author

4ch1m commented Mar 9, 2023

Before merging we need to look a little bit at details

OK.

I stumbled upon this issue while trying to switch from Codeclimate to SARIF output for my IntelliJ plugin; just as you suggested. 😄

Please keep in mind, that at the moment the match.details information is completely absent/lost in the SARIF output.
Which makes the Codeclimate output superior in that regard.
Also meaning, that the SARIF output is no equivalent substitute (UX wise) in my plugin; or for any other similar consumer.

because AFAIK, some rules might not have details and if true, it might be a regression in UX for these.

The PR attaches the match.details to the result object; not the rule object.

@ssbarnea ssbarnea added the incomplete Additional work or information is required label Mar 16, 2023
@4ch1m
Copy link
Contributor Author

4ch1m commented Mar 17, 2023

Hi there,

I just noticed that this PR got marked "incomplete" ("Additional work or information is required").

Is there anything more I can/should provide?

Thanks.

@ssbarnea
Copy link
Member

@4ch1m The lack of testing that covers the case where details is the empty string made me mark this as incomplete.

Many rule violations do not have any details (empty string) and this change would negatively impact the outcome for these.

For this reason, we need to ensure we test the behavior for both types of violations, those that have details and those that do not have details, ensuring that the proposed change does not create a case where the errors have no text displayed.

Probably it would make sense to fallback to message when details values as false.

@4ch1m
Copy link
Contributor Author

4ch1m commented Mar 17, 2023

That's a good idea; making things bullet-proof. 👍
I've updated the PR.

@4ch1m 4ch1m requested review from ssbarnea and removed request for audgirka and Ruchip16 March 20, 2023 11:00
@ssbarnea ssbarnea removed the incomplete Additional work or information is required label Mar 22, 2023
@ssbarnea ssbarnea enabled auto-merge (squash) March 22, 2023 09:29
auto-merge was automatically disabled March 22, 2023 18:06

Head branch was pushed to by a user without write access

@4ch1m
Copy link
Contributor Author

4ch1m commented Mar 22, 2023

Hmmmm. 🤔

The CI-setup seems to run into "concurrency issues" with my PR.
However, I don't get that when running the tests locally on my machine.

Still haven't figured what's being done here behind the curtains:

    def test_refresh_schemas() -> None:
        """Test for schema update skip."""
        # This is written as a single test in order to avoid concurrency issues,
        # which caused random issues on CI when the two tests run in parallel
        # and or in different order.
        assert refresh_schemas(min_age_seconds=3600 * 24 * 365 * 10) == 0
        sleep(1)
        # this should disable the cache and force an update
>       assert refresh_schemas(min_age_seconds=0) == 1
E       assert 2 == 1
E        +  where 2 = refresh_schemas(min_age_seconds=0)

Any quick hint would be much appreciated. Thanks. 🙇

@4ch1m
Copy link
Contributor Author

4ch1m commented Mar 23, 2023

Any quick hint would be much appreciated. Thanks. bow

Nevermind. I just realized this is a general problem with the current codebase. Not related to this PR.

@ssbarnea ssbarnea merged commit e53dcdd into ansible:main Mar 24, 2023
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants