Nodes: embed 'short_link' when 'short_code' is present and not empty.
This prevents calls to /nodes/<node-id>/share to get the short link.
This commit is contained in:
parent
2d5a538ad6
commit
9b3e75b9b9
@ -321,6 +321,10 @@ def before_returning_node(node):
|
|||||||
# Run validation process, since GET on nodes entry point is public
|
# Run validation process, since GET on nodes entry point is public
|
||||||
check_permissions('nodes', node, 'GET', append_allowed_methods=True)
|
check_permissions('nodes', node, 'GET', append_allowed_methods=True)
|
||||||
|
|
||||||
|
# Embed short_link_info if the node has a short_code.
|
||||||
|
short_code = node.get('short_code')
|
||||||
|
if short_code:
|
||||||
|
node['short_link'] = short_link_info(short_code)['short_link']
|
||||||
|
|
||||||
|
|
||||||
def before_returning_nodes(nodes):
|
def before_returning_nodes(nodes):
|
||||||
|
@ -358,3 +358,25 @@ class NodeSharingTest(AbstractPillarTest):
|
|||||||
|
|
||||||
self._check_share_data(share_data)
|
self._check_share_data(share_data)
|
||||||
self.assertEqual(3, create_short_link.call_count)
|
self.assertEqual(3, create_short_link.call_count)
|
||||||
|
|
||||||
|
def test_projections(self):
|
||||||
|
"""Projecting short_code should get us short_link as well."""
|
||||||
|
|
||||||
|
# Share the node
|
||||||
|
resp = self.post('/nodes/%s/share' % self.node_id, auth_token='token',
|
||||||
|
expected_status=201)
|
||||||
|
share_data = resp.json()
|
||||||
|
|
||||||
|
# Get the node with short_code
|
||||||
|
resp = self.get('/nodes/%s' % self.node_id,
|
||||||
|
json={'projection': {'short_code': 1}})
|
||||||
|
node = resp.json()
|
||||||
|
self.assertEqual(node['short_code'], share_data['short_code'])
|
||||||
|
self.assertTrue(node['short_link'].endswith(share_data['short_code']))
|
||||||
|
|
||||||
|
# Get the node without short_code
|
||||||
|
resp = self.get('/nodes/%s' % self.node_id,
|
||||||
|
qs={'projection': {'short_code': 0}})
|
||||||
|
node = resp.json()
|
||||||
|
self.assertNotIn('short_code', node)
|
||||||
|
self.assertNotIn('short_link', node)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user