-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f54c41
commit 0c13259
Showing
2 changed files
with
103 additions
and
2 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,80 @@ | ||
package hudson.model; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import jenkins.model.Jenkins; | ||
import org.htmlunit.html.HtmlPage; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.FlagRule; | ||
import org.jvnet.hudson.test.Issue; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.MockAuthorizationStrategy; | ||
|
||
public class Security3349Test { | ||
|
||
@Rule | ||
public JenkinsRule rule = new JenkinsRule(); | ||
|
||
@Rule public FlagRule<Boolean> skipPermissionCheck = new FlagRule<>(() -> MyViewsProperty.SKIP_PERMISSION_CHECK, x -> MyViewsProperty.SKIP_PERMISSION_CHECK = x); | ||
|
||
@Test | ||
@Issue("SECURITY-3349") | ||
public void usersCannotAccessOtherUsersViews() throws Exception { | ||
User user = User.getOrCreateByIdOrFullName("user"); | ||
User admin = User.getOrCreateByIdOrFullName("admin"); | ||
|
||
rule.jenkins.setSecurityRealm(rule.createDummySecurityRealm()); | ||
MockAuthorizationStrategy mockAuthorizationStrategy = new MockAuthorizationStrategy(); | ||
mockAuthorizationStrategy.grant(Jenkins.READ, View.READ).everywhere().to("user"); | ||
mockAuthorizationStrategy.grant(Jenkins.ADMINISTER).everywhere().to("admin"); | ||
rule.jenkins.setAuthorizationStrategy(mockAuthorizationStrategy); | ||
|
||
MyViewsProperty prop1 = new MyViewsProperty(null); | ||
MyView usersView = new MyView("User's view", prop1); | ||
user.addProperty(prop1); | ||
prop1.setUser(user); | ||
prop1.addView(usersView); | ||
|
||
MyViewsProperty prop2 = new MyViewsProperty(null); | ||
MyView adminsView = new MyView("Admin's view", prop2); | ||
admin.addProperty(prop2); | ||
prop2.setUser(admin); | ||
prop2.addView(adminsView); | ||
|
||
try (JenkinsRule.WebClient wc = rule.createWebClient()) { | ||
wc.setThrowExceptionOnFailingStatusCode(false); | ||
wc.login("user"); | ||
|
||
HtmlPage adminViews = wc.goTo("user/admin/my-views/view/all/"); | ||
assertEquals(403, adminViews.getWebResponse().getStatusCode()); | ||
|
||
HtmlPage adminUserPage = wc.goTo("user/admin/"); | ||
assertFalse(adminUserPage.getWebResponse().getContentAsString().contains("My Views")); | ||
|
||
HtmlPage userViews = wc.goTo("user/user/my-views/view/all/"); | ||
assertEquals(200, userViews.getWebResponse().getStatusCode()); | ||
|
||
HtmlPage userUserPage = wc.goTo("user/user/"); | ||
assertTrue(userUserPage.getWebResponse().getContentAsString().contains("My Views")); | ||
|
||
wc.login("admin"); | ||
|
||
adminViews = wc.goTo("user/admin/my-views/view/all/"); | ||
assertEquals(200, adminViews.getWebResponse().getStatusCode()); | ||
userViews = wc.goTo("user/user/my-views/view/all/"); | ||
assertEquals(200, userViews.getWebResponse().getStatusCode()); | ||
|
||
MyViewsProperty.SKIP_PERMISSION_CHECK = true; | ||
|
||
wc.login("user"); | ||
adminViews = wc.goTo("user/admin/my-views/view/all/"); | ||
assertEquals(200, adminViews.getWebResponse().getStatusCode()); | ||
adminUserPage = wc.goTo("user/admin/"); | ||
assertTrue(adminUserPage.getWebResponse().getContentAsString().contains("My Views")); | ||
|
||
} | ||
} | ||
} |