4
%% Copyright Ericsson AB 2008-2009. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
20
-module(ssl_payload_SUITE).
22
%% Note: This directive should only be used in test suites.
25
-include("test_server.hrl").
27
-define(TIMEOUT, 600000).
29
%% Test server callback functions
30
%%--------------------------------------------------------------------
31
%% Function: init_per_suite(Config) -> Config
33
%% A list of key/value pairs, holding the test case configuration.
34
%% Description: Initialization before the whole suite
36
%% Note: This function is free to add any key/value pairs to the Config
37
%% variable, but should NOT alter/remove any existing entries.
38
%%--------------------------------------------------------------------
39
init_per_suite(Config) ->
42
make_certs:all(?config(data_dir, Config), ?config(priv_dir, Config)),
43
ssl_test_lib:cert_options(Config).
45
%%--------------------------------------------------------------------
46
%% Function: end_per_suite(Config) -> _
48
%% A list of key/value pairs, holding the test case configuration.
49
%% Description: Cleanup after the whole suite
50
%%--------------------------------------------------------------------
51
end_per_suite(_Config) ->
55
%%--------------------------------------------------------------------
56
%% Function: init_per_testcase(TestCase, Config) -> Config
58
%% Name of the test case that is about to be run.
60
%% A list of key/value pairs, holding the test case configuration.
62
%% Description: Initialization before each test case
64
%% Note: This function is free to add any key/value pairs to the Config
65
%% variable, but should NOT alter/remove any existing entries.
66
%% Description: Initialization before each test case
67
%%--------------------------------------------------------------------
68
init_per_testcase(_TestCase, Config0) ->
69
Config = lists:keydelete(watchdog, 1, Config0),
70
Dog = ssl_test_lib:timetrap(?TIMEOUT),
71
[{watchdog, Dog} | Config].
73
%%--------------------------------------------------------------------
74
%% Function: end_per_testcase(TestCase, Config) -> _
76
%% Name of the test case that is about to be run.
78
%% A list of key/value pairs, holding the test case configuration.
79
%% Description: Cleanup after each test case
80
%%--------------------------------------------------------------------
81
end_per_testcase(_TestCase, Config) ->
82
Dog = ?config(watchdog, Config),
87
test_server:timetrap_cancel(Dog)
90
%%--------------------------------------------------------------------
91
%% Function: all(Clause) -> TestCases
92
%% Clause - atom() - suite | doc
95
%% Name of a test case.
96
%% Description: Returns a list of all test cases in this test suite
97
%%--------------------------------------------------------------------
99
["Test payload over ssl in all socket modes, active, active_once,"
100
"and passive mode."];
103
[server_echos_passive_small, server_echos_active_once_small,
104
server_echos_active_small,
105
client_echos_passive_small, client_echos_active_once_small,
106
client_echos_active_small,
107
server_echos_passive_big, server_echos_active_once_big,
108
server_echos_active_big,
109
client_echos_passive_big, client_echos_active_once_big,
110
client_echos_active_big,
111
server_echos_passive_huge, server_echos_active_once_huge,
112
server_echos_active_huge,
113
client_echos_passive_huge, client_echos_active_once_huge,
114
client_echos_active_huge
117
%% Test cases starts here.
118
%%--------------------------------------------------------------------
119
server_echos_passive_small(doc) ->
120
["Client sends 1000 bytes in passive mode to server, that receives them, "
121
"sends them back, and closes."];
123
server_echos_passive_small(suite) ->
126
server_echos_passive_small(Config) when is_list(Config) ->
127
ClientOpts = ?config(client_opts, Config),
128
ServerOpts = ?config(server_opts, Config),
129
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
133
server_echos_passive(Str, 1000, ClientOpts, ServerOpts,
134
ClientNode, ServerNode, Hostname).
136
%%--------------------------------------------------------------------
138
server_echos_active_once_small(doc) ->
139
["Client sends 1000 bytes in active once mode to server, that receives "
140
" them, sends them back, and closes."];
142
server_echos_active_once_small(suite) ->
145
server_echos_active_once_small(Config) when is_list(Config) ->
146
ClientOpts = ?config(client_opts, Config),
147
ServerOpts = ?config(server_opts, Config),
148
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
152
server_echos_active_once(Str, 1000, ClientOpts, ServerOpts,
153
ClientNode, ServerNode, Hostname).
155
%%--------------------------------------------------------------------
157
server_echos_active_small(doc) ->
158
["Client sends 1000 bytes in active mode to server, that receives them, "
159
"sends them back, and closes."];
161
server_echos_active_small(suite) ->
164
server_echos_active_small(Config) when is_list(Config) ->
165
ClientOpts = ?config(client_opts, Config),
166
ServerOpts = ?config(server_opts, Config),
167
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
171
server_echos_active(Str, 1000, ClientOpts, ServerOpts,
172
ClientNode, ServerNode, Hostname).
174
%%--------------------------------------------------------------------
175
client_echos_passive_small(doc) ->
176
["Server sends 1000 bytes in passive mode to client, that receives them, "
177
"sends them back, and closes."];
179
client_echos_passive_small(suite) ->
182
client_echos_passive_small(Config) when is_list(Config) ->
183
ClientOpts = ?config(client_opts, Config),
184
ServerOpts = ?config(server_opts, Config),
185
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
189
client_echos_passive(Str, 1000, ClientOpts, ServerOpts, ClientNode,
190
ServerNode, Hostname).
192
%%--------------------------------------------------------------------
193
client_echos_active_once_small(doc) ->
194
["Server sends 1000 bytes in active once mode to client, that receives "
195
"them, sends them back, and closes."];
197
client_echos_active_once_small(suite) ->
200
client_echos_active_once_small(Config) when is_list(Config) ->
201
ClientOpts = ?config(client_opts, Config),
202
ServerOpts = ?config(server_opts, Config),
203
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
207
client_echos_active_once(Str, 1000, ClientOpts, ServerOpts, ClientNode,
208
ServerNode, Hostname).
210
%%--------------------------------------------------------------------
211
client_echos_active_small(doc) ->
212
["Server sends 1000 bytes in active mode to client, that receives them, "
213
"sends them back, and closes."];
215
client_echos_active_small(suite) ->
218
client_echos_active_small(Config) when is_list(Config) ->
219
ClientOpts = ?config(client_opts, Config),
220
ServerOpts = ?config(server_opts, Config),
221
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
225
client_echos_active(Str, 1000, ClientOpts, ServerOpts, ClientNode,
226
ServerNode, Hostname).
229
%%--------------------------------------------------------------------
230
server_echos_passive_big(doc) ->
231
["Client sends 50000 bytes to server in passive mode, that receives them, "
232
"sends them back, and closes."];
234
server_echos_passive_big(suite) ->
237
server_echos_passive_big(Config) when is_list(Config) ->
238
ClientOpts = ?config(client_opts, Config),
239
ServerOpts = ?config(server_opts, Config),
240
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
244
server_echos_passive(Str, 50000, ClientOpts, ServerOpts, ClientNode,
245
ServerNode, Hostname).
247
%%--------------------------------------------------------------------
249
server_echos_active_once_big(doc) ->
250
["Client sends 50000 bytes to server in active once mode, that receives "
251
"them, sends them back, and closes."];
253
server_echos_active_once_big(suite) ->
256
server_echos_active_once_big(Config) when is_list(Config) ->
257
ClientOpts = ?config(client_opts, Config),
258
ServerOpts = ?config(server_opts, Config),
259
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
263
server_echos_active_once(Str, 50000, ClientOpts, ServerOpts, ClientNode,
264
ServerNode, Hostname).
266
%%--------------------------------------------------------------------
268
server_echos_active_big(doc) ->
269
["Client sends 50000 bytes to server in active once mode, that receives "
270
" them, sends them back, and closes."];
272
server_echos_active_big(suite) ->
275
server_echos_active_big(Config) when is_list(Config) ->
276
ClientOpts = ?config(client_opts, Config),
277
ServerOpts = ?config(server_opts, Config),
278
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
282
server_echos_active(Str, 50000, ClientOpts, ServerOpts, ClientNode,
283
ServerNode, Hostname).
285
%%--------------------------------------------------------------------
286
client_echos_passive_big(doc) ->
287
["Server sends 50000 bytes to client in passive mode, that receives them, "
288
"sends them back, and closes."];
290
client_echos_passive_big(suite) ->
293
client_echos_passive_big(Config) when is_list(Config) ->
294
ClientOpts = ?config(client_opts, Config),
295
ServerOpts = ?config(server_opts, Config),
296
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
300
client_echos_passive(Str, 50000, ClientOpts, ServerOpts, ClientNode,
301
ServerNode, Hostname).
303
%%--------------------------------------------------------------------
304
client_echos_active_once_big(doc) ->
305
["Server sends 50000 bytes to client in active once mode, that receives"
306
" them, sends them back, and closes."];
308
client_echos_active_once_big(suite) ->
311
client_echos_active_once_big(Config) when is_list(Config) ->
312
ClientOpts = ?config(client_opts, Config),
313
ServerOpts = ?config(server_opts, Config),
314
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
318
client_echos_active_once(Str, 50000, ClientOpts, ServerOpts, ClientNode,
319
ServerNode, Hostname).
321
%%--------------------------------------------------------------------
322
client_echos_active_big(doc) ->
323
["Server sends 50000 bytes to client in active mode, that receives them, "
324
"sends them back, and closes."];
326
client_echos_active_big(suite) ->
329
client_echos_active_big(Config) when is_list(Config) ->
330
ClientOpts = ?config(client_opts, Config),
331
ServerOpts = ?config(server_opts, Config),
332
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
336
client_echos_active(Str, 50000, ClientOpts, ServerOpts, ClientNode,
337
ServerNode, Hostname).
339
%%--------------------------------------------------------------------
340
server_echos_passive_huge(doc) ->
341
["Client sends 500000 bytes to server in passive mode, that receives "
342
" them, sends them back, and closes."];
344
server_echos_passive_huge(suite) ->
347
server_echos_passive_huge(Config) when is_list(Config) ->
348
ClientOpts = ?config(client_opts, Config),
349
ServerOpts = ?config(server_opts, Config),
350
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
354
server_echos_passive(Str, 500000, ClientOpts, ServerOpts, ClientNode,
355
ServerNode, Hostname).
357
%%--------------------------------------------------------------------
358
server_echos_active_once_huge(doc) ->
359
["Client sends 500000 bytes to server in active once mode, that receives "
360
"them, sends them back, and closes."];
362
server_echos_active_once_huge(suite) ->
365
server_echos_active_once_huge(Config) when is_list(Config) ->
366
ClientOpts = ?config(client_opts, Config),
367
ServerOpts = ?config(server_opts, Config),
368
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
372
server_echos_active_once(Str, 500000, ClientOpts, ServerOpts, ClientNode,
373
ServerNode, Hostname).
375
%%--------------------------------------------------------------------
376
server_echos_active_huge(doc) ->
377
["Client sends 500000 bytes to server in active mode, that receives them, "
378
"sends them back, and closes."];
380
server_echos_active_huge(suite) ->
383
server_echos_active_huge(Config) when is_list(Config) ->
384
ClientOpts = ?config(client_opts, Config),
385
ServerOpts = ?config(server_opts, Config),
386
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
390
server_echos_active(Str, 500000, ClientOpts, ServerOpts, ClientNode,
391
ServerNode, Hostname).
393
%%--------------------------------------------------------------------
394
client_echos_passive_huge(doc) ->
395
["Server sends 500000 bytes to client in passive mode, that receives "
396
"them, sends them back, and closes."];
398
client_echos_passive_huge(suite) ->
401
client_echos_passive_huge(Config) when is_list(Config) ->
402
ClientOpts = ?config(client_opts, Config),
403
ServerOpts = ?config(server_opts, Config),
404
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
407
client_echos_passive(Str, 500000, ClientOpts, ServerOpts, ClientNode,
408
ServerNode, Hostname).
410
%%--------------------------------------------------------------------
411
client_echos_active_once_huge(doc) ->
412
["Server sends 500000 bytes to client in active once mode, that receives "
413
"them, sends them back, and closes."];
415
client_echos_active_once_huge(suite) ->
418
client_echos_active_once_huge(Config) when is_list(Config) ->
419
ClientOpts = ?config(client_opts, Config),
420
ServerOpts = ?config(server_opts, Config),
421
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
424
client_echos_active_once(Str, 500000, ClientOpts, ServerOpts, ClientNode,
425
ServerNode, Hostname).
427
%%--------------------------------------------------------------------
428
client_echos_active_huge(doc) ->
429
["Server sends 500000 bytes to client in active mode, that receives them, "
430
"sends them back, and closes."];
432
client_echos_active_huge(suite) ->
435
client_echos_active_huge(Config) when is_list(Config) ->
436
ClientOpts = ?config(client_opts, Config),
437
ServerOpts = ?config(server_opts, Config),
438
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
441
client_echos_active(Str, 500000, ClientOpts, ServerOpts, ClientNode,
442
ServerNode, Hostname).
444
%%--------------------------------------------------------------------
446
server_echos_passive(Data, Length, ClientOpts, ServerOpts,
447
ClientNode, ServerNode, Hostname) ->
448
Server = ssl_test_lib:start_server([{node, ServerNode}, {port, 0},
454
[{active, false},{mode, binary}
456
Port = ssl_test_lib:inet_port(Server),
457
Client = ssl_test_lib:start_client([{node, ClientNode}, {port, Port},
465
[{active, false}, {mode, binary} |
467
ssl_test_lib:check_result(Server, ok, Client, ok),
469
ssl_test_lib:close(Server),
470
ssl_test_lib:close(Client).
473
server_echos_active_once(Data, Length, ClientOpts, ServerOpts, ClientNode,
474
ServerNode, Hostname) ->
475
Server = ssl_test_lib:start_server([{node, ServerNode}, {port, 0},
478
{?MODULE, echoer_once,
480
{options, [{active, once},
483
Port = ssl_test_lib:inet_port(Server),
484
Client = ssl_test_lib:start_client([{node, ClientNode}, {port, Port},
488
{?MODULE, sender_once,
490
{options, [{active, once},
493
ssl_test_lib:check_result(Server, ok, Client, ok),
495
ssl_test_lib:close(Server),
496
ssl_test_lib:close(Client).
499
server_echos_active(Data, Length, ClientOpts, ServerOpts,
500
ClientNode, ServerNode, Hostname) ->
501
Server = ssl_test_lib:start_server([{node, ServerNode}, {port, 0},
504
{?MODULE, echoer_active,
508
{mode, binary} | ServerOpts]}]),
509
Port = ssl_test_lib:inet_port(Server),
510
Client = ssl_test_lib:start_client([{node, ClientNode}, {port, Port},
514
{?MODULE, sender_active,
518
[{active, true}, {mode, binary}
520
ssl_test_lib:check_result(Server, ok, Client, ok),
522
ssl_test_lib:close(Server),
523
ssl_test_lib:close(Client).
525
client_echos_passive(Data, Length, ClientOpts, ServerOpts,
526
ClientNode, ServerNode, Hostname) ->
527
Server = ssl_test_lib:start_server([{node, ServerNode}, {port, 0},
533
[{active, false}, {mode, binary} |
535
Port = ssl_test_lib:inet_port(Server),
536
Client = ssl_test_lib:start_client([{node, ClientNode}, {port, Port},
544
[{active, false}, {mode, binary}
546
ssl_test_lib:check_result(Server, ok, Client, ok),
548
ssl_test_lib:close(Server),
549
ssl_test_lib:close(Client).
551
client_echos_active_once(Data, Length,
552
ClientOpts, ServerOpts, ClientNode, ServerNode,
554
Server = ssl_test_lib:start_server([{node, ServerNode}, {port, 0},
557
{?MODULE, sender_once,
559
{options, [{active, once},
562
Port = ssl_test_lib:inet_port(Server),
563
Client = ssl_test_lib:start_client([{node, ClientNode}, {port, Port},
567
{?MODULE, echoer_once,
570
{options,[{active, once},
573
ssl_test_lib:check_result(Server, ok, Client, ok),
575
ssl_test_lib:close(Server),
576
ssl_test_lib:close(Client).
578
client_echos_active(Data, Length, ClientOpts, ServerOpts, ClientNode,
581
Server = ssl_test_lib:start_server([{node, ServerNode}, {port, 0},
584
{?MODULE, sender_active,
586
{options, [{active, true},
589
Port = ssl_test_lib:inet_port(Server),
590
Client = ssl_test_lib:start_client([{node, ClientNode}, {port, Port},
594
{?MODULE, echoer_active,
597
{options, [{active, true},
600
ssl_test_lib:check_result(Server, ok, Client, ok),
602
ssl_test_lib:close(Server),
603
ssl_test_lib:close(Client).
605
send(_, _, _, 0,_) ->
607
send(Socket, Data, Size, Repeate,F) ->
608
NewData = lists:duplicate(Size div 10, Data),
609
ssl:send(Socket, NewData),
611
send(Socket, Data, Size, Repeate - 1,F).
613
sender(Socket, Data, Size) ->
614
ok = send(Socket, Data, Size, 100, fun() -> do_recv(Socket, Data, Size, <<>>, false) end),
615
test_server:format("Sender recv: ~p~n", [ssl:getopts(Socket, [active])]),
618
sender_once(Socket, Data, Size) ->
619
send(Socket, Data, Size, 100,
620
fun() -> do_active_once(Socket, Data, Size, <<>>, false) end),
621
test_server:format("Sender active once: ~p~n",
622
[ssl:getopts(Socket, [active])]),
625
sender_active(Socket, Data, Size) ->
626
F = fun() -> do_active(Socket, Data, Size, <<>>, false) end,
627
send(Socket, Data, Size, 100, F),
628
test_server:format("Sender active: ~p~n", [ssl:getopts(Socket, [active])]),
631
echoer(Socket, Data, Size) ->
632
test_server:format("Echoer recv: ~p~n", [ssl:getopts(Socket, [active])]),
633
echo(fun() -> do_recv(Socket, Data, Size, <<>>, true) end, 100).
635
echoer_once(Socket, Data, Size) ->
636
test_server:format("Echoer active once: ~p ~n",
637
[ssl:getopts(Socket, [active])]),
638
echo(fun() -> do_active_once(Socket, Data, Size, <<>>, true) end, 100).
640
echoer_active(Socket, Data, Size) ->
641
test_server:format("Echoer active: ~p~n", [ssl:getopts(Socket, [active])]),
642
echo(fun() -> do_active(Socket, Data, Size, <<>>, true) end, 100).
650
do_recv(_Socket, _Data, 0, _Acc, true) ->
652
do_recv(_Socket, Data, 0, Acc, false) ->
653
Data = lists:sublist(binary_to_list(Acc), 10);
655
do_recv(Socket, Data, Size, Acc, Echo) ->
656
{ok, NewData} = ssl:recv(Socket, 0),
657
NewSize = size(NewData),
660
ssl:send(Socket, NewData),
661
NewSize = size(NewData),
662
do_recv(Socket, Data, Size - NewSize, [], Echo);
664
case size(Acc) < 10 of
666
do_recv(Socket, Data, Size - NewSize,
667
<<Acc/binary, NewData/binary>>, Echo);
669
do_recv(Socket, Data, Size - NewSize, Acc, Echo)
673
do_active_once(_Socket, _Data, 0, _Acc, true) ->
675
do_active_once(_Socket, Data, 0, Acc, false) ->
676
Data = lists:sublist(binary_to_list(Acc), 10);
678
do_active_once(Socket, Data, Size, Acc, Echo) ->
680
{ssl, Socket, NewData} ->
681
NewSize = size(NewData),
684
ssl:send(Socket, NewData),
685
ssl:setopts(Socket, [{active, once}]),
686
do_active_once(Socket, Data, Size - NewSize, [], Echo);
688
case size(Acc) < 10 of
690
ssl:setopts(Socket, [{active, once}]),
691
do_active_once(Socket, Data, Size - NewSize,
692
<<Acc/binary, NewData/binary>>,
695
ssl:setopts(Socket, [{active, once}]),
696
do_active_once(Socket, Data,
697
Size - NewSize, Acc, Echo)
702
do_active(_Socket, _Data, 0, _Acc, true) ->
704
do_active(_Socket, Data, 0, Acc, false) ->
705
Data = lists:sublist(binary_to_list(Acc), 10);
707
do_active(Socket, Data, Size, Acc, Echo) ->
709
{ssl, Socket, NewData} ->
710
NewSize = size(NewData),
713
ssl:send(Socket, NewData),
714
do_active(Socket, Data, Size - NewSize, [], Echo);
716
case size(Acc) < 10 of
718
do_active(Socket, Data, Size - NewSize,
719
<<Acc/binary, NewData/binary>>,
722
do_active(Socket, Data,
723
Size - NewSize, Acc, Echo)