Rename variables in sort key validation
Avoid unnecessarily divisive terms. Change-Id: Ida9384c849cd664c5fc5d31449350d7cb6a68b78
This commit is contained in:
parent
73d05c0cdc
commit
2c28e6b978
@ -658,7 +658,7 @@ def stack_get_all_by_root_owner_id(context, owner_id):
|
||||
|
||||
|
||||
def _get_sort_keys(sort_keys, mapping):
|
||||
"""Returns an array containing only whitelisted keys
|
||||
"""Returns an array containing only allowed keys
|
||||
|
||||
:param sort_keys: an array of strings
|
||||
:param mapping: a mapping from keys to DB column names
|
||||
@ -770,11 +770,11 @@ def _filter_and_page_query(context, query, limit=None, sort_keys=None,
|
||||
rpc_api.STACK_STATUS: models.Stack.status.key,
|
||||
rpc_api.STACK_CREATION_TIME: models.Stack.created_at.key,
|
||||
rpc_api.STACK_UPDATED_TIME: models.Stack.updated_at.key}
|
||||
whitelisted_sort_keys = _get_sort_keys(sort_keys, sort_key_map)
|
||||
valid_sort_keys = _get_sort_keys(sort_keys, sort_key_map)
|
||||
|
||||
query = db_filters.exact_filter(query, models.Stack, filters)
|
||||
return _paginate_query(context, query, models.Stack, limit,
|
||||
whitelisted_sort_keys, marker, sort_dir)
|
||||
valid_sort_keys, marker, sort_dir)
|
||||
|
||||
|
||||
def stack_count_all(context, filters=None,
|
||||
@ -1059,12 +1059,12 @@ def _events_filter_and_page_query(context, query,
|
||||
|
||||
sort_key_map = {rpc_api.EVENT_TIMESTAMP: models.Event.created_at.key,
|
||||
rpc_api.EVENT_RES_TYPE: models.Event.resource_type.key}
|
||||
whitelisted_sort_keys = _get_sort_keys(sort_keys, sort_key_map)
|
||||
valid_sort_keys = _get_sort_keys(sort_keys, sort_key_map)
|
||||
|
||||
query = db_filters.exact_filter(query, models.Event, filters)
|
||||
|
||||
return _events_paginate_query(context, query, models.Event, limit,
|
||||
whitelisted_sort_keys, marker, sort_dir)
|
||||
valid_sort_keys, marker, sort_dir)
|
||||
|
||||
|
||||
def event_count_all_by_stack(context, stack_id):
|
||||
|
@ -173,8 +173,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
||||
self.assertTrue(mock_db_filter.called)
|
||||
|
||||
@mock.patch.object(db_api, '_paginate_query')
|
||||
def test_filter_and_page_query_whitelists_sort_keys(self,
|
||||
mock_paginate_query):
|
||||
def test_filter_and_page_query_allowed_sort_keys(self,
|
||||
mock_paginate_query):
|
||||
query = mock.Mock()
|
||||
sort_keys = ['stack_name', 'foo']
|
||||
db_api._filter_and_page_query(self.ctx, query, sort_keys=sort_keys)
|
||||
@ -183,7 +183,7 @@ class SqlAlchemyTest(common.HeatTestCase):
|
||||
self.assertIn(['name'], args)
|
||||
|
||||
@mock.patch.object(db_api, '_events_paginate_query')
|
||||
def test_events_filter_and_page_query_whitelists_sort_keys(
|
||||
def test_events_filter_and_page_query_allowed_sort_keys(
|
||||
self, mock_paginate_query):
|
||||
query = mock.Mock()
|
||||
sort_keys = ['event_time', 'foo']
|
||||
@ -259,14 +259,14 @@ class SqlAlchemyTest(common.HeatTestCase):
|
||||
filtered_keys = db_api._get_sort_keys(sort_keys, mapping)
|
||||
self.assertEqual([], filtered_keys)
|
||||
|
||||
def test_get_sort_keys_whitelists_single_key(self):
|
||||
def test_get_sort_keys_allow_single_key(self):
|
||||
sort_key = 'foo'
|
||||
mapping = {'foo': 'Foo'}
|
||||
|
||||
filtered_keys = db_api._get_sort_keys(sort_key, mapping)
|
||||
self.assertEqual(['Foo'], filtered_keys)
|
||||
|
||||
def test_get_sort_keys_whitelists_multiple_keys(self):
|
||||
def test_get_sort_keys_allow_multiple_keys(self):
|
||||
sort_keys = ['foo', 'bar', 'nope']
|
||||
mapping = {'foo': 'Foo', 'bar': 'Bar'}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user