Skip to content

Commit

Permalink
test and docs on rest ssl validation suppression
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartin-tech committed Jan 16, 2025
1 parent 5e87df2 commit ac2621b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/source/garak.generators.rest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Uses the following options from ``_config.plugins.generators["rest.RestGenerator
* ``request_timeout`` - How many seconds should we wait before timing out? Default 20
* ``ratelimit_codes`` - Which endpoint HTTP response codes should be caught as indicative of rate limiting and retried? ``List[int]``, default ``[429]``
* ``skip_codes`` - Which endpoint HTTP response code should lead to the generation being treated as not possible and skipped for this query. Takes precedence over ``ratelimit_codes``.
* ``verify_ssl`` - (optional) Enforce ssl certificate validation? Default is True (bool)

Templates can be either a string or a JSON-serialisable Python object.
Instance of ``$INPUT`` here are replaced with the prompt; instances of ``$KEY``
Expand Down
34 changes: 34 additions & 0 deletions tests/generators/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,37 @@ def test_rest_invalid_proxy(requests_mock):
with pytest.raises(GarakException) as exc_info:
_plugins.load_plugin("generators.rest.RestGenerator", config_root=_config)
assert "not in the required format" in str(exc_info.value)


@pytest.mark.usefixtures("set_rest_config")
@pytest.mark.parametrize("verify_ssl", (True, False, None))
def test_rest_ssl_suppression(mocker, requests_mock, verify_ssl):
if verify_ssl is not None:
_config.plugins.generators["rest"]["RestGenerator"]["verify_ssl"] = verify_ssl
else:
verify_ssl = RestGenerator.DEFAULT_PARAMS["verify_ssl"]
generator = _plugins.load_plugin(
"generators.rest.RestGenerator", config_root=_config
)
requests_mock.post(
DEFAULT_URI,
text=json.dumps(
{
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": DEFAULT_TEXT_RESPONSE,
},
}
]
}
),
)
mock_http_function = mocker.patch.object(
generator, "http_function", wraps=generator.http_function
)
generator._call_model("Who is Enabran Tain's son?")
mock_http_function.assert_called_once()
assert mock_http_function.call_args_list[0].kwargs["verify"] is verify_ssl

0 comments on commit ac2621b

Please sign in to comment.