Permalink
Browse files

[FIXED JENKINS-43071] Use Jenkins.READ perms for linter

  • Loading branch information...
abayer committed Jul 3, 2017
1 parent c62b5e0 commit 70c91e138da4f2a65dd9f759ac188a77459b5ebf
@@ -34,7 +34,7 @@
import java.util.ArrayList;
import java.util.List;

import static hudson.security.Permission.READ;
import static jenkins.model.Jenkins.READ;

@Extension
public class DeclarativeLinterCommand extends CLICommand {
@@ -26,6 +26,7 @@

import hudson.cli.CLICommandInvoker;
import hudson.model.Item;
import hudson.model.User;
import jenkins.model.Jenkins;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
@@ -46,14 +47,16 @@

public class DeclarativeLinterCommandTest extends AbstractModelDefTest {

private DeclarativeLinterCommand declarativeLinterCommand;
private CLICommandInvoker command;

@Rule
public TemporaryFolder tmp = new TemporaryFolder();

@Before
public void setUpPerTest() {
command = new CLICommandInvoker(j, "declarative-linter");
declarativeLinterCommand = new DeclarativeLinterCommand();
command = new CLICommandInvoker(j, declarativeLinterCommand);
}

@Test
@@ -96,6 +99,14 @@ public void invalidUser() throws Exception {

assertThat(result, not(succeeded()));
assertThat(result.stderr(), containsString("ERROR: anonymous is missing the Overall/Read permission"));

declarativeLinterCommand.setTransportAuth(User.get("alice").impersonate());
final CLICommandInvoker.Result result2 = command.withStdin(FileUtils.openInputStream(testPath)).invoke();

assertThat(result2, succeeded());
assertThat(result2, hasNoErrorOutput());
assertThat(result2.stdout(), containsString("Jenkinsfile successfully validated."));

}

private File writeJenkinsfileToTmpFile(String dir, String testName) throws IOException {

0 comments on commit 70c91e1

Please sign in to comment.