diff --git a/docs/source/garak.generators.rest.rst b/docs/source/garak.generators.rest.rst index 6a789ea73..2e9d3dfd2 100644 --- a/docs/source/garak.generators.rest.rst +++ b/docs/source/garak.generators.rest.rst @@ -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`` diff --git a/tests/generators/test_rest.py b/tests/generators/test_rest.py index 55aa9d128..c0486ef1c 100644 --- a/tests/generators/test_rest.py +++ b/tests/generators/test_rest.py @@ -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