Skip to content

Commit

Permalink
fix: Internal error in CLI, when the base_url is an invalid IPv6
Browse files Browse the repository at this point in the history
Ref: #890
  • Loading branch information
Stranger6667 committed Nov 25, 2020
1 parent 2f7a3eb commit 8593a01
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog.rst
Expand Up @@ -4,6 +4,10 @@ Changelog
`Unreleased`_ - TBD
-------------------

**Fixed**

- Internal error in CLI, when the ``base_url`` is an invalid IPv6. `#890`_

`2.8.1`_ - 2020-11-24
---------------------

Expand Down Expand Up @@ -1542,6 +1546,7 @@ Deprecated
.. _0.3.0: https://github.com/schemathesis/schemathesis/compare/v0.2.0...v0.3.0
.. _0.2.0: https://github.com/schemathesis/schemathesis/compare/v0.1.0...v0.2.0

.. _#890: https://github.com/schemathesis/schemathesis/issues/890
.. _#882: https://github.com/schemathesis/schemathesis/issues/882
.. _#877: https://github.com/schemathesis/schemathesis/issues/877
.. _#876: https://github.com/schemathesis/schemathesis/issues/876
Expand Down
6 changes: 5 additions & 1 deletion src/schemathesis/cli/callbacks.py
Expand Up @@ -35,7 +35,11 @@ def _validate_url(value: str) -> None:


def validate_base_url(ctx: click.core.Context, param: click.core.Parameter, raw_value: str) -> str:
if raw_value and not urlparse(raw_value).netloc:
try:
netloc = urlparse(raw_value).netloc
except ValueError as exc:
raise click.UsageError("Invalid base URL") from exc
if raw_value and not netloc:
raise click.UsageError("Invalid base URL")
return raw_value

Expand Down
1 change: 1 addition & 0 deletions test/cli/test_crashes.py
Expand Up @@ -103,6 +103,7 @@ def test_valid_parameters_combos(cli, schema_url, params, flags, multiple_params
@settings(deadline=None)
@given(schema=urls() | paths() | st.text(), base_url=urls() | paths() | st.text() | st.none())
@example(schema="//bla", base_url=None)
@example(schema="http://127.0.0.1/schema.yaml", base_url="//ÿ[")
@pytest.mark.usefixtures("mocked_schema")
def test_schema_validity(cli, schema, base_url):
args = ()
Expand Down

0 comments on commit 8593a01

Please sign in to comment.