Skip to content

Commit cca54bb

Browse files
authored
Fix tests for package (#47)
* make tests robust for changes in the cert for httpbingo * make tests robust for changes to the Mozilla certs file. Needed to pass tests in 1.12
1 parent 4ae02bc commit cca54bb

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "OpenSSL"
22
uuid = "4d8831e6-92b7-49fb-bdf8-b643e874388c"
3-
authors = ["Greg Lapinski <[email protected]>", "Jacob Quinn <[email protected]>"]
43
version = "1.5.0"
4+
authors = ["Greg Lapinski <[email protected]>", "Jacob Quinn <[email protected]>"]
55

66
[deps]
77
BitFlags = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
@@ -14,10 +14,12 @@ Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
1414
BitFlags = "0.1"
1515
MozillaCACerts_jll = ">= 2020"
1616
OpenSSL_jll = "1.1, 3.0"
17+
TimeZones = "1.22.1"
1718
julia = "1.6"
1819

1920
[extras]
2021
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
22+
TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
2123

2224
[targets]
23-
test = ["Test"]
25+
test = ["Test", "TimeZones"]

test/runtests.jl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using OpenSSL
44
using OpenSSL_jll
55
using Sockets
66
using Test
7+
using TimeZones
78

89
include(joinpath(dirname(pathof(OpenSSL)), "../test/http_helpers.jl"))
910

@@ -108,10 +109,20 @@ end
108109
cert = certs_pem[2]
109110

110111
x509_cert = X509Certificate(cert)
111-
@test String(x509_cert.subject_name) == "/C=BE/O=GlobalSign nv-sa/OU=Root CA/CN=GlobalSign Root CA"
112-
@test String(x509_cert.issuer_name) == "/C=BE/O=GlobalSign nv-sa/OU=Root CA/CN=GlobalSign Root CA"
113-
@test String(x509_cert.time_not_before) == "Sep 1 12:00:00 1998 GMT"
114-
@test String(x509_cert.time_not_after) == "Jan 28 12:00:00 2028 GMT"
112+
113+
@test occursin("/C=", String(x509_cert.subject_name))
114+
@test occursin("/OU=", String(x509_cert.subject_name))
115+
@test occursin("/CN=", String(x509_cert.subject_name))
116+
117+
@test occursin("/C=", String(x509_cert.issuer_name))
118+
@test occursin("/OU=", String(x509_cert.issuer_name))
119+
@test occursin("/CN=", String(x509_cert.issuer_name))
120+
121+
s_before_time = replace(String(x509_cert.time_not_before), r" +" => " ")
122+
@test DateTime(s_before_time, dateformat"u d HH:MM:SS yyyy Z") < today()
123+
124+
s_after_time = replace(String(x509_cert.time_not_after), r" +" => " ")
125+
@test DateTime(s_after_time, dateformat"u d HH:MM:SS yyyy Z") > today()
115126

116127
# finalizer will cleanup
117128
#finalize(x509_cert)
@@ -187,7 +198,7 @@ end
187198

188199
x509_server_cert = OpenSSL.get_peer_certificate(ssl)
189200

190-
@test String(x509_server_cert.issuer_name) == "/C=US/O=Let's Encrypt/CN=R11"
201+
@test occursin("/C=US/O=Let's Encrypt", String(x509_server_cert.issuer_name))
191202
@test String(x509_server_cert.subject_name) == "/CN=httpbingo.julialang.org"
192203

193204
request_str = "GET /status/200 HTTP/1.1\r\nHost: httpbingo.julialang.org\r\nUser-Agent: curl\r\nAccept: */*\r\n\r\n"

0 commit comments

Comments
 (0)