Skip to content
Browse files
[FIXED JENKINS-23988] Consider CLIAuthenticator for CLIMethods
  • Loading branch information
daniel-beck committed Jul 26, 2014
1 parent 551c968 commit 867884f6328a4a16899c49859230442b5316aee1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
@@ -149,8 +149,6 @@ private CmdLineParser bindMethod(List<MethodBinder> binders) {
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 int main(List<String> args, Locale locale, InputStream stdin, PrintStream
try {
// authentication
CliAuthenticator authenticator = Jenkins.getInstance().getSecurityRealm().createCliAuthenticator(this);
new ClassParser().parse(authenticator,parser);

// fill up all the binders
@@ -0,0 +1,61 @@
package hudson.cli;

import hudson.ExtensionComponent;
import hudson.cli.declarative.CLIRegisterer;
import hudson.model.Hudson;
import jenkins.model.Jenkins;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Locale;

public class CLIRegistererTest {

public JenkinsRule j = new JenkinsRule();

public void testAuthWithSecurityRealmCLIAuthenticator() {

Collection<ExtensionComponent<CLICommand>> extensions = new CLIRegisterer().find(CLICommand.class, (Hudson) j.getInstance());

CLICommand quietCommand = null;
CLICommand cancelCommand = null;

Assert.assertFalse("Jenkins not in quiet down mode", Jenkins.getInstance().isQuietingDown());

for (ExtensionComponent<CLICommand> extension : extensions) {
CLICommand command = extension.getInstance();
if (command.getName().equals("quiet-down")) {
quietCommand = command;
if (command.getName().equals("cancel-quiet-down")) {
cancelCommand = command;


ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream out = new PrintStream(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);

// run the CLI command with valid credentials
int quietResult = quietCommand.main(Arrays.asList("--username", "foo", "--password", "foo"), Locale.ENGLISH, bais, out, out);
Assert.assertTrue("Jenkins put into quiet down mode", Jenkins.getInstance().isQuietingDown());

// run the CLI command with invalid credentials
int cancelResult = cancelCommand.main(Arrays.asList("--username", "foo", "--password", "invalid"), Locale.ENGLISH, bais, out, out);
Assert.assertTrue("Jenkins still in quiet down mode", Jenkins.getInstance().isQuietingDown());

0 comments on commit 867884f

Please sign in to comment.