Skip to content

Commit

Permalink
Merge branch 'feature/auth-action-corrections' into release/yellowstone
Browse files Browse the repository at this point in the history
  • Loading branch information
felliott committed Jun 14, 2019
2 parents f055cbb + d601448 commit 0241ba3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
57 changes: 57 additions & 0 deletions tests/auth/osf/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,60 @@ async def test_permissions_post_copy_source_destination(self):
'user_agent': None
}
}, cookie=None, view_only=None)


class TestActionMapping:

@pytest.mark.asyncio
@pytest.mark.parametrize('method, action, auth_type, headers, query_args, expected', [
['post', 'copy', AuthType.SOURCE, None, None, 'download'],
['post', 'copy', AuthType.DESTINATION, None, None, 'upload'],
['post', 'move', AuthType.SOURCE, None, None, 'upload'], # TODO: really?
['post', 'move', AuthType.DESTINATION, None, None, 'upload'],
['post', 'rename', AuthType.SOURCE, None, None, 'upload'], # TODO: really?
['post', 'rename', AuthType.DESTINATION, None, None, 'upload'],
['head', None, None, {settings.MFR_ACTION_HEADER: 'render'}, None, 'render'],
['head', None, None, {settings.MFR_ACTION_HEADER: 'export'}, None, 'export'],
['get', None, None, None, None, 'download'],
['put', None, None, None, None, 'upload'],
['delete', None, None, None, None, 'delete'],
['get', None, None, None, {'meta': 1}, 'metadata'],
['get', None, None, None, {'revisions': 1}, 'revisions'],
])
async def test_action_type(self, method, action, auth_type, headers, query_args, expected):

handler = OsfAuthHandler()

request = mock.Mock()
request.method = method
request.headers = headers if headers is not None else {}
request.query_arguments = query_args if query_args is not None else {}
request.cookies = {}

kwargs = {}
if action is not None:
kwargs['action'] = action
if auth_type is not None:
kwargs['auth_type'] = auth_type

handler.build_payload = mock.Mock()
handler.make_request = utils.MockCoroutine(
return_value={'auth': {}, 'callback_url': 'dummy'}
)

await handler.get('test', 'test', request, **kwargs)

handler.build_payload.asssert_called_once()
args, _ = handler.build_payload.call_args
assert args[0]['action'] == expected

@pytest.mark.asyncio
async def test_unhandled_mfr_action(self):
handler = OsfAuthHandler()
request = mock.Mock()
request.method = 'head'
request.headers = {settings.MFR_ACTION_HEADER: 'bad-action'}
with pytest.raises(UnsupportedActionError):
await handler.get('test', 'test', request)
7 changes: 6 additions & 1 deletion waterbutler/auth/osf/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ async def get(self, resource, provider, request, action=None, auth_type=AuthType
raise exceptions.UnsupportedActionError(mfr_action, supported=mfr_action_map.keys())
else:
try:
osf_action = self.ACTION_MAP[method]
if method == 'get' and 'meta' in request.query_arguments:
osf_action = 'metadata'
elif method == 'get' and 'revisions' in request.query_arguments:
osf_action = 'revisions'
else:
osf_action = self.ACTION_MAP[method]
except KeyError:
raise exceptions.UnsupportedHTTPMethodError(method, supported=self.ACTION_MAP.keys())

Expand Down

0 comments on commit 0241ba3

Please sign in to comment.