[JENKINS-50324] User without READ cannot logout

- or even ask who they are
This commit is contained in:
Wadeck Follonier committed 2018-03-22 09:13:11 +01:00
1 parent 852ecdc5f2
commit b5ed977bbc
2 files changed
+27 -1

No files matched your search

@@ -273,7 +273,7 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
if (auth==Jenkins.ANONYMOUS)
auth = loadStoredAuthentication();
sc.setAuthentication(auth); // run the CLI with the right credential
if (!(this instanceof LoginCommand || this instanceof HelpCommand))
if (!(this instanceof LoginCommand || this instanceof LogoutCommand || this instanceof HelpCommand || this instanceof WhoAmICommand))
Jenkins.getActiveInstance().checkPermission(Jenkins.READ);
return run();
} catch (CmdLineException e) {
@@ -269,6 +269,32 @@ public class CLIActionTest {
assertEquals(0, proc.join());
}
@Test
@Issue("JENKINS-50324")
public void userWithoutReadCanLogout() throws Exception {
String userWithRead = "userWithRead";
String userWithoutRead = "userWithoutRead";
File jar = tmp.newFile("jenkins-cli.jar");
FileUtils.copyURLToFile(j.jenkins.getJnlpJars("jenkins-cli.jar").getURL(), jar);
j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
j.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy()
.grant(Jenkins.ADMINISTER).everywhere().to(ADMIN)
.grant(Jenkins.READ).everywhere().to(userWithRead)
// nothing to userWithoutRead
);
checkCanLogout(jar, ADMIN);
checkCanLogout(jar, userWithRead);
checkCanLogout(jar, userWithoutRead);
}
private void checkCanLogout(File cliJar, String userLoginAndPassword) throws Exception {
assertExitCode(0, false, cliJar, "-remoting", "login", "--username", userLoginAndPassword, "--password", userLoginAndPassword);
assertExitCode(0, false, cliJar, "-remoting", "who-am-i");
assertExitCode(0, false, cliJar, "-remoting", "logout");
}
@TestExtension("encodingAndLocale")
public static class TestDiagnosticCommand extends CLICommand {