diff --git a/pkl-cli/src/test/kotlin/org/pkl/cli/CliEvaluatorTest.kt b/pkl-cli/src/test/kotlin/org/pkl/cli/CliEvaluatorTest.kt index a177f18e..89dbaf9d 100644 --- a/pkl-cli/src/test/kotlin/org/pkl/cli/CliEvaluatorTest.kt +++ b/pkl-cli/src/test/kotlin/org/pkl/cli/CliEvaluatorTest.kt @@ -1230,6 +1230,92 @@ result = someLib.x ) } + @Test + fun `noProxy settings from PklProject file`() { + val moduleUri = + writePklFile( + "test.pkl", + """ + res = read("https://localhost:${packageServer.port}/birds@0.5.0").bytes.sha256 + """ + .trimIndent(), + ) + writePklFile( + "PklProject", + // language=Pkl + """ + amends "pkl:Project" + + evaluatorSettings { + http { + proxy { + address = "http://example.example" + noProxy { + "localhost:${packageServer.port}" + } + } + } + } + """ + .trimIndent(), + ) + val options = + CliEvaluatorOptions( + CliBaseOptions( + sourceModules = listOf(moduleUri), + workingDir = tempDir, + caCertificates = listOf(FileTestUtils.selfSignedCertificate), + ) + ) + val buffer = ByteArrayOutputStream() + CliEvaluator(options, outputStream = buffer).run() + assertThat(buffer.toString(StandardCharsets.UTF_8)) + .isEqualTo("res = \"b27206b80f4f227752b6f02143887f3ea41e554542cec38f7b572b987566c4de\"\n") + } + + @Test + fun `noProxy settings from settings file`() { + val moduleUri = + writePklFile( + "test.pkl", + """ + res = read("https://localhost:${packageServer.port}/birds@0.5.0").bytes.sha256 + """ + .trimIndent(), + ) + val settingsFile = + writePklFile( + "settings.pkl", + // language=Pkl + """ + amends "pkl:settings" + + http { + proxy { + address = "http://example.example" + noProxy { + "localhost:${packageServer.port}" + } + } + } + """ + .trimIndent(), + ) + val options = + CliEvaluatorOptions( + CliBaseOptions( + sourceModules = listOf(moduleUri), + workingDir = tempDir, + caCertificates = listOf(FileTestUtils.selfSignedCertificate), + settings = settingsFile, + ) + ) + val buffer = ByteArrayOutputStream() + CliEvaluator(options, outputStream = buffer).run() + assertThat(buffer.toString(StandardCharsets.UTF_8)) + .isEqualTo("res = \"b27206b80f4f227752b6f02143887f3ea41e554542cec38f7b572b987566c4de\"\n") + } + @Test fun `setting noCache will skip writing to the cache dir`() { val moduleUri = diff --git a/pkl-cli/src/test/kotlin/org/pkl/cli/CliMainTest.kt b/pkl-cli/src/test/kotlin/org/pkl/cli/CliMainTest.kt index a1554671..1d280823 100644 --- a/pkl-cli/src/test/kotlin/org/pkl/cli/CliMainTest.kt +++ b/pkl-cli/src/test/kotlin/org/pkl/cli/CliMainTest.kt @@ -149,6 +149,14 @@ class CliMainTest { assertThat(ex.message).contains("Rewrite rule must end with '/', but was 'http://foo.com'") } + @Test + fun `missing --http-no-proxy flag is null`(@TempDir tempDir: Path) { + val inputFile = tempDir.resolve("test.pkl").writeString("").toString() + val command = EvalCommand() + command.parse(arrayOf(inputFile)) + assertThat(command.baseOptions.noProxy).isNull() + } + private fun makeInput(tempDir: Path, fileName: String = "test.pkl"): String { val code = "x = 1" return tempDir.resolve(fileName).writeString(code).toString() diff --git a/pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/commands/BaseOptions.kt b/pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/commands/BaseOptions.kt index 3229f184..20579c15 100644 --- a/pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/commands/BaseOptions.kt +++ b/pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/commands/BaseOptions.kt @@ -321,7 +321,7 @@ class BaseOptions : OptionGroup() { noProject = projectOptions?.noProject ?: false, caCertificates = caCertificates, httpProxy = proxy, - httpNoProxy = noProxy ?: emptyList(), + httpNoProxy = noProxy, httpRewrites = httpRewrites.ifEmpty { null }, externalModuleReaders = externalModuleReaders, externalResourceReaders = externalResourceReaders,