-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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 #86 from jenkinsci-cert/SECURITY-380
[FIX SECURITY-380] Don't optimize permission check in getItems()
- Loading branch information
Showing
2 changed files
with
95 additions
and
6 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,95 @@ | ||
package jenkins.security; | ||
|
||
import com.gargoylesoftware.htmlunit.Page; | ||
import hudson.model.UnprotectedRootAction; | ||
import hudson.security.ACL; | ||
import hudson.security.FullControlOnceLoggedInAuthorizationStrategy; | ||
import hudson.util.HttpResponses; | ||
import jenkins.model.Jenkins; | ||
import org.junit.Assert; | ||
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.TestExtension; | ||
import org.kohsuke.stapler.HttpResponse; | ||
|
||
public class Security380Test { | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Issue("SECURITY-380") | ||
@Test | ||
public void testGetItemsWithoutAnonRead() throws Exception { | ||
FullControlOnceLoggedInAuthorizationStrategy strategy = new FullControlOnceLoggedInAuthorizationStrategy(); | ||
strategy.setAllowAnonymousRead(false); | ||
Jenkins.getInstance().setAuthorizationStrategy(strategy); | ||
|
||
Jenkins.getInstance().setSecurityRealm(j.createDummySecurityRealm()); | ||
|
||
j.createFreeStyleProject(); | ||
ACL.impersonate(Jenkins.ANONYMOUS, new Runnable() { | ||
@Override | ||
public void run() { | ||
Assert.assertEquals("no items", 0, Jenkins.getInstance().getItems().size()); | ||
} | ||
}); | ||
} | ||
|
||
@Issue("SECURITY-380") | ||
@Test | ||
public void testGetItems() throws Exception { | ||
FullControlOnceLoggedInAuthorizationStrategy strategy = new FullControlOnceLoggedInAuthorizationStrategy(); | ||
strategy.setAllowAnonymousRead(true); | ||
Jenkins.getInstance().setAuthorizationStrategy(strategy); | ||
|
||
Jenkins.getInstance().setSecurityRealm(j.createDummySecurityRealm()); | ||
|
||
j.createFreeStyleProject(); | ||
ACL.impersonate(Jenkins.ANONYMOUS, new Runnable() { | ||
@Override | ||
public void run() { | ||
Assert.assertEquals("one item", 1, Jenkins.getInstance().getItems().size()); | ||
} | ||
}); | ||
} | ||
|
||
@Issue("SECURITY-380") | ||
@Test | ||
public void testWithUnprotectedRootAction() throws Exception { | ||
FullControlOnceLoggedInAuthorizationStrategy strategy = new FullControlOnceLoggedInAuthorizationStrategy(); | ||
strategy.setAllowAnonymousRead(false); | ||
Jenkins.getInstance().setAuthorizationStrategy(strategy); | ||
|
||
Jenkins.getInstance().setSecurityRealm(j.createDummySecurityRealm()); | ||
j.createFreeStyleProject(); | ||
|
||
JenkinsRule.WebClient wc = j.createWebClient(); | ||
Page page = wc.goTo("listJobs", "text/plain"); | ||
Assert.assertEquals("expect 0 items", "0", page.getWebResponse().getContentAsString().trim()); | ||
} | ||
|
||
@TestExtension | ||
public static class JobListingUnprotectedRootAction implements UnprotectedRootAction { | ||
|
||
@Override | ||
public String getIconFileName() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getUrlName() { | ||
return "listJobs"; | ||
} | ||
|
||
public HttpResponse doIndex() throws Exception { | ||
return HttpResponses.plainText(Integer.toString(Jenkins.getInstance().getItems().size())); | ||
} | ||
} | ||
} |