Search in sources :

Example 6 with MockSecurityRealm

use of org.jenkinsci.test.acceptance.plugins.mock_security_realm.MockSecurityRealm in project acceptance-test-harness by jenkinsci.

the class CredentialsTest method createUserAndLogin.

private void createUserAndLogin() {
    final GlobalSecurityConfig security = new GlobalSecurityConfig(jenkins);
    security.open();
    MockSecurityRealm realm = security.useRealm(MockSecurityRealm.class);
    realm.configure(JENKINS_USER);
    security.save();
    jenkins.login().doLogin(JENKINS_USER);
}
Also used : MockSecurityRealm(org.jenkinsci.test.acceptance.plugins.mock_security_realm.MockSecurityRealm) GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig)

Example 7 with MockSecurityRealm

use of org.jenkinsci.test.acceptance.plugins.mock_security_realm.MockSecurityRealm in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method setUpSecurity.

/**
 * Set up global security. Two users 'admin', with admin permission,
 * and 'user', with permissions necessary to manipulate jobs, will be generated.
 * Script security for Job DSL scripts will be enabled.
 * @return The global security configuration.
 */
private GlobalSecurityConfig setUpSecurity() {
    GlobalSecurityConfig sc = new GlobalSecurityConfig(jenkins);
    sc.configure(() -> {
        MockSecurityRealm ms = sc.useRealm(MockSecurityRealm.class);
        ms.configure(ADMIN, USER);
        MatrixAuthorizationStrategy mas = sc.useAuthorizationStrategy(MatrixAuthorizationStrategy.class);
        MatrixRow a = mas.addUser(ADMIN);
        a.admin();
        MatrixRow b = mas.addUser(USER);
        b.developer();
        sc.setJobDslScriptSecurity(true);
    });
    return sc;
}
Also used : MockSecurityRealm(org.jenkinsci.test.acceptance.plugins.mock_security_realm.MockSecurityRealm) MatrixRow(org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixRow) GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig) MatrixAuthorizationStrategy(org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixAuthorizationStrategy)

Example 8 with MockSecurityRealm

use of org.jenkinsci.test.acceptance.plugins.mock_security_realm.MockSecurityRealm in project acceptance-test-harness by jenkinsci.

the class MatrixAuthPluginTest method projectMatrixAuth.

/**
 * Test scenario:
 */
@Test
public void projectMatrixAuth() throws Exception {
    GlobalSecurityConfig sc = new GlobalSecurityConfig(jenkins);
    sc.open();
    {
        MockSecurityRealm ms = sc.useRealm(MockSecurityRealm.class);
        ms.configure("alice", "bob");
        ProjectBasedMatrixAuthorizationStrategy mas = sc.useAuthorizationStrategy(ProjectBasedMatrixAuthorizationStrategy.class);
        MatrixRow a = mas.addUser("alice");
        a.admin();
        MatrixRow bob = mas.addUser("bob");
        bob.on(OVERALL_READ);
    }
    sc.save();
    jenkins.login().doLogin("alice");
    // just create the job without configuring
    FreeStyleJob j = jenkins.jobs.create();
    jenkins.logout();
    // bob shouldn't be able to see it without adding a permission for him
    jenkins.login().doLogin("bob");
    // check for job's existence
    assertFalse(j.open().getTitle().contains(j.name));
    jenkins.logout();
    // alice will expose this job to bob
    jenkins.login().doLogin("alice");
    j.configure();
    {
        ProjectMatrixProperty p = new ProjectMatrixProperty(j);
        p.enable.check();
        MatrixRow bob = p.addUser("bob");
        bob.on(ITEM_READ);
    }
    j.save();
    jenkins.logout();
    // bob should see this job
    jenkins.login().doLogin("bob");
    assertTrue(j.open().getTitle().contains(j.name));
}
Also used : ProjectMatrixProperty(org.jenkinsci.test.acceptance.plugins.matrix_auth.ProjectMatrixProperty) MockSecurityRealm(org.jenkinsci.test.acceptance.plugins.mock_security_realm.MockSecurityRealm) MatrixRow(org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixRow) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig) ProjectBasedMatrixAuthorizationStrategy(org.jenkinsci.test.acceptance.plugins.matrix_auth.ProjectBasedMatrixAuthorizationStrategy) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test)

Aggregations

MockSecurityRealm (org.jenkinsci.test.acceptance.plugins.mock_security_realm.MockSecurityRealm)8 GlobalSecurityConfig (org.jenkinsci.test.acceptance.po.GlobalSecurityConfig)7 MatrixAuthorizationStrategy (org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixAuthorizationStrategy)4 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)3 MatrixRow (org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixRow)3 Test (org.junit.Test)3 ProjectBasedMatrixAuthorizationStrategy (org.jenkinsci.test.acceptance.plugins.matrix_auth.ProjectBasedMatrixAuthorizationStrategy)2 FreeStyleJob (org.jenkinsci.test.acceptance.po.FreeStyleJob)2 ProjectMatrixProperty (org.jenkinsci.test.acceptance.plugins.matrix_auth.ProjectMatrixProperty)1 User (org.jenkinsci.test.acceptance.po.User)1 Before (org.junit.Before)1