Skip to content

Commit

Permalink
fix: Filter invalid path template variable
Browse files Browse the repository at this point in the history
Fixes a bug where an empty string would be accepted as a required path template variable.

See project gitter channel at 2019-03-18 11:58Z for more details.
  • Loading branch information
Hultner authored and Stranger6667 committed Mar 18, 2020
1 parent a4b15c8 commit b3777fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/schemathesis/_hypothesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,18 @@ def get_case_strategy(endpoint: Endpoint) -> st.SearchStrategy:


def filter_path_parameters(parameters: Dict[str, Any]) -> bool:
"""Single "." chars are excluded from path by urllib3.
"""Single "." chars and empty strings "" are excluded from path by urllib3.
In this case one variable in the path template will be empty, which will lead to 404 in most of the cases.
Because of it this case doesn't bring much value and might lead to false positives results of Schemathesis runs.
"""
return not any(value == "." for value in parameters.values())

path_parameter_blacklist = (
".",
"",
)

return not any(value in path_parameter_blacklist for value in parameters.values())


def quote_all(parameters: Dict[str, Any]) -> Dict[str, Any]:
Expand Down
3 changes: 2 additions & 1 deletion test/runner/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,10 @@ def test_response_conformance_malformed_json(args):
@pytest.fixture()
def filter_path_parameters():
# ".." and "." strings are treated specially, but this behavior is outside of the test's scope
# "" shouldn't be allowed as a valid path parameter

def schema_filter(strategy):
return strategy.filter(lambda x: x["key"] not in ("..", "."))
return strategy.filter(lambda x: x["key"] not in ("..", ".", ""))

schemathesis.hooks.register("path_parameters", schema_filter)
yield
Expand Down

0 comments on commit b3777fc

Please sign in to comment.