Example #1
0
def test_open_ssh_session_host_key_verification(mocker, instance_id, ssm_mock):
    m = mocker.patch("aws_gate.ssh.execute", return_value="output")

    sess = SshSession(instance_id=instance_id, ssm=ssm_mock)
    sess.open()

    assert m.called
    assert "UserKnownHostsFile=/dev/null" in m.call_args[0][1]
    assert "StrictHostKeyChecking=no" in m.call_args[0][1]
Example #2
0
def test_open_ssh_session(mocker, ssm_mock, instance_id, test_input):
    debug, ssh_cmd_arg = test_input
    mocker.patch("aws_gate.ssh.DEBUG", debug)
    m = mocker.patch("aws_gate.ssh.execute", return_value="output")

    sess = SshSession(instance_id=instance_id, ssm=ssm_mock)
    sess.open()

    assert m.called
    assert ssh_cmd_arg in m.call_args[0][1]
Example #3
0
def test_open_ssh_session_with_command(mocker, instance_id, ssm_mock):
    m = mocker.patch("aws_gate.ssh.execute", return_value="output")

    sess = SshSession(instance_id=instance_id,
                      ssm=ssm_mock,
                      command=["ls", "-l"])
    sess.open()

    assert m.called
    assert "--" in m.call_args[0][1]
    assert ["ls", "-l"] == m.call_args[0][1][-2:]
Example #4
0
def test_open_ssh_session_with_dynamic_forward(mocker, instance_id, ssm_mock):
    m = mocker.patch("aws_gate.ssh.execute", return_value="output")

    dynamic_fwd = "9000"

    sess = SshSession(instance_id=instance_id,
                      ssm=ssm_mock,
                      dynamic_forward=dynamic_fwd)
    sess.open()

    assert m.called
    assert "-N" in m.call_args[0][1]
    assert "-D" in m.call_args[0][1]
    assert dynamic_fwd == m.call_args[0][1][1 + m.call_args[0][1].index("-D")]
Example #5
0
def test_open_ssh_session_with_remote_forward(mocker, instance_id, ssm_mock):
    m = mocker.patch("aws_gate.ssh.execute", return_value="output")

    remote_fwd = "3306:127.0.0.1:3306"

    sess = SshSession(instance_id=instance_id,
                      ssm=ssm_mock,
                      remote_forward=remote_fwd)
    sess.open()

    assert m.called
    assert "-N" in m.call_args[0][1]
    assert "-R" in m.call_args[0][1]
    assert remote_fwd == m.call_args[0][1][1 + m.call_args[0][1].index("-R")]
Example #6
0
def test_open_ssh_session_with_local_forward(mocker, instance_id, ssm_mock):
    m = mocker.patch("aws_gate.ssh.execute", return_value="output")

    local_fwd = "3306:privatedb.abcdef123456.eu-west-1.rds.amazonaws.com:3306"

    sess = SshSession(instance_id=instance_id,
                      ssm=ssm_mock,
                      local_forward=local_fwd)
    sess.open()

    assert m.called
    assert "-N" in m.call_args[0][1]
    assert "-L" in m.call_args[0][1]
    assert local_fwd == m.call_args[0][1][1 + m.call_args[0][1].index("-L")]
Example #7
0
def test_terminate_ssh_session(ssm_mock, instance_id):
    sess = SshSession(instance_id=instance_id, ssm=ssm_mock)

    sess.create()
    sess.terminate()

    assert ssm_mock.terminate_session.called
Example #8
0
def test_open_ssh_session_context_manager(instance_id, ssm_mock):
    with SshSession(instance_id=instance_id, ssm=ssm_mock):
        pass

    assert ssm_mock.start_session.called
    assert ssm_mock.terminate_session.called