Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
PluggableAuthService.tests.test_MoreCaching.CachingTests Class Reference
Inheritance diagram for PluggableAuthService.tests.test_MoreCaching.CachingTests:
Inheritance graph
[legend]
Collaboration diagram for PluggableAuthService.tests.test_MoreCaching.CachingTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def assertCacheStats
def test__extractUserIds
def test__extractUserIds_two_extractors
def test__findUser
def test__verifyUser
def test_getUser
def test_getUserById
def test_validate
def test_validate_anonymous
def test_validate_utf8_credentials
def test_validate_unicode_credentials
def test_validate_utf16_credentials
def test__doAddUser

Public Attributes

 pas
 cache
 doc

Detailed Description

Definition at line 22 of file test_MoreCaching.py.


Member Function Documentation

Definition at line 24 of file test_MoreCaching.py.

00024 
00025     def afterSetUp(self):
00026         self.pas = self.folder.acl_users
00027         # Add a RAM cache
00028         factory = self.pas.manage_addProduct['StandardCacheManagers']
00029         factory.manage_addRAMCacheManager('ram_cache')
00030         self.cache = self.pas.ram_cache
00031         # Activate the cache
00032         self.pas.ZCacheable_setManagerId('ram_cache')
00033         # Create a protected document
00034         self.folder.manage_addDTMLMethod('doc', file='the document')
00035         self.doc = self.folder.doc
00036         self.doc.manage_permission(View, [pastc.user_role], acquire=False)

def PluggableAuthService.tests.test_MoreCaching.CachingTests.assertCacheStats (   self,
  entries,
  misses,
  hits 
)

Definition at line 37 of file test_MoreCaching.py.

00037 
00038     def assertCacheStats(self, entries, misses, hits):
00039         # Check cache statistics against expected values
00040         report_item = {'entries': 0, 'misses': 0, 'hits': 0}
00041         report = self.cache.getCacheReport()
00042         if len(report):
00043             report_item = report[0]
00044         self.assertEqual(report_item.get('entries'), entries)
00045         self.assertEqual(report_item.get('misses'), misses)
00046         self.assertEqual(report_item.get('hits'), hits)

Here is the caller graph for this function:

Definition at line 244 of file test_MoreCaching.py.

00244 
00245     def test__doAddUser(self):
00246         user_id = 'test_user_2_'
00247         password = 'secret'
00248 
00249         self.assertCacheStats(0, 0, 0)
00250 
00251         self.pas._doAddUser(user_id, password, [pastc.user_role], [])
00252 
00253         # XXX: _doAddUser calls getUser
00254         self.assertCacheStats(2, 2, 0)
00255 
00256         # XXX: As a result the user is now cached, but without roles
00257         user = self.pas.getUserById(user_id)
00258         self.failIf(user is None)
00259         self.assertEqual(user.getId(), user_id)
00260         self.assertEqual(user.getRoles(), ['Authenticated'])
00261 
00262         # XXX: Must clear cache to get roles
00263         self.pas.ZCacheable_invalidate()
00264 
00265         user = self.pas.getUserById(user_id)
00266         self.failIf(user is None)
00267         self.assertEqual(user.getId(), user_id)
00268         self.assertEqual(user.getRoles(), ['Authenticated', pastc.user_role])
00269 

Here is the call graph for this function:

Definition at line 47 of file test_MoreCaching.py.

00047 
00048     def test__extractUserIds(self):
00049         request = self.app.REQUEST
00050         request._auth = 'Basic %s' % pastc.user_auth
00051 
00052         # Extract, we should see a cache miss
00053         self.pas._extractUserIds(request, self.pas.plugins)
00054         self.assertCacheStats(1, 1, 0)
00055 
00056         # Extract again, we should see a cache hit
00057         self.pas._extractUserIds(request, self.pas.plugins)
00058         self.assertCacheStats(1, 1, 1)
00059 
00060         # Extract yet again, we should see another hit
00061         self.pas._extractUserIds(request, self.pas.plugins)
00062         self.assertCacheStats(1, 1, 2)

Here is the call graph for this function:

Definition at line 63 of file test_MoreCaching.py.

00063 
00064     def test__extractUserIds_two_extractors(self):
00065         # Two extractors should result in two cache entries
00066         request = self.app.REQUEST
00067         request._auth = 'Basic %s' % pastc.user_auth
00068 
00069         factory = self.pas.manage_addProduct['PluggableAuthService']
00070         factory.addHTTPBasicAuthHelper('http_auth_2')
00071         self.pas.plugins.activatePlugin(IExtractionPlugin, 'http_auth_2')
00072 
00073         # Extract, we should see cache misses
00074         self.pas._extractUserIds(request, self.pas.plugins)
00075         self.assertCacheStats(2, 2, 0)
00076 
00077         # Extract again, we should see cache hits
00078         self.pas._extractUserIds(request, self.pas.plugins)
00079         self.assertCacheStats(2, 2, 2)
00080 
00081         # Extract yet again, we should see more hits
00082         self.pas._extractUserIds(request, self.pas.plugins)
00083         self.assertCacheStats(2, 2, 4)

Here is the call graph for this function:

Definition at line 84 of file test_MoreCaching.py.

00084 
00085     def test__findUser(self):
00086         # Find, we should see a cache miss
00087         self.pas._findUser(self.pas.plugins, pastc.user_name)
00088         self.assertCacheStats(1, 1, 0)
00089 
00090         # Find again, we should see a cache hit
00091         self.pas._findUser(self.pas.plugins, pastc.user_name)
00092         self.assertCacheStats(1, 1, 1)
00093 
00094         # Find yet again, we should see another hit
00095         self.pas._findUser(self.pas.plugins, pastc.user_name)
00096         self.assertCacheStats(1, 1, 2)

Here is the call graph for this function:

Definition at line 97 of file test_MoreCaching.py.

00097 
00098     def test__verifyUser(self):
00099         # Verify, we should see a cache miss
00100         self.pas._verifyUser(self.pas.plugins, pastc.user_name)
00101         self.assertCacheStats(1, 1, 0)
00102 
00103         # Verify again, we should see a cache hit
00104         self.pas._verifyUser(self.pas.plugins, pastc.user_name)
00105         self.assertCacheStats(1, 1, 1)
00106 
00107         # Verify yet again, we should see another hit
00108         self.pas._verifyUser(self.pas.plugins, pastc.user_name)
00109         self.assertCacheStats(1, 1, 2)

Here is the call graph for this function:

Definition at line 110 of file test_MoreCaching.py.

00110 
00111     def test_getUser(self):
00112         self.pas.getUser(pastc.user_name)
00113         self.assertCacheStats(2, 2, 0)
00114 
00115         self.pas.getUser(pastc.user_name)
00116         self.assertCacheStats(2, 2, 2)
00117 
00118         self.pas.getUser(pastc.user_name)
00119         self.assertCacheStats(2, 2, 4)

Here is the call graph for this function:

Definition at line 120 of file test_MoreCaching.py.

00120 
00121     def test_getUserById(self):
00122         self.pas.getUserById(pastc.user_name)
00123         self.assertCacheStats(2, 2, 0)
00124 
00125         self.pas.getUserById(pastc.user_name)
00126         self.assertCacheStats(2, 2, 2)
00127 
00128         self.pas.getUserById(pastc.user_name)
00129         self.assertCacheStats(2, 2, 4)

Here is the call graph for this function:

Definition at line 130 of file test_MoreCaching.py.

00130 
00131     def test_validate(self):
00132         # Rig the request so it looks like we traversed to doc
00133         request = self.app.REQUEST
00134         request['PUBLISHED'] = self.doc
00135         request['PARENTS'] = [self.app, self.folder]
00136         request.steps = list(self.doc.getPhysicalPath())
00137         request._auth = 'Basic %s' % pastc.user_auth
00138 
00139         user = self.pas.validate(request)
00140         self.failIf(user is None)
00141         self.assertEqual(user.getId(), pastc.user_name)
00142         self.assertEqual(user.getRoles(), ['Authenticated', pastc.user_role])
00143 
00144         self.assertCacheStats(2, 2, 0)
00145 
00146         self.pas.validate(request)
00147         self.assertCacheStats(2, 2, 2)
00148 
00149         self.pas.validate(request)
00150         self.assertCacheStats(2, 2, 4)

Here is the call graph for this function:

Definition at line 151 of file test_MoreCaching.py.

00151 
00152     def test_validate_anonymous(self):
00153         # Rig the request so it looks like we traversed to doc
00154         request = self.app.REQUEST
00155         request['PUBLISHED'] = self.doc
00156         request['PARENTS'] = [self.app, self.folder]
00157         request.steps = list(self.doc.getPhysicalPath())
00158 
00159         user = self.pas.validate(request)
00160         self.failUnless(user is None)
00161 
00162         self.assertCacheStats(0, 0, 0)

Here is the call graph for this function:

Definition at line 190 of file test_MoreCaching.py.

00190 
00191     def test_validate_unicode_credentials(self):
00192         # Rig the request so it looks like we traversed to doc
00193         request = self.app.REQUEST
00194         request['PUBLISHED'] = self.doc
00195         request['PARENTS'] = [self.app, self.folder]
00196         request.steps = list(self.doc.getPhysicalPath())
00197 
00198         # Rig the extractor so it returns Unicode credentials
00199         self.pas.http_auth.extractCredentials = \
00200             lambda req: { 'login': pastc.user_name
00201                         , 'password': pastc.user_password
00202                         , 'extra': u'M\344dchen'
00203                         }
00204 
00205         user = self.pas.validate(request)
00206         self.failIf(user is None)
00207         self.assertEqual(user.getId(), pastc.user_name)
00208         self.assertEqual(user.getRoles(), ['Authenticated', pastc.user_role])
00209 
00210         self.assertCacheStats(2, 2, 0)
00211 
00212         self.pas.validate(request)
00213         self.assertCacheStats(2, 2, 2)
00214 
00215         self.pas.validate(request)
00216         self.assertCacheStats(2, 2, 4)

Here is the call graph for this function:

Definition at line 217 of file test_MoreCaching.py.

00217 
00218     def test_validate_utf16_credentials(self):
00219         # Rig the request so it looks like we traversed to doc
00220         request = self.app.REQUEST
00221         request['PUBLISHED'] = self.doc
00222         request['PARENTS'] = [self.app, self.folder]
00223         request.steps = list(self.doc.getPhysicalPath())
00224 
00225         # Rig the extractor so it returns UTF-16 credentials
00226         self.pas.http_auth.extractCredentials = \
00227             lambda req: { 'login': pastc.user_name
00228                         , 'password': pastc.user_password
00229                         , 'extra': u'M\344dchen'.encode('utf-16')
00230                         }
00231 
00232         user = self.pas.validate(request)
00233         self.failIf(user is None)
00234         self.assertEqual(user.getId(), pastc.user_name)
00235         self.assertEqual(user.getRoles(), ['Authenticated', pastc.user_role])
00236 
00237         self.assertCacheStats(2, 2, 0)
00238 
00239         self.pas.validate(request)
00240         self.assertCacheStats(2, 2, 2)
00241 
00242         self.pas.validate(request)
00243         self.assertCacheStats(2, 2, 4)

Here is the call graph for this function:

Definition at line 163 of file test_MoreCaching.py.

00163 
00164     def test_validate_utf8_credentials(self):
00165         # Rig the request so it looks like we traversed to doc
00166         request = self.app.REQUEST
00167         request['PUBLISHED'] = self.doc
00168         request['PARENTS'] = [self.app, self.folder]
00169         request.steps = list(self.doc.getPhysicalPath())
00170 
00171         # Rig the extractor so it returns UTF-8 credentials
00172         self.pas.http_auth.extractCredentials = \
00173             lambda req: { 'login': pastc.user_name
00174                         , 'password': pastc.user_password
00175                         , 'extra': 'M\303\244dchen'
00176                         }
00177 
00178         user = self.pas.validate(request)
00179         self.failIf(user is None)
00180         self.assertEqual(user.getId(), pastc.user_name)
00181         self.assertEqual(user.getRoles(), ['Authenticated', pastc.user_role])
00182 
00183         self.assertCacheStats(2, 2, 0)
00184 
00185         self.pas.validate(request)
00186         self.assertCacheStats(2, 2, 2)
00187 
00188         self.pas.validate(request)
00189         self.assertCacheStats(2, 2, 4)

Here is the call graph for this function:


Member Data Documentation

Definition at line 29 of file test_MoreCaching.py.

Definition at line 34 of file test_MoreCaching.py.

Definition at line 25 of file test_MoreCaching.py.


The documentation for this class was generated from the following file: