-
Notifications
You must be signed in to change notification settings - Fork 804
Feature: configuration based rest proxy support #1073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| import json | ||
| import pytest | ||
| import requests_mock | ||
| from sympy import is_increasing | ||
|
|
||
| from garak import _config, _plugins | ||
|
|
||
|
|
@@ -122,3 +120,51 @@ def test_rest_skip_code(requests_mock): | |
| ) | ||
| output = generator._call_model("Who is Enabran Tain's son?") | ||
| assert output == [None] | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("set_rest_config") | ||
| def test_rest_valid_proxy(mocker, requests_mock): | ||
| test_proxies = { | ||
| "http": "http://localhost:8080", | ||
| "https": "https://localhost:8443", | ||
| } | ||
| _config.plugins.generators["rest"]["RestGenerator"]["proxies"] = test_proxies | ||
| 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["proxies"] == test_proxies | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i guess maybe this isn't the strongest possible test we can do (we could check mock proxy logs), but validation shows that the code works (by tailing proxy logs) |
||
|
|
||
|
|
||
| @pytest.mark.usefixtures("set_rest_config") | ||
| def test_rest_invalid_proxy(requests_mock): | ||
| from garak.exception import GarakException | ||
|
|
||
| test_proxies = [ | ||
| "http://localhost:8080", | ||
| "https://localhost:8443", | ||
| ] | ||
| _config.plugins.generators["rest"]["RestGenerator"]["proxies"] = test_proxies | ||
| 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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good thinking |
||
Uh oh!
There was an error while loading. Please reload this page.