Skip to content

Commit

Permalink
Test chained auth fallback to builtin functions
Browse files Browse the repository at this point in the history
  • Loading branch information
frafra committed Jan 25, 2019
1 parent 2b9ad65 commit 4fd7329
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ckanext/datastore/tests/test_chained_auth_functions.py
Expand Up @@ -27,6 +27,11 @@ def datastore_search_sql_auth(up_func, context, data_dict):
raise TestAuthException(auth_message)


@p.toolkit.chained_auth_function
def user_create(up_func, context, data_dict):
return up_func(context, data_dict)


class ExampleDataStoreSearchSQLPlugin(p.SingletonPlugin):
p.implements(p.IAuthFunctions)

Expand All @@ -48,3 +53,21 @@ def test_datastore_search_sql_auth(self):
u'user': u'annafan', u'table_names': []}, {})
# check that exception returned has the message from our auth function
assert_equals(raise_context.exception.message, auth_message)


class ExampleExternalProviderPlugin(p.SingletonPlugin):
p.implements(p.IAuthFunctions)

def get_auth_functions(self):
return {u'user_create': user_create}


class TestChainedAuthBuiltInFallback(DatastoreFunctionalTestBase):
_load_plugins = (
u'datastore',
u'example_external_provider_plugin')

def test_user_create_chained_auth(self):
ctd.CreateTestData.create()
# check if chained auth fallbacks to built-in user_create
check_access(u'user_create', {u'user': u'annafan'}, {})
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -194,6 +194,7 @@ def parse_version(s):
'sample_datastore_plugin = ckanext.datastore.tests.sample_datastore_plugin:SampleDataStorePlugin',
'example_datastore_deleted_with_count_plugin = ckanext.datastore.tests.test_chained_action:ExampleDataStoreDeletedWithCountPlugin',
'example_data_store_search_sql_plugin = ckanext.datastore.tests.test_chained_auth_functions:ExampleDataStoreSearchSQLPlugin',
'example_external_provider_plugin = ckanext.datastore.tests.test_chained_auth_functions:ExampleExternalProviderPlugin',
'test_datastore_view = ckan.tests.lib.test_datapreview:MockDatastoreBasedResourceView',
'test_datapusher_plugin = ckanext.datapusher.tests.test_interfaces:FakeDataPusherPlugin',
'test_routing_plugin = ckan.tests.config.test_middleware:MockRoutingPlugin',
Expand Down

0 comments on commit 4fd7329

Please sign in to comment.