mirror of
https://github.com/apple/pkl.git
synced 2026-03-31 06:03:11 +02:00
Add support for HTTP proxying (#506)
* Add `--proxy` and `--no-proxy` CLI flags * Add property `http` to `pkl:settings` * Move `EvaluatorSettings` from `pkl:Project` to its own module and add property `http` * Add support for proxying in server mode, and through Gradle * Add `setProxy()` to `HttpClient` * Add documentation
This commit is contained in:
committed by
GitHub
parent
a520ae7d04
commit
b03530ed1f
@@ -1,13 +1,59 @@
|
||||
# This is a Gradle generated file for dependency locking.
|
||||
# Manual edits can break the build and are not advised.
|
||||
# This file is expected to be part of source control.
|
||||
com.ethlo.time:itu:1.8.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.fasterxml.jackson.core:jackson-annotations:2.17.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.fasterxml.jackson.core:jackson-core:2.17.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.fasterxml.jackson.core:jackson-databind:2.17.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.17.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.fasterxml.jackson:jackson-bom:2.17.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.github.ajalt.clikt:clikt-jvm:3.5.1=compileClasspath,default,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
com.github.ajalt.clikt:clikt:3.5.1=apiDependenciesMetadata,compileClasspath,default,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.github.jknack:handlebars-helpers:4.3.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.github.jknack:handlebars:4.3.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.google.errorprone:error_prone_annotations:2.26.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.google.guava:failureaccess:1.0.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.google.guava:guava:33.2.0-jre=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.google.j2objc:j2objc-annotations:3.0.0=testCompileClasspath,testImplementationDependenciesMetadata
|
||||
com.jayway.jsonpath:json-path:2.9.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.networknt:json-schema-validator:1.4.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.tunnelvisionlabs:antlr4-runtime:4.9.0=default,runtimeClasspath,testRuntimeClasspath
|
||||
net.bytebuddy:byte-buddy:1.14.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
commons-fileupload:commons-fileupload:1.5=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
commons-io:commons-io:2.11.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
net.bytebuddy:byte-buddy:1.14.16=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
net.java.dev.jna:jna:5.6.0=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
net.javacrumbs.json-unit:json-unit-core:2.38.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
net.minidev:accessors-smart:2.5.1=testRuntimeClasspath
|
||||
net.minidev:json-smart:2.5.1=testRuntimeClasspath
|
||||
net.sf.jopt-simple:jopt-simple:5.0.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.apache.httpcomponents.client5:httpclient5:5.3.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.apache.httpcomponents.core5:httpcore5-h2:5.2.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.apache.httpcomponents.core5:httpcore5:5.2.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
|
||||
org.assertj:assertj-core:3.25.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.assertj:assertj-core:3.26.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.checkerframework:checker-qual:3.42.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty.http2:http2-common:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty.http2:http2-hpack:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty.http2:http2-server:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty.toolchain:jetty-jakarta-servlet-api:5.0.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-alpn-client:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-alpn-java-client:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-alpn-java-server:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-alpn-server:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-bom:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-client:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-http:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-io:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-proxy:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-security:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-server:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-servlet:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-servlets:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-util:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-webapp:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-xml:11.0.20=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.fusesource.jansi:jansi:2.4.0=default
|
||||
org.fusesource.jansi:jansi:2.4.1=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.graalvm.compiler:compiler:23.0.2=compileClasspath,compileOnlyDependenciesMetadata
|
||||
@@ -17,6 +63,8 @@ org.graalvm.nativeimage:pointsto:23.0.2=compileClasspath,compileOnlyDependencies
|
||||
org.graalvm.nativeimage:svm:23.0.2=compileClasspath,compileOnlyDependenciesMetadata
|
||||
org.graalvm.sdk:graal-sdk:23.0.2=compileClasspath,compileOnlyDependenciesMetadata,default,runtimeClasspath,testRuntimeClasspath
|
||||
org.graalvm.truffle:truffle-api:23.0.2=compileClasspath,compileOnlyDependenciesMetadata,default,runtimeClasspath,testRuntimeClasspath
|
||||
org.hamcrest:hamcrest-core:2.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.hamcrest:hamcrest:2.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.7.10=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.jetbrains.kotlin:kotlin-daemon-embeddable:1.7.10=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
@@ -32,14 +80,10 @@ org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10=apiDependenciesMetadata,compileCl
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10=apiDependenciesMetadata,compileClasspath,default,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jetbrains.kotlin:kotlin-stdlib:1.7.10=apiDependenciesMetadata,compileClasspath,default,implementationDependenciesMetadata,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jetbrains:annotations:13.0=apiDependenciesMetadata,compileClasspath,default,implementationDependenciesMetadata,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jline:jline-native:3.23.0=default
|
||||
org.jline:jline-native:3.23.0=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jline:jline-reader:3.23.0=default
|
||||
org.jline:jline-reader:3.23.0=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jline:jline-terminal-jansi:3.23.0=default
|
||||
org.jline:jline-terminal-jansi:3.23.0=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jline:jline-terminal:3.23.0=default
|
||||
org.jline:jline-terminal:3.23.0=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jline:jline-native:3.23.0=compileClasspath,default,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jline:jline-reader:3.23.0=compileClasspath,default,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jline:jline-terminal-jansi:3.23.0=compileClasspath,default,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jline:jline-terminal:3.23.0=compileClasspath,default,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.junit.jupiter:junit-jupiter-api:5.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
|
||||
org.junit.jupiter:junit-jupiter-engine:5.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
|
||||
org.junit.jupiter:junit-jupiter-params:5.10.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
@@ -49,5 +93,12 @@ org.junit:junit-bom:5.10.2=testCompileClasspath,testImplementationDependenciesMe
|
||||
org.msgpack:msgpack-core:0.9.0=default,runtimeClasspath,testRuntimeClasspath
|
||||
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
|
||||
org.organicdesign:Paguro:3.10.3=default,runtimeClasspath,testRuntimeClasspath
|
||||
org.slf4j:slf4j-api:2.0.11=testRuntimeClasspath
|
||||
org.slf4j:slf4j-api:2.0.9=testCompileClasspath,testImplementationDependenciesMetadata
|
||||
org.snakeyaml:snakeyaml-engine:2.5=default,runtimeClasspath,testRuntimeClasspath
|
||||
org.wiremock:wiremock:3.6.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.xmlunit:xmlunit-core:2.10.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.xmlunit:xmlunit-legacy:2.10.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.xmlunit:xmlunit-placeholders:2.10.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.yaml:snakeyaml:2.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
empty=annotationProcessor,archives,compile,intransitiveDependenciesMetadata,javaExecutable,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDef,kotlinScriptDefExtensions,runtime,runtimeOnlyDependenciesMetadata,shadow,signatures,sourcesJar,stagedAlpineLinuxAmd64Executable,stagedLinuxAarch64Executable,stagedLinuxAmd64Executable,stagedMacAarch64Executable,stagedMacAmd64Executable,testAnnotationProcessor,testApiDependenciesMetadata,testCompile,testCompileOnly,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDef,testKotlinScriptDefExtensions,testRuntime
|
||||
|
||||
@@ -56,6 +56,7 @@ dependencies {
|
||||
}
|
||||
|
||||
testImplementation(projects.pklCommonsTest)
|
||||
testImplementation(libs.wiremock)
|
||||
|
||||
fun executableDir(name: String) = files(layout.buildDirectory.dir("executable/$name"))
|
||||
stagedMacAmd64Executable(executableDir("pkl-macos-amd64"))
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.pkl.server.Server
|
||||
class CliServer(options: CliBaseOptions) : CliCommand(options) {
|
||||
override fun doRun() =
|
||||
try {
|
||||
val server = Server(MessageTransports.stream(System.`in`, System.out), httpClient)
|
||||
val server = Server(MessageTransports.stream(System.`in`, System.out))
|
||||
server.use { it.start() }
|
||||
} catch (e: ProtocolException) {
|
||||
throw CliException(e.message!!)
|
||||
|
||||
@@ -15,17 +15,23 @@
|
||||
*/
|
||||
package org.pkl.cli
|
||||
|
||||
import com.github.tomakehurst.wiremock.client.WireMock.*
|
||||
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo
|
||||
import com.github.tomakehurst.wiremock.junit5.WireMockTest
|
||||
import java.io.StringReader
|
||||
import java.io.StringWriter
|
||||
import java.net.ServerSocket
|
||||
import java.net.URI
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.time.Duration
|
||||
import java.util.regex.Pattern
|
||||
import kotlin.io.path.*
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatCode
|
||||
import org.junit.jupiter.api.AfterAll
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import org.junit.jupiter.api.condition.DisabledOnOs
|
||||
@@ -40,8 +46,10 @@ import org.pkl.commons.cli.CliException
|
||||
import org.pkl.commons.test.FileTestUtils
|
||||
import org.pkl.commons.test.PackageServer
|
||||
import org.pkl.core.OutputFormat
|
||||
import org.pkl.core.SecurityManagers
|
||||
import org.pkl.core.util.IoUtils
|
||||
|
||||
@WireMockTest(httpsEnabled = true, proxyMode = true)
|
||||
class CliEvaluatorTest {
|
||||
companion object {
|
||||
private val defaultContents =
|
||||
@@ -1262,6 +1270,196 @@ result = someLib.x
|
||||
.hasMessageNotContainingAny("java.", "sun.") // class names have been filtered out
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `eval http module from proxy`(wwRuntimeInfo: WireMockRuntimeInfo) {
|
||||
stubFor(
|
||||
get(urlEqualTo("/bar.pkl")).withHost(equalTo("not.a.valid.host")).willReturn(ok("foo = 1"))
|
||||
)
|
||||
val options =
|
||||
CliEvaluatorOptions(
|
||||
CliBaseOptions(
|
||||
sourceModules = listOf(URI("http://not.a.valid.host/bar.pkl")),
|
||||
proxyAddress = URI("http://localhost:${wwRuntimeInfo.httpPort}"),
|
||||
allowedModules = SecurityManagers.defaultAllowedModules + Pattern.compile("http:"),
|
||||
),
|
||||
)
|
||||
val output = evalToConsole(options)
|
||||
assertThat(output).isEqualTo("foo = 1\n")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `eval https -- no proxy`(wwRuntimeInfo: WireMockRuntimeInfo) {
|
||||
// pick an address on the local machine so we can be sure this test is not making any outbound
|
||||
// connections.
|
||||
val openPort = ServerSocket(0).use { it.localPort }
|
||||
val targetAddress = "https://127.0.0.1:$openPort"
|
||||
val options =
|
||||
CliEvaluatorOptions(
|
||||
CliBaseOptions(
|
||||
// use loopback address to prevent test from making outbound http connection.
|
||||
sourceModules = listOf(URI("$targetAddress/foo.pkl")),
|
||||
proxyAddress = URI(wwRuntimeInfo.httpBaseUrl),
|
||||
noProxy = listOf("*"),
|
||||
allowedModules = SecurityManagers.defaultAllowedModules + Pattern.compile("http:"),
|
||||
)
|
||||
)
|
||||
assertThatCode { evalToConsole(options) }
|
||||
.hasMessageContaining("I/O error loading module `$targetAddress/foo.pkl`")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO: figure out why this is failing.
|
||||
fun `eval package from proxy`(wwRuntimeInfo: WireMockRuntimeInfo) {
|
||||
stubFor(
|
||||
any(anyUrl()).willReturn(aResponse().proxiedFrom("https://localhost:${packageServer.port}"))
|
||||
)
|
||||
val options =
|
||||
CliEvaluatorOptions(
|
||||
CliBaseOptions(
|
||||
sourceModules = listOf(URI("package://localhost:1/birds@0.5.0#/catalog/Ostritch.pkl")),
|
||||
noCache = true,
|
||||
proxyAddress = URI(wwRuntimeInfo.httpBaseUrl),
|
||||
caCertificates = listOf(FileTestUtils.selfSignedCertificate),
|
||||
allowedModules = SecurityManagers.defaultAllowedModules + Pattern.compile("http:")
|
||||
)
|
||||
)
|
||||
val output = evalToConsole(options)
|
||||
assertThat(output)
|
||||
.isEqualTo(
|
||||
"""
|
||||
name = "Ostritch"
|
||||
|
||||
favoriteFruit {
|
||||
name = "Orange"
|
||||
}
|
||||
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
verify(getRequestedFor(urlEqualTo("birds@0.5.0")))
|
||||
verify(getRequestedFor(urlEqualTo("fruit@1.0.5")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `eval http module from proxy -- configured in settings`(
|
||||
@TempDir tempDir: Path,
|
||||
wwRuntimeInfo: WireMockRuntimeInfo
|
||||
) {
|
||||
val settingsModule =
|
||||
tempDir.writeFile(
|
||||
"settings.pkl",
|
||||
"""
|
||||
amends "pkl:settings"
|
||||
|
||||
http {
|
||||
proxy {
|
||||
address = "${wwRuntimeInfo.httpBaseUrl}"
|
||||
}
|
||||
}
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
|
||||
stubFor(
|
||||
get(urlEqualTo("/bar.pkl")).withHost(equalTo("not.a.valid.host")).willReturn(ok("foo = 1"))
|
||||
)
|
||||
val options =
|
||||
CliEvaluatorOptions(
|
||||
CliBaseOptions(
|
||||
sourceModules = listOf(URI("http://not.a.valid.host/bar.pkl")),
|
||||
settings = settingsModule.toUri(),
|
||||
allowedModules = SecurityManagers.defaultAllowedModules + Pattern.compile("http:"),
|
||||
),
|
||||
)
|
||||
val output = evalToConsole(options)
|
||||
assertThat(output).isEqualTo("foo = 1\n")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `eval http module from proxy -- configured in PklProject`(
|
||||
@TempDir tempDir: Path,
|
||||
wwRuntimeInfo: WireMockRuntimeInfo
|
||||
) {
|
||||
tempDir.writeFile(
|
||||
"PklProject",
|
||||
"""
|
||||
amends "pkl:Project"
|
||||
|
||||
evaluatorSettings {
|
||||
http {
|
||||
proxy {
|
||||
address = "${wwRuntimeInfo.httpBaseUrl}"
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
|
||||
stubFor(
|
||||
get(urlEqualTo("/bar.pkl")).withHost(equalTo("not.a.valid.host")).willReturn(ok("foo = 1"))
|
||||
)
|
||||
val options =
|
||||
CliEvaluatorOptions(
|
||||
CliBaseOptions(
|
||||
sourceModules = listOf(URI("http://not.a.valid.host/bar.pkl")),
|
||||
allowedModules = SecurityManagers.defaultAllowedModules + Pattern.compile("http:"),
|
||||
projectDir = tempDir
|
||||
),
|
||||
)
|
||||
val output = evalToConsole(options)
|
||||
assertThat(output).isEqualTo("foo = 1\n")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `eval http module from proxy -- PklProject beats user settings`(
|
||||
@TempDir tempDir: Path,
|
||||
wwRuntimeInfo: WireMockRuntimeInfo
|
||||
) {
|
||||
val projectDir = tempDir.resolve("my-project")
|
||||
projectDir.writeFile(
|
||||
"PklProject",
|
||||
"""
|
||||
amends "pkl:Project"
|
||||
|
||||
evaluatorSettings {
|
||||
http {
|
||||
proxy {
|
||||
address = "${wwRuntimeInfo.httpBaseUrl}"
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
val homeDir = tempDir.resolve("my-home")
|
||||
homeDir.writeFile(
|
||||
"settings.pkl",
|
||||
"""
|
||||
amends "pkl:settings"
|
||||
|
||||
http {
|
||||
proxy {
|
||||
address = "http://invalid.proxy.address"
|
||||
}
|
||||
}
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
val options =
|
||||
CliEvaluatorOptions(
|
||||
CliBaseOptions(
|
||||
sourceModules = listOf(URI("http://not.a.valid.host/bar.pkl")),
|
||||
allowedModules = SecurityManagers.defaultAllowedModules + Pattern.compile("http:"),
|
||||
projectDir = projectDir,
|
||||
settings = homeDir.resolve("settings.pkl").toUri()
|
||||
),
|
||||
)
|
||||
stubFor(get(anyUrl()).willReturn(ok("result = 1")))
|
||||
val output = evalToConsole(options)
|
||||
assertThat(output).isEqualTo("result = 1\n")
|
||||
}
|
||||
|
||||
private fun evalModuleThatImportsPackage(certsFile: Path, testPort: Int = -1) {
|
||||
val moduleUri =
|
||||
writePklFile(
|
||||
|
||||
Reference in New Issue
Block a user