Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1340 from daniel-beck/JENKINS-23988
[FIXED JENKINS-23988] Consider CLIAuthenticator for CLIMethods
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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()); | ||
} | ||
} |