1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2006-2016. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20%% 21 22-module(orber_nat_SUITE). 23 24-include_lib("common_test/include/ct.hrl"). 25-include_lib("orber/include/corba.hrl"). 26-include_lib("orber/COSS/CosNaming/CosNaming.hrl"). 27-include_lib("orber/src/orber_iiop.hrl"). 28-include_lib("orber/src/ifr_objects.hrl"). 29-include("idl_output/orber_test_server.hrl"). 30-include_lib("orber/COSS/CosNaming/CosNaming_NamingContextExt.hrl"). 31-include_lib("orber/COSS/CosNaming/CosNaming_NamingContext.hrl"). 32 33 34-define(default_timeout, test_server:minutes(15)). 35 36-define(match(ExpectedRes,Expr), 37 fun() -> 38 AcTuAlReS = (catch (Expr)), 39 case AcTuAlReS of 40 ExpectedRes -> 41 io:format("------ CORRECT RESULT ------~n~p~n", 42 [AcTuAlReS]), 43 AcTuAlReS; 44 _ -> 45 io:format("###### ERROR ERROR ######~nRESULT: ~p~n", 46 [AcTuAlReS]), 47 exit(AcTuAlReS) 48 end 49 end()). 50 51%%----------------------------------------------------------------- 52%% External exports 53%%----------------------------------------------------------------- 54-export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2, cases/0, 55 init_per_suite/1, end_per_suite/1, 56 init_per_testcase/2, end_per_testcase/2, 57 nat_ip_address/1, nat_ip_address_multiple/1, 58 nat_ip_address_local/1, nat_ip_address_local_local/1, 59 nat_iiop_port/1, nat_iiop_port_local/1, 60 nat_iiop_port_local_local/1, 61 nat_iiop_ssl_port/1, nat_iiop_ssl_port_local/1]). 62 63 64%%----------------------------------------------------------------- 65%% Internal exports 66%%----------------------------------------------------------------- 67 68%%----------------------------------------------------------------- 69%% Func: all/1 70%% Args: 71%% Returns: 72%%----------------------------------------------------------------- 73suite() -> [{ct_hooks,[ts_install_cth]}]. 74 75all() -> 76 cases(). 77 78groups() -> 79 []. 80 81init_per_group(_GroupName, Config) -> 82 Config. 83 84end_per_group(_GroupName, Config) -> 85 Config. 86 87 88cases() -> 89 [nat_ip_address, 90 nat_ip_address_multiple, 91 nat_ip_address_local, 92 nat_iiop_port, 93 nat_iiop_port_local, 94 nat_ip_address_local_local, 95 nat_iiop_port_local_local, 96 nat_iiop_ssl_port, 97 nat_iiop_ssl_port_local]. 98 99%%----------------------------------------------------------------- 100%% Init and cleanup functions. 101%%----------------------------------------------------------------- 102init_per_testcase(TC, Config) 103 when TC =:= nat_iiop_ssl_port; 104 TC =:= nat_iiop_ssl_port_local -> 105 case proplists:get_value(crypto_started, Config) of 106 true -> 107 case orber_test_lib:ssl_version() of 108 no_ssl -> 109 {skip,"SSL not installed!"}; 110 _ -> 111 init_per_testcase(dummy_tc, Config) 112 end; 113 false -> 114 {skip, "Crypto did not start"} 115 end; 116init_per_testcase(_Case, Config) -> 117 Path = code:which(?MODULE), 118 code:add_pathz(filename:join(filename:dirname(Path), "idl_output")), 119 Dog=test_server:timetrap(?default_timeout), 120 orber:jump_start([{iiop_port, 0}, 121 {flags, 0}]), 122 oe_orber_test_server:oe_register(), 123 [{watchdog, Dog}|Config]. 124 125 126end_per_testcase(_Case, Config) -> 127 oe_orber_test_server:oe_unregister(), 128 orber:jump_stop(), 129 Path = code:which(?MODULE), 130 code:del_path(filename:join(filename:dirname(Path), "idl_output")), 131 Dog = proplists:get_value(watchdog, Config), 132 test_server:timetrap_cancel(Dog), 133 ok. 134 135init_per_suite(Config) -> 136 if 137 is_list(Config) -> 138 try crypto:start() of 139 ok -> 140 [{crypto_started, true} | Config] 141 catch _:_ -> 142 [{crypto_started, false} | Config] 143 end; 144 true -> 145 exit("Config not a list") 146 end. 147 148end_per_suite(Config) -> 149 application:stop(crypto), 150 Config. 151 152%%----------------------------------------------------------------- 153%% API tests for NAT 154%%----------------------------------------------------------------- 155%% These case test if the server ORB use the correct 156%% interface when exporting IOR:s 157nat_ip_address(_Config) -> 158 IP = orber_test_lib:get_host(), 159 Loopback = orber_test_lib:get_loopback_interface(), 160 {ok, ServerNode, _ServerHost} = 161 ?match({ok,_,_}, orber_test_lib:js_node([{flags, ?ORB_ENV_ENABLE_NAT}, 162 {nat_ip_address, Loopback}])), 163 ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []), 164 IOR = ?match(#'IOP_IOR'{}, 165 corba:string_to_object("corbaloc::1.2@"++IP++":"++integer_to_list(ServerPort)++"/NameService")), 166 ?match({'external', {Loopback, ServerPort, _ObjectKey, _Counter, _TP, _NewHD}}, 167 iop_ior:get_key(IOR)), 168 ok. 169 170nat_ip_address_multiple(_Config) -> 171 IP = orber_test_lib:get_host(), 172 173 {ok, ServerNode, _ServerHost} = 174 ?match({ok,_,_}, orber_test_lib:js_node([{flags, ?ORB_ENV_ENABLE_NAT}, 175 {nat_ip_address, {multiple, ["10.0.0.1"]}}])), 176 ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []), 177 IOR = ?match(#'IOP_IOR'{}, 178 corba:string_to_object("corbaloc::1.2@"++IP++":"++integer_to_list(ServerPort)++"/NameService")), 179 ?match({'external', {"10.0.0.1", ServerPort, _ObjectKey, _Counter, _TP, _NewHD}}, 180 iop_ior:get_key(IOR)), 181 ok. 182 183nat_ip_address_local(_Config) -> 184 IP = orber_test_lib:get_host(), 185 {ok, ServerNode, _ServerHost} = 186 ?match({ok,_,_}, orber_test_lib:js_node([{flags, ?ORB_ENV_ENABLE_NAT}, 187 {nat_ip_address, {local, "10.0.0.1", [{IP, "127.0.0.1"}]}}])), 188 ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []), 189 IOR = ?match(#'IOP_IOR'{}, 190 corba:string_to_object("corbaloc::1.2@"++IP++":"++integer_to_list(ServerPort)++"/NameService")), 191 ?match({'external', {"10.0.0.1", ServerPort, _ObjectKey, _Counter, _TP, _NewHD}}, 192 iop_ior:get_key(IOR)), 193 ok. 194 195nat_ip_address_local_local(_Config) -> 196 IP = orber_test_lib:get_host(), 197 Loopback = orber_test_lib:get_loopback_interface(), 198 {ok, ServerNode, _ServerHost} = 199 ?match({ok,_,_}, orber_test_lib:js_node([{flags, 200 (?ORB_ENV_LOCAL_INTERFACE bor 201 ?ORB_ENV_ENABLE_NAT)}, 202 {nat_ip_address, {local, "10.0.0.1", [{IP, "10.0.0.2"}]}}])), 203 ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []), 204 IOR1 = ?match(#'IOP_IOR'{}, 205 corba:string_to_object("corbaloc::1.2@"++IP++":"++integer_to_list(ServerPort)++"/NameService")), 206 ?match({'external', {"10.0.0.2", ServerPort, _ObjectKey, _Counter, _TP, _NewHD}}, 207 iop_ior:get_key(IOR1)), 208 IOR2 = ?match(#'IOP_IOR'{}, 209 corba:string_to_object("corbaloc::1.2@"++Loopback++":"++integer_to_list(ServerPort)++"/NameService")), 210 ?match({'external', {"10.0.0.1", ServerPort, _ObjectKey, _Counter, _TP, _NewHD}}, 211 iop_ior:get_key(IOR2)), 212 ok. 213 214nat_iiop_port(_Config) -> 215 IP = orber_test_lib:get_host(), 216 {ok, ServerNode, _ServerHost} = 217 ?match({ok,_,_}, orber_test_lib:js_node([{flags, ?ORB_ENV_ENABLE_NAT}, 218 {nat_iiop_port, 42}])), 219 ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []), 220 IOR = ?match(#'IOP_IOR'{}, 221 corba:string_to_object("corbaloc::1.2@"++IP++":"++integer_to_list(ServerPort)++"/NameService")), 222 ?match({'external', {_IP, 42, _ObjectKey, _Counter, _TP, _NewHD}}, 223 iop_ior:get_key(IOR)), 224 ok. 225 226nat_iiop_port_local(_Config) -> 227 IP = orber_test_lib:get_host(), 228 {ok, ServerNode, _ServerHost} = 229 ?match({ok,_,_}, orber_test_lib:js_node([{flags, ?ORB_ENV_ENABLE_NAT}, 230 {nat_iiop_port, {local, 42, [{4001, 43}]}}])), 231 ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []), 232 IOR = ?match(#'IOP_IOR'{}, 233 corba:string_to_object("corbaloc::1.2@"++IP++":"++integer_to_list(ServerPort)++"/NameService")), 234 ?match({'external', {_IP, 42, _ObjectKey, _Counter, _TP, _NewHD}}, 235 iop_ior:get_key(IOR)), 236 ok. 237 238nat_iiop_port_local_local(_Config) -> 239 IP = orber_test_lib:get_host(), 240 Loopback = orber_test_lib:get_loopback_interface(), 241 {ok, ServerNode, _ServerHost} = 242 ?match({ok,_,_}, orber_test_lib:js_node([{flags, 243 (?ORB_ENV_LOCAL_INTERFACE bor 244 ?ORB_ENV_ENABLE_NAT)}, 245 {ip_address, IP}])), 246 ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []), 247 orber_test_lib:remote_apply(ServerNode, orber_env, configure_override, [nat_iiop_port, {local, 42, [{ServerPort, 43}]}]), 248 IOR1 = ?match(#'IOP_IOR'{}, 249 corba:string_to_object("corbaloc::1.2@"++IP++":"++integer_to_list(ServerPort)++"/NameService")), 250 ?match({'external', {IP, 43, _ObjectKey, _Counter, _TP, _NewHD}}, 251 iop_ior:get_key(IOR1)), 252 {ok, Ref} = ?match({ok, _}, 253 orber_test_lib:remote_apply(ServerNode, orber, 254 add_listen_interface, 255 [Loopback, normal, 10088])), 256 IOR2 = ?match(#'IOP_IOR'{}, 257 corba:string_to_object("corbaloc::1.2@"++Loopback++":10088/NameService")), 258 ?match({'external', {IP, 42, _ObjectKey, _Counter, _TP, _NewHD}}, 259 iop_ior:get_key(IOR2)), 260 ?match(ok, 261 orber_test_lib:remote_apply(ServerNode, orber, 262 remove_listen_interface, [Ref])), 263 ok. 264 265 266%%----------------------------------------------------------------- 267%% API tests for ORB to ORB, ssl security depth 1 268%%----------------------------------------------------------------- 269%% SECURE MULTI ORB API tests (SSL depth 1) 270%% Make sure NAT works for SSL 271nat_iiop_ssl_port(_Config) -> 272 273 IP = orber_test_lib:get_host(), 274 ServerOptions = orber_test_lib:get_options(iiop_ssl, server, 275 1, [{iiop_ssl_port, 0}, 276 {flags, ?ORB_ENV_ENABLE_NAT}, 277 {ip_address, IP}]), 278 ClientOptions = orber_test_lib:get_options(iiop_ssl, client, 279 1, [{iiop_ssl_port, 0}]), 280 {ok, ServerNode, _ServerHost} = 281 ?match({ok,_,_}, orber_test_lib:js_node(ServerOptions)), 282 ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []), 283 SSLServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_ssl_port, []), 284 NATSSLServerPort = SSLServerPort+1, 285 {ok, Ref} = ?match({ok, _}, 286 orber_test_lib:remote_apply(ServerNode, orber, 287 add_listen_interface, 288 [IP, ssl, NATSSLServerPort])), 289 orber_test_lib:remote_apply(ServerNode, orber_env, configure_override, 290 [nat_iiop_ssl_port, 291 {local, NATSSLServerPort, [{4001, 43}]}]), 292 293 {ok, ClientNode, _ClientHost} = 294 ?match({ok,_,_}, orber_test_lib:js_node(ClientOptions)), 295 ?match(ok, orber_test_lib:remote_apply(ServerNode, orber_test_lib, 296 install_test_data, 297 [ssl])), 298 299 IOR1 = ?match(#'IOP_IOR'{}, 300 orber_test_lib:remote_apply(ClientNode, corba, 301 string_to_object, 302 ["corbaname::1.2@"++IP++":"++ 303 integer_to_list(ServerPort)++"/NameService#mamba"])), 304 305 ?match({'external', {_IP, _Port, _ObjectKey, _Counter, _TP, 306 #host_data{protocol = ssl, 307 ssl_data = #'SSLIOP_SSL'{port = NATSSLServerPort}}}}, 308 iop_ior:get_key(IOR1)), 309 ?match(ok, orber_test_lib:remote_apply(ServerNode, orber_test_lib, 310 uninstall_test_data, 311 [ssl])), 312 ?match(ok, 313 orber_test_lib:remote_apply(ServerNode, orber, 314 remove_listen_interface, [Ref])), 315 ok. 316 317nat_iiop_ssl_port_local(_Config) -> 318 319 IP = orber_test_lib:get_host(), 320 ServerOptions = orber_test_lib:get_options(iiop_ssl, server, 321 1, [{iiop_ssl_port, 0}, 322 {flags, 323 (?ORB_ENV_LOCAL_INTERFACE bor 324 ?ORB_ENV_ENABLE_NAT)}, 325 {ip_address, IP}]), 326 ClientOptions = orber_test_lib:get_options(iiop_ssl, client, 327 1, [{iiop_ssl_port, 0}]), 328 {ok, ServerNode, _ServerHost} = 329 ?match({ok,_,_}, orber_test_lib:js_node(ServerOptions)), 330 ServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_port, []), 331 SSLServerPort = orber_test_lib:remote_apply(ServerNode, orber, iiop_ssl_port, []), 332 NATSSLServerPort = SSLServerPort+1, 333 {ok, Ref} = ?match({ok, _}, 334 orber_test_lib:remote_apply(ServerNode, orber, 335 add_listen_interface, 336 [IP, ssl, NATSSLServerPort])), 337 orber_test_lib:remote_apply(ServerNode, orber_env, configure_override, 338 [nat_iiop_ssl_port, 339 {local, NATSSLServerPort, [{NATSSLServerPort, NATSSLServerPort}]}]), 340 341 {ok, ClientNode, _ClientHost} = 342 ?match({ok,_,_}, orber_test_lib:js_node(ClientOptions)), 343 ?match(ok, orber_test_lib:remote_apply(ServerNode, orber_test_lib, 344 install_test_data, 345 [ssl])), 346 347 IOR1 = ?match(#'IOP_IOR'{}, 348 orber_test_lib:remote_apply(ClientNode, corba, 349 string_to_object, 350 ["corbaname::1.2@"++IP++":"++ 351 integer_to_list(ServerPort)++"/NameService#mamba"])), 352 353 ?match({'external', {_IP, _Port, _ObjectKey, _Counter, _TP, 354 #host_data{protocol = ssl, 355 ssl_data = #'SSLIOP_SSL'{port = NATSSLServerPort}}}}, 356 iop_ior:get_key(IOR1)), 357 ?match(ok, orber_test_lib:remote_apply(ServerNode, orber_test_lib, 358 uninstall_test_data, 359 [ssl])), 360 ?match(ok, 361 orber_test_lib:remote_apply(ServerNode, orber, 362 remove_listen_interface, [Ref])), 363 ok. 364 365