[ckan-changes] commit/ckanext-dgu: dread: Characterise the joint auth middleware with a unit test. Want a functional test too sometime.

Bitbucket commits-noreply at bitbucket.org
Tue Jun 21 11:58:02 UTC 2011


1 new changeset in ckanext-dgu:

http://bitbucket.org/okfn/ckanext-dgu/changeset/597e71fc595a/
changeset:   597e71fc595a
user:        dread
date:        2011-06-21 13:57:32
summary:     Characterise the joint auth middleware with a unit test. Want a functional test too sometime.
affected #:  3 files (975 bytes)

--- a/ckanext/dgu/middleware.py	Tue Jun 14 15:12:02 2011 +0100
+++ b/ckanext/dgu/middleware.py	Tue Jun 21 12:57:32 2011 +0100
@@ -31,21 +31,24 @@
     def __call__(self, environ, start_response):
         if self.drupal_client is None:
             self.drupal_client = DrupalClient()
+
+        # establish from the cookie whether ckan and drupal are signed in
         ckan_signed_in = [False]
         drupal_signed_in = [False]
-
         for k, v in environ.items():
             key = k.lower()
             if key  == 'http_cookie':
                 ckan_signed_in[0] = is_ckan_signed_in(v)
                 drupal_signed_in[0] = drupal_extract_cookie(v)
-
         ckan_signed_in = ckan_signed_in[0]
         drupal_signed_in = drupal_signed_in[0]
-        environ['drupal.user_id'] = None
-        environ['drupal.publisher'] = None
+
+        environ['drupal.uid'] = None
+        environ['drupal.publishers'] = None
         new_start_response = start_response
         if drupal_signed_in and not ckan_signed_in:
+            # get info about the user from drupal and store in environ for
+            # use by main CKAN app
             user_id = self.drupal_client.get_user_id_from_session_id(drupal_signed_in)
             res = self.drupal_client.get_user_properties(user_id)
             environ['drupal.uid'] = res['uid']
@@ -71,6 +74,10 @@
                 Session.commit()
             else:
                 user = query.one()
+
+            # We want to store values in the user's cookie, so
+            # prepare the response header with this value,
+            # using auth_tkt to sign it.
             new_header = environ['repoze.who.plugins']['auth_tkt'].remember(
                 environ,
                 {
@@ -79,7 +86,7 @@
                     'userdata': '',
                 }
             )
-
+            # e.g. new_header = [('Set-Cookie', 'bob=ab48fe; Path=/;')]
             cookie_template = new_header[0][1].split('; ')
 
             cookie_string = ''


--- a/ckanext/dgu/testtools/mock_drupal.py	Tue Jun 14 15:12:02 2011 +0100
+++ b/ckanext/dgu/testtools/mock_drupal.py	Tue Jun 21 12:57:32 2011 +0100
@@ -18,8 +18,10 @@
         'rpc_host': 'localhost',
         'rpc_port': MOCK_DRUPAL_PORT,
         'test_users': {'62': {'name': 'testname',
+                              'uid': '62',
                               'publishers': test_organisations}
                        },
+        'test_sessions': {'4160a72a4d6831abec1ac57d7b5a59eb': '62'}
         }
 
 class Command(paste.script.command.Command):
@@ -152,6 +154,16 @@
                     else:
                         raise Fault(404, 'No department for organisation ID %r' % org_id)
 
+            class session:
+                @classmethod
+                def get(cls, session_id):
+                    # return user_id given a session_id
+                    # Example response:
+                    #   62
+                    try:
+                        return config['test_sessions'][session_id]
+                    except KeyError:
+                        raise Fault(404, 'There is no session with such ID.')                    
         server.register_instance(MyFuncs(), allow_dotted_names=True)
 
         # Run the server's main loop

Repository URL: https://bitbucket.org/okfn/ckanext-dgu/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list