aboutsummaryrefslogtreecommitdiffstats
path: root/lib/orber/test/orber_firewall_ipv4_in_SUITE.erl
blob: 6d085d3bf5c52f9609250ae3f55876783ff16847 (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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
%%
%% %CopyrightBegin%
%% 
%% Copyright Ericsson AB 2004-2016. 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(orber_firewall_ipv4_in_SUITE).

-include_lib("common_test/include/ct.hrl").
-include_lib("orber/include/corba.hrl").
-include_lib("orber/COSS/CosNaming/CosNaming.hrl").
-include_lib("orber/src/orber_iiop.hrl").
-include_lib("orber/src/ifr_objects.hrl").
-include("idl_output/orber_test_server.hrl").
-include_lib("orber/COSS/CosNaming/CosNaming_NamingContextExt.hrl").
-include_lib("orber/COSS/CosNaming/CosNaming_NamingContext.hrl").

-define(default_timeout, test_server:minutes(15)).

-define(match(ExpectedRes,Expr),
	fun() ->
		AcTuAlReS = (catch (Expr)),
		case AcTuAlReS of
		    ExpectedRes ->
			io:format("------ CORRECT RESULT ------~n~p~n",
				 [AcTuAlReS]),
			AcTuAlReS;
		    _ ->
			io:format("###### ERROR ERROR ######~nRESULT:  ~p~n",
				  [AcTuAlReS]),
			exit(AcTuAlReS)
		end
	end()).

%%-----------------------------------------------------------------
%% External exports
%%-----------------------------------------------------------------
-export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2, cases/0, 
	 init_per_suite/1, end_per_suite/1, 
	 init_per_testcase/2, end_per_testcase/2,  
	 deny_port_api/1, deny_port_range_api/1, deny_host_api/1,
	 deny_peerhost_api/1, allow_port_range_api/1, 
	 allow_host_api/1, allow_peerhost_api/1, check_address_api/1]).

%%-----------------------------------------------------------------
%% Func: all/1
%% Args: 
%% Returns: 
%%-----------------------------------------------------------------
suite() -> [{ct_hooks,[ts_install_cth]}].

all() -> 
    cases().

groups() -> 
    [].

init_per_group(_GroupName, Config) ->
    Config.

end_per_group(_GroupName, Config) ->
    Config.


%% NOTE - the fragment test cases must bu first since we explicitly set a request
%% id. Otherwise, the request-id counter would be increased and we cannot know
%% what it is.
cases() -> 
    [deny_port_api, deny_port_range_api, deny_host_api,
     deny_peerhost_api, allow_port_range_api, allow_host_api,
     allow_peerhost_api, check_address_api].


init_per_testcase(_Case, Config) ->
    Dog=test_server:timetrap(?default_timeout),
    [{watchdog, Dog}|Config].


end_per_testcase(_Case, Config) ->
    Dog = proplists:get_value(watchdog, Config),
    test_server:timetrap_cancel(Dog),
    ok.

init_per_suite(Config) ->
    if
	is_list(Config) ->
	    orber:jump_start([{iiop_port, 0},
			      {iiop_out_ports, {5980, 6000}}]),
	    Config;
	true ->
	    exit("Config not a list")
    end.

end_per_suite(Config) ->
    orber:jump_stop(),
    Config.

%%-----------------------------------------------------------------
%%  Incomming connections - Deny
%%-----------------------------------------------------------------
%% Deny Access due to invalid local port
deny_port_api(_Config) ->
    [IP] = ?match([_], orber:host()),
    {ok, ServerNode, _ServerHost} = 
	?match({ok,_,_}, orber_test_lib:js_node([{flags, ?ORB_ENV_USE_ACL_INCOMING},
						 {iiop_acl, [{tcp_in, IP++"/32#7000"}]}])),
    ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []),
    ?match({'EXCEPTION', #'CosNaming_NamingContextExt_InvalidAddress'{}}, 
	   corba:string_to_object("corbaloc::1.2@"++IP++":"++integer_to_list(ServerPort)++"/NameService")),
%    catch orber_test_lib:destroy_node(ServerNode, timeout),
    ok.

%% Deny Access due to invalid local port range
deny_port_range_api(_Config) ->
    [IP] = ?match([_], orber:host()),
    {ok, ServerNode, _ServerHost} = 
	?match({ok,_,_}, orber_test_lib:js_node([{flags, ?ORB_ENV_USE_ACL_INCOMING},
						 {iiop_acl, [{tcp_in, IP++"/32#7000/8000"}]}])),
    ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []),
    ?match({'EXCEPTION', #'CosNaming_NamingContextExt_InvalidAddress'{}}, 
	   corba:string_to_object("corbaloc::1.2@"++IP++":"++integer_to_list(ServerPort)++"/NameService")),
%    catch orber_test_lib:destroy_node(ServerNode, timeout),
    ok.


%% Deny Access due to invalid host
deny_host_api(_Config) ->
    [IP] = ?match([_], orber:host()),
    {ok, ServerNode, _ServerHost} = 
	?match({ok,_,_}, orber_test_lib:js_node([{flags, ?ORB_ENV_USE_ACL_INCOMING},
						 {iiop_acl, [{tcp_in, "123.123.123.123/32"}]}])),
    ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []),
    ?match({'EXCEPTION', #'CosNaming_NamingContextExt_InvalidAddress'{}}, 
	   corba:string_to_object("corbaloc::1.2@"++IP++":"++integer_to_list(ServerPort)++"/NameService")),
%    catch orber_test_lib:destroy_node(ServerNode, timeout),
    ok.

%% Deny Access due to invalid peerhost
deny_peerhost_api(_Config) ->
    [IP] = ?match([_], orber:host()),
    {ok, ServerNode, _ServerHost} = 
	?match({ok,_,_}, orber_test_lib:js_node([{flags, ?ORB_ENV_USE_ACL_INCOMING},
						 {iiop_acl, [{tcp_in, IP++"/32", ["123.123.123.123"]}]}])),
    ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []),
    ?match({'EXCEPTION', #'CosNaming_NamingContextExt_InvalidAddress'{}}, 
	   corba:string_to_object("corbaloc::1.2@"++IP++":"++integer_to_list(ServerPort)++"/NameService")),
%    catch orber_test_lib:destroy_node(ServerNode, timeout),
    ok.

%%-----------------------------------------------------------------
%%  Incomming connections - Allow
%%-----------------------------------------------------------------
%% Allow Access due to valid local port range
allow_port_range_api(_Config) ->
    [IP] = ?match([_], orber:host()),
    {ok, ServerNode, _ServerHost} = 
	?match({ok,_,_}, orber_test_lib:js_node([{flags, ?ORB_ENV_USE_ACL_INCOMING},
						 {iiop_acl, [{tcp_in, IP++"/32#5980/6000"}]}])),
    ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []),
    IOR =
	?match({'IOP_IOR',_,_},
	       corba:string_to_object("corbaloc::1.2@"++IP++":"++integer_to_list(ServerPort)++"/NameService")),
    ?match(false, corba_object:not_existent(IOR)),
%    catch orber_test_lib:destroy_node(ServerNode, timeout),
    ok.


%% Allow Access due to valid host
allow_host_api(_Config) ->
    [IP] = ?match([_], orber:host()),
    {ok, ServerNode, _ServerHost} = 
	?match({ok,_,_}, orber_test_lib:js_node([{flags, ?ORB_ENV_USE_ACL_INCOMING},
						 {iiop_acl, [{tcp_in, IP++"/32"}]}])),
    ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []),
    IOR =
	?match({'IOP_IOR',_,_}, 
	       corba:string_to_object("corbaloc::1.2@"++IP++":"++integer_to_list(ServerPort)++"/NameService")),
    ?match(false, corba_object:not_existent(IOR)),
%    catch orber_test_lib:destroy_node(ServerNode, timeout),
    ok.

%% Allow Access due to valid peerhost
allow_peerhost_api(_Config) ->
    [IP] = ?match([_], orber:host()),
    {ok, ServerNode, _ServerHost} = 
	?match({ok,_,_}, orber_test_lib:js_node([{flags, ?ORB_ENV_USE_ACL_INCOMING},
						 {iiop_acl, [{tcp_in, IP++"/32", [IP]}]}])),
    ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []),
    IOR =
	?match({'IOP_IOR',_,_}, 
	       corba:string_to_object("corbaloc::1.2@"++IP++":"++integer_to_list(ServerPort)++"/NameService",
				      [#'IOP_ServiceContext'
				       {context_id=?ORBER_GENERIC_CTX_ID, 
					context_data = {interface, IP}}])),
    ?match(false, corba_object:not_existent(IOR,
					    [#'IOP_ServiceContext'
					     {context_id=?ORBER_GENERIC_CTX_ID, 
					      context_data = {interface, IP}}])),
%    catch orber_test_lib:destroy_node(ServerNode, timeout),
    ok.

%%-----------------------------------------------------------------
%%  Test corbaloc strings
%%-----------------------------------------------------------------
check_address_api(_Config) ->
    ?match({[[iiop,{1,0},"10.0.0.1",2809]],"NameService"},
	   orber_cosnaming_utils:addresses(":10.0.0.1/NameService")),
    ?match({[[iiop,{1,0},"10.0.0.1",2809]],[]},
	   orber_cosnaming_utils:addresses(":10.0.0.1")),
    ?match({[[iiop,{1,2},"10.0.0.1",2809]],"NameService"},
	   orber_cosnaming_utils:addresses(":[email protected]/NameService")),
    ?match({[[iiop,{1,0},"10.0.0.1",4001]],"NameService"},
	   orber_cosnaming_utils:addresses(":10.0.0.1:4001/NameService")),
    ?match({[[iiop,{1,1},"10.0.0.1",4001]],"NameService"},
	   orber_cosnaming_utils:addresses(":[email protected]:4001/NameService")),
    ?match({[[iiop,{1,1},"10.0.0.1",4001]],[]},
	   orber_cosnaming_utils:addresses(":[email protected]:4001")),
    ?match({[[iiop,{1,1},"10.0.0.1",4001]],[]},
	   orber_cosnaming_utils:addresses("iiop:[email protected]:4001")),
    ?match({[[iiop,{1,1},"10.0.0.1",4001]],[]},
	   orber_cosnaming_utils:addresses("iiop:[email protected]:4001/")),

    ?match({[[iiop,{1,1},"myhost",4001]],[]},
	   orber_cosnaming_utils:addresses("iiop:1.1@myhost:4001")),
    ?match({[[iiop,{1,1},"myhost.full.name",4001]],"NameService"},
	   orber_cosnaming_utils:addresses("iiop:[email protected]:4001/NameService")),
    ?match({[[iiop,{1,1},"myhost",4001], 
	     [iiop,{1,1},"myhost.full.name",2809]],"NameService"},
	   orber_cosnaming_utils:addresses("iiop:1.1@myhost:4001,iiop:[email protected]/NameService")),

    ?match({[[iiop,{1,1},"123.12.23.2",4001],
	     [iiop,{1,1},"10.0.0.1",4001]], "NameService"},
	   orber_cosnaming_utils:addresses(":[email protected]:4001,:[email protected]:4001/NameService")),
    ?match({[[iiop,{1,1},"123.12.23.2",4001],
	     [iiop,{1,1},"10.0.0.1",4001]], []},
	   orber_cosnaming_utils:addresses(":[email protected]:4001,:[email protected]:4001")),
    ?match({[[iiop,{1,0},"123.12.23.2",4001],
	     [iiop,{1,1},"10.0.0.1",4001]], "NameService"},
	   orber_cosnaming_utils:addresses(":123.12.23.2:4001,:[email protected]:4001/NameService")),
    ?match({[[iiop,{1,1},"123.12.23.2",4001],
	     [iiop,{1,0},"10.0.0.1",4001]], "NameService"},
	   orber_cosnaming_utils:addresses(":[email protected]:4001,:10.0.0.1:4001/NameService")),
    ?match({[[iiop,{1,1},"123.12.23.2",2809],
	     [iiop,{1,1},"10.0.0.1",4001]], "NameService"},
	   orber_cosnaming_utils:addresses(":[email protected],:[email protected]:4001/NameService")),
    ?match({[[iiop,{1,1},"123.12.23.2",4001],
	     [iiop,{1,1},"10.0.0.1",2809]], "NameService"},
	   orber_cosnaming_utils:addresses(":[email protected]:4001,:[email protected]/NameService")),
    ?match({[[iiop,{1,0},"123.12.23.2",2809],
	     [iiop,{1,0},"10.0.0.1",2809]], "NameService"},
	   orber_cosnaming_utils:addresses(":123.12.23.2,:10.0.0.1/NameService")),
    ?match({[[iiop,{1,0},"123.12.23.2",2809],
	     [iiop,{1,0},"10.0.0.1",2809]], []},
	   orber_cosnaming_utils:addresses(":123.12.23.2,:10.0.0.1/")),
    ?match({[[iiop,{1,0},"123.12.23.2",2809],
	     [iiop,{1,0},"10.0.0.1",2809]], []},
	   orber_cosnaming_utils:addresses("iiop:123.12.23.2,:10.0.0.1/")),

    [IP] = ?match([_], orber:host()),
    {ok, ServerNode, _ServerHost} = 
	?match({ok,_,_}, orber_test_lib:js_node([{flags, ?ORB_ENV_USE_ACL_INCOMING},
						 {iiop_acl, [{tcp_in, IP++"/32"}]}])),
    ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []),
    ?match({'IOP_IOR',_,_}, 
	   corba:string_to_object("corbaloc::1.2@"++IP++":"++integer_to_list(ServerPort)++"/NameService")),
%    catch orber_test_lib:destroy_node(ServerNode, timeout),

    ok.