Exemple #1
0
def selftest_machine_ssh_shell(
    lab: typing.Optional[selftest.SelftestHost] = None, ) -> None:
    """Test an SSH shell."""
    from tbot.tc.selftest import minisshd

    with lab or selftest.SelftestHost() as lh:
        if not minisshd.check_minisshd(lh):
            tbot.skip("dropbear is not installed so ssh can't be tested")

        with minisshd.minisshd(lh) as ssh:
            selftest_machine_shell(ssh)
Exemple #2
0
def selftest_machine_channel(ch: channel.Channel, remote_close: bool) -> None:
    tbot.skip("Channel tests need to be reimplemented for machine-v2")

    out = ch.raw_command("echo Hello World", timeout=1)
    assert out == "Hello World\n", repr(out)

    # Check recv_n
    ch.send("echo Foo Bar\n")
    out2 = ch.recv_n(8, timeout=1.0)
    assert out2 == b"echo Foo", repr(out)
    ch.read_until_prompt(channel.TBOT_PROMPT)

    # Check timeout
    raised = False
    try:
        ch.send("echo Foo Bar")
        ch.read_until_prompt(channel.TBOT_PROMPT, timeout=0)
    except TimeoutError:
        raised = True
    assert raised
    ch.send("\n")
    ch.read_until_prompt(channel.TBOT_PROMPT)

    assert ch.isopen()

    if remote_close:
        ch.send("exit\n")
        time.sleep(0.1)
        ch.recv(timeout=1)

        raised = False
        try:
            ch.recv(timeout=1)
        except channel.ChannelClosedException:
            raised = True
        assert raised
    else:
        ch.close()

    assert not ch.isopen()

    raised = False
    try:
        ch.send("\n")
    except channel.ChannelClosedException:
        raised = True
    assert raised

    raised = False
    try:
        ch.recv(timeout=1)
    except channel.ChannelClosedException:
        raised = True
    assert raised
Exemple #3
0
def selftest_machine_ssh_shell(
    lab: typing.Optional[linux.Lab] = None, ) -> None:
    """Test an SSH shell."""
    from tbot.tc.selftest import minisshd

    with lab or tbot.acquire_lab() as lh:
        if not minisshd.check_minisshd(lh):
            tbot.skip("dropbear is not installed so ssh can't be tested")

        with minisshd.minisshd(lh) as ssh:
            selftest_machine_shell(ssh)

            selftest_machine_channel(ssh.ch, True)
Exemple #4
0
def selftest_board_linux(lab: typing.Optional[tbot.selectable.LabHost] = None) -> None:
    """Test board's linux."""

    with contextlib.ExitStack() as cx:
        lh = cx.enter_context(lab or tbot.acquire_lab())

        try:
            b = cx.enter_context(tbot.acquire_board(lh))
        except NotImplementedError:
            tbot.skip("No board available")

        lnx = cx.enter_context(tbot.acquire_linux(b))

        mach.selftest_machine_shell(lnx)
Exemple #5
0
def selftest_board_linux_bad_console(
    lab: typing.Optional[tbot.selectable.LabHost] = None,
) -> None:
    """Test linux booting standalone."""

    tbot.skip("board-linux bad console test is not implemented")

    class BadBoard(connector.ConsoleConnector, board.Board):
        def connect(self, mach: linux.LinuxShell) -> channel.Channel:  # noqa: D102
            return mach.open_channel(
                linux.Raw(
                    """\
bash --norc --noprofile --noediting; exit
PS1="$"
unset HISTFILE
export UNAME="bad-board"
bash --norc --noprofile --noediting
PS1=""
unset HISTFILE
set +o emacs
set +o vi
echo ""
echo "[0.127] We will go into test mode now ..."
echo "[0.128] Let's see if I can behave bad enough to break you"
read -p 'bad-board login: [0.129] No clean login prompt for you';\
sleep 0.02;\
echo "[0.1337] Oh you though it was this easy?";\
read -p "Password: [0.ORLY?] Password ain't clean either you fool
It's even worse tbh";\
sleep 0.02;\
echo "[0.512] I have one last trick >:|";\
sleep 0.2;\
read -p ""\
"""
                )
            )

    class BadBoardLinux(board.Connector, board.LinuxBootLogin, linux.Bash):
        username = "******"
        password = "******"
        login_delay = 1

    with lab or tbot.acquire_lab() as lh:
        with BadBoard(lh) as b:
            with BadBoardLinux(b) as lnx:
                name = lnx.env("UNAME")
                assert name == "bad-board", repr(name)
Exemple #6
0
def selftest_machine_sshlab_shell(
    lab: typing.Optional[selftest.SelftestHost] = None, ) -> None:
    """Test an SSH LabHost shell."""
    from tbot.tc.selftest import minisshd

    with lab or selftest.SelftestHost() as lh:
        if not minisshd.check_minisshd(lh):
            tbot.skip("dropbear is not installed so ssh can't be tested")

        with minisshd.minisshd(lh) as ssh:
            ssh.exec0("true")

            tbot.log.message(tbot.log.c("Testing with paramiko ...").bold)
            with minisshd.MiniSSHLabHostParamiko(ssh.port) as slp:
                selftest_machine_shell(slp)

            tbot.log.message(tbot.log.c("Testing with plain ssh ...").bold)
            with minisshd.MiniSSHLabHostSSH(ssh.port) as sls:
                selftest_machine_shell(sls)
Exemple #7
0
 def inner() -> typing.Optional[int]:
     tbot.skip("This test is skipped on purpose")
     return 123