Skip to content
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

porting #63836 to master #63851

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/63835.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix cherrypy 400 error output to be less generic.
8 changes: 4 additions & 4 deletions salt/netapi/rest_cherrypy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,10 +863,10 @@ def hypermedia_handler(*args, **kwargs):
salt.exceptions.AuthorizationError,
salt.exceptions.EauthAuthenticationError,
salt.exceptions.TokenAuthenticationError,
):
raise cherrypy.HTTPError(401)
except salt.exceptions.SaltInvocationError:
raise cherrypy.HTTPError(400)
) as e:
raise cherrypy.HTTPError(401, e.message)
except salt.exceptions.SaltInvocationError as e:
raise cherrypy.HTTPError(400, e.message)
except (
salt.exceptions.SaltDaemonNotRunning,
salt.exceptions.SaltReqTimeoutError,
Expand Down
8 changes: 6 additions & 2 deletions tests/pytests/integration/netapi/rest_cherrypy/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@


@pytest.fixture
def client_config(client_config, netapi_port):
def client_config(client_config, netapi_port, request):
client_config["rest_cherrypy"] = {"port": netapi_port, "debug": True}
client_config["netapi_enable_clients"] = ["local", "runner"]
marker = request.node.get_closest_marker("netapi_client_data")
if marker is None:
client_config["netapi_enable_clients"] = []
else:
client_config["netapi_enable_clients"] = marker.args[0]
return client_config


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


@pytest.mark.slow_test
@pytest.mark.netapi_client_data(["local", "runner"])
async def test_accepts_arg_kwarg_keys(
http_client, auth_creds, content_type_map, subtests
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


@pytest.mark.slow_test
@pytest.mark.netapi_client_data(["local", "runner"])
async def test_all_jobs(http_client, auth_creds, content_type_map):
"""
test query to /jobs returns job data
Expand Down
25 changes: 25 additions & 0 deletions tests/pytests/integration/netapi/rest_cherrypy/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from salt.ext.tornado.httpclient import HTTPError


@pytest.mark.netapi_client_data(["local"])
async def test_run_good_login(http_client, auth_creds):
"""
Test the run URL with good auth credentials
Expand All @@ -16,6 +17,24 @@ async def test_run_good_login(http_client, auth_creds):
assert response.code == 200


async def test_run_netapi_client_not_set(http_client, auth_creds):
"""
Test the run URL with good auth credentials
"""
low = {"client": "local", "tgt": "*", "fun": "test.ping", **auth_creds}
body = urllib.parse.urlencode(low)

response = await http_client.fetch(
"/run", method="POST", body=body, raise_error=False
)
assert response.code == 400
assert (
"Client disabled: 'local'. Add to 'netapi_enable_clients' master config option to enable"
in response.body
)


@pytest.mark.netapi_client_data(["local"])
async def test_run_bad_login(http_client):
"""
Test the run URL with bad auth credentials
Expand All @@ -36,6 +55,7 @@ async def test_run_bad_login(http_client):
assert exc.value.code == 401


@pytest.mark.netapi_client_data(["local"])
async def test_run_empty_token(http_client):
"""
Test the run URL with empty token
Expand All @@ -51,6 +71,7 @@ async def test_run_empty_token(http_client):
assert exc.value.code == 401


@pytest.mark.netapi_client_data(["local"])
async def test_run_empty_token_upercase(http_client):
"""
Test the run URL with empty token with upercase characters
Expand All @@ -66,6 +87,7 @@ async def test_run_empty_token_upercase(http_client):
assert exc.value.code == 401


@pytest.mark.netapi_client_data(["local"])
async def test_run_wrong_token(http_client):
"""
Test the run URL with incorrect token
Expand All @@ -81,6 +103,7 @@ async def test_run_wrong_token(http_client):
assert exc.value.code == 401


@pytest.mark.netapi_client_data(["local"])
async def test_run_pathname_token(http_client):
"""
Test the run URL with path that exists in token
Expand All @@ -101,6 +124,7 @@ async def test_run_pathname_token(http_client):
assert exc.value.code == 401


@pytest.mark.netapi_client_data(["local"])
async def test_run_pathname_not_exists_token(http_client):
"""
Test the run URL with path that does not exist in token
Expand All @@ -122,6 +146,7 @@ async def test_run_pathname_not_exists_token(http_client):


@pytest.mark.slow_test
@pytest.mark.netapi_client_data(["local"])
async def test_run_extra_parameters(http_client, auth_creds):
"""
Test the run URL with good auth credentials
Expand Down