Skip to content

Commit

Permalink
Merge pull request #6 from aarranz/fix/ignore-empty-env
Browse files Browse the repository at this point in the history
Ignore env variables/config settings if they contain an empty string
  • Loading branch information
aarranz authored Jul 18, 2018
2 parents 297a515 + e219138 commit 735f734
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ckanext/right_time_context/controller.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 735f734

Please sign in to comment.