tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_symbols_path.py (2731B)


      1 #!/usr/bin/env python
      2 # coding=UTF-8
      3 
      4 import zipfile
      5 from io import BytesIO
      6 from urllib.parse import urlunsplit
      7 
      8 import mozhttpd
      9 import mozunit
     10 
     11 
     12 def test_symbols_path_not_present(check_for_crashes, minidump_files):
     13    """Test that no symbols path let mozcrash try to find the symbols."""
     14    assert 1 == check_for_crashes(symbols_path=None)
     15 
     16 
     17 def test_symbols_path_unicode(check_for_crashes, minidump_files, tmpdir, capsys):
     18    """Test that check_for_crashes can handle unicode in dump_directory."""
     19    symbols_path = tmpdir.mkdir("🍪")
     20 
     21    assert 1 == check_for_crashes(symbols_path=str(symbols_path), quiet=False)
     22 
     23    out, _ = capsys.readouterr()
     24    assert str(symbols_path) in out
     25 
     26 
     27 def test_symbols_path_url(check_for_crashes, minidump_files):
     28    """Test that passing a URL as symbols_path correctly fetches the URL."""
     29    data = {"retrieved": False}
     30 
     31    def make_zipfile():
     32        zdata = BytesIO()
     33        z = zipfile.ZipFile(zdata, "w")
     34        z.writestr("symbols.txt", "abc/xyz")
     35        z.close()
     36        return zdata.getvalue()
     37 
     38    def get_symbols(req):
     39        data["retrieved"] = True
     40 
     41        headers = {}
     42        return (200, headers, make_zipfile())
     43 
     44    httpd = mozhttpd.MozHttpd(
     45        port=0,
     46        urlhandlers=[{"method": "GET", "path": "/symbols", "function": get_symbols}],
     47    )
     48    httpd.start()
     49    symbol_url = urlunsplit((
     50        "http",
     51        "%s:%d" % httpd.httpd.server_address,
     52        "/symbols",
     53        "",
     54        "",
     55    ))
     56 
     57    assert 1 == check_for_crashes(symbols_path=symbol_url)
     58    assert data["retrieved"]
     59 
     60 
     61 def test_symbols_retry(check_for_crashes, minidump_files):
     62    """Test that passing a URL as symbols_path succeeds on retry after temporary HTTP failure."""
     63    data = {"retrieved": False}
     64    get_symbols_calls = 0
     65 
     66    def make_zipfile():
     67        zdata = BytesIO()
     68        z = zipfile.ZipFile(zdata, "w")
     69        z.writestr("symbols.txt", "abc/xyz")
     70        z.close()
     71        return zdata.getvalue()
     72 
     73    def get_symbols(req):
     74        nonlocal get_symbols_calls
     75        data["retrieved"] = True
     76        if get_symbols_calls > 0:
     77            ret = 200
     78        else:
     79            ret = 504
     80        get_symbols_calls += 1
     81 
     82        headers = {}
     83        return (ret, headers, make_zipfile())
     84 
     85    httpd = mozhttpd.MozHttpd(
     86        port=0,
     87        urlhandlers=[{"method": "GET", "path": "/symbols", "function": get_symbols}],
     88    )
     89    httpd.start()
     90    symbol_url = urlunsplit((
     91        "http",
     92        "%s:%d" % httpd.httpd.server_address,
     93        "/symbols",
     94        "",
     95        "",
     96    ))
     97 
     98    assert 1 == check_for_crashes(symbols_path=symbol_url)
     99    assert data["retrieved"]
    100    assert 2 == get_symbols_calls
    101 
    102 
    103 if __name__ == "__main__":
    104    mozunit.main()