Example #1
0
 def test_first_unauth_userid(self):
     """ unauthenticated_userid returns first valid userid """
     p1, p2 = MagicMock(), MagicMock()
     policy = MixedAuthenticationPolicy(p1, p2)
     userid = policy.unauthenticated_userid(self.request)
     self.assertEqual(userid, p1.unauthenticated_userid())
     self.assertFalse(p2.unauthenticated_userid.called)
Example #2
0
 def test_merge_forget(self):
     """ merge all forget headers """
     p1, p2 = MagicMock(), MagicMock()
     headers = ['foo', 'bar']
     p1.forget.return_value = headers[:1]
     p2.forget.return_value = headers[1:]
     policy = MixedAuthenticationPolicy(p1, p2)
     forget = policy.forget(self.request)
     self.assertItemsEqual(forget, headers)
Example #3
0
 def test_merge_remember(self):
     """ merge all remember headers """
     p1, p2 = MagicMock(), MagicMock()
     headers = ['foo', 'bar']
     p1.remember.return_value = headers[:1]
     p2.remember.return_value = headers[1:]
     policy = MixedAuthenticationPolicy(p1, p2)
     remember = policy.remember(self.request, 'foo')
     self.assertItemsEqual(remember, headers)
Example #4
0
 def test_merge_principals(self):
     """ merge all principals from all auth policies """
     p1, p2 = MagicMock(), MagicMock()
     principals = ['foo', 'bar']
     p1.effective_principals.return_value = principals[:1]
     p2.effective_principals.return_value = principals[1:]
     policy = MixedAuthenticationPolicy(p1, p2)
     policy_principals = policy.effective_principals(self.request)
     self.assertItemsEqual(policy_principals, principals)
Example #5
0
 def test_no_unauth_userid(self):
     """ unauthenticated_userid returns None if no valid userid """
     p1, p2 = MagicMock(), MagicMock()
     p1.unauthenticated_userid.return_value = None
     p2.unauthenticated_userid.return_value = None
     policy = MixedAuthenticationPolicy(p1, p2)
     userid = policy.unauthenticated_userid(self.request)
     self.assertIsNone(userid)
     self.assertTrue(p1.unauthenticated_userid.called)
     self.assertTrue(p2.unauthenticated_userid.called)
Example #6
0
 def test_add_auth_to_mixed(self):
     """ Adding a policy to MixedAuthenticationPolicy stores it in a list """
     policy = MixedAuthenticationPolicy()
     policy.add_policy('foobar')
     self.assertEqual(policy._policies, ['foobar'])