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

Ignore env variables/config settings if they contain an empty string #6

Merged
merged 1 commit into from Jul 18, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions ckanext/right_time_context/controller.py
Expand Up @@ -151,10 +151,10 @@ def proxy_ngsi_resource(self, resource_id):

# Process verify configuration
verify_conf = os.environ.get('CKAN_RIGHT_TIME_CONTEXT_VERIFY_REQUESTS', toolkit.config.get('ckan.right_time_context.verify_requests'))
if verify_conf is None:
if verify_conf is None or (isinstance(verify_conf, six.string_types) and verify_conf.strip() == ""):
verify_conf = os.environ.get('CKAN_VERIFY_REQUESTS', toolkit.config.get('ckan.verify_requests'))

if isinstance(verify_conf, six.string_types):
if isinstance(verify_conf, six.string_types) and verify_conf.strip() != "":
compare_env = verify_conf.lower().strip()
if compare_env in ("true", "1", "on"):
verify = True
Expand Down
4 changes: 4 additions & 0 deletions ckanext/right_time_context/tests/test_controller.py
Expand Up @@ -239,7 +239,10 @@ def test_auth_required_request(self, exception, status_code, base, logic, reques

@parameterized.expand([
({}, {}, True),
({"CKAN_RIGHT_TIME_CONTEXT_VERIFY_REQUESTS": " "}, {}, True),
({"CKAN_VERIFY_REQUESTS": " "}, {}, True),
({}, {"ckan.verify_requests": False}, False),
({}, {"ckan.right_time_context.verify_requests": False}, False),
({}, {"ckan.right_time_context.verify_requests": False, "ckan.verify_requests": True}, False),
({"CKAN_VERIFY_REQUESTS": "false"}, {"ckan.verify_requests": True}, False),
({"CKAN_RIGHT_TIME_CONTEXT_VERIFY_REQUESTS": "True"}, {"ckan.verify_requests": False}, True),
Expand All @@ -250,6 +253,7 @@ def test_auth_required_request(self, exception, status_code, base, logic, reques
({"CKAN_RIGHT_TIME_CONTEXT_VERIFY_REQUESTS": "off"}, {"ckan.verify_requests": True}, False),
({"CKAN_RIGHT_TIME_CONTEXT_VERIFY_REQUESTS": "0"}, {"ckan.verify_requests": True}, False),
({"CKAN_RIGHT_TIME_CONTEXT_VERIFY_REQUESTS": "/path"}, {"ckan.verify_requests": True}, "/path"),
({"CKAN_RIGHT_TIME_CONTEXT_VERIFY_REQUESTS": " "}, {"ckan.verify_requests": False}, False),
({"CKAN_VERIFY_REQUESTS": "/path/A/b"}, {"ckan.verify_requests": "path/2"}, "/path/A/b"),
])
@patch.multiple("ckanext.right_time_context.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
Expand Down