Skip to content

Autotailor validate datastream fields maint 1.3#2344

Open
ggbecker wants to merge 3 commits intoOpenSCAP:maint-1.3from
ggbecker:autotailor-validate-datastream-fields-maint-1.3
Open

Autotailor validate datastream fields maint 1.3#2344
ggbecker wants to merge 3 commits intoOpenSCAP:maint-1.3from
ggbecker:autotailor-validate-datastream-fields-maint-1.3

Conversation

@ggbecker
Copy link
Copy Markdown
Member

@ggbecker ggbecker commented Apr 27, 2026

Backport of #2342

Add DataStreamValidator class that validates all IDs against the SCAP
datastream before generating tailoring XML. This prevents silent failures
from invalid variable names, rule IDs, group IDs, or profile IDs.

Key features:
- Parses datastream to extract valid profiles, values, rules, and groups
- Validates IDs before use in Profile and Tailoring classes
- Provides fuzzy matching suggestions for typos using difflib
- Generates clear error messages with suggestions
- Add --no-validate flag for performance-critical use cases

Performance:
- ~227ms overhead on 20MB datastream (validation enabled by default)
- ~33ms with --no-validate flag (7x faster)
- Validation prevents compliance drift and silent failures

Fixes issue where autotailor accepted arbitrary variable names without
validation, creating invalid XML that fails at evaluation time.
Add comprehensive unit tests for the new validation feature:

- test_datastream_validator: Tests validator with valid and invalid IDs
  for profiles, values, rules, and groups

- test_profile_with_validator: Tests Profile class integration with
  validator, ensuring invalid IDs are rejected

- test_validator_suggestions: Tests fuzzy matching suggestions for
  typos in ID names

All tests pass and verify that:
- Valid IDs are accepted
- Invalid IDs are rejected with clear error messages
- Similar valid IDs are suggested for typos
- Validation integrates properly with Profile class
- Move XML namespace dict to module-level DS_NAMESPACES constant
- Split _parse_datastream into _extract_profiles/values/rules/groups
- Add selector validation for -V/--var-select option
- Fix terminology: "datastream" -> "data stream" in all user-facing text
- Add --no-validate option to the man page
@ggbecker ggbecker added this to the 1.3.15 milestone Apr 27, 2026
@sonarqubecloud
Copy link
Copy Markdown

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 this pull request may close these issues.

1 participant