File size: 1,333 Bytes
cd17fb2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import asyncio
import json
from pathlib import Path
from unittest.mock import patch
from app import review

def test_arjun_json_result_is_in_scope_and_structured(tmp_path):
    path = tmp_path / "parameters.json"
    path.write_text(json.dumps({
        "https://example.org/api": {
            "method": "GET",
            "params": [{"name": "id", "reason": "body differs"},
                       {"name": "debug"}]},
        "https://other.example.org/api": {
            "params": [{"name": "private"}]},
    }))
    output = review.read_arjun_results(str(path), "example.org")
    assert [x["name"] for x in output] == ["id", "debug"]
    assert all(x["url"] == "https://example.org/api" for x in output)

def test_arjun_review_consumes_json_export():
    async def fake(args, timeout):
        assert "-oJ" in args
        path = Path(args[args.index("-oJ")+1])
        path.write_text(json.dumps({"https://example.org/path": {
            "method": "GET", "params": [{"name": "page"}]}}))
        return ["[+] Found parameters"], "completed"
    with patch.object(review, "execute", fake):
        result = asyncio.run(review.review("arjun", "https://example.org/path",
                                           "example.org"))
    assert result["status"] == "completed"
    assert result["parameters"][0]["name"] == "page"