Skip to content

Commit 7f450d5

Browse files
committed
test(supply-chain): pin the SC6 length-difference boundary; make popular sets frozensets
Follow-up to the #687 review: - requestsxx (length difference 2) is still flagged, requestsxxx (3) is not, so a '>' to '>=' slip in the skip fails a test (checked: it does). - _POPULAR_PYPI and _POPULAR_NPM are frozensets, like _KNOWN_LEGIT_*, so the target cache hits on object identity. Contents unchanged (compared before and after); most of the diff is ruff-format re-indentation. Signed-off-by: Presend <[email protected]>
1 parent 40dca48 commit 7f450d5

2 files changed

Lines changed: 112 additions & 96 deletions

File tree

‎src/skillspector/nodes/analyzers/static_patterns_supply_chain.py‎

Lines changed: 100 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -342,103 +342,107 @@ def _decoded_literal_xor_calls(content: str) -> list[tuple[int, str]]:
342342
# SC6: Typosquatting — popular packages and edit-distance check
343343
# ---------------------------------------------------------------------------
344344

345-
_POPULAR_PYPI: set[str] = {
346-
"requests",
347-
"numpy",
348-
"pandas",
349-
"flask",
350-
"django",
351-
"boto3",
352-
"setuptools",
353-
"pip",
354-
"urllib3",
355-
"pyyaml",
356-
"cryptography",
357-
"pillow",
358-
"pydantic",
359-
"sqlalchemy",
360-
"pytest",
361-
"click",
362-
"jinja2",
363-
"httpx",
364-
"aiohttp",
365-
"fastapi",
366-
"celery",
367-
"paramiko",
368-
"beautifulsoup4",
369-
"lxml",
370-
"scrapy",
371-
"redis",
372-
"pymongo",
373-
"psycopg2",
374-
"matplotlib",
375-
"scipy",
376-
"scikit-learn",
377-
"tensorflow",
378-
"torch",
379-
"keras",
380-
"transformers",
381-
"openai",
382-
"langchain",
383-
"gunicorn",
384-
"uvicorn",
385-
"rich",
386-
"typer",
387-
"black",
388-
"ruff",
389-
"mypy",
390-
"pylint",
391-
"flake8",
392-
"isort",
393-
"colorama",
394-
"python-dateutil",
395-
"discord.py",
396-
"python-dotenv",
397-
"pycryptodome",
398-
"perseus-ctx",
399-
"mimir-mcp",
400-
}
345+
_POPULAR_PYPI: frozenset[str] = frozenset(
346+
{
347+
"requests",
348+
"numpy",
349+
"pandas",
350+
"flask",
351+
"django",
352+
"boto3",
353+
"setuptools",
354+
"pip",
355+
"urllib3",
356+
"pyyaml",
357+
"cryptography",
358+
"pillow",
359+
"pydantic",
360+
"sqlalchemy",
361+
"pytest",
362+
"click",
363+
"jinja2",
364+
"httpx",
365+
"aiohttp",
366+
"fastapi",
367+
"celery",
368+
"paramiko",
369+
"beautifulsoup4",
370+
"lxml",
371+
"scrapy",
372+
"redis",
373+
"pymongo",
374+
"psycopg2",
375+
"matplotlib",
376+
"scipy",
377+
"scikit-learn",
378+
"tensorflow",
379+
"torch",
380+
"keras",
381+
"transformers",
382+
"openai",
383+
"langchain",
384+
"gunicorn",
385+
"uvicorn",
386+
"rich",
387+
"typer",
388+
"black",
389+
"ruff",
390+
"mypy",
391+
"pylint",
392+
"flake8",
393+
"isort",
394+
"colorama",
395+
"python-dateutil",
396+
"discord.py",
397+
"python-dotenv",
398+
"pycryptodome",
399+
"perseus-ctx",
400+
"mimir-mcp",
401+
}
402+
)
401403

402-
_POPULAR_NPM: set[str] = {
403-
"express",
404-
"react",
405-
"react-dom",
406-
"next",
407-
"vue",
408-
"angular",
409-
"lodash",
410-
"axios",
411-
"moment",
412-
"chalk",
413-
"commander",
414-
"inquirer",
415-
"webpack",
416-
"babel",
417-
"eslint",
418-
"prettier",
419-
"typescript",
420-
"jest",
421-
"mocha",
422-
"chai",
423-
"puppeteer",
424-
"socket.io",
425-
"mongoose",
426-
"sequelize",
427-
"passport",
428-
"jsonwebtoken",
429-
"dotenv",
430-
"cors",
431-
"body-parser",
432-
"nodemon",
433-
"pm2",
434-
"electron",
435-
"discord.js",
436-
"ethers",
437-
"cross-env",
438-
"jquery",
439-
"nodemailer",
440-
"bootstrap",
441-
}
404+
_POPULAR_NPM: frozenset[str] = frozenset(
405+
{
406+
"express",
407+
"react",
408+
"react-dom",
409+
"next",
410+
"vue",
411+
"angular",
412+
"lodash",
413+
"axios",
414+
"moment",
415+
"chalk",
416+
"commander",
417+
"inquirer",
418+
"webpack",
419+
"babel",
420+
"eslint",
421+
"prettier",
422+
"typescript",
423+
"jest",
424+
"mocha",
425+
"chai",
426+
"puppeteer",
427+
"socket.io",
428+
"mongoose",
429+
"sequelize",
430+
"passport",
431+
"jsonwebtoken",
432+
"dotenv",
433+
"cors",
434+
"body-parser",
435+
"nodemon",
436+
"pm2",
437+
"electron",
438+
"discord.js",
439+
"ethers",
440+
"cross-env",
441+
"jquery",
442+
"nodemailer",
443+
"bootstrap",
444+
}
445+
)
442446

443447
# SC6 known-legitimate neighbours: established packages whose names fall within
444448
# the typosquat threshold of a _POPULAR_* entry and are never reported. Built by

‎tests/unit/test_patterns_new.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,6 +2689,18 @@ def test_is_typosquat_positive(self) -> None:
26892689
def test_is_typosquat_exact_match_returns_none(self) -> None:
26902690
assert sc_mod._is_typosquat("requests", {"requests"}) is None
26912691

2692+
def test_is_typosquat_length_difference_boundary(self):
2693+
# The length-difference skip is exact (OSA distance >= length difference).
2694+
# A difference of 2 is still within max_distance, a difference of 3 is not;
2695+
# a ">" -> ">=" slip in the skip would make the first assertion fail.
2696+
assert sc_mod._is_typosquat("requestsxx", {"requests"}) == "requests"
2697+
assert sc_mod._is_typosquat("requestsxxx", {"requests"}) is None
2698+
2699+
def test_popular_sets_are_frozensets(self):
2700+
# Module-level target sets are frozensets, so the target cache hits on identity.
2701+
assert isinstance(sc_mod._POPULAR_PYPI, frozenset)
2702+
assert isinstance(sc_mod._POPULAR_NPM, frozenset)
2703+
26922704
@pytest.mark.parametrize(
26932705
"package,popular",
26942706
[

0 commit comments

Comments
 (0)