Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ephemeral ports for idp-fixture #40333

Merged
merged 6 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion distribution/bwc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ bwcVersions.forPreviousUnreleased { BwcVersions.UnreleasedVersionInfo unreleased
'JAVA_HOME',
getJavaHome(it, Integer.parseInt(
lines
.findAll({ it.startsWith("ES_BUILD_JAVA=")})
.findAll({ it.startsWith("ES_BUILD_JAVA=") })
.collect({ it.replace("ES_BUILD_JAVA=java", "").trim() })
.collect({ it.replace("ES_BUILD_JAVA=openjdk", "").trim() })
.join("!!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@

public class OpenLdapTests extends ESTestCase {

public static final String OPEN_LDAP_DNS_URL = "ldaps://localhost:60636";
public static final String OPEN_LDAP_IP_URL = "ldaps://127.0.0.1:60636";
public static final String OPEN_LDAP_DNS_URL = "ldaps://localhost:" + getFromProperty("636");
public static final String OPEN_LDAP_IP_URL = "ldaps://127.0.0.1:" + getFromProperty("636");

public static final String PASSWORD = "NickFuryHeartsES";
private static final String HAWKEYE_DN = "uid=hawkeye,ou=people,dc=oldap,dc=test,dc=elasticsearch,dc=com";
Expand Down Expand Up @@ -286,4 +286,11 @@ private Map<String, Object> resolve(LDAPConnection connection, LdapMetaDataResol
resolver.resolve(connection, HAWKEYE_DN, TimeValue.timeValueSeconds(1), logger, null, future);
return future.get();
}

private static String getFromProperty(String port) {
String key = "test.fixtures.openldap.tcp." + port;
final String value = System.getProperty(key);
assertNotNull("Expected the actual value for port " + port + " to be in system property " + key, value);
return value;
}
}
28 changes: 23 additions & 5 deletions x-pack/qa/saml-idp-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,29 @@ testFixtures.useFixture ":x-pack:test:idp-fixture"


String outputDir = "${project.buildDir}/generated-resources/${project.name}"
task copyIdpCertificate(type: Copy) {
from idpFixtureProject.file('idp/shibboleth-idp/credentials/idp-browser.pem');
task copyIdpFiles(type: Copy) {
from idpFixtureProject.files('idp/shibboleth-idp/credentials/idp-browser.pem', 'idp/shibboleth-idp/metadata/idp-metadata.xml');
into outputDir
}
project.sourceSets.test.output.dir(outputDir, builtBy: copyIdpCertificate)
integTestCluster.dependsOn copyIdpCertificate
project.sourceSets.test.output.dir(outputDir, builtBy: copyIdpFiles)

task setupPorts {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing and fixing this @jaymode !
The code to look up the ports is not necessary TestFixturesPlugin already sets this up,
postProcessFixture will have extension properties with the ports, so you just need something like this: postProcessFixture.doLast { println ext."test.fixtures.shibboleth-idp.tcp.443" } Note that any testing task also gets passed a system property by the same name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for that tip!

dependsOn copyIdpFiles, idpFixtureProject.postProcessFixture
doLast {
String portString = idpFixtureProject.postProcessFixture.ext."test.fixtures.shibboleth-idp.tcp.4443"
int ephemeralPort = Integer.valueOf(portString)
File idpMetaFile = file(outputDir + '/idp-metadata.xml')
List<String> lines = idpMetaFile.readLines("UTF-8")
StringBuilder content = new StringBuilder()
for (String line : lines) {
content.append(line.replace("localhost:4443", "localhost:" + ephemeralPort))
}
idpMetaFile.delete()
idpMetaFile.createNewFile()
idpMetaFile.write(content.toString(), "UTF-8")
}
}
integTestCluster.dependsOn setupPorts

integTestCluster {
setting 'xpack.license.self_generated.type', 'trial'
Expand Down Expand Up @@ -51,8 +68,9 @@ integTestCluster {
setting 'xpack.security.authc.realms.native.native.order', '3'

setting 'xpack.ml.enabled', 'false'
setting 'logger.org.elasticsearch.xpack.security', 'TRACE'

extraConfigFile 'idp-metadata.xml', idpFixtureProject.file("idp/shibboleth-idp/metadata/idp-metadata.xml")
extraConfigFile 'idp-metadata.xml', file(outputDir + "/idp-metadata.xml")

setupCommand 'setupTestAdmin',
'bin/elasticsearch-users', 'useradd', "test_admin", '-p', 'x-pack-test-password', '-r', "superuser"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,5 +639,4 @@ private URI getWebServerUri() {
throw new ElasticsearchException("Cannot construct URI for httpServer @ {}:{}", e, host, port);
}
}

}
6 changes: 3 additions & 3 deletions x-pack/test/idp-fixture/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ services:
command: --copy-service --loglevel debug
image: "osixia/openldap:1.2.3"
ports:
- "30389:389"
- "60636:636"
- "389"
- "636"
environment:
LDAP_ADMIN_PASSWORD: "NickFuryHeartsES"
LDAP_DOMAIN: "oldap.test.elasticsearch.com"
Expand All @@ -31,7 +31,7 @@ services:
- JETTY_BROWSER_SSL_KEYSTORE_PASSWORD=secret
- JETTY_BACKCHANNEL_SSL_KEYSTORE_PASSWORD=secret
ports:
- "4443:4443"
- "4443"
links:
- openldap:openldap
volumes:
Expand Down