]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- extended testsuite 1156/head
authorArvin Schnell <aschnell@suse.de>
Tue, 23 Jun 2026 05:43:33 +0000 (07:43 +0200)
committerArvin Schnell <aschnell@suse.de>
Tue, 23 Jun 2026 05:43:33 +0000 (07:43 +0200)
stomp/Stomp.cc
stomp/testsuite/read1.cc

index 170290005f5af38e781734c5fad0296023ab515c..cf9ef0e3c957e656dc49e9b4053ddc9481099a4f 100644 (file)
@@ -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)
     {
index a5c31eb4ab090aa31c4ab661a7cbf02503cea6a2..5124e17e066633e55c8e0630ed98e53e79f2db13 100644 (file)
@@ -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;
+    });
+}