Ejemplo n.º 1
0
    def test_pagination(self, rest_api):
        """Tests CVEs pagination using POST."""
        old_cves = []
        name, num = CVES_PAGE
        pages = ceil(num / PAGE_SIZE)
        for i in range(1, pages + 1):
            request_body = tools.gen_cves_body(cves=[name],
                                               page=i,
                                               page_size=PAGE_SIZE)
            cves = rest_api.get_cves(body=request_body).response_check()
            if i < pages:
                assert len(cves) == PAGE_SIZE
            else:
                # last page
                assert len(cves) == num % PAGE_SIZE

            schemas.cves_schema.validate(cves.raw.body)
            # Check if page/page_size/pages values are correct
            assert i == cves.raw.body['page']
            assert PAGE_SIZE == cves.raw.body['page_size']
            assert pages == cves.raw.body['pages']
            # erratum from old pages are not present on actual page
            for erratum in old_cves:
                assert erratum not in cves
            old_cves += cves
Ejemplo n.º 2
0
 def test_post_single(self, rest_api, cve_name):
     """Tests single CVE using POST."""
     request_body = tools.gen_cves_body([cve_name])
     cves = rest_api.get_cves(body=request_body).response_check()
     schemas.cves_schema.validate(cves.raw.body)
     assert len(cves) == 1
     cve, = cves
     assert cve.name == cve_name
Ejemplo n.º 3
0
    def post_single(self, rest_api, cve_in, rh_data_required=True):
        """Tests single CVE using POST."""
        cve_name, __, expected = cve_in
        if cve_name:
            request_body = tools.gen_cves_body([cve_name])
            cves = rest_api.get_cves(body=request_body).response_check()
        else:
            request_body = tools.gen_cves_body([])
            rest_api.get_cves(body=request_body).response_check(400)
            return

        if cve_name in [c[0] for c in CVES_NEG]:
            assert not cves
        else:
            assert len(cves) == 1
            cve, = cves
            tools.validate_cves(cve, expected, rh_data_required)
Ejemplo n.º 4
0
 def test_post_multi(self, rest_api):
     """Tests multiple CVEs using POST."""
     request_body = tools.gen_cves_body(CVES)
     cves = rest_api.get_cves(body=request_body).response_check()
     schemas.cves_schema.validate(cves.raw.body)
     assert len(cves) == len(CVES)
     for cve_name in CVES:
         assert cve_name in cves
Ejemplo n.º 5
0
 def post_multi(self, rest_api, rh_data_required=True):
     """Tests multiple CVEs using POST."""
     request_body = tools.gen_cves_body([c[0] for c in CVES])
     cves = rest_api.get_cves(body=request_body).response_check()
     expected_cves = [x for x in CVES if x not in CVES_NEG]
     assert len(cves) == len(expected_cves)
     for cve_name, _, expected in expected_cves:
         cve = cves[cve_name]
         tools.validate_cves(cve, expected, rh_data_required)
Ejemplo n.º 6
0
    def test_post_single(self, rest_api, cve_in):
        """Tests single CVE using POST."""
        cve_name, _, _ = cve_in
        if cve_name:
            request_body = tools.gen_cves_body([cve_name])
            cves = rest_api.get_cves(body=request_body).response_check()
        else:
            request_body = tools.gen_cves_body([])
            rest_api.get_cves(body=request_body).response_check(400)
            return

        if cve_name in [c[0] for c in CVES_NEG]:
            assert not cves
        else:
            schemas.cves_schema.validate(cves.raw.body)
            assert len(cves) == 1
            cve, = cves
            assert cve.name == cve_name
Ejemplo n.º 7
0
 def test_post_multi(self, rest_api):
     """Tests multiple CVEs using POST."""
     request_body = tools.gen_cves_body([c[0] for c in CVES])
     cves = rest_api.get_cves(body=request_body).response_check()
     schemas.cves_schema.validate(cves.raw.body)
     expected_cves = [x for x in CVES if x not in CVES_NEG]
     assert len(cves) == len(expected_cves)
     for cve_name, _, _ in expected_cves:
         assert cve_name in cves
Ejemplo n.º 8
0
 def test_post_multi(self, rest_api):
     """Tests multiple CVEs using POST."""
     request_body = tools.gen_cves_body(
         [c[0] for c in CVES], modified_since='2018-01-01T00:00:00+01:00')
     cves = rest_api.get_cves(body=request_body).response_check()
     schemas.cves_schema.validate(cves.raw.body)
     assert len(cves) == len([c[1] for c in CVES if c[1]])
     for _, expected_name, _ in CVES:
         if expected_name:  # not None
             assert expected_name in cves
Ejemplo n.º 9
0
 def test_post_single(self, rest_api, cve_in):
     """Tests single CVE using POST."""
     cve_name, expected_name, _ = cve_in
     request_body = tools.gen_cves_body(
         [cve_name], modified_since='2018-01-01T00:00:00+01:00')
     cves = rest_api.get_cves(body=request_body).response_check()
     # don't validate schema on empty response
     if expected_name:
         schemas.cves_schema.validate(cves.raw.body)
         assert len(cves) == 1
         cve, = cves
         assert cve.name == expected_name
     else:
         assert not cves
Ejemplo n.º 10
0
    def test_post_single(self, rest_api, cve):
        """Tests single cve regex using POST."""
        cve_name, cve_num, not_grep = cve
        if cve_name in ['CVE-2017.*', 'CVE-2018-1[0-9]{3}', 'CVE.*'
                        ] and GH(320).blocks:
            pytest.skip("Blocked by GH#320")
        request_body = tools.gen_cves_body([cve_name])
        if cve_name == '*':
            rest_api.get_cves(body=request_body).response_check(400)
            return

        cve = rest_api.get_cves(body=request_body).response_check()
        schemas.cves_schema.validate(cve.raw.body)
        if cve_num == 1:
            assert len(cve) == 1
        else:
            assert len(cve) >= cve_num
        if not_grep:
            assert not_grep not in cve.raw
Ejemplo n.º 11
0
    def test_pagination_neg(self, rest_api, page_info):
        """Negative testing of CVEs pagination with page/page_size <= 0"""
        name, _ = CVES_PAGE
        _, page, page_size = page_info
        request_body = tools.gen_cves_body(cves=[name],
                                           page=page,
                                           page_size=page_size)
        if isinstance(page, str) or isinstance(page_size, str):
            rest_api.get_cves(body=request_body).response_check(400)
            return
        else:
            cves = rest_api.get_cves(body=request_body).response_check()

        assert DEFAULT_PAGE_SIZE == cves.raw.body['page_size']
        if page > DEFAULT_PAGE:
            assert page == cves.raw.body['page']
            assert not cves.raw.body['cve_list']
        else:
            assert DEFAULT_PAGE == cves.raw.body['page']
            assert cves
Ejemplo n.º 12
0
 def test_modified_no_tz(self, rest_api, cve):
     """Tests modified since without timezone using POST."""
     request_body = tools.gen_cves_body(
         [cve], modified_since='2018-01-01T00:00:00')
     cves = rest_api.get_cves(body=request_body).response_check(400)
     assert 'Wrong date format' in cves.raw.body