Beispiel #1
0
    def test_11_policy(self):
        p = Policy("pol1", active="true",
                   scope="selfservice", action="action1",
                   realm="*")
        p.save()
        self.assertTrue(p.action == "action1", p)
        self.assertTrue("action1" in p.get().get("action"), p)
        self.assertTrue("action1" in p.get("action"), p)
        
        p2 = Policy("pol1", active="false",
                    scope="selfservice", action="action1",
                    realm="*")
        self.assertFalse(p2.active, p2.active)
        
        # update
        self.assertTrue(p.user == "", p.user)
        p.user = "******"
        p.resolver = "*"
        p.client = "0.0.0.0"
        p.time = "anytime"
        p.save()
        self.assertTrue(p.user == "cornelius", p.user)

        # save admin policy
        p3 = Policy("pol3", active="false", scope="admin",
                    adminrealm='superuser', action="*")
        self.assertEqual(p3.adminrealm, "superuser")
Beispiel #2
0
    def test_11_policy(self):
        p = Policy("pol1", active="true",
                   scope="selfservice", action="action1",
                   realm="*")
        p.save()
        self.assertTrue(p.action == "action1", p)
        self.assertTrue("action1" in p.get().get("action"), p)
        self.assertTrue("action1" in p.get("action"), p)
        
        p2 = Policy("pol1", active="false",
                    scope="selfservice", action="action1",
                    realm="*")
        self.assertFalse(p2.active, p2.active)
        
        # update
        self.assertTrue(p.user == "", p.user)
        p.user = "******"
        p.resolver = "*"
        p.client = "0.0.0.0"
        p.time = "anytime"
        p.save()
        self.assertTrue(p.user == "cornelius", p.user)

        # save admin policy
        p3 = Policy("pol3", active="false", scope="admin",
                    adminrealm='superuser', action="*")
        self.assertEqual(p3.adminrealm, "superuser")
Beispiel #3
0
    def test_11_policy(self):
        p = Policy("pol1",
                   active="true",
                   scope="selfservice",
                   action="action1",
                   realm="*")
        p.save()
        self.assertTrue(p.action == "action1", p)
        self.assertTrue("action1" in p.get().get("action"), p)
        self.assertTrue("action1" in p.get("action"), p)
        self.assertEqual(p.get()["conditions"], [])

        p2 = Policy("pol1",
                    active="false",
                    scope="selfservice",
                    action="action1",
                    realm="*")
        self.assertFalse(p2.active, p2.active)

        # update
        self.assertTrue(p.user == "", p.user)
        p.user = "******"
        p.resolver = "*"
        p.client = "0.0.0.0"
        p.time = "anytime"
        p.save()
        self.assertTrue(p.user == "cornelius", p.user)

        # save admin policy
        p3 = Policy("pol3",
                    active="false",
                    scope="admin",
                    adminrealm='superuser',
                    action="*")
        self.assertEqual(p3.adminrealm, "superuser")
        p3.save()

        # set conditions
        p3.set_conditions([("userinfo", "type", "==", "foobar", False),
                           ("request", "user_agent", "==", "abcd", True)])
        self.assertEqual(p3.get_conditions_tuples(),
                         [("userinfo", "type", "==", "foobar", False),
                          ("request", "user_agent", "==", "abcd", True)])
        self.assertEqual(p3.get()["conditions"],
                         [("userinfo", "type", "==", "foobar", False),
                          ("request", "user_agent", "==", "abcd", True)])
        self.assertEqual(PolicyCondition.query.count(), 2)

        p3.set_conditions([("userinfo", "type", "==", "baz", True)])
        p3.save()
        self.assertEqual(p3.get()["conditions"],
                         [("userinfo", "type", "==", "baz", True)])
        self.assertEqual(len(p3.conditions), 1)
        self.assertEqual(p3.conditions[0].Value, "baz")
        self.assertEqual(PolicyCondition.query.count(), 1)

        # Check that the change has been persisted to the database
        p3_reloaded1 = Policy.query.filter_by(name="pol3").one()
        self.assertEqual(p3_reloaded1.get()["conditions"],
                         [("userinfo", "type", "==", "baz", True)])
        self.assertEqual(len(p3_reloaded1.conditions), 1)
        self.assertEqual(p3_reloaded1.conditions[0].Value, "baz")
        self.assertEqual(PolicyCondition.query.count(), 1)

        p3.set_conditions([])
        p3.save()
        self.assertEqual(p3.get()["conditions"], [])
        self.assertEqual(
            Policy.query.filter_by(name="pol3").one().get()["conditions"], [])
        self.assertEqual(PolicyCondition.query.count(), 0)

        # Test policies with adminusers
        p = Policy("pol1admin",
                   active="true",
                   scope="admin",
                   action="action1",
                   adminuser="******")
        r = p.save()
        adminusers = p.get("adminuser")
        self.assertEqual([u"jan", u"hein", u"klaas", u"pit"], adminusers)
        p2 = Policy.query.filter_by(id=r).one()
        self.assertEqual("jan, hein, klaas, pit", p2.adminuser)