Skip to content

Commit e613632

Browse files
ca_roots: bundled_ca_roots cannot be a constant (#4)
Fixes JuliaLang/julia#38429
1 parent 9b248a8 commit e613632

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/ca_roots.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ case this function will always return that path (whether it exists or not).
4242
"""
4343
ca_roots_path()::String = _ca_roots(false)
4444

45-
const BUNDLED_CA_ROOTS = normpath(Sys.BINDIR, "..", "share", "julia", "cert.pem")
45+
# NOTE: this has to be a function not a constant since the
46+
# value of Sys.BINDIR changes from build time to run time.
47+
bundled_ca_roots() =
48+
normpath(Sys.BINDIR::String, "..", "share", "julia", "cert.pem")
4649

4750
const LINUX_CA_ROOTS = [
4851
"/etc/ssl/cert.pem" # Alpine Linux
@@ -73,7 +76,7 @@ function system_ca_roots()
7376
return
7477
end
7578
# TODO: extract system certs on Windows & macOS
76-
SYSTEM_CA_ROOTS[] = BUNDLED_CA_ROOTS
79+
SYSTEM_CA_ROOTS[] = bundled_ca_roots()
7780
end
7881
return SYSTEM_CA_ROOTS[]
7982
end

test/runtests.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
include("setup.jl")
22

33
@testset "ca_roots" begin
4+
@test isfile(bundled_ca_roots())
45
withenv(
56
"JULIA_SSL_CA_ROOTS_PATH" => nothing,
67
) do
78
@test ca_roots_path() isa String
89
@test ispath(ca_roots_path())
910
if Sys.iswindows() || Sys.isapple()
10-
@test ca_roots_path() == BUNDLED_CA_ROOTS
11+
@test ca_roots_path() == bundled_ca_roots()
1112
@test ca_roots() === nothing
1213
else
13-
@test ca_roots_path() != BUNDLED_CA_ROOTS
14+
@test ca_roots_path() != bundled_ca_roots()
1415
@test ca_roots() == ca_roots_path()
1516
end
1617
unset = ca_roots(), ca_roots_path()

test/setup.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Test
22
using Logging
33
using NetworkOptions
4-
using NetworkOptions: BUNDLED_CA_ROOTS
4+
using NetworkOptions: bundled_ca_roots
55

66
const TEST_URLS = [
77
"" # not a valid host name

0 commit comments

Comments
 (0)