def test_reseller_prefix_init(self): app = FakeApp() ath = auth.filter_factory({})(app) self.assertEquals(ath.reseller_prefix, 'AUTH_') ath = auth.filter_factory({'reseller_prefix': 'TEST'})(app) self.assertEquals(ath.reseller_prefix, 'TEST_') ath = auth.filter_factory({'reseller_prefix': 'TEST_'})(app) self.assertEquals(ath.reseller_prefix, 'TEST_')
def test_no_ext_authentication_url(self): app = FakeApp() try: # Use original auth.filter_factory and NOT monkey patched version unpatch_filter_factory() auth.filter_factory({})(app) except RuntimeError as e: # Restore monkey patched version patch_filter_factory() self.assertTrue(e.args[0].startswith("Missing filter parameter " "ext_authentication_url"))
def test_override_asked_for_and_allowed(self): self.test_auth = \ auth.filter_factory({'allow_overrides': 'true'})(FakeApp()) req = self._make_request('/v1/AUTH_account', environ={'swift.authorize_override': True}) resp = req.get_response(self.test_auth) self.assertEquals(resp.status_int, 404) self.assertTrue('swift.authorize' not in req.environ)
def test_auth_prefix_init(self): app = FakeApp() ath = auth.filter_factory({})(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': '/'})(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) self.assertEquals(ath.auth_prefix, '/test/') ath = auth.filter_factory({'auth_prefix': 'test/'})(app) self.assertEquals(ath.auth_prefix, '/test/') ath = auth.filter_factory({'auth_prefix': 'test'})(app) self.assertEquals(ath.auth_prefix, '/test/')
def test_passive_handle_get_token_kinit_realm_and_memcache(self): req = self._make_request('/auth/v1.0', headers={'X-Auth-User': '******', 'X-Auth-Key': 'password'}) req.environ['swift.cache'] = None _auth_passive = \ auth.filter_factory({'auth_method': 'passive', 'realm_name': 'EXAMPLE.COM'})(FakeApp()) _mock_run_kinit = Mock(return_value=0) _mock_get_groups = Mock(return_value="user,auth_test") with patch('swiftkerbauth.kerbauth.run_kinit', _mock_run_kinit): with patch('swiftkerbauth.kerbauth.get_groups_from_username', _mock_get_groups): try: _auth_passive.handle_get_token(req) except Exception as e: self.assertTrue(e.args[0].startswith("Memcache " "required")) else: self.fail("Expected Exception - Memcache required") _mock_run_kinit.assert_called_once_with('*****@*****.**', 'password') _mock_get_groups.assert_called_once_with('user')
def test_passive_handle_get_token_kinit_realm_and_memcache(self): req = self._make_request('/auth/v1.0', headers={ 'X-Auth-User': '******', 'X-Auth-Key': 'password' }) req.environ['swift.cache'] = None _auth_passive = \ auth.filter_factory({'auth_method': 'passive', 'realm_name': 'EXAMPLE.COM'})(FakeApp()) _mock_run_kinit = Mock(return_value=0) _mock_get_groups = Mock(return_value="user,auth_test") with patch('swiftkerbauth.kerbauth.run_kinit', _mock_run_kinit): with patch('swiftkerbauth.kerbauth.get_groups_from_username', _mock_get_groups): try: _auth_passive.handle_get_token(req) except Exception as e: self.assertTrue(e.args[0].startswith("Memcache " "required")) else: self.fail("Expected Exception - Memcache required") _mock_run_kinit.assert_called_once_with('*****@*****.**', 'password') _mock_get_groups.assert_called_once_with('user')
def setUp(self): self.test_auth = \ auth.filter_factory({'auth_method': 'active'})(FakeApp()) self.test_auth_passive = \ auth.filter_factory({'auth_method': 'passive'})(FakeApp())
def setUp(self): self.test_auth = auth.filter_factory({})(FakeApp())