Skip to content

Commit

Permalink
ca_roots: bundled_ca_roots cannot be a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Nov 13, 2020
1 parent 9b248a8 commit 00627d8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/ca_roots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ case this function will always return that path (whether it exists or not).
"""
ca_roots_path()::String = _ca_roots(false)

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

const LINUX_CA_ROOTS = [
"/etc/ssl/cert.pem" # Alpine Linux
Expand Down Expand Up @@ -73,7 +76,7 @@ function system_ca_roots()
return
end
# TODO: extract system certs on Windows & macOS
SYSTEM_CA_ROOTS[] = BUNDLED_CA_ROOTS
SYSTEM_CA_ROOTS[] = bundled_ca_roots()
end
return SYSTEM_CA_ROOTS[]
end
Expand Down
5 changes: 3 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
include("setup.jl")

@testset "ca_roots" begin
@test isfile(bundled_ca_roots())
withenv(
"JULIA_SSL_CA_ROOTS_PATH" => nothing,
) do
@test ca_roots_path() isa String
@test ispath(ca_roots_path())
if Sys.iswindows() || Sys.isapple()
@test ca_roots_path() == BUNDLED_CA_ROOTS
@test ca_roots_path() == bundled_ca_roots()
@test ca_roots() === nothing
else
@test ca_roots_path() != BUNDLED_CA_ROOTS
@test ca_roots_path() != bundled_ca_roots()
@test ca_roots() == ca_roots_path()
end
unset = ca_roots(), ca_roots_path()
Expand Down
2 changes: 1 addition & 1 deletion test/setup.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Test
using Logging
using NetworkOptions
using NetworkOptions: BUNDLED_CA_ROOTS
using NetworkOptions: bundled_ca_roots

const TEST_URLS = [
"" # not a valid host name
Expand Down

0 comments on commit 00627d8

Please sign in to comment.