]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/beast/test/beast/websocket/handshake.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / beast / test / beast / websocket / handshake.cpp
index acf27f91c3f22d6668d14a4fac39bdcf499ccff2..61a861f7af1b519287a089588b0e4f08f5f7556f 100644 (file)
@@ -12,6 +12,9 @@
 
 #include "test.hpp"
 
+#include <boost/asio/io_service.hpp>
+#include <boost/asio/strand.hpp>
+
 namespace boost {
 namespace beast {
 namespace websocket {
@@ -137,7 +140,7 @@ public:
         });
 
         auto const check =
-        [&](std::string const& s)
+        [&](error e, std::string const& s)
         {
             stream<test::stream> ws{ioc_};
             auto tr = connect(ws.next_layer());
@@ -150,11 +153,11 @@ public:
             }
             catch(system_error const& se)
             {
-                BEAST_EXPECT(se.code() == error::handshake_failed);
+                BEAST_EXPECTS(se.code() == e, se.what());
             }
         };
-        // wrong HTTP version
-        check(
+        // bad HTTP version
+        check(error::bad_http_version,
             "HTTP/1.0 101 Switching Protocols\r\n"
             "Server: beast\r\n"
             "Upgrade: WebSocket\r\n"
@@ -163,38 +166,46 @@ public:
             "Sec-WebSocket-Version: 13\r\n"
             "\r\n"
         );
-        // wrong status
-        check(
-            "HTTP/1.1 200 OK\r\n"
+        // no Connection
+        check(error::no_connection,
+            "HTTP/1.1 101 Switching Protocols\r\n"
             "Server: beast\r\n"
             "Upgrade: WebSocket\r\n"
-            "Connection: upgrade\r\n"
             "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
             "Sec-WebSocket-Version: 13\r\n"
             "\r\n"
         );
-        // missing upgrade token
-        check(
+        // no Connection upgrade
+        check(error::no_connection_upgrade,
+            "HTTP/1.1 101 Switching Protocols\r\n"
+            "Server: beast\r\n"
+            "Upgrade: WebSocket\r\n"
+            "Connection: keep-alive\r\n"
+            "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
+            "Sec-WebSocket-Version: 13\r\n"
+            "\r\n"
+        );
+        // no Upgrade
+        check(error::no_upgrade,
             "HTTP/1.1 101 Switching Protocols\r\n"
             "Server: beast\r\n"
-            "Upgrade: HTTP/2\r\n"
             "Connection: upgrade\r\n"
             "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
             "Sec-WebSocket-Version: 13\r\n"
             "\r\n"
         );
-        // missing connection token
-        check(
+        // no Upgrade websocket
+        check(error::no_upgrade_websocket,
             "HTTP/1.1 101 Switching Protocols\r\n"
             "Server: beast\r\n"
-            "Upgrade: WebSocket\r\n"
-            "Connection: keep-alive\r\n"
+            "Upgrade: HTTP/2\r\n"
+            "Connection: upgrade\r\n"
             "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
             "Sec-WebSocket-Version: 13\r\n"
             "\r\n"
         );
-        // missing accept key
-        check(
+        // no Sec-WebSocket-Accept
+        check(error::no_sec_accept,
             "HTTP/1.1 101 Switching Protocols\r\n"
             "Server: beast\r\n"
             "Upgrade: WebSocket\r\n"
@@ -202,8 +213,8 @@ public:
             "Sec-WebSocket-Version: 13\r\n"
             "\r\n"
         );
-        // wrong accept key
-        check(
+        // bad Sec-WebSocket-Accept
+        check(error::bad_sec_accept,
             "HTTP/1.1 101 Switching Protocols\r\n"
             "Server: beast\r\n"
             "Upgrade: WebSocket\r\n"
@@ -212,6 +223,16 @@ public:
             "Sec-WebSocket-Version: 13\r\n"
             "\r\n"
         );
+        // declined
+        check(error::upgrade_declined,
+            "HTTP/1.1 200 OK\r\n"
+            "Server: beast\r\n"
+            "Upgrade: WebSocket\r\n"
+            "Connection: upgrade\r\n"
+            "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
+            "Sec-WebSocket-Version: 13\r\n"
+            "\r\n"
+        );
     }
 
     // Compression Extensions for WebSocket
@@ -466,6 +487,35 @@ public:
             "permessage-deflate");
     }
 
+    void
+    testMoveOnly()
+    {
+        boost::asio::io_context ioc;
+        stream<test::stream> ws{ioc};
+        ws.async_handshake("", "", move_only_handler{});
+    }
+
+    struct copyable_handler
+    {
+        template<class... Args>
+        void
+        operator()(Args&&...) const
+        {
+        }
+    };
+
+    void
+    testAsioHandlerInvoke()
+    {
+        // make sure things compile, also can set a
+        // breakpoint in asio_handler_invoke to make sure
+        // it is instantiated.
+        boost::asio::io_context ioc;
+        boost::asio::io_service::strand s{ioc};
+        stream<test::stream> ws{ioc};
+        ws.async_handshake("localhost", "/", s.wrap(copyable_handler{}));
+    }
+
     void
     run() override
     {
@@ -473,6 +523,8 @@ public:
         testExtRead();
         testExtWrite();
         testExtNegotiate();
+        testMoveOnly();
+        testAsioHandlerInvoke();
     }
 };