public void simpleRootTest() {
    RunScriptOnNodeUsingSsh testMe =
        new RunScriptOnNodeUsingSsh(
            sshFactory,
            eventBus,
            node,
            exec("echo $USER\necho $USER"),
            wrapInInitScript(false).runAsRoot(true));

    testMe.init();

    sshClient.connect();
    expect(sshClient.getUsername()).andReturn("tester");
    expect(sshClient.getHostAddress()).andReturn("somewhere.example.com");
    expect(
            sshClient.exec(
                "sudo sh <<'RUN_SCRIPT_AS_ROOT_SSH'\n"
                    + "echo $USER\n"
                    + "echo $USER\n"
                    + "RUN_SCRIPT_AS_ROOT_SSH\n"))
        .andReturn(new ExecResponse("root\nroot\n", null, 0));
    sshClient.disconnect();
    replay(sshClient);

    testMe.call();
  }
  public void simpleRootTestWithSudoPassword() {
    node = createMock(NodeMetadata.class);
    expect(node.getCredentials())
        .andReturn(new LoginCredentials("tester", "testpassword!", null, true))
        .atLeastOnce();
    replay(node);
    RunScriptOnNodeUsingSsh testMe =
        new RunScriptOnNodeUsingSsh(
            sshFactory,
            eventBus,
            node,
            exec("echo $USER\necho $USER"),
            wrapInInitScript(false).runAsRoot(true));
    testMe.init();

    sshClient.connect();
    expect(sshClient.getUsername()).andReturn("tester");
    expect(sshClient.getHostAddress()).andReturn("somewhere.example.com");
    expect(
            sshClient.exec(
                "sudo -S sh <<'RUN_SCRIPT_AS_ROOT_SSH'\n"
                    + "testpassword!\n"
                    + "echo $USER\n"
                    + "echo $USER\n"
                    + "RUN_SCRIPT_AS_ROOT_SSH\n"))
        .andReturn(new ExecResponse("root\nroot\n", null, 0));
    sshClient.disconnect();
    replay(sshClient);

    testMe.call();
  }
  public void testUserAddAsRoot() {
    RunScriptOnNodeUsingSsh testMe =
        new RunScriptOnNodeUsingSsh(
            sshFactory,
            eventBus,
            node,
            UserAdd.builder().login("testuser").build(),
            wrapInInitScript(false).runAsRoot(true).overrideLoginPassword("test"));

    testMe.init();

    sshClient.connect();
    expect(sshClient.getUsername()).andReturn("tester");
    expect(sshClient.getHostAddress()).andReturn("somewhere.example.com");
    expect(
            sshClient.exec(
                "sudo sh <<'RUN_SCRIPT_AS_ROOT_SSH'\n"
                    + "mkdir -p /home/users\n"
                    + "useradd -s /bin/bash -m  -d /home/users/testuser testuser\n"
                    + "chown -R testuser /home/users/testuser\n"
                    + "RUN_SCRIPT_AS_ROOT_SSH\n"))
        .andReturn(new ExecResponse("done", null, 0));
    sshClient.disconnect();
    replay(sshClient);

    testMe.call();
  }
  public void simpleTest() {
    RunScriptOnNodeUsingSsh testMe =
        new RunScriptOnNodeUsingSsh(
            sshFactory,
            node,
            exec("echo $USER\necho $USER"),
            wrapInInitScript(false).runAsRoot(false));

    testMe.init();

    sshClient.connect();
    expect(sshClient.getUsername()).andReturn("tester");
    expect(sshClient.getHostAddress()).andReturn("somewhere.example.com");
    expect(sshClient.exec("echo $USER\n" + "echo $USER\n"))
        .andReturn(new ExecResponse("tester\ntester\n", null, 0));
    sshClient.disconnect();
    replay(sshClient);

    testMe.call();
  }