diff --git a/docs/changelog.rst b/docs/changelog.rst index e832417b98..5b085bbfc7 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -13,6 +13,7 @@ Fixed - Crash on non latin-1 encodable value in ``auth`` CLI option. `#404`_ - Crash on invalid value in ``header`` CLI options. `#405`_ - Crash on some invalid URLs in ``schema`` CLI option. `#406`_ +- Validation of ``--request-timeout`` parameter. `#407`_ `0.24.1`_ - 2020-02-08 ---------------------- @@ -695,6 +696,7 @@ Fixed .. _0.3.0: https://github.com/kiwicom/schemathesis/compare/v0.2.0...v0.3.0 .. _0.2.0: https://github.com/kiwicom/schemathesis/compare/v0.1.0...v0.2.0 +.. _#407: https://github.com/kiwicom/schemathesis/issues/407 .. _#406: https://github.com/kiwicom/schemathesis/issues/406 .. _#405: https://github.com/kiwicom/schemathesis/issues/405 .. _#404: https://github.com/kiwicom/schemathesis/issues/404 diff --git a/src/schemathesis/cli/__init__.py b/src/schemathesis/cli/__init__.py index 0bb351d233..a339b0d5ce 100644 --- a/src/schemathesis/cli/__init__.py +++ b/src/schemathesis/cli/__init__.py @@ -113,7 +113,11 @@ def schemathesis(pre_run: Optional[str] = None) -> None: callback=callbacks.validate_base_url, ) @click.option("--app", help="WSGI application to test", type=str, callback=callbacks.validate_app) -@click.option("--request-timeout", help="Timeout in milliseconds for network requests during the test run.", type=int) +@click.option( + "--request-timeout", + help="Timeout in milliseconds for network requests during the test run.", + type=click.IntRange(1), +) @click.option("--validate-schema", help="Enable or disable validation of input schema.", type=bool, default=True) @click.option("--show-errors-tracebacks", help="Show full tracebacks for internal errors.", is_flag=True, default=False) @click.option( diff --git a/test/cli/test_commands.py b/test/cli/test_commands.py index dc6353d608..13cb137c97 100644 --- a/test/cli/test_commands.py +++ b/test/cli/test_commands.py @@ -59,6 +59,14 @@ def test_commands_version(cli): (("run", SIMPLE_PATH), 'Error: Missing argument, "--base-url" is required for SCHEMA specified by file.'), (("run", SIMPLE_PATH, "--base-url=test"), "Error: Invalid base URL"), (("run", SIMPLE_PATH, "--base-url=127.0.0.1:8080"), "Error: Invalid base URL"), + ( + ("run", "http://127.0.0.1", "--request-timeout=-5"), + 'Error: Invalid value for "--request-timeout": -5 is smaller than the minimum valid value 1.', + ), + ( + ("run", "http://127.0.0.1", "--request-timeout=0"), + 'Error: Invalid value for "--request-timeout": 0 is smaller than the minimum valid value 1.', + ), ( ("run", "http://127.0.0.1", "--method=+"), 'Error: Invalid value for "--method" / "-M": Invalid regex: nothing to repeat at position 0', @@ -157,7 +165,8 @@ def test_commands_run_help(cli): " -b, --base-url TEXT Base URL address of the API, required for", " SCHEMA if specified by file.", " --app TEXT WSGI application to test", - " --request-timeout INTEGER Timeout in milliseconds for network requests", + " --request-timeout INTEGER RANGE", + " Timeout in milliseconds for network requests", " during the test run.", " --validate-schema BOOLEAN Enable or disable validation of input schema.", " --show-errors-tracebacks Show full tracebacks for internal errors.",