Skip to content

Commit

Permalink
[FIXED JENKINS-43071] Use Jenkins.READ perms for linter
Browse files Browse the repository at this point in the history
  • Loading branch information
abayer committed Jul 3, 2017
1 parent c62b5e0 commit 70c91e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Expand Up @@ -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 {
Expand Down
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 70c91e1

Please sign in to comment.