File size: 1,426 Bytes
e4f3d12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from __future__ import annotations

from commitguard_env.parse_action import parse_action


def test_parse_action_request_context() -> None:
    raw = """
    <action>
      <action_type>request_context</action_type>
      <file_path>auth.c</file_path>
    </action>
    """
    a = parse_action(raw)
    assert a.action_type == "request_context"
    assert a.file_path == "auth.c"
    assert a.parse_error is None


def test_parse_action_analyze() -> None:
    raw = """
    <action>
      <action_type>analyze</action_type>
      <reasoning>hello</reasoning>
    </action>
    """
    a = parse_action(raw)
    assert a.action_type == "analyze"
    assert a.reasoning == "hello"
    assert a.parse_error is None


def test_parse_action_verdict() -> None:
    raw = """
    <action>
      <action_type>verdict</action_type>
      <is_vulnerable>true</is_vulnerable>
      <vuln_type>CWE-89</vuln_type>
      <exploit_sketch>sql injection</exploit_sketch>
    </action>
    """
    a = parse_action(raw)
    assert a.action_type == "verdict"
    assert a.is_vulnerable is True
    assert a.vuln_type == "CWE-89"
    assert a.exploit_sketch == "sql injection"
    assert a.parse_error is None


def test_parse_action_malformed_never_throws_and_sets_error() -> None:
    raw = "<action><action_type>???</action_type><fields>"
    a = parse_action(raw)
    assert a.action_type == "analyze"
    assert a.parse_error is not None