couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [28/45] mochiweb commit: updated refs/heads/master to cb521b3
Date Tue, 25 Aug 2015 17:38:46 GMT
end to end test with text frames (ssl is broken)


Project: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/commit/0be75c24
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/tree/0be75c24
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/diff/0be75c24

Branch: refs/heads/master
Commit: 0be75c24c70aa5b4714843f3953052345aea190e
Parents: ffaa90a
Author: Bob Ippolito <bob@redivi.com>
Authored: Sun Jan 11 18:09:03 2015 +1300
Committer: Bob Ippolito <bob@redivi.com>
Committed: Sun Jan 11 18:09:03 2015 +1300

----------------------------------------------------------------------
 src/mochiweb_websocket.erl        | 11 +++--------
 test/mochiweb_test_util.erl       |  8 ++++++--
 test/mochiweb_websocket_tests.erl | 26 +++++++++++++++++++++++++-
 3 files changed, 34 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/0be75c24/src/mochiweb_websocket.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb_websocket.erl b/src/mochiweb_websocket.erl
index cc3127e..b7a4a62 100644
--- a/src/mochiweb_websocket.erl
+++ b/src/mochiweb_websocket.erl
@@ -27,6 +27,9 @@
 
 -export([loop/5, upgrade_connection/2, request/5]).
 -export([send/3]).
+-ifdef(TEST).
+-compile(export_all).
+-endif.
 
 loop(Socket, Body, State, WsVersion, ReplyChannel) ->
     ok = mochiweb_socket:setopts(Socket, [{packet, 0}, {active, once}]),
@@ -276,11 +279,3 @@ parse_hixie(<<255, Rest/binary>>, Buffer) ->
   {Buffer, Rest};
 parse_hixie(<<H, T/binary>>, Buffer) ->
   parse_hixie(T, <<Buffer/binary, H>>).
-
-%%
-%% Tests
-%%
--ifdef(TEST).
--include_lib("eunit/include/eunit.hrl").
--compile(export_all).
--endif.

http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/0be75c24/test/mochiweb_test_util.erl
----------------------------------------------------------------------
diff --git a/test/mochiweb_test_util.erl b/test/mochiweb_test_util.erl
index 690f134..0801ab5 100644
--- a/test/mochiweb_test_util.erl
+++ b/test/mochiweb_test_util.erl
@@ -35,7 +35,9 @@ sock_fun(Transport, Port) ->
                 ({send, Data}) ->
                     gen_tcp:send(Socket, Data);
                 ({setopts, L}) ->
-                    inet:setopts(Socket, L)
+                    inet:setopts(Socket, L);
+                (get) ->
+                    Socket
             end;
         ssl ->
             {ok, Socket} = ssl:connect("127.0.0.1", Port, [{ssl_imp, new} | Opts]),
@@ -46,7 +48,9 @@ sock_fun(Transport, Port) ->
                 ({send, Data}) ->
                     ssl:send(Socket, Data);
                 ({setopts, L}) ->
-                    ssl:setopts(Socket, L)
+                    ssl:setopts(Socket, L);
+                (get) ->
+                    {ssl, Socket}
             end
     end.
 

http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/0be75c24/test/mochiweb_websocket_tests.erl
----------------------------------------------------------------------
diff --git a/test/mochiweb_websocket_tests.erl b/test/mochiweb_websocket_tests.erl
index 20967fb..4ca404b 100644
--- a/test/mochiweb_websocket_tests.erl
+++ b/test/mochiweb_websocket_tests.erl
@@ -99,10 +99,13 @@ end_to_end_server(Req) ->
                                    fun end_to_end_ws_loop/3),
     ReentryWs(ok).
 
-end_to_end_ws_loop(_Payload, State, _ReplyChannel) ->
+end_to_end_ws_loop(Payload, State, ReplyChannel) ->
+    %% Echo server
+    lists:foreach(ReplyChannel, Payload),
     State.
 
 end_to_end_client(S) ->
+    %% Key and Accept per https://tools.ietf.org/html/rfc6455
     UpgradeReq = string:join(
                    ["GET / HTTP/1.1",
                     "Host: localhost",
@@ -123,6 +126,27 @@ end_to_end_client(S) ->
              {"Sec-Websocket-Accept", "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="}])),
     ?assertEqual([], gb_trees:to_list(D)),
     ok = S({setopts, [{packet, raw}]}),
+    %% The first message sent over telegraph :)
+    SmallMessage = <<"What hath God wrought?">>,
+    ok = S({send,
+       << 1:1, %% Fin
+          0:1, %% Rsv1
+          0:1, %% Rsv2
+          0:1, %% Rsv3
+          2:4, %% Opcode, 1 = text frame
+          1:1, %% Mask on
+          (byte_size(SmallMessage)):7, %% Length, <125 case
+          0:32, %% Mask (trivial)
+          SmallMessage/binary >>}),
+    {ok, WsFrames} = S(recv),
+    << 1:1, %% Fin
+       0:1, %% Rsv1
+       0:1, %% Rsv2
+       0:1, %% Rsv3
+       1:4, %% Opcode, text frame (all mochiweb suports for now)
+       MsgSize:8, %% Expecting small size
+       SmallMessage/binary >> = WsFrames,
+    ?assertEqual(MsgSize, byte_size(SmallMessage)),
     ok.
 
 gb_from_list(L) ->


Mime
View raw message