Package com.xebialabs.overthere

Examples of com.xebialabs.overthere.CmdLine


    public void shouldQuoteOriginalCommand() {
        connectionOptions.set(SUDO_COMMAND_PREFIX, "su -u {0}");
        connectionOptions.set(SUDO_QUOTE_COMMAND, true);
        connection = new SshSudoConnection(SSH_PROTOCOL, connectionOptions, resolver);

        CmdLine cmdLine = connection.processCommandLine(CmdLine.build("ls", "/tmp"));
        List<CmdLineArgument> args = cmdLine.getArguments();
        assertThat(args.size(), equalTo(4));
        assertThat(args.get(0).toString(UNIX, false), equalTo("su"));
        assertThat(args.get(1).toString(UNIX, false), equalTo("-u"));
        assertThat(args.get(2).toString(UNIX, false), equalTo("some-other-user"));
        assertThat(args.get(3).toString(UNIX, false), equalTo("ls\\ /tmp"));
        assertThat(cmdLine.toString(), equalTo("su -u some-other-user ls\\ /tmp"));
    }
View Full Code Here


    @Test
    public void commandWithPipeShouldHaveTwoSudoSectionsIfNotQuotingCommand() {
        connection = new SshSudoConnection(SSH_PROTOCOL, connectionOptions, resolver);

        CmdLine cmdLine = new CmdLine().addArgument("a").addRaw("|").addArgument("b");
        List<CmdLineArgument> prefixed = connection.prefixWithElevationCommand(cmdLine).getArguments();
        assertThat(prefixed.size(), equalTo(9));
        assertThat(prefixed.get(0).toString(UNIX, false), equalTo("sudo"));
        assertThat(prefixed.get(5).toString(UNIX, false), equalTo("sudo"));
    }
View Full Code Here

    public void commandWithPipeShouldNotHaveTwoSudoSectionsIfQuotingCommand() {
        connectionOptions.set(SUDO_COMMAND_PREFIX, "su -u {0}");
        connectionOptions.set(SUDO_QUOTE_COMMAND, true);
        connection = new SshSudoConnection(SSH_PROTOCOL, connectionOptions, resolver);

        CmdLine cmdLine = new CmdLine().addArgument("a").addRaw("|").addArgument("b");
        List<CmdLineArgument> prefixed = connection.prefixWithElevationCommand(cmdLine).getArguments();
        assertThat(prefixed.size(), equalTo(4));
        assertThat(prefixed.get(0).toString(UNIX, false), equalTo("su"));
        assertThat(prefixed.get(1).toString(UNIX, false), equalTo("-u"));
        assertThat(prefixed.get(2).toString(UNIX, false), equalTo("some-other-user"));
View Full Code Here

    @Test
    public void commandWithSemiColonShouldHaveTwoSudoSectionsIfNotQuotingCommand() {
        connection = new SshSudoConnection(SSH_PROTOCOL, connectionOptions, resolver);

        CmdLine cmdLine = new CmdLine().addArgument("a").addRaw(";").addArgument("b");
        List<CmdLineArgument> prefixed = connection.prefixWithElevationCommand(cmdLine).getArguments();
        assertThat(prefixed.size(), equalTo(9));
        assertThat(prefixed.get(0).toString(UNIX, false), equalTo("sudo"));
        assertThat(prefixed.get(5).toString(UNIX, false), equalTo("sudo"));
    }
View Full Code Here

    public void commandWithSemiColonShouldNotHaveTwoSudoSectionsIfQuotingCommand() {
        connectionOptions.set(SUDO_COMMAND_PREFIX, "su -u {0}");
        connectionOptions.set(SUDO_QUOTE_COMMAND, true);
        connection = new SshSudoConnection(SSH_PROTOCOL, connectionOptions, resolver);

        CmdLine cmdLine = new CmdLine().addArgument("a").addRaw(";").addArgument("b");
        List<CmdLineArgument> prefixed = connection.prefixWithElevationCommand(cmdLine).getArguments();
        assertThat(prefixed.size(), equalTo(4));
        assertThat(prefixed.get(0).toString(UNIX, false), equalTo("su"));
        assertThat(prefixed.get(1).toString(UNIX, false), equalTo("-u"));
        assertThat(prefixed.get(2).toString(UNIX, false), equalTo("some-other-user"));
View Full Code Here

    @Test
    public void canExecuteCommand() {
        OverthereFile tempFile = connection.getTempFile("afile");
        OverthereUtils.write("Some text", "UTF-8", tempFile);
        String lsCommand = connection.getHostOperatingSystem() == UNIX ? "ls" : "dir";
        CmdLine commandLine = CmdLine.build(lsCommand, tempFile.getParentFile().getPath());
        CapturingOverthereExecutionOutputHandler handler = capturingHandler();

        int res = connection.execute(handler, syserrHandler(), commandLine);
        assertThat(res, equalTo(0));
        assertThat(handler.getOutputLines().contains(tempFile.getName()), equalTo(true));
View Full Code Here

TOP

Related Classes of com.xebialabs.overthere.CmdLine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.