From 68d46bd02b3353a33e7684e81bc6de9c009cda91 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Tue, 29 Jul 2025 10:58:40 -0400 Subject: [PATCH 1/2] Produce debug output when tests fail --- test/ssl.jl | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/test/ssl.jl b/test/ssl.jl index 98614a6..13fe275 100644 --- a/test/ssl.jl +++ b/test/ssl.jl @@ -10,6 +10,24 @@ function curl_write_cb(curlbuf::Ptr{Cvoid}, s::Csize_t, n::Csize_t, p_ctxt::Ptr{ return sz::Csize_t end +# Setup the callback function to collect debug information +const infotype_str = Dict( + 0 => "CURLINFO_TEXT", + 1 => "CURLINFO_HEADER_IN", + 2 => "CURLINFO_HEADER_OUT", + 3 => "CURLINFO_DATA_IN", + 4 => "CURLINFO_DATA_OUT", + 5 => "CURLINFO_SSL_DATA_IN", + 6 => "CURLINFO_SSL_DATA_OUT", +) + +function curl_debug_cb(handle::Ptr{Cvoid}, type::Cint, data::Ptr{Cvoid}, sz::Csize_t, clientp::Ptr{Cvoid}) + debug_buffer = unsafe_pointer_to_objref(clientp)::IOBuffer + data = UInt8[unsafe_load(reinterpret(Ptr{Cuchar}, data), n) for n in 1:sz] + println(debug_buffer, "$(infotype_str[type]) \"$(String(data))\"") + return Cint(0) +end + @testset "SSL verify" begin # Set up the write function to consume the curl output so we don't see it in the # test output @@ -27,11 +45,27 @@ end curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1) curl_easy_setopt(curl, CURLOPT_CAINFO, LibCURL.cacert) - @testset "SSL Success" begin - res = curl_easy_perform(curl) - @test res == CURLE_OK - end + # For debugging -- we see that `res ≠ CURLE_OK` below and want to know why + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1) + c_curl_debug_cb = @cfunction( + curl_debug_cb, + Cint, + (Ptr{Cvoid}, Cint, Ptr{Cvoid}, Csize_t, Ptr{Cvoid}) + ) + debug_buffer = IOBuffer() + GC.@preserve debug_buffer begin + curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, c_curl_debug_cb) + curl_easy_setopt(curl, CURLOPT_DEBUGDATA, pointer_from_objref(debug_buffer)) + @testset "SSL Success" begin + res = curl_easy_perform(curl) + if !(res == CURLE_OK) + println("CURL debug output:\n") + print(takestring!(debug_buffer)) + end + @test res == CURLE_OK + end + end end curl_easy_cleanup(curl) From 0476ddb2b454a713d6fd57d7d69c65cbb0d0f7c8 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Tue, 29 Jul 2025 11:18:55 -0400 Subject: [PATCH 2/2] Simplify code --- test/ssl.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ssl.jl b/test/ssl.jl index 13fe275..3b45b16 100644 --- a/test/ssl.jl +++ b/test/ssl.jl @@ -23,7 +23,7 @@ const infotype_str = Dict( function curl_debug_cb(handle::Ptr{Cvoid}, type::Cint, data::Ptr{Cvoid}, sz::Csize_t, clientp::Ptr{Cvoid}) debug_buffer = unsafe_pointer_to_objref(clientp)::IOBuffer - data = UInt8[unsafe_load(reinterpret(Ptr{Cuchar}, data), n) for n in 1:sz] + data = unsafe_wrap(Array, reinterpret(Ptr{UInt8}, data), sz) println(debug_buffer, "$(infotype_str[type]) \"$(String(data))\"") return Cint(0) end