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