Example #1
0
def test_ResultErrorCircuit_from_dict(time_mock):
    t = 2000
    time_mock.side_effect = monotonic_time(start=t)
    fp1 = 'A' * 40
    fp2 = 'Z' * 40
    ed25519 = 'g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s'
    circ = [fp1, fp2]
    dest_url = 'http://example.com/sbws.bin'
    scanner_nick = 'sbwsscanner'
    nick = 'Mooooooo'
    relay_ip = '169.254.100.1'
    relay = Result.Relay(fp1, nick, relay_ip, ed25519)
    msg = 'aaaaayyyyyy bb'
    r1 = ResultErrorCircuit(relay, circ, dest_url, scanner_nick, msg=msg)
    d = {
        'msg': msg,
        'fingerprint': fp1,
        'nickname': nick,
        'address': relay_ip,
        'circ': circ,
        'dest_url': dest_url,
        'scanner': scanner_nick,
        'version': RESULT_VERSION,
        'type': _ResultType.ErrorCircuit,
        'time': t,
        'master_key_ed25519': ed25519,
    }
    r2 = Result.from_dict(d)
    assert isinstance(r1, ResultErrorCircuit)
    assert isinstance(r2, ResultErrorCircuit)
    assert str(r1) == str(r2)
Example #2
0
def test_ResultErrorCircuit(time_mock):
    t = 2000
    time_mock.side_effect = monotonic_time(start=t)
    fp1 = 'A' * 40
    fp2 = 'Z' * 40
    ed25519 = 'g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s'
    circ = [fp1, fp2]
    dest_url = 'http://example.com/sbws.bin'
    scanner_nick = 'sbwsscanner'
    nick = 'Mooooooo'
    relay_ip = '169.254.100.1'
    relay = Result.Relay(fp1, nick, relay_ip, ed25519)
    msg = 'aaaaayyyyyy bb'
    r1 = ResultErrorCircuit(relay, circ, dest_url, scanner_nick, msg=msg)
    r2 = ResultErrorCircuit(relay, circ, dest_url, scanner_nick, msg=msg, t=t)
    assert r1.msg == msg
    assert r1.nickname == nick
    assert r1.time == t
    assert r1.fingerprint == fp1
    assert r1.scanner == scanner_nick
    assert r1.type == _ResultType.ErrorCircuit
    assert r1.address == relay_ip
    assert r1.circ == circ
    assert r1.dest_url == dest_url
    assert r1.version == RESULT_VERSION
    assert str(r1) == str(r2)
Example #3
0
def test_stats_fresh_results(time_mock, sbwshome_success_result_two_relays,
                             args, conf, capsys, caplog):
    '''
    An initialized .sbws directory with a fresh error and fresh success should
    have some exciting stats and exit cleanly
    '''
    caplog.set_level(logging.DEBUG)
    start = 1529232278
    time_mock.side_effect = monotonic_time(start=start)
    sbws.core.stats.main(args, conf)
    captured = capsys.readouterr()
    lines = captured.out.strip().split('\n')
    assert '1 relays have recent results' in lines[0]
Example #4
0
def test_stats_fresh_result(time_mock, sbwshome_error_result, args, conf,
                            capsys, caplog):
    '''
    An initialized .sbws directory with a fresh error result should have some
    boring stats and exit cleanly
    '''
    args.error_types = False
    start = 1529232278
    time_mock.side_effect = monotonic_time(start=start)
    sbws.core.stats.main(args, conf)
    captured = capsys.readouterr()
    lines = captured.out.strip().split('\n')
    assert '1 relays have recent results' in lines[0]