| 1 |
# We expect a warning with this textual form: |
| 2 |
# |
| 3 |
# . PATH/diagnostic-test-metadata-sarif.c: In function 'test_cwe': |
| 4 |
# . PATH/diagnostic-test-metadata-sarif.c:8:3: warning: never use 'gets' [CWE-242] [STR34-C] |
| 5 |
|
| 6 |
from sarif import * |
| 7 |
|
| 8 |
import pytest |
| 9 |
|
| 10 |
@pytest.fixture(scope='function', autouse=True) |
| 11 |
def sarif(): |
| 12 |
return sarif_from_env() |
| 13 |
|
| 14 |
def test_basics(sarif): |
| 15 |
schema = sarif['$schema'] |
| 16 |
assert schema == "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json" |
| 17 |
|
| 18 |
version = sarif['version'] |
| 19 |
assert version == "2.1.0" |
| 20 |
|
| 21 |
def test_plugin_metadata(sarif): |
| 22 |
runs = sarif['runs'] |
| 23 |
assert len(runs) == 1 |
| 24 |
|
| 25 |
run = runs[0] |
| 26 |
tool = run['tool'] |
| 27 |
|
| 28 |
# We expect an extension, for the plugin. |
| 29 |
extensions = tool['extensions'] |
| 30 |
assert len(extensions) == 1 |
| 31 |
|
| 32 |
extension = extensions[0] |
| 33 |
assert extension['name'] == 'diagnostic_plugin_test_metadata' |
| 34 |
assert 'diagnostic_plugin_test_metadata' in extension['fullName'] |
| 35 |
|
| 36 |
# TODO: ideally there would be a rule for [STR34-C] within |
| 37 |
# the extension for the plugin with |
| 38 |
# 'id': 'STR34-C', |
| 39 |
# 'helpUri': 'https://example.com/' |
| 40 |
|
| 41 |
def test_result(sarif): |
| 42 |
runs = sarif['runs'] |
| 43 |
run = runs[0] |
| 44 |
results = run['results'] |
| 45 |
|
| 46 |
assert len(results) == 1 |
| 47 |
|
| 48 |
result = results[0] |
| 49 |
assert result['level'] == 'warning' |
| 50 |
assert result['message']['text'] == "never use 'gets'" |
| 51 |
|
| 52 |
assert len(result['taxa']) == 1 |
| 53 |
taxon = result['taxa'][0] |
| 54 |
assert taxon['id'] == '242' |
| 55 |
assert taxon['toolComponent']['name'] == 'cwe' |