Defer noProxy to settings.pkl or PklProject if not set explicitly (#1143)

Fixes an issue where `http.noProxy` settings are ignored.
This commit is contained in:
Daniel Chao
2025-07-23 10:57:31 -07:00
committed by GitHub
parent bdf6aa6b60
commit 7c8c4438d5
3 changed files with 95 additions and 1 deletions

View File

@@ -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 =

View File

@@ -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()

View File

@@ -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,