-
Notifications
You must be signed in to change notification settings - Fork 714
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
73afe3c
commit 1c531c1
Showing
2 changed files
with
69 additions
and
0 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
51 changes: 51 additions & 0 deletions
51
plugin/src/test/java/io/jenkins/plugins/casc/Security1290Test.java
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,51 @@ | ||
package io.jenkins.plugins.casc; | ||
|
||
import com.gargoylesoftware.htmlunit.HttpMethod; | ||
import com.gargoylesoftware.htmlunit.WebRequest; | ||
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule; | ||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import jenkins.model.Jenkins; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.MockAuthorizationStrategy; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class Security1290Test { | ||
|
||
@Rule | ||
public JenkinsConfiguredWithCodeRule j = new JenkinsConfiguredWithCodeRule(); | ||
|
||
@Test | ||
public void configurationAsCodePagesPermissions() throws Exception { | ||
final String ADMIN = "admin"; | ||
final String USER = "user"; | ||
|
||
j.jenkins.setCrumbIssuer(null); | ||
j.jenkins.setSecurityRealm(j.createDummySecurityRealm()); | ||
j.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy() | ||
.grant(Jenkins.ADMINISTER).everywhere().to(ADMIN) | ||
.grant(Jenkins.READ).everywhere().to(USER) | ||
); | ||
|
||
JenkinsRule.WebClient adminWc = j.createWebClient(); | ||
adminWc.login(ADMIN); | ||
|
||
JenkinsRule.WebClient userWc = j.createWebClient() | ||
.withThrowExceptionOnFailingStatusCode(false); | ||
userWc.login(USER); | ||
|
||
assertRightPermissionConfigurations("configuration-as-code/schema", adminWc, userWc); | ||
assertRightPermissionConfigurations("configuration-as-code/reference", adminWc, userWc); | ||
} | ||
|
||
private void assertRightPermissionConfigurations(String relativeUrl, JenkinsRule.WebClient adminWc, JenkinsRule.WebClient userWc) throws IOException { | ||
WebRequest request = new WebRequest(new URL(j.getURL() + relativeUrl), HttpMethod.GET); | ||
|
||
assertEquals(HttpURLConnection.HTTP_OK, adminWc.getPage(request).getWebResponse().getStatusCode()); | ||
assertEquals(HttpURLConnection.HTTP_FORBIDDEN, userWc.getPage(request).getWebResponse().getStatusCode()); | ||
} | ||
} |