8OI-529 regression coverage — :func:`_name_matches_secret` and the
9``--secret-match {substring,word}`` CLI flag.
11The legacy ``substring`` matcher flagged any name that happened to
12contain a secret-shaped substring, so ordinary identifiers like
13``tokenizer`` (contains ``token``) or ``pwdistance`` (contains ``pwd``)
14tripped the scanner. The ``word`` mode splits on ``_``/``-``/camelCase
15boundaries and only flags whole-segment hits, so ``user_password``
16still flags but ``tokenizer`` does not.
20- ``substring`` mode flags ``compass``.
21- ``word`` mode does not flag ``compass``.
22- ``word`` mode still flags ``compass_password`` and ``apiKey``.
23- ``check_no_hardcoded_secrets`` threads the mode through unchanged.
30 L3 — assertion details
35- Tests operate on in-memory strings and AST snippets; no files are
39from __future__
import annotations
41from oct.tools.secret_scanner
import (
43 check_no_hardcoded_secrets,
54 assert _name_matches_secret(
"tokenizer", mode=
"substring")
is True
60 assert _name_matches_secret(
"tokenizer", mode=
"word")
is False
64 assert _name_matches_secret(
"user_password", mode=
"word")
is True
65 assert _name_matches_secret(
"db_connection_string", mode=
"word")
is True
69 assert _name_matches_secret(
"apiKey", mode=
"word")
is True
70 assert _name_matches_secret(
"userToken", mode=
"word")
is True
75 assert _name_matches_secret(
"pwdistance", mode=
"substring")
is True
76 assert _name_matches_secret(
"pwdistance", mode=
"word")
is False
85 source =
'tokenizer = "not-a-secret"\n'
87 ok_sub, msg_sub = check_no_hardcoded_secrets(source, mode=
"substring")
88 assert ok_sub
is False, msg_sub
90 ok_word, msg_word = check_no_hardcoded_secrets(source, mode=
"word")
91 assert ok_word
is True, msg_word
95 source =
'api_key = "AKIA1234567890"\n'
96 ok, msg = check_no_hardcoded_secrets(source, mode=
"word")
97 assert ok
is False,
"word mode must still flag real secrets"
98 assert "api_key" in msg
test_check_still_flags_real_secret_in_word_mode()
test_word_mode_does_not_flag_pwdistance()
test_check_threads_mode_and_ignores_tokenizer_in_word_mode()
test_substring_mode_flags_tokenizer_as_false_positive()
test_word_mode_does_not_flag_tokenizer()
test_word_mode_flags_camel_case_secret_segment()
test_word_mode_flags_snake_case_secret_segment()