Esempio n. 1
0
def test_init_ssh_config_file():
    test_host = {
        "setup_host": "someswitch1",
        "setup_ssh_config_file": f"{UNIT_TEST_DIR}_ssh_config",
    }
    conn = SSH2Net(**test_host)
    assert conn.auth_user == "carl"
Esempio n. 2
0
def test_bool():
    test_host = {
        "setup_host": "my_device  ",
        "auth_user": "******",
        "auth_password": "******"
    }
    conn = SSH2Net(**test_host)
    assert bool(conn) is False
Esempio n. 3
0
def test_init__shell():
    test_host = {
        "setup_host": "my_device  ",
        "auth_user": "******",
        "auth_password": "******"
    }
    conn = SSH2Net(**test_host)
    assert conn._shell is False
Esempio n. 4
0
def test__socket_alive_false():
    test_host = {
        "setup_host": "127.0.0.1",
        "auth_user": "******",
        "auth_password": "******"
    }
    conn = SSH2Net(**test_host)
    assert conn._socket_alive() is False
Esempio n. 5
0
def test_init_valid_comms_disable_paging_default():
    test_host = {
        "setup_host": "my_device",
        "auth_user": "******",
        "auth_password": "******"
    }
    conn = SSH2Net(**test_host)
    assert conn.comms_disable_paging == "terminal length 0"
Esempio n. 6
0
def test_init_ssh_key_strip():
    test_host = {
        "setup_host": "my_device",
        "auth_user": "******",
        "auth_public_key": "/some/public/key  ",
    }
    conn = SSH2Net(**test_host)
    assert conn.auth_public_key == b"/some/public/key"
Esempio n. 7
0
def test_init_host_strip():
    test_host = {
        "setup_host": "my_device  ",
        "auth_user": "******",
        "auth_password": "******"
    }
    conn = SSH2Net(**test_host)
    assert conn.host == "my_device"
Esempio n. 8
0
def test_init_valid_comms_prompt_regex():
    test_host = {
        "setup_host": "my_device",
        "auth_user": "******",
        "auth_password": "******",
        "comms_prompt_regex": "somestr",
    }
    conn = SSH2Net(**test_host)
    assert conn.comms_prompt_regex == "somestr"
Esempio n. 9
0
def test_init_valid_comms_disable_paging_str():
    test_host = {
        "setup_host": "my_device",
        "auth_user": "******",
        "auth_password": "******",
        "comms_disable_paging": "do some paging stuff",
    }
    conn = SSH2Net(**test_host)
    assert conn.comms_disable_paging == "do some paging stuff"
Esempio n. 10
0
def test_init_validate_host():
    test_host = {
        "setup_host": "8.8.8.8",
        "setup_validate_host": True,
        "auth_user": "******",
        "auth_password": "******",
    }
    conn = SSH2Net(**test_host)
    assert conn.host == "8.8.8.8"
Esempio n. 11
0
def test_init_valid_comms_return_char():
    test_host = {
        "setup_host": "my_device",
        "auth_user": "******",
        "auth_password": "******",
        "comms_return_char": "\rn",
    }
    conn = SSH2Net(**test_host)
    assert conn.comms_return_char == "\rn"
Esempio n. 12
0
def test_init_valid_comms_prompt_timeout():
    test_host = {
        "setup_host": "my_device  ",
        "auth_user": "******",
        "auth_password": "******",
        "comms_operation_timeout": 10,
    }
    conn = SSH2Net(**test_host)
    assert conn.comms_operation_timeout == 10
Esempio n. 13
0
def test_init_valid_port():
    test_host = {
        "setup_host": "my_device  ",
        "setup_port": 123,
        "auth_user": "******",
        "auth_password": "******",
    }
    conn = SSH2Net(**test_host)
    assert conn.port == 123
Esempio n. 14
0
def test_init_valid_comms_strip_ansi():
    test_host = {
        "setup_host": "my_device",
        "auth_user": "******",
        "auth_password": "******",
        "comms_strip_ansi": True,
    }
    conn = SSH2Net(**test_host)
    assert conn.comms_strip_ansi is True
Esempio n. 15
0
def test_init_valid_session_keepalive_pattern():
    test_host = {
        "setup_host": "my_device  ",
        "auth_user": "******",
        "auth_password": "******",
        "session_keepalive_pattern": "\007",
    }
    conn = SSH2Net(**test_host)
    assert conn.session_keepalive_pattern == "\x07"
Esempio n. 16
0
def test_init_invalid_session_keepalive_type():
    test_host = {
        "setup_host": "my_device  ",
        "auth_user": "******",
        "auth_password": "******",
        "session_keepalive_type": "notvalid",
    }
    with pytest.raises(ValueError):
        SSH2Net(**test_host)
Esempio n. 17
0
def test_init_valid_session_keepalive_type():
    test_host = {
        "setup_host": "my_device  ",
        "auth_user": "******",
        "auth_password": "******",
        "session_keepalive_type": "standard",
    }
    conn = SSH2Net(**test_host)
    assert conn.session_keepalive_type == "standard"
Esempio n. 18
0
def test_init_valid_session_keepalive_interval():
    test_host = {
        "setup_host": "my_device  ",
        "auth_user": "******",
        "auth_password": "******",
        "session_keepalive_interval": 10,
    }
    conn = SSH2Net(**test_host)
    assert conn.session_keepalive_interval == 10
Esempio n. 19
0
def test_init_invalid_comms_prompt_regex():
    test_host = {
        "setup_host": "my_device",
        "auth_user": "******",
        "auth_password": "******",
        "comms_prompt_regex": 123,
    }
    with pytest.raises(TypeError):
        SSH2Net(**test_host)
Esempio n. 20
0
def test_init_invalid_session_timeout():
    test_host = {
        "setup_host": "my_device  ",
        "auth_user": "******",
        "auth_password": "******",
        "session_timeout": "notanint",
    }
    with pytest.raises(ValueError):
        SSH2Net(**test_host)
Esempio n. 21
0
def test_init_valid_session_keepalive():
    test_host = {
        "setup_host": "my_device  ",
        "auth_user": "******",
        "auth_password": "******",
        "session_keepalive": True,
    }
    conn = SSH2Net(**test_host)
    assert conn.session_keepalive is True
Esempio n. 22
0
def test_init_valid_session_timeout():
    test_host = {
        "setup_host": "my_device  ",
        "auth_user": "******",
        "auth_password": "******",
        "session_timeout": 10,
    }
    conn = SSH2Net(**test_host)
    assert conn.session_timeout == 10
Esempio n. 23
0
def test__validate_host_valid_dns():
    test_host = {
        "setup_host": "google.com",
        "auth_user": "******",
        "auth_password": "******"
    }
    conn = SSH2Net(**test_host)
    r = conn._validate_host()
    assert r is None
Esempio n. 24
0
def test__socket_open_timeout():
    test_host = {
        "setup_host": "240.0.0.1",
        "setup_timeout": 1,
        "auth_user": "******",
        "auth_password": "******",
    }
    conn = SSH2Net(**test_host)
    with pytest.raises(SetupTimeout):
        conn._socket_open()
Esempio n. 25
0
def test_str():
    test_host = {
        "setup_host": "1.2.3.4",
        "auth_user": "******",
        "auth_password": "******"
    }
    conn = SSH2Net(**test_host)
    assert str(
        conn
    ) == f"SSH2Net Connection Object for host {test_host['setup_host']}"
Esempio n. 26
0
def test_init_invalid_comms_return_char():
    test_host = {
        "setup_host": "my_device",
        "auth_user": "******",
        "auth_password": "******",
        "comms_return_char": False,
    }
    with pytest.raises(TypeError) as e:
        SSH2Net(**test_host)
    assert str(
        e.value
    ) == "'comms_return_char' must be <class 'str'>, got: <class 'bool'>'"
Esempio n. 27
0
def test__validate_host_invalid_dns():
    test_host = {
        "setup_host": "notresolvablename",
        "auth_user": "******",
        "auth_password": "******",
    }
    conn = SSH2Net(**test_host)
    with pytest.raises(ValidationError) as e:
        conn._validate_host()
    assert str(
        e.value
    ) == f"Host {test_host['setup_host']} is not an IP or resolvable DNS name."
Esempio n. 28
0
def test_init_valid_comms_disable_paging_ext_func():
    test_host = {
        "setup_host":
        "my_device",
        "auth_user":
        "******",
        "auth_password":
        "******",
        "comms_disable_paging":
        "tests.unit.ext_test_funcs.some_disable_paging_func",
    }
    conn = SSH2Net(**test_host)
    assert callable(conn.comms_disable_paging)
Esempio n. 29
0
def test_init_invalid_comms_disable_paging_ext_func():
    test_host = {
        "setup_host":
        "my_device",
        "auth_user":
        "******",
        "auth_password":
        "******",
        "comms_disable_paging":
        "tests.unit.ext_test_funcs.some_disable_paging_func_BAD",
    }
    with pytest.raises(AttributeError):
        SSH2Net(**test_host)
Esempio n. 30
0
def test_init_invalid_comms_disable_paging_str():
    test_host = {
        "setup_host": "my_device",
        "auth_user": "******",
        "auth_password": "******",
        "comms_disable_paging": 1234,
    }
    with pytest.raises(ValueError) as e:
        SSH2Net(**test_host)
    assert (
        str(e.value) ==
        f"{test_host['comms_disable_paging']} is an invalid comms_disable_paging function, path to a function, or is not a string."
    )