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

Add Resource Root URL test for permissions assigned to groups #9906

Merged
merged 1 commit into from
Oct 25, 2024
Merged
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
28 changes: 28 additions & 0 deletions test/src/test/java/jenkins/security/ResourceDomainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,34 @@ public void prepare() throws Exception {
configuration.setUrl(resourceRoot);
}

@Test
public void groupPermissionsWork() throws Exception {
final JenkinsRule.DummySecurityRealm securityRealm = j.createDummySecurityRealm();
securityRealm.addGroups("alice", "admins");
Copy link
Member Author

Choose a reason for hiding this comment

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

Commenting out this line makes the test fail.

j.jenkins.setSecurityRealm(securityRealm);
MockAuthorizationStrategy a = new MockAuthorizationStrategy().grant(Jenkins.READ).everywhere().to("admins");
j.jenkins.setAuthorizationStrategy(a);

JenkinsRule.WebClient webClient = j.createWebClient().login("alice");

{ // DBS directory listing is shown as always
Page page = webClient.goTo("userContent");
Assert.assertEquals("successful request", 200, page.getWebResponse().getStatusCode());
Assert.assertTrue("still on the original URL", page.getUrl().toString().contains("/userContent"));
Assert.assertTrue("web page", page.isHtmlPage());
Assert.assertTrue("complex web page", page.getWebResponse().getContentAsString().contains("javascript"));
}
{ // DBS on primary domain forwards to second domain when trying to access a file URL
webClient.setRedirectEnabled(true);
Page page = webClient.goTo("userContent/readme.txt", "text/plain");
final String resourceResponseUrl = page.getUrl().toString();
Assert.assertEquals("resource response success", 200, page.getWebResponse().getStatusCode());
Assert.assertNull("no CSP headers", page.getWebResponse().getResponseHeaderValue("Content-Security-Policy"));
Assert.assertTrue("Served from resource domain", resourceResponseUrl.contains(RESOURCE_DOMAIN));
Assert.assertTrue("Served from resource action", resourceResponseUrl.contains("static-files"));
}
}

@Test
public void secondDomainBasics() throws Exception {
JenkinsRule.WebClient webClient = j.createWebClient();
Expand Down
Loading