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

Changing error code for AuthErrorStates.NotRequired to 406 #516

Merged
merged 5 commits into from
Aug 12, 2021
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
11 changes: 11 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## v2.4.0

### Improvements

- Add toggle to turn off evaluate API.
jakeichikawasalesforce marked this conversation as resolved.
Show resolved Hide resolved

### Breaking changes

- Changing error code to 406 when server not configured for authentication
but credentials are provided by client.

## v2.3.2

### Improvements
Expand Down
2 changes: 1 addition & 1 deletion tabpy/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.2
2.4.0
12 changes: 6 additions & 6 deletions tabpy/tabpy_server/handlers/base_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def should_fail_with_auth_error(self):

def fail_with_auth_error(self):
"""
Prepares server 401 response and server 400 response depending
Prepares server 401 response and server 406 response depending
on the value of the self.auth_error flag
"""
if self.auth_error == AuthErrorStates.NotAuthorized:
Expand All @@ -434,11 +434,11 @@ def fail_with_auth_error(self):
log_message="Invalid credentials provided.",
)
else:
self.logger.log(logging.ERROR, "Failing with 400 for Bad Request")
self.set_status(400)
self.logger.log(logging.ERROR, "Failing with 406 for Not Acceptable")
self.set_status(406)
self.set_header("WWW-Authenticate", f'Basic realm="{self.tabpy_state.name}"')
self.error_out(
400,
info="Bad request.",
log_message="Username or Password provided when authentication not available",
406,
info="Not Acceptable",
log_message="Username or password provided when authentication not available.",
)
2 changes: 1 addition & 1 deletion tests/unit/server_tests/test_endpoint_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ def test_creds_no_auth_fails(self):
)
},
)
self.assertEqual(400, response.code)
self.assertEqual(406, response.code)
2 changes: 1 addition & 1 deletion tests/unit/server_tests/test_endpoints_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@ def test_creds_no_auth_fails(self):
)
},
)
self.assertEqual(400, response.code)
self.assertEqual(406, response.code)
2 changes: 1 addition & 1 deletion tests/unit/server_tests/test_evaluation_plane_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def test_creds_no_auth_fails(self):
)
},
)
self.assertEqual(400, response.code)
self.assertEqual(406, response.code)


class TestEvaluationPlainHandlerDisabled(AsyncHTTPTestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/server_tests/test_service_info_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ def test_given_server_with_no_auth_and_password_expect_correct_info_response(sel
}

response = self.fetch("/info", headers=header)
self.assertEqual(response.code, 400)
self.assertEqual(response.code, 406)