Пример #1
0
def test_remote_ip_invalis_ips_count():
    ips = [ip_address('10.10.10.10'), ip_address('20.20.20.20')]
    trusted = parse_trusted_list([['40.40.40.40'], ['20.20.20.20']])
    with pytest.raises(IncorrectIPCount) as ctx:
        remote_ip(trusted, ips)
    assert ctx.value.expected == 3
    assert ctx.value.actual == [
        IPv4Address('10.10.10.10'),
        IPv4Address('20.20.20.20')
    ]
Пример #2
0
def test_remote_ip_not_trusted_ip():
    ips = [
        ip_address('10.10.10.10'),
        ip_address('20.20.20.20'),
        ip_address('30.30.30.30')
    ]
    trusted = parse_trusted_list([['40.40.40.40'], ['20.20.20.20']])
    with pytest.raises(UntrustedIP) as ctx:
        remote_ip(trusted, ips)
    assert ctx.value.trusted == [ip_address('40.40.40.40')]
    assert ctx.value.ip == ip_address('10.10.10.10')
Пример #3
0
def test_remote_ip_ok():
    ips = [
        ip_address('10.10.10.10'),
        ip_address('20.20.20.20'),
        ip_address('30.30.30.30')
    ]
    trusted = parse_trusted_list([['10.10.0.0/16'], ['20.20.20.20']])
    assert ips[-1] == remote_ip(trusted, ips)
Пример #4
0
def test_remote_with_ellipsis():
    ips = [
        ip_address('10.10.10.10'),
        ip_address('20.20.20.20'),
        ip_address('30.30.30.30')
    ]
    trusted = parse_trusted_list([['10.10.0.0/16'], ...])
    assert ips[-2] == remote_ip(trusted, ips)
Пример #5
0
def test_remote_ip_no_trusted():
    ip = ip_address('10.10.10.10')
    assert ip == remote_ip([], [ip])