Search in sources :

Example 16 with MockAuthorizationStrategy

use of org.jvnet.hudson.test.MockAuthorizationStrategy in project configuration-as-code-plugin by jenkinsci.

the class PermissionsTest method checkPermissionsForManager.

@Test
public void checkPermissionsForManager() throws Exception {
    final String MANAGER = "manager";
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    j.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy().grant(Jenkins.READ).everywhere().to(MANAGER).grant(Jenkins.MANAGE).everywhere().to(MANAGER));
    JenkinsRule.WebClient webClient = j.createWebClient().withThrowExceptionOnFailingStatusCode(false);
    assertUserPermissions(webClient, MANAGER, ImmutableMap.<Action, Boolean>builder().put(RELOAD_EXISTING_CONFIGURATION, true).build());
}
Also used : MockAuthorizationStrategy(org.jvnet.hudson.test.MockAuthorizationStrategy) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClient(org.jvnet.hudson.test.JenkinsRule.WebClient) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) Test(org.junit.Test)

Example 17 with MockAuthorizationStrategy

use of org.jvnet.hudson.test.MockAuthorizationStrategy in project configuration-as-code-plugin by jenkinsci.

the class PermissionsTest method checkPermissionsForAdmin.

@Test
public void checkPermissionsForAdmin() throws Exception {
    final String ADMIN = "admin";
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    j.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy().grant(Jenkins.ADMINISTER).everywhere().to(ADMIN));
    JenkinsRule.WebClient webClient = j.createWebClient().withThrowExceptionOnFailingStatusCode(false);
    assertUserPermissions(webClient, ADMIN, ImmutableMap.<Action, Boolean>builder().put(VIEW_CONFIGURATION, true).put(DOWNLOAD_CONFIGURATION, true).put(APPLY_NEW_CONFIGURATION, true).put(RELOAD_EXISTING_CONFIGURATION, true).build());
}
Also used : MockAuthorizationStrategy(org.jvnet.hudson.test.MockAuthorizationStrategy) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClient(org.jvnet.hudson.test.JenkinsRule.WebClient) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) Test(org.junit.Test)

Aggregations

MockAuthorizationStrategy (org.jvnet.hudson.test.MockAuthorizationStrategy)17 Test (org.junit.Test)14 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)8 Matchers.containsString (org.hamcrest.Matchers.containsString)5 WebClient (org.jvnet.hudson.test.JenkinsRule.WebClient)5 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)4 Issue (org.jvnet.hudson.test.Issue)4 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)3 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)3 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)2 RestartableJenkinsRule (org.jvnet.hudson.test.RestartableJenkinsRule)2 ElementNotFoundException (com.gargoylesoftware.htmlunit.ElementNotFoundException)1 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)1 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 ACLContext (hudson.security.ACLContext)1 URL (java.net.URL)1 ScriptApproval (org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval)1 Statement (org.junit.runners.model.Statement)1