/usr/share/pyshared/repoze/who/plugins/tests/test_basicauth.py is in python-repoze.who 1.0.18-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | import unittest
class TestBasicAuthPlugin(unittest.TestCase):
def _getTargetClass(self):
from repoze.who.plugins.basicauth import BasicAuthPlugin
return BasicAuthPlugin
def _makeOne(self, *arg, **kw):
plugin = self._getTargetClass()(*arg, **kw)
return plugin
def _makeEnviron(self, kw=None):
environ = {}
environ['wsgi.version'] = (1,0)
if kw is not None:
environ.update(kw)
return environ
def test_implements(self):
from zope.interface.verify import verifyClass
from repoze.who.interfaces import IChallenger
from repoze.who.interfaces import IIdentifier
klass = self._getTargetClass()
verifyClass(IChallenger, klass)
verifyClass(IIdentifier, klass)
def test_challenge(self):
plugin = self._makeOne('realm')
environ = self._makeEnviron()
result = plugin.challenge(environ, '401 Unauthorized', [], [])
self.assertNotEqual(result, None)
app_iter = result(environ, lambda *arg: None)
items = []
for item in app_iter:
items.append(item)
response = ''.join(items)
self.failUnless(response.startswith('401 Unauthorized'))
def test_identify_noauthinfo(self):
plugin = self._makeOne('realm')
environ = self._makeEnviron()
creds = plugin.identify(environ)
self.assertEqual(creds, None)
def test_identify_nonbasic(self):
plugin = self._makeOne('realm')
environ = self._makeEnviron({'HTTP_AUTHORIZATION':'Digest abc'})
creds = plugin.identify(environ)
self.assertEqual(creds, None)
def test_identify_basic_badencoding(self):
plugin = self._makeOne('realm')
environ = self._makeEnviron({'HTTP_AUTHORIZATION':'Basic abc'})
creds = plugin.identify(environ)
self.assertEqual(creds, None)
def test_identify_basic_badrepr(self):
plugin = self._makeOne('realm')
value = 'foo'.encode('base64')
environ = self._makeEnviron({'HTTP_AUTHORIZATION':'Basic %s' % value})
creds = plugin.identify(environ)
self.assertEqual(creds, None)
def test_identify_basic_ok(self):
plugin = self._makeOne('realm')
value = 'foo:bar'.encode('base64')
environ = self._makeEnviron({'HTTP_AUTHORIZATION':'Basic %s' % value})
creds = plugin.identify(environ)
self.assertEqual(creds, {'login':'foo', 'password':'bar'})
def test_remember(self):
plugin = self._makeOne('realm')
creds = {}
environ = self._makeEnviron()
result = plugin.remember(environ, creds)
self.assertEqual(result, None)
def test_forget(self):
plugin = self._makeOne('realm')
creds = {'login':'foo', 'password':'password'}
environ = self._makeEnviron()
result = plugin.forget(environ, creds)
self.assertEqual(result, [('WWW-Authenticate', 'Basic realm="realm"')] )
def test_challenge_forgetheaders_includes(self):
plugin = self._makeOne('realm')
creds = {'login':'foo', 'password':'password'}
environ = self._makeEnviron()
forget = plugin._get_wwwauth()
result = plugin.challenge(environ, '401 Unauthorized', [], forget)
self.assertEqual(result.headers, forget)
def test_challenge_forgetheaders_omits(self):
plugin = self._makeOne('realm')
creds = {'login':'foo', 'password':'password'}
environ = self._makeEnviron()
forget = plugin._get_wwwauth()
result = plugin.challenge(environ, '401 Unauthorized', [], [])
self.assertEqual(result.headers, forget)
def test_factory(self):
from repoze.who.plugins.basicauth import make_plugin
plugin = make_plugin('realm')
self.assertEqual(plugin.realm, 'realm')
|