Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ca_roots: bundled_ca_roots cannot be a constant #4

Merged
merged 1 commit into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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