示例#1
0
def test_update_vulnerability(client, db_session, use_group, expected_status):
    if use_group:
        use_group(client)
    data = {
        'cve_id': 'CVE-1970-1000',
        'comment': 'This is the new comment',
        'commits-0-commit_link':
        'https://github.com/OWNER/REPO/commit/12345678',
        'commits-0-repo_name': 'REPO',
        'commits-0-repo_url': 'https://github.com/OWNER/REPO',
        'commits-0-commit_hash': '12345678',
    }

    resp = client.post('/CVE-1970-1000/create', data=data)
    assert resp.status_code == expected_status
    if use_group == as_admin:
        assert resp.headers.get('Location', '<empty>').endswith(f'/1')

    vuln = Vulnerability.get_by_id(1)
    assert vuln.cve_id == data['cve_id']
    assert len(vuln.commits) == 1

    if use_group == as_admin:
        assert vuln.comment == data['comment']
        assert vuln.commits[0].commit_link == data['commits-0-commit_link']
        assert vuln.commits[0].repo_name == data['commits-0-repo_name']
        assert vuln.commits[0].repo_url == data['commits-0-repo_url']
        assert vuln.commits[0].commit_hash == data['commits-0-commit_hash']
    else:
        assert vuln.comment == 'Vulnerability 1 comment'
        assert vuln.commits[
            0].commit_link == 'https://github.com/OWNER/REPO1/commit/1234568'
        assert vuln.commits[0].repo_name == 'REPO1'
        assert vuln.commits[0].repo_url == 'https://github.com/OWNER/REPO1'
        assert vuln.commits[0].commit_hash == '1234568'
示例#2
0
def test_update_vulnerability(client, db_session, use_group, expected_status):
    if use_group:
        use_group(client)
    data = {
        "cve_id": "CVE-1970-1000",
        "comment": "This is the new comment",
        "commits-0-commit_link":
        "https://github.com/OWNER/REPO/commit/12345678",
        "commits-0-repo_name": "REPO",
        "commits-0-repo_url": "https://github.com/OWNER/REPO",
        "commits-0-commit_hash": "12345678",
    }

    resp = client.post("/CVE-1970-1000/create", data=data)
    assert resp.status_code == expected_status
    if use_group == as_admin:
        assert resp.headers.get("Location", "<empty>").endswith(f"/1")

    vuln = Vulnerability.get_by_id(1)
    assert vuln.cve_id == data["cve_id"]
    assert len(vuln.commits) == 1

    if use_group == as_admin:
        assert vuln.comment == data["comment"]
        assert vuln.commits[0].commit_link == data["commits-0-commit_link"]
        assert vuln.commits[0].repo_name == data["commits-0-repo_name"]
        assert vuln.commits[0].repo_url == data["commits-0-repo_url"]
        assert vuln.commits[0].commit_hash == data["commits-0-commit_hash"]
    else:
        assert vuln.comment == "Vulnerability 1 comment"
        assert (vuln.commits[0].commit_link ==
                "https://github.com/OWNER/REPO1/commit/1234568")
        assert vuln.commits[0].repo_name == "REPO1"
        assert vuln.commits[0].repo_url == "https://github.com/OWNER/REPO1"
        assert vuln.commits[0].commit_hash == "1234568"
示例#3
0
def test_update_vulnerabilty(client, db_session):
    data = {
        'cve_id': 'CVE-1970-1000',
        'comment': 'This is the new comment',
        'commits-0-commit_link':
        'https://github.com/OWNER/REPO/commit/12345678',
        'commits-0-repo_name': 'REPO',
        'commits-0-repo_url': 'https://github.com/OWNER/REPO',
        'commits-0-commit_hash': '12345678',
    }

    resp = client.post('/CVE-1970-1000/create', data=data)
    assert resp.status_code == 401

    vuln = Vulnerability.get_by_id(1)
    assert vuln.comment == 'Vulnerability 1 comment'
    assert vuln.cve_id == data['cve_id']
    assert len(vuln.commits) == 1
    assert vuln.commits[
        0].commit_link == 'https://github.com/OWNER/REPO1/commit/1234568'
    assert vuln.commits[0].repo_name == 'REPO1'
    assert vuln.commits[0].repo_url == 'https://github.com/OWNER/REPO1'
    assert vuln.commits[0].commit_hash == '1234568'
示例#4
0
def test_update_vulnerabilty_as_admin(client, db_session):
    data = {
        'cve_id': 'CVE-1970-1000',
        'comment': 'This is the new comment',
        'commits-0-commit_link':
        'https://github.com/OWNER/REPO/commit/12345678',
        'commits-0-repo_name': 'REPO',
        'commits-0-repo_url': 'https://github.com/OWNER/REPO',
        'commits-0-commit_hash': '12345678',
    }

    as_admin(client)
    resp = client.post('/CVE-1970-1000/create', data=data)
    assert resp.status_code == 302
    assert resp.headers.get('Location', '<empty>').endswith(f'/1')

    vuln = Vulnerability.get_by_id(1)
    assert vuln.comment == data['comment']
    assert vuln.cve_id == data['cve_id']
    assert len(vuln.commits) == 1
    assert vuln.commits[0].commit_link == data['commits-0-commit_link']
    assert vuln.commits[0].repo_name == data['commits-0-repo_name']
    assert vuln.commits[0].repo_url == data['commits-0-repo_url']
    assert vuln.commits[0].commit_hash == data['commits-0-commit_hash']