prevent irregular auth_prefix config in tempauth

Tempauth handles a authorization request by request path.
If a request's path start with auth_prefix, tempauth middleware
handles that request to authorization method.
Therefore, when configuring auth_prefix to '/', all requests
handle to authorization method.

This change enables tempauth to prevent invalid auth_prefix
config '/' and similar empty auth_prefix in initialization method.

Fixes bug #1096538.

Change-Id: I20b157e2a0809c17409fc65a8eff0858fe4aff29
This commit is contained in:
Kota Tsuyuzaki 2013-01-05 23:56:59 -08:00
parent 3814f9fcdd
commit 161aa89bd5
2 changed files with 6 additions and 1 deletions

View File

@ -77,7 +77,10 @@ class TempAuth(object):
self.logger.set_statsd_prefix('tempauth.%s' % (
self.reseller_prefix if self.reseller_prefix else 'NONE',))
self.auth_prefix = conf.get('auth_prefix', '/auth/')
if not self.auth_prefix:
if not self.auth_prefix or not self.auth_prefix.strip('/'):
self.logger.warning('Rewriting invalid auth prefix "%s" to '
'"/auth/" (Non-empty auth prefix path '
'is required)' % self.auth_prefix)
self.auth_prefix = '/auth/'
if self.auth_prefix[0] != '/':
self.auth_prefix = '/' + self.auth_prefix

View File

@ -125,6 +125,8 @@ class TestAuth(unittest.TestCase):
self.assertEquals(ath.auth_prefix, '/auth/')
ath = auth.filter_factory({'auth_prefix': ''})(app)
self.assertEquals(ath.auth_prefix, '/auth/')
ath = auth.filter_factory({'auth_prefix': '/'})(app)
self.assertEquals(ath.auth_prefix, '/auth/')
ath = auth.filter_factory({'auth_prefix': '/test/'})(app)
self.assertEquals(ath.auth_prefix, '/test/')
ath = auth.filter_factory({'auth_prefix': '/test'})(app)