提交 c869cfdc 编写于 作者: D Daniel Beck

Merge pull request #1340 from daniel-beck/JENKINS-23988

[FIXED JENKINS-23988] Consider CLIAuthenticator for CLIMethods
......@@ -149,8 +149,6 @@ public class CLIRegisterer extends ExtensionFinder {
while (!chains.isEmpty())
binders.add(new MethodBinder(chains.pop(),this,parser));
new ClassParser().parse(Jenkins.getInstance().getSecurityRealm().createCliAuthenticator(this), parser);
return parser;
}
......@@ -169,6 +167,7 @@ public class CLIRegisterer extends ExtensionFinder {
try {
// authentication
CliAuthenticator authenticator = Jenkins.getInstance().getSecurityRealm().createCliAuthenticator(this);
new ClassParser().parse(authenticator,parser);
// fill up all the binders
parser.parseArgument(args);
......
package hudson.cli;
import static hudson.cli.CLICommandInvoker.Matcher.failedWith;
import static hudson.cli.CLICommandInvoker.Matcher.succeededSilently;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
import jenkins.model.Jenkins;
import hudson.cli.CLICommandInvoker;
import hudson.cli.CLICommandInvoker.Result;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
public class CLIRegistererTest {
@Rule
public JenkinsRule j = new JenkinsRule();
@Test
public void testAuthWithSecurityRealmCLIAuthenticator() {
j.getInstance().setSecurityRealm(j.createDummySecurityRealm());
CLICommandInvoker command = new CLICommandInvoker(j, "quiet-down");
Result invocation = command.invokeWithArgs("--username", "foo", "--password", "invalid");
assertThat(invocation, failedWith(1));
assertThat(invocation.stderr(), containsString("BadCredentialsException: foo"));
Assert.assertFalse("Unauthorized command was executed", Jenkins.getInstance().isQuietingDown());
invocation = command.invokeWithArgs("--username", "foo", "--password", "foo");
assertThat(invocation, succeededSilently());
Assert.assertTrue("Authorized command was not executed", Jenkins.getInstance().isQuietingDown());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册