KeyHunter parser v10 + 18 scanners + tests (synthetic fixtures only, no keys/db/tokens)
This commit is contained in:
37
tests/test_baipiao.py
Normal file
37
tests/test_baipiao.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""Fixtures for baipiao_eternal: link extraction, scan_page, dedup, junk filter.
|
||||
No network. Run: python tests/test_baipiao.py
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
os.environ["KF_DB"] = os.path.join(tempfile.mkdtemp(prefix="kf_bp_test_"), "keys.db")
|
||||
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, HERE)
|
||||
import baipiao_eternal as B
|
||||
|
||||
DS = "sk-3f9a1c7e5b2d8460a1c3e5f7091b2d4c"
|
||||
HTML = """<html><body>
|
||||
<a href="/free/api/glm-free-key/">GLM</a>
|
||||
<a href="/free/api/deepseek-credit/">DS</a>
|
||||
<code>DASHSCOPE_API_KEY=%s</code>
|
||||
<code>sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</code>
|
||||
</body></html>""" % DS
|
||||
NOISE = """<code>sk-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</code>"""
|
||||
|
||||
def main():
|
||||
links = B.LINK_RE.findall(HTML)
|
||||
assert sorted(links) == ["/free/api/deepseek-credit/", "/free/api/glm-free-key/"], links
|
||||
n = B.scan_page(HTML, "https://baipiao.org/free/api/x/")
|
||||
assert n >= 1, f"expected key insert, got {n}"
|
||||
rows = B.conn.execute("SELECT val, prov, found FROM keys").fetchall()
|
||||
assert any(r[0] == DS and r[2] == "baipiao" for r in rows), rows
|
||||
assert not any("xxxx" in r[0] for r in rows), "junk leaked"
|
||||
n2 = B.scan_page(HTML, "https://baipiao.org/free/api/x/")
|
||||
assert n2 == 0, f"dedup failed: {n2}"
|
||||
n3 = B.scan_page(NOISE, "noise")
|
||||
assert n3 == 0, f"junk leaked: {n3}"
|
||||
print("PASS: link extraction, scan_page, junk filter, dedup")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user