Beispiel #1
0
def test_taking(ch: channel.Channel) -> None:
    ch.sendline("echo Hello")

    ch2 = ch.take()
    ch2.sendline("echo World")

    with pytest.raises(channel.ChannelTakenException):
        ch.sendline("echo Illegal")
Beispiel #2
0
def wait_for_shell(ch: channel.Channel) -> None:
    # Repeatedly sends `echo TBOT''LOGIN\r`.  At some point, the shell
    # interprets this command and prints out `TBOTLOGIN` because of the
    # quotation-marks being removed.  Once we detect this, this function
    # can return, knowing the shell is now running on the other end.
    #
    # Credit to Pavel for this idea!
    while True:
        ch.sendline("echo TBOT''LOGIN")
        try:
            ch.expect("TBOTLOGIN", timeout=0.2)
            break
        except TimeoutError:
            pass
Beispiel #3
0
def test_borrowing(ch: channel.Channel) -> None:
    ch.sendline("echo Hello")

    with ch.borrow() as ch2:
        ch2.sendline("echo World")

        raised = False
        try:
            ch.sendline("echo Illegal")
        except channel.ChannelBorrowedException:
            raised = True

        assert raised, "Borrow was unsuccessful"

    ch.sendline("echo back again")
Beispiel #4
0
def test_simple_expect3(ch: channel.Channel) -> None:
    ch.sendline("echo Lo1337rem")
    res = ch.expect(["Dolor", "roloD", tbot.Re(r"Lo(\d{1,20})"), "rem"])
    assert res.i == 2
    assert isinstance(res.match, Match), "Not a match object"
    assert res.match.group(1) == b"1337"
Beispiel #5
0
def test_simple_expect2(ch: channel.Channel) -> None:
    ch.sendline("echo Lorem Ipsum Dolor Sit")
    res = ch.expect(["Lol", "Dolor", "Dol"])
    assert res.i == 1
    assert res.match == "Dolor"
Beispiel #6
0
def test_simple_expect(ch: channel.Channel) -> None:
    ch.sendline("echo Lorem Ipsum")
    res = ch.expect(["Lol", "Ip"])
    assert res.i == 1
    assert res.match == "Ip"
Beispiel #7
0
def test_simple_readline(ch: channel.Channel) -> None:
    ch.sendline("echo Hello; echo World", read_back=True)
    out_s = ch.readline()
    assert out_s == "Hello\n"
    out_s = ch.readline()
    assert out_s == "World\n"
Beispiel #8
0
def test_simple_command(ch: channel.Channel) -> None:
    ch.sendline("echo Hello World", read_back=True)
    out = ch.read()
    assert out.startswith(b"Hello World")