示例#1
0
 def test_superuser_success_private_repo(self):
     client, superuser = self.make_user_and_client(StaffSuperuserFactory())
     response = client.get("/api/testmethod_perf/")
     js = json.loads(response.content)
     print(response.content)
     assert "count" in js, js
     self.assertGreater(js["count"], 2)
示例#2
0
 def test_superuser_access(self):
     superuser = StaffSuperuserFactory()
     client, u = self.make_user_and_client(superuser)
     assert superuser == u
     assert client.login(username=u.username, password="******")
     assert client.get("/api/").status_code == 200
     assert client.get("/api/branches/").status_code == 200
示例#3
0
 def test_api_schema_superuser(self):
     client, user = self.make_user_and_client(StaffSuperuserFactory())
     response = client.get("/api/")
     self.debugmsg(response)
     self.assertEqual(response.status_code, 200)
     self.assertIn("application/json", response["content-type"])
     self.assertIn(bytes("/api/", "ascii"), response.content)
 def make_user_and_client(cls):
     user = StaffSuperuserFactory()
     client = APIClient()
     client.force_authenticate(user)
     response = client.get("/api/")
     assert response.status_code == 200, response.content
     return client, user
示例#5
0
 def setUpTestData(cls):
     cls.client = Client()
     cls.superuser = StaffSuperuserFactory()
     cls.user = UserFactory()
     cls.repo = RepositoryFactory()
     cls.plan1 = PlanFactory()
     cls.plan1.role = "scratch"
     cls.plan1.save()
     cls.plan2 = PlanFactory()
     cls.plan2.role = "qa"
     cls.plan2.save()
     cls.planrepo1 = PlanRepositoryFactory(repo=cls.repo, plan=cls.plan1)
     cls.planrepo2 = PlanRepositoryFactory(repo=cls.repo, plan=cls.plan2)
     super(TestCreateOrgViews, cls).setUpTestData()
示例#6
0
    def setUpClass(cls):
        super().setUpClass()
        cls.superuser = StaffSuperuserFactory()
        cls.user = UserFactory()
        cls.client = APIClient()

        TestResultFactory(method__testclass__test_type="Robot")
        TestResultFactory(method__testclass__test_type="Robot")
        TestResultFactory(method__testclass__test_type="Robot")

        testresults = TestResult.objects.all()
        assign_perm("plan.view_builds", cls.user,
                    testresults[0].build_flow.build.planrepo)
        assign_perm("plan.view_builds", cls.user,
                    testresults[1].build_flow.build.planrepo)
示例#7
0
 def setUpTestData(cls):
     cls.client = Client()
     cls.superuser = StaffSuperuserFactory()
     cls.user = UserFactory()
     cls.plan = PlanFactory(name="Plan1")
     cls.plan.dashboard = "last"
     cls.plan.trigger = "tag"
     cls.plan.regex = "beta"
     cls.plan.save()
     cls.repo = RepositoryFactory(name="PublicRepo")
     cls.planrepo = PlanRepositoryFactory(plan=cls.plan, repo=cls.repo)
     cls.branch = BranchFactory(name="test-branch", repo=cls.repo)
     cls.build = BuildFactory(
         branch=cls.branch, repo=cls.repo, plan=cls.plan, planrepo=cls.planrepo
     )
     super(TestRepositoryViews, cls).setUpTestData()
示例#8
0
    def test_api_methods_IP_view_protection_normal_user(self):
        client, user = self.make_user_and_client()
        superclient, superduper = self.make_user_and_client(
            StaffSuperuserFactory())

        ip = base.ipv4_networks
        BAD_ADDR = "192.250.0.8"
        GOOD_ADDR = "192.168.0.8"

        all_apis = urls.router.get_urls()

        for route in all_apis:
            pattern = route.pattern.regex.pattern
            is_simple = "(" not in pattern
            if is_simple:
                callable_url = pattern.strip("^$")

                def get(client, addr):
                    self.debugmsg("/api/" + callable_url, addr)
                    return client.get("/api/" + callable_url,
                                      REMOTE_ADDR=addr).status_code

                is_public = callable_url in [
                    "testmethod_perf_UI/",
                    "testmethod_perf/",
                    "testmethod_results/",
                    "robot/",
                ]
                if is_public:
                    # IP address and user role don't matter for public URL
                    self.assertEqual(get(client, BAD_ADDR), 200)
                else:
                    with self.settings(
                            ADMIN_API_ALLOWED_SUBNETS=ip("192.168.0.0/16")):
                        # IP matters even for superusers
                        self.assertEqual(get(superclient, BAD_ADDR), 403)
                        # IP matters for normal users
                        self.assertEqual(get(client, BAD_ADDR), 403)

                    with self.settings(
                            ADMIN_API_ALLOWED_SUBNETS=ip("192.168.0.0/16")):
                        # private URL, good IP and superuser permissions = success
                        self.assertEqual(get(superclient, GOOD_ADDR), 200)
                        # private URL, good IP and poor permissions = failure
                        self.assertEqual(get(client, GOOD_ADDR), 403)
示例#9
0
    def setUpClass(cls):
        super().setUpClass()
        cls.superuser = StaffSuperuserFactory()
        cls.user = UserFactory()
        cls.client = APIClient()

        repo = RepositoryFactory(name="repo1")
        master = BranchFactory(name="master")

        today = timezone.make_aware(dateutil.parser.parse("01:00:00"),
                                    timezone.get_current_timezone())
        cls.today = today.strftime("%Y-%m-%d %H:%M:%S")

        # create some data that spans several days, plus one for today
        tz = timezone.get_current_timezone()
        for date in (
                cls.today,
                "2020-Jan-01",
                "2020-Jan-02",
                "2020-Jan-02",
                "2020-Jan-03",
                "2020-Jan-03",
                "2020-Jan-03",
        ):
            time_end = timezone.make_aware(
                dateutil.parser.parse(f"{date} 01:00:00"), tz)
            TestResultFactory(
                method__testclass__test_type="Robot",
                build_flow__build__repo=repo,
                build_flow__build__branch=master,
                build_flow__time_end=time_end,
                method__name="Test 1",
                outcome="Pass",
                source_file="/tmp/example.robot",
                robot_keyword="Some keyword",
                robot_tags="",
                duration=0.1,
                message="",
            )
示例#10
0
    def setUpClass(cls):
        super().setUpClass()
        cls.superuser = StaffSuperuserFactory()
        cls.user = UserFactory()
        cls.client = APIClient()

        repo1 = RepositoryFactory(name="repo1")
        repo2 = RepositoryFactory(name="repo2")
        master = BranchFactory(name="master")
        feature = BranchFactory(name="feature/robot")

        # The default for queries is today's date, so we need to use that
        # when creating results
        time_end = timezone.make_aware(dateutil.parser.parse("01:00:00"),
                                       timezone.get_current_timezone())
        cls.today = time_end.strftime("%Y-%m-%d %H:%M:%S")

        # One apex test, just to make sure it doesn't appear in any test results
        TestResultFactory(
            build_flow__time_end=time_end,
            method__testclass__test_type="Apex",
            outcome="Pass",
            duration=0.1,
        )

        # ... and several robot tests, some passing, some failing
        # oof. This is one place where I think black made the code much
        # less readable than my hand-edited version.
        for (
                repo,
                source,
                outcome,
                branch,
                test_name,
                tags,
                robot_keyword,
                message,
        ) in (
            (repo1, "file1.robot", "Pass", master, "Passing 1", None, None,
             None),
            (repo1, "file1.robot", "Pass", master, "Passing 2", None, None,
             None),
            (
                repo2,
                "file2.robot",
                "Fail",
                feature,
                "Failing 1",
                "",
                "KW1",
                "epic fail",
            ),
            (
                repo2,
                "file2.robot",
                "Fail",
                feature,
                "Failing 2",
                "",
                "KW1",
                "epic fail",
            ),
            (
                repo2,
                "file3.robot",
                "Fail",
                feature,
                "Failing 3",
                "",
                "KW2",
                "epic fail",
            ),
            (
                repo2,
                "file3.robot",
                "Fail",
                feature,
                "Failing 4",
                "t1,t2",
                "KW3",
                "ʃıɐɟ ɔıdǝ",
            ),
        ):
            TestResultFactory(
                method__testclass__test_type="Robot",
                build_flow__build__repo=repo,
                build_flow__build__branch=branch,
                build_flow__time_end=time_end,
                method__name=test_name,
                outcome=outcome,
                source_file=source,
                robot_keyword=robot_keyword,
                duration=0.1,
                robot_tags=tags,
                message=message,
            )
示例#11
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.client = Client()
     cls.superuser = StaffSuperuserFactory()
     cls.user = UserFactory()
     cls.build = BuildFactory()