Esempio n. 1
0
    def test_update_site(self):
        group1 = Group("group1")
        group2 = Group("group2")
        group3 = Group("group3")
        group1.create()
        group2.create()
        group3.create()

        site = Site(self.target_url)
        res1 = site.create()
        site_id = res1.json()["site"]["id"]
        # Verify that the new site has no plans and no groups
        self.assertEqual(res1.json()["site"]['plans'], site.plans)
        self.assertEqual(res1.json()["site"]['groups'], site.groups)

        # Update the site, add a plan and group
        res2 = site.update(site_id, groups=[group1.group_name],
            plans=[self.TEST_PLAN["name"]])
        # Verify that the site has these new settings
        res3 = site.get(site_id)
        self.assertEqual(res3.json()["site"]['plans'], [self.TEST_PLAN["name"]])
        self.assertEqual(res3.json()["site"]["groups"], [group1.group_name])
        self.assertEqual(res3.json()["site"]['url'], site.url)

        # Update the site, replace plans and groups
        res4 = site.update(site_id, groups=[group2.group_name, group3.group_name]) # bug #144
        res5 = site.get(site_id)
        self.assertEqual(res5.json()["site"]['plans'], [self.TEST_PLAN["name"]])
        self.assertEqual(set(res5.json()["site"]['groups']), set([group2.group_name, group3.group_name]))
        self.assertEqual(res5.json()["site"]['url'], site.url)
Esempio n. 2
0
    def test_update_only_change_plans(self):
        group = Group(self.group_name)
        group.create()
        site = Site(self.target_url, groups=[group.group_name], plans=[self.TEST_PLAN["name"]])
        res1 = site.create()
        site_id = res1.json()["site"]["id"]
        self.assertEqual(res1.json()["success"], True)
        self.assertEqual(res1.json()["site"]["plans"], [self.TEST_PLAN["name"]])
        self.assertEqual(res1.json()["site"]["groups"], [group.group_name])

        res2 = site.update(site_id, plans=[self.TEST_PLAN["name"]])
        self.assertEqual(res2.json()["success"], True)
        self.assertEqual(set(res2.json()["site"]["plans"]), set([self.TEST_PLAN["name"], self.TEST_PLAN["name"]]))
        self.assertEqual(res2.json()["site"]["groups"], [group.group_name])
Esempio n. 3
0
 def test_update_site_with_unknown_plan(self):
     site = Site(self.target_url)
     res1 = site.create()
     site_id = res1.json()["site"]["id"]
     res2 = site.update(site_id, plans=["non-existing-plan"])
     self.assertEqual(res2.json(), {'success': False, 'reason': 'unknown-plan'})
Esempio n. 4
0
 def test_update_unknown_site(self):
     site = Site(self.target_url)
     res = site.update("e22dbe0c-b958-4050-a339-b9a88fa7cd01",
         plans=["nmap", "zap"], groups=["foo", "bar"])
     self.assertEqual(res.json(), {'success': False, 'reason': 'no-such-site'})
Esempio n. 5
0
 def test_update_site_with_unknown_group(self):
     site = Site(self.target_url)
     res1 = site.create()
     site_id = res1.json()["site"]["id"]
     res2 = site.update(site_id, groups=["non-existing-group"])
     self.assertEqual(res2.json(), {"success": False, "reason": "unknown-group"})