1
0
Эх сурвалжийг харах

Fix hacky ephemeral port config for SAML tests (#91301)

This commit re-implements how the SAML tests configure their ephemeral ports. 
The prior implementation had 2 tasks competing over files in the output directory 
resulting in some odd behavior w.r.t. when the task was up to date or was not. 
The change here removes the unnecessary task and leverages a lazy map with 
the expand option to lazily populate the port mapping.
Jake Landis 2 жил өмнө
parent
commit
a94347e002

+ 12 - 21
x-pack/qa/saml-idp-tests/build.gradle

@@ -1,3 +1,5 @@
+import org.elasticsearch.gradle.LazyPropertyMap
+
 Project idpFixtureProject = project(':x-pack:test:idp-fixture')
 
 apply plugin: 'elasticsearch.internal-java-rest-test'
@@ -12,36 +14,25 @@ dependencies {
 testFixtures.useFixture ":x-pack:test:idp-fixture"
 
 String outputDir = "${project.buildDir}/generated-resources/${project.name}"
-def copyIdpFiles = tasks.register("copyIdpFiles", Sync) {
+tasks.register("copyIdpFiles", Sync) {
+  dependsOn idpFixtureProject.postProcessFixture
+  // Don't attempt to get ephemeral ports when Docker is not available
+  onlyIf { idpFixtureProject.postProcessFixture.state.skipped == false }
   from idpFixtureProject.files('idp/shibboleth-idp/credentials/idp-browser.pem', 'idp/shibboleth-idp/metadata/idp-metadata.xml',
     'idp/shibboleth-idp/credentials/sp-signing.key', 'idp/shibboleth-idp/credentials/sp-signing.crt');
   into outputDir
-  outputs.upToDateWhen { false } //ensure this copy is always done to prevent stale configuration
-}
-
-def setupPorts = tasks.register("setupPorts") {
-  dependsOn copyIdpFiles, idpFixtureProject.postProcessFixture
-  // Don't attempt to get ephemeral ports when Docker is not available
-  onlyIf { idpFixtureProject.postProcessFixture.state.skipped == false }
-  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")
+  def expandProps = new LazyPropertyMap<>("lazy port config")
+  expandProps.put("port", () -> idpFixtureProject.postProcessFixture.ext."test.fixtures.shibboleth-idp.tcp.4443")
+  inputs.properties(expandProps)
+  filesMatching("idp-metadata.xml") {
+    expand(expandProps)
   }
 }
 
 project.sourceSets.javaRestTest.output.dir(outputDir, builtBy: [copyIdpFiles])
 
 tasks.named("javaRestTest").configure {
-  dependsOn setupPorts
+  dependsOn tasks.named("copyIdpFiles")
   onlyIf { idpFixtureProject.postProcessFixture.state.skipped == false }
 }
 

+ 1 - 1
x-pack/test/idp-fixture/idp/shibboleth-idp/metadata/idp-metadata.xml

@@ -115,7 +115,7 @@ NgQpDdo=
         </KeyDescriptor>
 
         <SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" req-attr:supportsRequestedAttributes="true"
-                             Location="https://localhost:4443/idp/profile/SAML2/Redirect/SSO"/>
+                             Location="https://localhost:${port}/idp/profile/SAML2/Redirect/SSO"/>
 
     </IDPSSODescriptor>
 </EntityDescriptor>