-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
597 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2022, Red Hat, Inc. | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import json | ||
|
||
import pytest | ||
from jsonschema import validate | ||
|
||
from openscap_report.debug_settings import DebugSetting | ||
from openscap_report.report_generators.json import JSONReportGenerator | ||
from tests.unit_tests.test_data_structure import get_parser, get_report | ||
|
||
from ..constants import PATH_TO_ARF, PATH_TO_JSON_SCHEMA | ||
|
||
|
||
@pytest.mark.integration_test | ||
def test_json_structure_with_schema(): | ||
json_schema = None | ||
with open(PATH_TO_JSON_SCHEMA, "r", encoding="utf-8") as schema_file: | ||
json_schema = json.load(schema_file) | ||
json_gen = JSONReportGenerator(get_parser(PATH_TO_ARF)) | ||
json_data = json_gen.generate_report(DebugSetting()).read().decode("utf-8") | ||
validate(json.loads(json_data), json_schema) | ||
|
||
|
||
@pytest.mark.integration_test | ||
def test_json_count_of_rules(): | ||
report = get_report() | ||
json_dict = report.as_dict_for_default_json() | ||
assert len(json_dict["rules"]) == 714 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,311 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"properties": { | ||
"profile_info": { | ||
"title": "Profile Info", | ||
"type": "object", | ||
"properties": { | ||
"title": { | ||
"title": "Title", | ||
"type": "string" | ||
}, | ||
"description": { | ||
"title": "Description", | ||
"type": "string" | ||
}, | ||
"profile_id": { | ||
"title": "Profile ID", | ||
"type": "string" | ||
}, | ||
"extends": { | ||
"title": "Extends profile", | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"profile_id" | ||
] | ||
}, | ||
"scan_results":{ | ||
"title": "Results of performed scan", | ||
"type": "object", | ||
"properties": { | ||
"title": { | ||
"title": "Title", | ||
"type": "string" | ||
}, | ||
"identity": { | ||
"title": "Identity", | ||
"type": "string" | ||
}, | ||
"profile_id": { | ||
"title": "Profile ID", | ||
"type": "string" | ||
}, | ||
"target": { | ||
"title": "Target", | ||
"type": "string" | ||
}, | ||
"cpe_platforms": { | ||
"title": "CPE Platforms", | ||
"type": "array", | ||
"items": { | ||
"oneOf": [ | ||
{ | ||
"type": "string", | ||
"pattern": "^\\#\\w+" | ||
}, | ||
{ | ||
"type": "string", | ||
"pattern": "[cC][pP][eE]:/[AHOaho]?(:[A-Za-z0-9\\._\\-~%]*){0,6}" | ||
} | ||
] | ||
} | ||
}, | ||
"scanner": { | ||
"title": "Scanner", | ||
"default": "", | ||
"type": "string" | ||
}, | ||
"scanner_version": { | ||
"title": "Scanner Version", | ||
"default": "", | ||
"type": "string" | ||
}, | ||
"benchmark_url": { | ||
"title": "Benchmark URL", | ||
"default": "", | ||
"type": "string" | ||
}, | ||
"benchmark_id": { | ||
"title": "Benchmark ID", | ||
"pattern": "xccdf_[^_]+_benchmark_.+", | ||
"type": "string" | ||
}, | ||
"benchmark_version": { | ||
"title": "Benchmark Version", | ||
"default": "", | ||
"type": "string" | ||
}, | ||
"start_time": { | ||
"title": "Start Time", | ||
"default": "", | ||
"type": "string" | ||
}, | ||
"end_time": { | ||
"title": "End Time", | ||
"default": "", | ||
"type": "string" | ||
}, | ||
"test_system": { | ||
"title": "Test System", | ||
"default": "", | ||
"type": "string" | ||
}, | ||
"score": { | ||
"title": "Score", | ||
"default": 0.0, | ||
"type": "number" | ||
}, | ||
"score_max": { | ||
"title": "Score Max", | ||
"default": 0.0, | ||
"type": "number" | ||
} | ||
}, | ||
"required": [ | ||
"title", | ||
"identity", | ||
"profile_id", | ||
"target", | ||
"scanner", | ||
"scanner_version", | ||
"benchmark_url", | ||
"benchmark_id", | ||
"benchmark_version", | ||
"start_time", | ||
"end_time", | ||
"test_system", | ||
"score", | ||
"score_max" | ||
] | ||
}, | ||
"rules": { | ||
"title": "Rules", | ||
"type": "object", | ||
"patternProperties": { | ||
"xccdf_[^_]+_rule_.+": { | ||
"$ref": "#/definitions/Rule" | ||
} | ||
} | ||
}, | ||
"references": { | ||
"title": "References", | ||
"type": "object", | ||
"patternProperties": { | ||
".": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"identifiers": { | ||
"title": "Identifiers", | ||
"type": "object", | ||
"patternProperties": { | ||
".": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"Warning": { | ||
"title": "Warning", | ||
"type": "object", | ||
"properties": { | ||
"category": { | ||
"title": "Category", | ||
"type": "string" | ||
}, | ||
"text": { | ||
"title": "Text", | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"Remediation": { | ||
"title": "Remediation", | ||
"type": "object", | ||
"properties": { | ||
"remediation_id": { | ||
"title": "Remediation ID", | ||
"type": "string" | ||
}, | ||
"system": { | ||
"title": "System", | ||
"type": "string" | ||
}, | ||
"complexity": { | ||
"title": "Complexity", | ||
"type": "string" | ||
}, | ||
"disruption": { | ||
"title": "Disruption", | ||
"type": "string" | ||
}, | ||
"strategy": { | ||
"title": "Strategy", | ||
"type": "string" | ||
}, | ||
"fix": { | ||
"title": "Fix", | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"remediation_id", | ||
"fix" | ||
] | ||
}, | ||
"Rule": { | ||
"title": "Rule", | ||
"type": "object", | ||
"properties": { | ||
"rule_id": { | ||
"title": "Rule ID", | ||
"pattern": "xccdf_[^_]+_rule_.+", | ||
"type": "string" | ||
}, | ||
"title": { | ||
"title": "Title", | ||
"type": "string" | ||
}, | ||
"result": { | ||
"title": "Result", | ||
"type": "string" | ||
}, | ||
"time": { | ||
"title": "Time", | ||
"type": "string" | ||
}, | ||
"severity": { | ||
"title": "Severity", | ||
"type": "string" | ||
}, | ||
"identifiers": { | ||
"title": "Identifiers", | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
}, | ||
"references": { | ||
"title": "References", | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
}, | ||
"description": { | ||
"title": "Description", | ||
"type": "string" | ||
}, | ||
"rationale": { | ||
"title": "Rationale", | ||
"type": "string" | ||
}, | ||
"warnings": { | ||
"title": "Warnings", | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/Warning" | ||
} | ||
}, | ||
"platforms": { | ||
"title": "Platforms", | ||
"type": "array", | ||
"items": { | ||
"oneOf": [ | ||
{ | ||
"type": "string", | ||
"pattern": "^\\#\\w+" | ||
}, | ||
{ | ||
"type": "string", | ||
"pattern": "[cC][pP][eE]:/[AHOaho]?(:[A-Za-z0-9\\._\\-~%]*){0,6}" | ||
} | ||
] | ||
} | ||
}, | ||
"oval_definition_id": { | ||
"title": "Oval Definition ID", | ||
"pattern": "(oval:[A-Za-z0-9_\\-\\.]+:def:[1-9][0-9]*)|^$" | ||
}, | ||
"messages": { | ||
"title": "Messages", | ||
"items": { | ||
"type": "string" | ||
} | ||
}, | ||
"remediations": { | ||
"title": "Remediations", | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/Remediation" | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"rule_id", | ||
"result", | ||
"time", | ||
"severity" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"scan_result", | ||
"rules" | ||
] | ||
} |
Oops, something went wrong.