(self)
| 12 | return webtest.TestApp(DebugApp()) |
| 13 | |
| 14 | def test_basic_authorization(self): |
| 15 | app = self.callFUT() |
| 16 | authorization = ('Basic', ['gawel', 'passwd']) |
| 17 | app.authorization = authorization |
| 18 | |
| 19 | self.assertIn('HTTP_AUTHORIZATION', app.extra_environ) |
| 20 | self.assertEqual(app.authorization, authorization) |
| 21 | |
| 22 | resp = app.get('/') |
| 23 | resp.mustcontain('HTTP_AUTHORIZATION: Basic Z2F3ZWw6cGFzc3dk') |
| 24 | header = resp.request.environ['HTTP_AUTHORIZATION'] |
| 25 | self.assertTrue(header.startswith('Basic ')) |
| 26 | authtype, value = header.split(' ') |
| 27 | auth = (authtype, |
| 28 | b64decode(to_bytes(value)).decode('latin1').split(':')) |
| 29 | self.assertEqual(authorization, auth) |
| 30 | |
| 31 | app.authorization = None |
| 32 | self.assertNotIn('HTTP_AUTHORIZATION', app.extra_environ) |
| 33 | |
| 34 | def test_bearer_authorization(self): |
| 35 | app = self.callFUT() |
nothing calls this directly
no test coverage detected