Skip to content

Commit

Permalink
[#1358] Fix auth error on datapusher_hook
Browse files Browse the repository at this point in the history
When logged in as a non-sysadmin user, you always got an error like:

Process completed but unable to post to result_url

This was caused by calling task_status_update, which is sysadmin only on
datapusher_hook without ignore_auth in the context. We can safely add it
at this point because access has been already checked.

Added some tests.
  • Loading branch information
amercader committed Dec 3, 2013
1 parent 38f1e30 commit 5ef1ac6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions ckanext/datapusher/logic/action.py
Expand Up @@ -153,6 +153,7 @@ def datapusher_hook(context, data_dict):
task['state'] = status
task['last_updated'] = str(datetime.datetime.now())

context['ignore_auth'] = True
p.toolkit.get_action('task_status_update')(context, task)


Expand Down
12 changes: 10 additions & 2 deletions ckanext/datapusher/tests/test.py
Expand Up @@ -138,7 +138,7 @@ def test_send_datapusher_creates_task(self):

assert task['state'] == 'pending', task

def test_datapusher_hook(self):
def _call_datapusher_hook(self, user):
package = model.Package.get('annakarenina')
resource = package.resources[0]

Expand All @@ -163,7 +163,7 @@ def test_datapusher_hook(self):
}
}
postparams = '%s=1' % json.dumps(data)
auth = {'Authorization': str(self.sysadmin_user.apikey)}
auth = {'Authorization': str(user.apikey)}
res = self.app.post('/api/action/datapusher_hook', params=postparams,
extra_environ=auth, status=200)
print res.body
Expand All @@ -182,3 +182,11 @@ def test_datapusher_hook(self):
task_type='datapusher', key='datapusher')

assert task['state'] == 'success', task

def test_datapusher_hook_sysadmin(self):

self._call_datapusher_hook(self.sysadmin_user)

def test_datapusher_hook_normal_user(self):

self._call_datapusher_hook(self.normal_user)

0 comments on commit 5ef1ac6

Please sign in to comment.