提交 a559b163 编写于 作者: K kohsuke
上级 db7f908f
......@@ -713,7 +713,7 @@ public abstract class Launcher {
final InputStream in = ps.stdin==null ? null : new RemoteInputStream(ps.stdin);
final String workDir = ps.pwd==null ? null : ps.pwd.getRemote();
return new RemoteProc(getChannel().callAsync(new RemoteLaunchCallable(ps.commands, ps.envs, in, out, err, workDir, listener)));
return new RemoteProc(getChannel().callAsync(new RemoteLaunchCallable(ps.commands, ps.masks, ps.envs, in, out, err, workDir, listener)));
}
public Channel launchChannel(String[] cmd, OutputStream err, FilePath _workDir, Map<String,String> envOverrides) throws IOException, InterruptedException {
......@@ -756,6 +756,7 @@ public abstract class Launcher {
private static class RemoteLaunchCallable implements Callable<Integer,IOException> {
private final List<String> cmd;
private final boolean[] masks;
private final String[] env;
private final InputStream in;
private final OutputStream out;
......@@ -763,8 +764,9 @@ public abstract class Launcher {
private final String workDir;
private final TaskListener listener;
RemoteLaunchCallable(List<String> cmd, String[] env, InputStream in, OutputStream out, OutputStream err, String workDir, TaskListener listener) {
RemoteLaunchCallable(List<String> cmd, boolean[] masks, String[] env, InputStream in, OutputStream out, OutputStream err, String workDir, TaskListener listener) {
this.cmd = new ArrayList<String>(cmd);
this.masks = masks;
this.env = env;
this.in = in;
this.out = out;
......@@ -775,7 +777,7 @@ public abstract class Launcher {
public Integer call() throws IOException {
Launcher.ProcStarter ps = new LocalLauncher(listener).launch();
ps.cmds(cmd).envs(env).stdin(in).stdout(out).stderr(err);
ps.cmds(cmd).masks(masks).envs(env).stdin(in).stdout(out).stderr(err);
if(workDir!=null) ps.pwd(workDir);
Proc p = ps.start();
......
......@@ -47,6 +47,9 @@ import org.jvnet.animal_sniffer.IgnoreJRERequirement;
*/
public class ArgumentListBuilder implements Serializable {
private final List<String> args = new ArrayList<String>();
/**
* Bit mask indicating arguments that shouldn't be echoed-back (e.g., password)
*/
private BitSet mask = new BitSet();
public ArgumentListBuilder() {
......
......@@ -18,6 +18,7 @@ import java.util.Collections;
* Slave that pretends to fork processes.
*
* @author Kohsuke Kawaguchi
* @see HudsonTestCase#createPretendSlave(FakeLauncher)
*/
public class PretendSlave extends Slave {
private transient FakeLauncher faker;
......
/*
* The MIT License
*
* Copyright (c) 2010, Kohsuke Kawaguchi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.util;
import hudson.Launcher.RemoteLauncher;
import hudson.model.Slave;
import org.jvnet.hudson.test.Email;
import org.jvnet.hudson.test.HudsonTestCase;
import java.io.StringWriter;
/**
*
* @author Kohsuke Kawaguchi
*/
public class ArgumentListBuilder2Test extends HudsonTestCase {
/**
* Makes sure {@link RemoteLauncher} properly masks arguments.
*/
@Email("http://n4.nabble.com/Password-masking-when-running-commands-on-a-slave-tp1753033p1753033.html")
public void testSlaveMask() throws Exception {
ArgumentListBuilder args = new ArgumentListBuilder();
args.add("java");
args.addMasked("-version");
Slave s = createSlave();
s.toComputer().connect(false).get();
StringWriter out = new StringWriter();
assertEquals(0,s.createLauncher(new StreamTaskListener(out)).launch().cmds(args).join());
System.out.println(out);
assertTrue(out.toString().contains("$ java ********"));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册