From: Arvin Schnell Date: Tue, 23 Jun 2026 05:43:33 +0000 (+0200) Subject: - extended testsuite X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1814cfc48d2726cf2ca34b414b8c114f75dbbb5f;p=thirdparty%2Fsnapper.git - extended testsuite --- diff --git a/stomp/Stomp.cc b/stomp/Stomp.cc index 17029000..cf9ef0e3 100644 --- a/stomp/Stomp.cc +++ b/stomp/Stomp.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019-2024] SUSE LLC + * Copyright (c) [2019-2026] SUSE LLC * * All Rights Reserved. * @@ -24,6 +24,7 @@ #include "Stomp.h" + namespace Stomp { @@ -106,11 +107,6 @@ namespace Stomp { has_content_length = true; - if (value.empty()) - { - throw runtime_error("stomp error: empty content-length value"); - } - try { size_t parsed_chars = 0; @@ -128,7 +124,7 @@ namespace Stomp } catch (const invalid_argument&) { - throw runtime_error("stomp error: invalid content-length syntax"); + throw runtime_error("stomp error: invalid content-length syntax '" + value + "'"); } catch (const out_of_range&) { @@ -144,6 +140,7 @@ namespace Stomp throw runtime_error("stomp error: expected a message, got a part of it"); } + void write_message(ostream& os, const Message& msg) { diff --git a/stomp/testsuite/read1.cc b/stomp/testsuite/read1.cc index a5c31eb4..5124e17e 100644 --- a/stomp/testsuite/read1.cc +++ b/stomp/testsuite/read1.cc @@ -89,3 +89,44 @@ BOOST_AUTO_TEST_CASE(escape1) BOOST_CHECK_EQUAL(msg.body, "WORLD"); } + + +BOOST_AUTO_TEST_CASE(error1) +{ + // missing \0 at frame end + + istringstream s1("HELLO\nkey:value\ncontent-length:5\n\nWORL" + null); + istream s2(s1.rdbuf()); + + BOOST_CHECK_EXCEPTION(read_message(s2), exception, [](const exception& e) { + return strcmp(e.what(), "stomp error: missing \\0 at frame end") == 0; + }); +} + + +BOOST_AUTO_TEST_CASE(error2) +{ + // empty content-lenght value + + istringstream s1("HELLO\nkey:value\ncontent-length:\n\nWORLD" + null); + istream s2(s1.rdbuf()); + + BOOST_CHECK_EXCEPTION(read_message(s2), exception, [](const exception& e) { + cout << e.what() << '\n'; + return strcmp(e.what(), "stomp error: invalid content-length syntax ''") == 0; + }); +} + + +BOOST_AUTO_TEST_CASE(error3) +{ + // invalid content-lenght value + + istringstream s1("HELLO\nkey:value\ncontent-length:5a\n\nWORLD" + null); + istream s2(s1.rdbuf()); + + BOOST_CHECK_EXCEPTION(read_message(s2), exception, [](const exception& e) { + cout << e.what() << '\n'; + return strcmp(e.what(), "stomp error: invalid content-length value '5a'") == 0; + }); +}