Пример #1
0
 def test_selected_policy_cached_with_real_request(self):
     policies = [TestAuthnPolicy2(), TestAuthnPolicy3()]
     policy = create_selectable_authentication_policy(self.config, policies)
     self.request.set_property(policy.select_policy,
                               'sa_selected_policy',
                               reify=True)
     self.assertEqual(policy.unauthenticated_userid(self.request), "test2")
     policies.reverse()
     self.assertEqual(policy.unauthenticated_userid(self.request), "test2")
Пример #2
0
 def test_selecting_of_effective_principals(self):
     policies = [TestAuthnPolicy3(), TestAuthnPolicy2()]
     policy = create_selectable_authentication_policy(self.config, policies)
     self.assertEqual(sorted(policy.effective_principals(self.request)),
                      [Authenticated, Everyone, "test3", "test4"])
     self.assertEqual(sorted(policy.effective_principals(self.request)),
                      [Authenticated, Everyone, "test3", "test4"])
     policies.append(TestAuthnPolicy1())
     self.assertEqual(sorted(policy.effective_principals(self.request)),
                      [Authenticated, Everyone, "test3", "test4"])
Пример #3
0
    def test_directive(self):
        policy = create_selectable_authentication_policy(self.config)
        self.config.add_selectauth_policy(TestAuthnPolicy1())
        self.config.set_authorization_policy(ACLAuthorizationPolicy)
        self.config.set_authentication_policy(policy)
        self.config.commit()

        policy = self.config.registry.getUtility(IAuthenticationPolicy)
        self.assertTrue(isinstance(policy, SelectableAuthenticationPolicy))
        self.assertEqual(len(policy._policies), 1)
        self.assertEqual(policy.authenticated_userid(self.request), "test1")
        self.assertEqual(sorted(policy.effective_principals(self.request)),
                         [Authenticated, Everyone, "test1"])
Пример #4
0
 def test_no_good_policy(self):
     policies = [TestAuthnPolicyNull(), TestAuthnPolicyUnauthOnly()]
     policy = create_selectable_authentication_policy(self.config, policies)
     self.assertEqual(sorted(policy.effective_principals(self.request)),
                      [Everyone])
Пример #5
0
 def test_select_first_policy_with_unauthenticated_userid(self):
     policies = [TestAuthnPolicyNull(), TestAuthnPolicy3()]
     policy = create_selectable_authentication_policy(self.config, policies)
     self.assertEqual(sorted(policy.effective_principals(self.request)),
                      [Authenticated, Everyone, "test3", "test4"])
Пример #6
0
 def test_select_of_remember_and_forget(self):
     policies = [TestAuthnPolicy1(), TestAuthnPolicy2(), TestAuthnPolicy3()]
     policy = create_selectable_authentication_policy(self.config, policies)
     self.assertEqual(policy.remember(self.request, "ha"),
                      [("X-Remember", "ha")])
     self.assertEqual(policy.forget(self.request), [("X-Forget", "foo")])
Пример #7
0
 def test_selecting_of_authenticated_userid(self):
     policies = [TestAuthnPolicy2(), TestAuthnPolicy3()]
     policy = create_selectable_authentication_policy(self.config, policies)
     self.assertEqual(policy.authenticated_userid(self.request), "test2")
Пример #8
0
 def test_selected_policy_not_cached_with_dummyrequest(self):
     policies = [TestAuthnPolicy2(), TestAuthnPolicy3()]
     policy = create_selectable_authentication_policy(self.config, policies)
     self.assertEqual(policy.unauthenticated_userid(self.request), "test2")
     policies.reverse()
     self.assertEqual(policy.unauthenticated_userid(self.request), "test3")
Пример #9
0
 def test_basic_select(self):
     policies = [TestAuthnPolicy1(), TestAuthnPolicy2()]
     policy = create_selectable_authentication_policy(self.config, policies)
     self.assertEqual(policy.authenticated_userid(self.request), "test1")
     self.assertEqual(sorted(policy.effective_principals(self.request)),
                      [Authenticated, Everyone, "test1"])