Search in sources :

Example 26 with GlobalSecurityConfig

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

the class LdapPluginTest method login_use_fallback_server.

@Test
public void login_use_fallback_server() {
    // Given
    LdapContainer ldapContainer = ldap.get();
    GlobalSecurityConfig securityConfig = new GlobalSecurityConfig(jenkins);
    securityConfig.configure();
    LdapSecurityRealm realm = securityConfig.useRealm(LdapSecurityRealm.class);
    int freePort = this.findAvailablePort();
    LdapDetails ldapDetails = new LdapDetails("", 0, ldapContainer.getManagerDn(), ldapContainer.getManagerPassword(), ldapContainer.getRootDn());
    // Fallback-Config: primary server is not running, alternative server is running docker fixture
    ldapDetails.setHostWithPort("localhost:" + freePort + ' ' + ldapContainer.getHost() + ':' + ldapContainer.getPort());
    realm.configure(ldapDetails);
    securityConfig.save();
    // When
    Login login = jenkins.login();
    login.doLogin("jenkins", "root");
    // Then
    assertThat(jenkins, hasLoggedInUser("jenkins"));
}
Also used : LdapDetails(org.jenkinsci.test.acceptance.plugins.ldap.LdapDetails) LdapSecurityRealm(org.jenkinsci.test.acceptance.po.LdapSecurityRealm) Login(org.jenkinsci.test.acceptance.po.Login) LdapContainer(org.jenkinsci.test.acceptance.docker.fixtures.LdapContainer) GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig) Test(org.junit.Test)

Example 27 with GlobalSecurityConfig

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

the class LdapPluginTest method login_no_ldap.

@Test
public void login_no_ldap() throws InterruptedException {
    // Given
    // don't start docker fixture here
    // When
    GlobalSecurityConfig security = new GlobalSecurityConfig(jenkins);
    security.configure();
    LdapSecurityRealm realm = security.useRealm(LdapSecurityRealm.class);
    int freePort = findAvailablePort();
    LdapDetails notRunningLdap = new LdapDetails("localhost", freePort, "cn=admin,dc=jenkins-ci,dc=org", "root", "dc=jenkins-ci,dc=org");
    realm.configure(notRunningLdap);
    security.save();
    // Then
    waitFor(security.open(), hasContent("Unable to connect to localhost:" + freePort), 5);
    Login login = jenkins.login();
    login.doLogin("jenkins", "root");
    assertThat(jenkins, not(hasLoggedInUser("jenkins")));
}
Also used : LdapDetails(org.jenkinsci.test.acceptance.plugins.ldap.LdapDetails) LdapSecurityRealm(org.jenkinsci.test.acceptance.po.LdapSecurityRealm) Login(org.jenkinsci.test.acceptance.po.Login) GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig) Test(org.junit.Test)

Example 28 with GlobalSecurityConfig

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

Example 29 with GlobalSecurityConfig

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

the class SAMLPluginTest method authenticationOKPostBinding.

@Test
@WithDocker
@WithPlugins({ "saml", "matrix-auth" })
public void authenticationOKPostBinding() throws IOException, InterruptedException {
    // navigate to root
    jenkins.open();
    String rootUrl = jenkins.getCurrentUrl();
    SAMLContainer samlServer = startSimpleSAML(rootUrl);
    GlobalSecurityConfig sc = new GlobalSecurityConfig(jenkins);
    sc.open();
    // Authentication
    SamlSecurityRealm realm = configureBasicSettings(sc);
    String idpMetadata = readIdPMetadataFromURL(samlServer);
    realm.setXml(idpMetadata);
    realm.setBinding(SAML2_POST_BINDING_URI);
    configureEncrytion(realm);
    configureAuthorization(sc);
    // SAML service login page
    waitFor().withTimeout(10, TimeUnit.SECONDS).until(() -> hasContent("Enter your username and password"));
    // SAML server login
    makeLoginWithUser1();
}
Also used : SAMLContainer(org.jenkinsci.test.acceptance.docker.fixtures.SAMLContainer) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig) SamlSecurityRealm(org.jenkinsci.test.acceptance.plugins.saml.SamlSecurityRealm) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins) WithDocker(org.jenkinsci.test.acceptance.junit.WithDocker)

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