Skip to content

test(security): the security and crypto tests split by behaviour, with snapshots, property tests and the shared builders - #2566

Merged
dan-petty merged 3 commits into
mainfrom
test/2545-security-tests-by-behaviour
Oct 28, 2026
Merged

dan-petty merged 3 commits into
mainfrom
test/2545-security-tests-by-behaviour

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

The security and crypto tests now have one file for each behaviour, with snapshots, Hypothesis properties, the shared builders and the cli fixture. This is part 4 of #1332.

  • tests/test_security_sarif.py becomes seven files under tests/security/: finding normalization, fingerprints, correlation, SARIF emission, SARIF ingestion, the suppression policy and the scan report. tests/test_reference_extractor.py becomes six: address classes, name classes, extraction, false positives, the literal parsers and the report order.
  • Each catch-all test of the named files becomes one test or one parametrized table for each behaviour, with no assertion lost.
  • The two tflint files become tests/security/test_tflint.py, and the consolidation-named files become tests/security/test_scanner_base_and_registry.py and tests/security/test_secret_redaction.py.
  • The SARIF document and the AIBOM document are syrupy snapshots. The SARIF snapshot holds the same document as tests/golden/sarif_report.json, which is deleted. The AIBOM snapshot matches its random serial number and its timestamp by type.
  • Hypothesis properties cover redaction, suppression-policy evaluation and the GitHub host keys that _ensure_known_host appends to known_hosts.
  • make_normalized_finding joins make_finding in tests/support/builders.py and replaces the SARIF file's local factory; make_finding replaces the gitleaks file's. The cli fixture replaces the eleven module-level CliRunner()s.
  • The SBOM gets no snapshot: devops scan sbom passes Trivy's output through byte for byte, which the tests already assert.

Closes #2545

Change: openspec/changes/archive/2026-10-28-2545-security-tests-by-behaviour/

…F document and run the CLI tests through the cli fixture

The SARIF tests become seven behaviour files under tests/security/, the
two tflint files become one, and the consolidation-named scanner-base
test file takes a behaviour name. The SARIF document is a syrupy
snapshot, which holds the same document as the deleted golden file.
make_normalized_finding and make_finding replace the local finding
factories, the cli fixture replaces the module-level CliRunner()s, and
the remaining catch-all tests of the named files are dissolved.
@dan-petty

Copy link
Copy Markdown
Owner Author

Test evidence:

  • Collected test IDs of the named files: 902 on origin/main 0702d13, 1,053 on the branch. 849 test names stay (394 in their file, 455 moved to a new file). 52 test functions were renamed or dissolved; the map below names the new test(s) of each. The 203 new IDs also count the new property and snapshot tests.
  • uv run pytest of the 30 changed and new test files after the last rebase: 872 passed, 2 snapshots passed.
  • uv run devops ci typecheck: no issues in 566 source files. ruff check and ruff format pass.
  • The SARIF snapshot was compared with tests/golden/sarif_report.json before the file was deleted: equal.

Mutation checks (each run on the new property test alone, product code restored after):

  • suppression is_expired -> always False: test_an_expired_rule_suppresses_no_finding failed.
  • suppression fingerprint compare -> always True: test_a_fingerprint_rule_matches_only_the_finding_with_that_fingerprint failed.
  • suppression glob match -> exact match: test_a_rule_of_wildcards_with_no_expiry_suppresses_every_finding failed.
  • suppression apply drops the last kept finding: test_applying_a_policy_loses_and_invents_no_finding failed.
  • mask_secrets appends *: test_masking_masked_text_changes_nothing failed.
  • redaction skips the GitHub token patterns: test_a_github_token_in_any_text_leaves_no_part_of_its_body failed.
  • mask_uri_credentials returns the URI unchanged: test_a_uri_keeps_everything_but_its_password failed.
  • _ensure_known_host appends every pinned line: test_the_pinned_keys_are_appended_once_after_every_existing_line failed.
  • _ensure_known_host writes no newline before the appended lines: the same test failed.

Old test name (file) -> new test(s) (file under tests/security/ unless named):

test_reference_extractor.py

  • test_is_public_ip -> test_only_a_global_address_is_public[7 cases] (test_reference_address_classes.py)
  • test_reference_extractor_documented_examples_and_rfc_exclusions (catch-all) -> test_an_rfc_2606_name_is_an_example_domain_and_target[7], test_a_local_or_real_name_is_not_an_example_domain[7], test_a_fictitious_phone_number_is_an_example[8] (test_reference_name_classes.py); test_a_documentation_or_benchmarking_address_is_an_example_target[14], test_shared_discard_and_public_addresses_are_not_example_targets[6] (test_reference_address_classes.py); test_example_targets_are_kept_and_tagged_when_examples_are_not_excluded, test_example_targets_are_omitted_when_examples_are_excluded (test_reference_extraction.py)
  • test_reference_extractor_extended_network_and_lockfiles (catch-all) -> lockfile, registry and local-suffix cases in test_a_lockfile_or_ignore_file_is_recognized_by_name, test_only_a_package_registry_host_is_trusted, test_a_name_under_a_local_suffix_is_local_or_reserved (test_reference_name_classes.py); test_a_local_url_is_a_reference_only_when_local_targets_are_included[2], test_a_public_address_is_an_external_reference_without_local_targets, test_the_string_values_of_a_structured_file_are_read[json,toml,yaml] (test_reference_literal_parsers.py)
  • test_reference_extractor_advanced_edge_cases (catch-all) -> local-suffix cases in test_a_name_under_a_local_suffix_is_local_or_reserved; test_a_single_label_url_is_a_local_reference (test_reference_extraction.py)
  • test_reference_extractor_language_parsers (catch-all) -> test_python_literals_and_comments_are_read, test_hcl_literals_and_comments_are_read, test_a_yaml_scalar_loses_its_template_expressions_and_keeps_its_url (test_reference_literal_parsers.py)
  • test_extract_network_references_package_files_and_lockfile_filtering (catch-all) -> lockfile and registry cases above; test_a_lockfile_gives_no_reference, test_a_source_file_keeps_service_urls_and_arbitrary_downloads_but_not_registry_files (test_reference_extraction.py)
  • test_token_string_parsing -> test_a_python_string_token_is_read_as_its_value[4] (test_reference_literal_parsers.py)
  • test_dependency_and_network_reference_canonical_location_formatting -> test_a_dependency_location_is_its_file_and_line_and_line_one_without_one, test_a_network_reference_location_is_its_file_and_line (test_reference_report_order.py)
  • test_extract_network_references -> test_a_document_gives_its_urls_and_addresses_with_their_scope
  • test_extract_network_references_json_and_yaml_scalars -> test_json_and_yaml_values_give_their_urls_and_addresses
  • test_extract_network_references_local_and_reserved_spaces -> test_local_urls_and_private_addresses_are_local_and_local_names_are_not_references
  • test_extract_network_references_from_various_files -> test_a_url_in_go_rust_or_a_dockerfile_is_a_reference[go,rust,dockerfile]
  • test_extract_network_references_edge_cases -> test_a_shell_style_assignment_gives_its_public_url_and_address
  • test_network_references_splits_comma_separated_urls -> test_a_comma_separated_list_of_urls_gives_each_url
  • test_python_literals_in_dict_keys_and_telemetry_calls -> test_urls_and_addresses_in_dict_keys_and_call_arguments_are_references
  • test_any_scheme_url_reference_extraction -> test_a_url_of_any_network_scheme_is_a_reference_and_a_file_url_is_not
  • test_download_url_registry_vs_arbitrary_host -> test_a_download_from_a_package_registry_is_skipped_by_host
  • test_no_dns_lookups_during_reference_extraction -> test_reference_extraction_makes_no_dns_lookup (all six in test_reference_extraction.py)
  • test_extract_network_references_gitignore_filtering -> test_a_gitignore_gives_no_reference
  • test_extract_network_references_python_code_token_filtering -> test_python_imports_calls_and_attributes_are_not_references
  • test_extract_network_references_toml_table_filtering -> test_toml_table_headers_are_not_references
  • test_extract_network_references_code_false_positives_filtering -> test_workflow_git_config_keys_and_a_bare_registry_name_are_not_references, test_mock_patch_paths_and_module_names_are_not_references
  • test_extract_network_references_tf_and_python_imports -> test_terraform_attribute_references_are_not_references, test_python_import_paths_are_not_references
  • test_extract_network_references_function_calls_and_workspace_files -> test_function_calls_file_names_and_package_symbols_are_not_references
  • test_extract_network_references_file_extensions_and_code_properties -> test_source_file_names_and_span_attribute_names_are_not_references
  • test_network_references_rejects_unspecified_ip_and_example_domains -> test_unspecified_addresses_example_domains_and_bare_names_are_rejected
  • test_network_references_rejects_regex_patterns -> test_a_regex_with_escaped_dots_is_not_a_url (all eleven in test_reference_false_positives.py)
  • The other 8 test functions of the file (35 in all) keep their names in the new files.

test_aibom.py (stays in tests/)

  • test_estimate_hardware_requirements -> test_a_dense_model_needs_more_than_its_weights_in_vram_and_ram, test_quantization_lowers_the_disk_and_vram_estimates, test_a_mixture_of_experts_model_is_marked_and_needs_vram, test_a_model_with_no_parameters_needs_no_vram
  • test_detect_trust_remote_code + test_detect_trust_remote_code_branches -> test_trust_remote_code_is_detected_from_config_and_source[7], test_a_directory_that_does_not_exist_asks_for_no_remote_code, test_a_file_that_does_not_exist_has_no_digest
  • test_classify_license_all_branches (catch-all) -> test_a_license_name_falls_in_one_governance_category[11]
  • test_generate_aibom_payload -> test_a_model_directory_becomes_one_component, test_the_aibom_document_of_a_workspace (snapshot)
  • test_extract_aibom_modelfile_and_weights -> test_a_modelfile_names_its_model_and_its_files_are_hashed (the document part is in the snapshot)
  • test_scan_aibom_cli -> test_scan_aibom_prints_the_document, test_scan_aibom_writes_the_document_to_a_file, test_scan_aibom_refuses_an_unknown_format, test_scan_aibom_dry_run_succeeds

test_ssh.py (stays in tests/)

  • test_crypto_ssh_keys_edge_cases (catch-all) -> test_a_devcontainer_json_that_does_not_parse_falls_back_to_the_directory_name, test_a_managed_key_name_with_an_empty_prefix_has_no_leading_dash, test_the_prefix_of_a_key_name_is_read_only_from_a_managed_name[unmanaged,managed]

test_tflint.py + test_security_tflint.py -> tests/security/test_tflint.py

  • test_tflint_native_fallback -> test_the_fallback_flags_an_open_cidr_on_a_security_group
  • test_tflint_fallback_cidr_check -> test_the_fallback_flags_an_open_cidr_on_a_security_group_rule_at_its_line
  • test_tflint_fallback_multiline_cidr_check -> test_the_fallback_flags_an_open_cidr_in_a_multi_line_list
  • test_tflint_native_fallback_clean -> test_the_fallback_finds_nothing_without_a_security_group
  • test_run_tflint_scan_missing_binary -> test_a_scan_without_tflint_uses_the_fallback
  • test_run_tflint_scan_with_binary -> test_a_scan_maps_each_tflint_severity
  • test_tflint_scan_mocked_binary -> test_a_tflint_issue_becomes_a_finding_with_its_message_and_location (on scanner_fake; no subprocess or shutil patch)
  • test_run_tflint_scan_empty_output -> test_a_scan_with_empty_tflint_output_has_no_finding
  • test_run_tflint_scan_exception_fallback -> test_a_scan_falls_back_when_tflint_cannot_start

test_security_sarif.py -> eight files under tests/security/ (136 of its 137 tests keep their names)

  • test_golden_sarif_report_matches_and_validates_against_schema -> test_the_sarif_document_of_findings_from_three_tools (test_sarif_emission.py, a syrupy snapshot of the same document; tests/golden/sarif_report.json is deleted)

Other catch-alls in the named files, dissolved the same way:

  • test_ssh.py: test_ssh_commands -> test_each_ssh_command_succeeds_with_a_current_managed_key[generate,status,audit,register,rotate,rotate-force]; test_ssh_dry_run_commands -> test_each_ssh_command_succeeds_in_a_dry_run[generate,register,rotate,audit,status]; test_ssh_register_error_branches -> test_ssh_register_without_a_managed_key_exits_1, test_ssh_register_of_a_key_without_its_public_file_exits_1, test_ssh_register_that_github_refuses_exits_1
  • test_dependency_remediator.py: test_apply_action_edge_cases -> test_an_action_with_no_upgrade_command_is_skipped, test_an_upgrade_command_that_exits_non_zero_fails_the_action_with_its_stderr, test_an_upgrade_command_that_raises_fails_the_action_with_the_error
  • test_crypto_tls.py: test_tls_edge_cases_and_cached_returns -> test_an_existing_ca_is_returned_again_without_overwrite, test_an_existing_server_certificate_is_returned_again_with_duplicate_and_empty_sans
  • test_secret_redaction.py (was test_consolidation_security_sanitizer.py): test_mask_uri_credentials_edge_cases -> test_a_uri_password_is_masked_and_a_user_alone_is_kept[6]
  • test_scanner_base_and_registry.py (was test_consolidation_security_scanner_base.py): test_scanner_registry_lifecycle -> test_a_registered_scanner_is_found_by_name_and_listed, test_a_batch_scan_gives_each_scanner_its_findings, test_a_scanner_that_raises_is_failed_and_only_named_registered_scanners_run
  • test_vault_broker.py: test_vault_broker_error_branches, which test(security): scanner, secret and crypto tests run on the executor, process, http and keyring fakes, and scanners stop looking for mocks #1332 names, is already gone on main.

Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD).

@dan-petty
dan-petty marked this pull request as ready for review October 28, 2026 23:52
@dan-petty
dan-petty merged commit dbfbb65 into main Oct 28, 2026
17 checks passed
@dan-petty
dan-petty deleted the test/2545-security-tests-by-behaviour branch October 28, 2026 23:54
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.

test(security): the security and crypto test files split by behaviour, with document snapshots, property tests and the shared builders

1 participant