aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssl/test/ssl_upgrade_SUITE.erl
blob: 77804d6b9815edf0330c9e772f5aee97a09ea223 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2014-2015. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%     http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%
-module(ssl_upgrade_SUITE).

%% Note: This directive should only be used in test suites.
-compile(export_all).

-include_lib("common_test/include/ct.hrl").

-record(state, {
	  config,
	  server,
	  client,
	  soft
	 }).

all() -> 
    [
     minor_upgrade,
     major_upgrade
    ].

init_per_suite(Config0) ->
    catch crypto:stop(),
    try {crypto:start(), erlang:system_info({wordsize, internal}) == erlang:system_info({wordsize, external})} of
	{ok, true} ->
	    case ct_release_test:init(Config0) of
		{skip, Reason} ->
		    {skip, Reason};
		Config ->
		    Result =
			(catch make_certs:all(?config(data_dir, Config),
					      ?config(priv_dir, Config))),
		    ct:log("Make certs  ~p~n", [Result]),
		    ssl_test_lib:cert_options(Config)
	    end;
	{ok, false} ->
	    {skip, "Test server will not handle halfwordemulator correctly. Skip as halfwordemulator is deprecated"} 
    catch _:_ ->
	    {skip, "Crypto did not start"}
    end.

end_per_suite(Config) ->
    ct_release_test:cleanup(Config),
    crypto:stop().

init_per_testcase(_TestCase, Config) ->
    Config.
end_per_testcase(_TestCase, Config) ->
    Config.

major_upgrade(Config) when is_list(Config) ->
    ct_release_test:upgrade(ssl, major,{?MODULE, #state{config = Config}}, Config).

minor_upgrade(Config) when is_list(Config) ->
    ct_release_test:upgrade(ssl, minor,{?MODULE, #state{config = Config}}, Config).

upgrade_init(CTData, #state{config = Config} = State) -> 
    {ok, {_, _, Up, _Down}} = ct_release_test:get_appup(CTData, ssl),
    ct:pal("Up: ~p", [Up]),
    Soft = is_soft(Up), %% It is symmetrical, if upgrade is soft so is downgrade  
    case Soft of 
	true ->
	    {Server, Client} = soft_start_connection(Config),
	    State#state{server = Server, client = Client,
			soft = Soft};
	false ->
	    State#state{soft = Soft}
    end.

upgrade_upgraded(_, #state{soft = false, config = Config} = State) -> 
    {Server, Client} = restart_start_connection(Config),
    ssl_test_lib:check_result(Server, ok, Client, ok),
    ssl_test_lib:close(Server),
    ssl_test_lib:close(Client),
    State;

upgrade_upgraded(_, #state{server = Server0, client = Client0,
			   config = Config, soft = true} = State) -> 
    Server0 ! changed_version,
    Client0 ! changed_version,
    ssl_test_lib:check_result(Server0, ok, Client0, ok),
    ssl_test_lib:close(Server0),
    ssl_test_lib:close(Client0),
    {Server, Client} = soft_start_connection(Config),
    State#state{server = Server, client = Client}.

upgrade_downgraded(_, #state{soft = false, config = Config} = State) -> 
    {Server, Client} = restart_start_connection(Config),
    ssl_test_lib:check_result(Server, ok, Client, ok),
    ssl_test_lib:close(Server),
    ssl_test_lib:close(Client),
    State;

upgrade_downgraded(_, #state{server = Server, client = Client, soft = true} = State) -> 
    Server ! changed_version,
    Client ! changed_version,
    ssl_test_lib:check_result(Server, ok, Client, ok),
    ssl_test_lib:close(Server),
    ssl_test_lib:close(Client),
    State.

use_connection(Socket) ->
    ssl_test_lib:send_recv_result_active(Socket),
    receive 
	changed_version ->
	    ssl_test_lib:send_recv_result_active(Socket)
    end.

soft_start_connection(Config) ->
    ClientOpts = ?config(client_verification_opts, Config),
    ServerOpts = ?config(server_verification_opts, Config),
    {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
    Server = ssl_test_lib:start_server([{node, ServerNode}, {port, 0}, 
					{from, self()}, 
					{mfa, {?MODULE, use_connection, []}},
					{options, ServerOpts}]),
    
    Port = ssl_test_lib:inet_port(Server),
    Client = ssl_test_lib:start_client([{node, ClientNode}, {port, Port},
					{host, Hostname},
					{from, self()}, 
					{mfa, {?MODULE, use_connection, []}},
					{options, ClientOpts}]),
    {Server, Client}.

restart_start_connection(Config) ->
    ClientOpts = ?config(client_verification_opts, Config),
    ServerOpts = ?config(server_verification_opts, Config),
    {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),
    Server = ssl_test_lib:start_server([{node, ServerNode}, {port, 0}, 
					{from, self()}, 
					{mfa, {ssl_test_lib, send_recv_result_active, []}},
					{options, ServerOpts}]),
    
    Port = ssl_test_lib:inet_port(Server),
    Client = ssl_test_lib:start_client([{node, ClientNode}, {port, Port},
					{host, Hostname},
					{from, self()}, 
					{mfa, {ssl_test_lib, send_recv_result_active, []}},
					{options, ClientOpts}]),
    {Server, Client}.

is_soft([{restart_application, ssl}]) ->	       
    false;
is_soft(_) ->	
    true.