38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
||
"""raw 凭据过滤的离线回归测试。"""
|
||
import pathlib
|
||
import sys
|
||
|
||
PROJECT_ROOT = pathlib.Path(__file__).resolve().parents[3]
|
||
SCRIPT_DIR = PROJECT_ROOT / "muse" / "authority" / "evidence" / "skills" / "record-run-evidence" / "scripts"
|
||
sys.path.insert(0, str(SCRIPT_DIR))
|
||
from persist_raw import _check_no_secrets # noqa: E402
|
||
|
||
|
||
def test_normal_prompt_words_are_allowed():
|
||
_check_no_secrets("输出不超过 4000 字;token budget 只用于篇幅估算。")
|
||
|
||
|
||
def test_secret_assignments_are_rejected():
|
||
for text in (
|
||
"api_key=sk-example-secret-value",
|
||
"token: abcdefghijklmnop",
|
||
"Authorization: Bearer abcdefghijklmnop",
|
||
"-----BEGIN PRIVATE KEY-----",
|
||
):
|
||
try:
|
||
_check_no_secrets(text)
|
||
except ValueError:
|
||
continue
|
||
raise AssertionError(f"凭据未被拒绝: {text}")
|
||
|
||
|
||
def main():
|
||
test_normal_prompt_words_are_allowed()
|
||
test_secret_assignments_are_rejected()
|
||
print("全部通过")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|