Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routine maintenance #15

Merged
merged 1 commit into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
buildPlugin(jenkinsVersions: [null, '2.89.3'])
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.19</version>
<version>3.2</version>
<relativePath/>
</parent>
<artifactId>build-token-root</artifactId>
<version>1.5-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>Build Authorization Token Root Plugin</name>
<description>Lets build and related REST build triggers be accessed even when anonymous users cannot see Jenkins.</description>
<url>https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin</url>
<url>https://wiki.jenkins.io/display/JENKINS/Build+Token+Root+Plugin</url>
<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<url>https://opensource.org/licenses/MIT</url>
</license>
</licenses>
<developers>
Expand All @@ -26,8 +26,8 @@
</developer>
</developers>
<properties>
<jenkins.version>1.580.1</jenkins.version>
<java.level>6</java.level>
<jenkins.version>2.7.3</jenkins.version>
<java.level>7</java.level>
<workflow.version>1.4.3</workflow.version>
</properties>
<dependencies>
Expand Down Expand Up @@ -59,19 +59,19 @@
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<scm>
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>http://github.com/jenkinsci/${project.artifactId}-plugin</url>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
<tag>HEAD</tag>
</scm>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

package org.jenkinsci.plugins.build_token_root;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Extension;
import hudson.model.Cause;
import hudson.model.CauseAction;
Expand All @@ -46,8 +45,9 @@
import java.util.logging.Logger;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import static javax.servlet.http.HttpServletResponse.SC_CREATED;
import jenkins.model.Jenkins;
import jenkins.model.ParameterizedJobMixIn;
import jenkins.triggers.SCMTriggerItem;
Expand All @@ -60,9 +60,6 @@
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import static javax.servlet.http.HttpServletResponse.SC_CREATED;

@SuppressFBWarnings(value="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification="Jenkins.getInstance() can be assumed non-null from web methods")
@Extension
public class BuildRootAction implements UnprotectedRootAction {

Expand Down Expand Up @@ -111,7 +108,7 @@ public void doBuildWithParameters(StaplerRequest req, StaplerResponse rsp, @Quer
LOGGER.fine("wrong kind");
throw HttpResponses.error(HttpServletResponse.SC_BAD_REQUEST, "Use /buildByToken/build for this job since it takes no parameters");
}
List<ParameterValue> values = new ArrayList<ParameterValue>();
List<ParameterValue> values = new ArrayList<>();
for (ParameterDefinition d : pp.getParameterDefinitions()) {
ParameterValue value = d.createValue(req);
if (value != null) {
Expand Down Expand Up @@ -189,9 +186,9 @@ private CauseAction getBuildCause(StaplerRequest req) {

private void ok(StaplerResponse rsp) throws IOException {
rsp.setContentType("text/html");
PrintWriter w = rsp.getWriter();
w.write("Scheduled.\n");
w.close();
try (PrintWriter w = rsp.getWriter()) {
w.write("Scheduled.\n");
}
}

@Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,35 +41,31 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import jenkins.model.ParameterizedJobMixIn;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.PresetData;
import org.jvnet.hudson.test.LoggerRule;
import org.jvnet.hudson.test.MockAuthorizationStrategy;

@SuppressWarnings({"deprecation", "unchecked"}) // RunList.size, BuildAuthorizationToken, AbstractItem.getParent snafu
public class BuildRootActionTest {

private static final Logger logger = Logger.getLogger(BuildRootAction.class.getName());
@BeforeClass public static void logging() {
logger.setLevel(Level.ALL);
Handler handler = new ConsoleHandler();
handler.setLevel(Level.ALL);
logger.addHandler(handler);
}

@Rule public JenkinsRule j = new JenkinsRule();
@Rule public LoggerRule logging = new LoggerRule().record(BuildRootAction.class, Level.ALL);

@Before public void noAnonymousReadAccess() {
j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
j.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy().grant(Jenkins.ADMINISTER).everywhere().toAuthenticated());
}

@PresetData(PresetData.DataSet.NO_ANONYMOUS_READACCESS)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Test public void build() throws Exception {
testBuild(j.createFreeStyleProject("p"));
}
Expand Down Expand Up @@ -116,15 +112,13 @@ private void assertCreated(Page page) throws Exception {
}

@Issue("JENKINS-26693")
@PresetData(PresetData.DataSet.NO_ANONYMOUS_READACCESS)
@Test public void buildWorkflow() throws Exception {
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("", true));
testBuild(p);
}

@Issue("JENKINS-28543")
@PresetData(PresetData.DataSet.NO_ANONYMOUS_READACCESS)
@Test public void buildWithParameters() throws Exception {
FreeStyleProject p = j.createFreeStyleProject("p");
setAuthToken(p);
Expand All @@ -143,12 +137,11 @@ private void assertCreated(Page page) throws Exception {
// TODO test projects in folders

@Issue("JENKINS-25637")
@PresetData(PresetData.DataSet.NO_ANONYMOUS_READACCESS)
@Test public void testCrumbBypass() throws Exception {
FreeStyleProject p = j.createFreeStyleProject("p");
setAuthToken(p);

List<NameValuePair> parameters = new ArrayList<NameValuePair>();
List<NameValuePair> parameters = new ArrayList<>();
parameters.add(new NameValuePair("job", p.getFullName()));
parameters.add(new NameValuePair("token", "secret"));
parameters.add(new NameValuePair("delay", "0sec"));
Expand Down