Skip to content

Commit

Permalink
Add Resource Root URL test for permissions assigned to groups (jenkin…
Browse files Browse the repository at this point in the history
…sci#9906)

Co-authored-by: Daniel Beck <daniel-beck@users.noreply.github.com>
  • Loading branch information
daniel-beck and daniel-beck authored Oct 25, 2024
1 parent e553af0 commit 23bcc39
Showing 1 changed file with 28 additions and 0 deletions.
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");
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

0 comments on commit 23bcc39

Please sign in to comment.