From 21767acdd354a9395ba036e5aaccdc1051567a43 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Thu, 8 Feb 2024 15:47:20 +0100 Subject: [PATCH] Add test to prevent download shenanigans --- spacy/tests/test_cli.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spacy/tests/test_cli.py b/spacy/tests/test_cli.py index ff53ed1e1..84c073d93 100644 --- a/spacy/tests/test_cli.py +++ b/spacy/tests/test_cli.py @@ -25,6 +25,8 @@ from spacy.cli.debug_data import ( _get_spans_length_freq_dist, _print_span_characteristics, ) + +from spacy.cli import download_module from spacy.cli.download import get_compatibility, get_version from spacy.cli.evaluate import render_parses from spacy.cli.find_threshold import find_threshold @@ -1066,3 +1068,15 @@ def test_debug_data_trainable_lemmatizer_not_annotated(): def test_project_api_imports(): from spacy.cli import project_run from spacy.cli.project.run import project_run # noqa: F401, F811 + + +def test_download_rejects_relative_urls(monkeypatch): + """Test that we can't tell spacy download to get an arbitrary model by using a + relative path in the filename""" + + monkeypatch.setattr(download_module, "run_command", lambda cmd: None) + + # Check that normal download works + download_module.download("en_core_web_sm-3.7.1", direct=True) + with pytest.raises(SystemExit): + download_module.download("../en_core_web_sm-3.7.1", direct=True)