diff options
author | Fabian Dellwing <fabian.dellwing@gmail.com> | 2023-04-10 15:57:38 +0200 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2023-04-11 06:40:33 -0400 |
commit | 550635164d7c1cb6b9d7b8c402dd0ec330d91d63 (patch) | |
tree | b17a7fcfce94a94967c5b8a489531d1dd323fd86 /Tests/LibTLS | |
parent | 48d5cde29987c55a64809610c63d32654148bcc6 (diff) | |
download | serenity-550635164d7c1cb6b9d7b8c402dd0ec330d91d63.zip |
Tests+LibTLS: Use `TRY_OR_FAIL` for TestTLSHandshake
Diffstat (limited to 'Tests/LibTLS')
-rw-r--r-- | Tests/LibTLS/TestTLSHandshake.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/Tests/LibTLS/TestTLSHandshake.cpp b/Tests/LibTLS/TestTLSHandshake.cpp index 37531645dd..ab766ecbcd 100644 --- a/Tests/LibTLS/TestTLSHandshake.cpp +++ b/Tests/LibTLS/TestTLSHandshake.cpp @@ -23,7 +23,7 @@ static ByteBuffer operator""_b(char const* string, size_t length) return ByteBuffer::copy(string, length).release_value(); } -Vector<Certificate> load_certificates(); +ErrorOr<Vector<Certificate>> load_certificates(); DeprecatedString locate_ca_certs_file(); DeprecatedString locate_ca_certs_file() @@ -38,20 +38,18 @@ DeprecatedString locate_ca_certs_file() return ""; } -Vector<Certificate> load_certificates() +ErrorOr<Vector<Certificate>> load_certificates() { - auto cacert_file = MUST(Core::File::open(locate_ca_certs_file(), Core::File::OpenMode::Read)); - auto data = MUST(cacert_file->read_until_eof()); - return MUST(DefaultRootCACertificates::the().reload_certificates(data)); + auto cacert_file = TRY(Core::File::open(locate_ca_certs_file(), Core::File::OpenMode::Read)); + auto data = TRY(cacert_file->read_until_eof()); + return TRY(DefaultRootCACertificates::the().reload_certificates(data)); } -static Vector<Certificate> s_root_ca_certificates = load_certificates(); - TEST_CASE(test_TLS_hello_handshake) { Core::EventLoop loop; TLS::Options options; - options.set_root_certificates(s_root_ca_certificates); + options.set_root_certificates(TRY_OR_FAIL(load_certificates())); options.set_alert_handler([&](TLS::AlertDescription) { FAIL("Connection failure"); loop.quit(1); @@ -60,10 +58,10 @@ TEST_CASE(test_TLS_hello_handshake) loop.quit(0); }); - auto tls = MUST(TLS::TLSv12::connect(DEFAULT_SERVER, port, move(options))); + auto tls = TRY_OR_FAIL(TLS::TLSv12::connect(DEFAULT_SERVER, port, move(options))); ByteBuffer contents; tls->on_ready_to_read = [&] { - auto read_bytes = MUST(tls->read_some(contents.must_get_bytes_for_writing(4 * KiB))); + auto read_bytes = TRY_OR_FAIL(tls->read_some(contents.must_get_bytes_for_writing(4 * KiB))); if (read_bytes.is_empty()) { FAIL("No data received"); loop.quit(1); |