コード例 #1
0
def test_login_with_user(username, password, MockAerohive):
    aerohive = MockAerohive()
    aerohive.addUser(username, password)
    port = aerohive.run("127.0.0.1")

    connection = pexpect.spawn("ssh -o UserKnownHostsFile=/dev/null \"" +
                               username + "@" + "127.0.0.1\" -p " + str(port),
                               timeout=5)
    connection.expect_exact("continue connecting (yes/no)? ")
    connection.sendline("yes")
    connection.expect_exact("assword: ")
    connection.sendline(password)
    index = connection.expect_exact(["#", "denied"])
    if index == 1:
        raise Exception("Password rejected.")
    connection.sendline("exit")
    connection.expect_exact("closed.")
    connection.expect_exact(pexpect.EOF)
コード例 #2
0
def test_completely_wrong(MockAerohive):
    username = "******"
    password = "******"
    aerohive = MockAerohive()
    aerohive.addUser(username, password)
    aerohive.commands.append(add_foobar(aerohive))

    connection = connect_set_prompt(aerohive, username, password, "example-1")

    connection.expect_exact("example-1#")
    connection.sendline("foobar foob1")
    #        example-1#foobar z
    error = "                 ^-- unknown keyword or invalid input"
    connection.expect_exact(error)

    connection.expect_exact(aerohive.prompt())
    connection.sendline("exit")
    connection.expect_exact("closed.")
    connection.expect_exact(pexpect.EOF)
コード例 #3
0
def test_hostname_change(MockAerohive):
    username = "******"
    password = "******"
    aerohive = MockAerohive()
    aerohive.addUser(username, password)
    port = aerohive.run("127.0.0.1")

    connection = pexpect.spawn("ssh -o UserKnownHostsFile=/dev/null \"" +
                               username + "@" + "127.0.0.1\" -p " + str(port),
                               timeout=5)
    connection.expect_exact("continue connecting (yes/no)? ")
    connection.sendline("yes")
    connection.expect_exact("assword: ")
    connection.sendline(password)
    connection.expect_exact(aerohive.prompt())
    connection.sendline("hostname example-1")
    connection.expect_exact("example-1#example-1#")
    connection.sendline("exit")
    connection.expect_exact("closed.")
    connection.expect_exact(pexpect.EOF)
コード例 #4
0
def test_hostname_three_arguments(MockAerohive):
    username = "******"
    password = "******"
    aerohive = MockAerohive()
    aerohive.addUser(username, password)
    port = aerohive.run("127.0.0.1")

    connection = pexpect.spawn("ssh -o UserKnownHostsFile=/dev/null \"" +
                               username + "@" + "127.0.0.1\" -p " + str(port),
                               timeout=5)
    connection.expect_exact("continue connecting (yes/no)? ")
    connection.sendline("yes")
    connection.expect_exact("assword: ")
    connection.sendline(password)
    connection.expect_exact(aerohive.prompt())
    connection.sendline("hostname example-1")
    connection.expect_exact("example-1#")

    connection.expect_exact("example-1#")
    connection.sendline("hostname example-2 random-text")
    #        example-1#hostname example-2 random-text
    error = "                             ^-- unknown keyword or invalid input"
    connection.expect_exact(error)

    connection.expect_exact(aerohive.prompt())
    connection.sendline("exit")
    connection.expect_exact("closed.")
    connection.expect_exact(pexpect.EOF)
コード例 #5
0
def test_stop_server(MockAerohive):
    username = "******"
    password = "******"
    aerohive = MockAerohive()
    aerohive.addUser(username, password)
    port = aerohive.run("127.0.0.1")

    alive = pexpect.spawn(
        "ssh -o ConnectTimeout=1 -o UserKnownHostsFile=/dev/null \"" +
        username + "@" + "127.0.0.1\" -p " + str(port),
        timeout=5)
    index = alive.expect_exact(
        ["Connection refused", "Connection timed out", "continue connecting"])
    if index != 2:
        raise Exception("Server is not alive.")
    alive.terminate(force=True)

    aerohive.stop()

    dead = pexpect.spawn(
        "ssh -o ConnectTimeout=1 -o UserKnownHostsFile=/dev/null \"" +
        username + "@" + "127.0.0.1\" -p " + str(port),
        timeout=5)
    index = dead.expect_exact(
        ["Connection refused", "Connection timed out", "continue connecting"])
    if index == 2:
        raise Exception("Server is still alive.")
    dead.expect_exact(pexpect.EOF)