Search in sources :

Example 1 with SAMLContainer

use of org.jenkinsci.test.acceptance.docker.fixtures.SAMLContainer in project acceptance-test-harness by jenkinsci.

the class SAMLPluginTest method authenticationOKFromURL.

@Test
@WithDocker
@WithPlugins({ "saml", "matrix-auth" })
public void authenticationOKFromURL() 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);
    realm.setUrl(createIdPMetadataURL(samlServer));
    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)

Example 2 with SAMLContainer

use of org.jenkinsci.test.acceptance.docker.fixtures.SAMLContainer in project acceptance-test-harness by jenkinsci.

the class SAMLPluginTest method authenticationFail.

@Test
@WithDocker
@WithPlugins({ "saml", "matrix-auth" })
public void authenticationFail() 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);
    configureEncrytion(realm);
    configureAuthorization(sc);
    // SAML service login page
    waitFor().withTimeout(10, TimeUnit.SECONDS).until(() -> hasContent("Enter your username and password"));
    // SAML server login
    find(by.id("username")).sendKeys("user1");
    find(by.id("password")).sendKeys("WrOnGpAsSwOrD");
    find(by.button("Login")).click();
    // wait for the login to propagate
    waitFor().withTimeout(5, TimeUnit.SECONDS).until(() -> hasContent("Either no user with the given username could be found, or the password you gave was wrong").matchesSafely(driver));
    assertThat(jenkins.getCurrentUrl(), containsString("simplesaml/module.php/core/loginuserpass.php"));
}
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)

Example 3 with SAMLContainer

use of org.jenkinsci.test.acceptance.docker.fixtures.SAMLContainer in project acceptance-test-harness by jenkinsci.

the class SAMLPluginTest method authenticationOK.

@Test
@WithDocker
@WithPlugins({ "saml", "matrix-auth" })
public void authenticationOK() 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_REDIRECT_BINDING_URI);
    configureEncrytion(realm);
    configureAuthorization(sc);
    // SAML service login page
    waitFor().withTimeout(10, TimeUnit.SECONDS).until(() -> hasContent("Enter your username and password"));
    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)

Example 4 with SAMLContainer

use of org.jenkinsci.test.acceptance.docker.fixtures.SAMLContainer in project acceptance-test-harness by jenkinsci.

the class SAMLPluginTest method startSimpleSAML.

private SAMLContainer startSimpleSAML(String rootUrl) throws IOException, InterruptedException {
    Starter<SAMLContainer> starter = samlContainer.starter();
    File users = new File("src/test/resources/saml_plugin/users.php");
    File config = new File("src/test/resources/saml_plugin/config.php");
    File idp_metadata = new File("src/test/resources/saml_plugin/saml20-idp-hosted.php");
    starter.withOptions(new CommandBuilder(// service provider ID
    "-e", // service provider ID
    "SIMPLESAMLPHP_SP_ENTITY_ID=" + SERVICE_PROVIDER_ID, // login back URL
    "-e", // login back URL
    "SIMPLESAMLPHP_SP_ASSERTION_CONSUMER_SERVICE=" + rootUrl + "securityRealm/finishLogin", // unused
    "-e", // unused
    "SIMPLESAMLPHP_SP_SINGLE_LOGOUT_SERVICE=" + rootUrl + "logout", // users info
    "-v", // users info
    users.getAbsolutePath() + ":/var/www/simplesamlphp/config/authsources.php", // config info,
    "-v", // config info,
    config.getAbsolutePath() + ":/var/www/simplesamlphp/config/config.php", // IdP advanced configuration
    "-v", // IdP advanced configuration
    idp_metadata.getAbsolutePath() + ":/var/www/simplesamlphp/metadata/saml20-idp-hosted.php"));
    SAMLContainer samlServer = starter.start();
    System.out.println("============ SAML Server: " + samlServer.host() + ":" + samlServer.port());
    return samlServer;
}
Also used : SAMLContainer(org.jenkinsci.test.acceptance.docker.fixtures.SAMLContainer) CommandBuilder(org.jenkinsci.utils.process.CommandBuilder) File(java.io.File)

Example 5 with SAMLContainer

use of org.jenkinsci.test.acceptance.docker.fixtures.SAMLContainer 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

SAMLContainer (org.jenkinsci.test.acceptance.docker.fixtures.SAMLContainer)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)4 WithDocker (org.jenkinsci.test.acceptance.junit.WithDocker)4 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)4 SamlSecurityRealm (org.jenkinsci.test.acceptance.plugins.saml.SamlSecurityRealm)4 GlobalSecurityConfig (org.jenkinsci.test.acceptance.po.GlobalSecurityConfig)4 Test (org.junit.Test)4 File (java.io.File)1 CommandBuilder (org.jenkinsci.utils.process.CommandBuilder)1