Search in sources :

Example 21 with GlobalSecurityConfig

use of org.jenkinsci.test.acceptance.po.GlobalSecurityConfig in project acceptance-test-harness by jenkinsci.

the class AntisamyMarkupFormatterTest method safeHtmlTest.

@Test
public void safeHtmlTest() {
    final GlobalSecurityConfig security = new GlobalSecurityConfig(jenkins);
    security.open();
    security.selectSafeHtmlFormatter();
    security.save();
    final FreeStyleJob job = jenkins.jobs.create(FreeStyleJob.class);
    job.description(NO_HTML, true);
    assertThat(driver, hasContent(NO_HTML));
    job.description(String.format(HREF_ELEM, HREF_VALID), true);
    assertThat(driver, hasContent(HREF_MESSAGE));
    this.assertHref(HREF_VALID, true);
    job.description(String.format(HREF_ELEM, HREF_INVALID), true);
    assertThat(driver, hasContent(HREF_MESSAGE));
    this.assertHref(HREF_INVALID, false);
}
Also used : FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test)

Example 22 with GlobalSecurityConfig

use of org.jenkinsci.test.acceptance.po.GlobalSecurityConfig in project acceptance-test-harness by jenkinsci.

the class JenkinsDatabaseSecurityRealmTest method setUp.

@Before
public void setUp() {
    GlobalSecurityConfig security = new GlobalSecurityConfig(jenkins);
    security.configure();
    realm = security.useRealm(JenkinsDatabaseSecurityRealm.class);
    realm.allowUsersToSignUp(true);
    security.save();
}
Also used : GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig) JenkinsDatabaseSecurityRealm(org.jenkinsci.test.acceptance.po.JenkinsDatabaseSecurityRealm) Before(org.junit.Before)

Example 23 with GlobalSecurityConfig

use of org.jenkinsci.test.acceptance.po.GlobalSecurityConfig 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 24 with GlobalSecurityConfig

use of org.jenkinsci.test.acceptance.po.GlobalSecurityConfig in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method should_disallow_importing_groovy_classes_when_script_security_enabled.

/**
 * Verifies that if script security for Job DSL scripts is enabled and Jenkins
 * security is enabled, it is not possible to import Groovy classes from the
 * workspace.
 */
@Test
@WithPlugins({ "matrix-auth@2.3", "mock-security-realm" })
public void should_disallow_importing_groovy_classes_when_script_security_enabled() {
    GlobalSecurityConfig sc = setUpSecurity();
    jenkins.login().doLogin(ADMIN);
    FreeStyleJob seedJob = createSeedJob();
    seedJob.copyResource(resource("/job_dsl_plugin/MyUtilities.groovy"), "utilities/MyUtilities.groovy");
    JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
    jobDsl.setScript("import utilities.MyUtilities\n" + "\n" + "def newJob = job('New_Job')\n" + "MyUtilities.addDescription(newJob)");
    seedJob.save();
    // Build should fail because importing Groovy classes not allowed if script security is enabled
    Build build = seedJob.scheduleBuild().shouldFail();
    assertThat(build.getConsole(), containsString("unable to resolve class utilities.MyUtilities"));
    sc.configure(() -> sc.setJobDslScriptSecurity(false));
    seedJob.scheduleBuild().shouldSucceed();
}
Also used : JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) Build(org.jenkinsci.test.acceptance.po.Build) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 25 with GlobalSecurityConfig

use of org.jenkinsci.test.acceptance.po.GlobalSecurityConfig in project acceptance-test-harness by jenkinsci.

the class LdapPluginTest method useLdapAsSecurityRealm.

/**
 * "Jenkins is using ldap as security realm"
 */
private void useLdapAsSecurityRealm(LdapDetails ldapDetails) {
    GlobalSecurityConfig security = new GlobalSecurityConfig(jenkins);
    security.configure();
    LdapSecurityRealm realm = security.useRealm(LdapSecurityRealm.class);
    realm.configure(ldapDetails);
    security.save();
}
Also used : LdapSecurityRealm(org.jenkinsci.test.acceptance.po.LdapSecurityRealm) GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig)

Aggregations

GlobalSecurityConfig (org.jenkinsci.test.acceptance.po.GlobalSecurityConfig)29 Test (org.junit.Test)17 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)15 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)9 FreeStyleJob (org.jenkinsci.test.acceptance.po.FreeStyleJob)9 MockSecurityRealm (org.jenkinsci.test.acceptance.plugins.mock_security_realm.MockSecurityRealm)7 JobDslBuildStep (org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep)5 Build (org.jenkinsci.test.acceptance.po.Build)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 SAMLContainer (org.jenkinsci.test.acceptance.docker.fixtures.SAMLContainer)4 WithDocker (org.jenkinsci.test.acceptance.junit.WithDocker)4 MatrixAuthorizationStrategy (org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixAuthorizationStrategy)4 SamlSecurityRealm (org.jenkinsci.test.acceptance.plugins.saml.SamlSecurityRealm)4 Before (org.junit.Before)4 MatrixRow (org.jenkinsci.test.acceptance.plugins.matrix_auth.MatrixRow)3 LdapSecurityRealm (org.jenkinsci.test.acceptance.po.LdapSecurityRealm)3 LdapDetails (org.jenkinsci.test.acceptance.plugins.ldap.LdapDetails)2 ProjectBasedMatrixAuthorizationStrategy (org.jenkinsci.test.acceptance.plugins.matrix_auth.ProjectBasedMatrixAuthorizationStrategy)2 JenkinsDatabaseSecurityRealm (org.jenkinsci.test.acceptance.po.JenkinsDatabaseSecurityRealm)2 Login (org.jenkinsci.test.acceptance.po.Login)2