2 #include "ace/Get_Opt.h"
5 #include "orbsvcs/SecurityC.h"
6 #include "ace/SString.h"
8 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
9 const char *cert_file
= "cacert.pem";
12 insecure_invocation_test (CORBA::ORB_ptr orb
,
13 CORBA::Object_ptr obj
)
15 // Disable protection for this insecure invocation test.
17 Security::QOP qop
= Security::SecQOPNoProtection
;
19 CORBA::Any no_protection
;
20 no_protection
<<= qop
;
22 // Create the Security::QOPPolicy.
23 CORBA::Policy_var policy
=
24 orb
->create_policy (Security::SecQOPPolicy
,
27 CORBA::PolicyList
policy_list (1);
28 policy_list
.length (1);
29 policy_list
[0] = CORBA::Policy::_duplicate (policy
.in ());
31 // Create an object reference that uses plain IIOP (i.e. no
33 CORBA::Object_var object
=
34 obj
->_set_policy_overrides (policy_list
,
38 Foo::Bar::_narrow (object
.in ());
40 if (CORBA::is_nil (server
.in ()))
43 "(%P|%t) ERROR: Object reference <%s> is "
47 throw CORBA::INTERNAL ();
52 // This invocation should result in a CORBA::NO_PERMISSION
56 catch (const CORBA::NO_PERMISSION
&)
59 "(%P|%t) Received CORBA::NO_PERMISSION from "
60 "server, as expected.\n"));
66 "(%P|%t) ERROR: CORBA::NO_PERMISSION was not thrown.\n"
67 "(%P|%t) ERROR: It should have been thrown.\n"));
69 throw CORBA::INTERNAL ();
73 secure_invocation_test (CORBA::Object_ptr object
)
76 Foo::Bar::_narrow (object
);
78 if (CORBA::is_nil (server
.in ()))
81 "(%P|%t) ERROR: Object reference <%s> is "
85 throw CORBA::INTERNAL ();
88 // This invocation should return successfully.
95 parse_args (int argc
, ACE_TCHAR
*argv
[])
97 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
100 while ((c
= get_opts ()) != -1)
104 ior
= get_opts
.opt_arg ();
108 ACE_ERROR_RETURN ((LM_ERROR
,
115 // Indicates successful parsing of the command line
120 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
125 CORBA::ORB_init (argc
, argv
);
127 if (parse_args (argc
, argv
) != 0)
130 CORBA::Object_var object
=
131 orb
->string_to_object (ior
);
133 // This test sets creates a Security::QOPPolicy with the
134 // Quality-of-Protection set to "no protection." It then
135 // invokes a method on the server (insecurely), which should
136 // then result in a CORBA::NO_PERMISSION exception.
138 // The server is not shutdown by this test.
139 insecure_invocation_test (orb
.in (), object
.in ());
141 // This test uses the default secure SSLIOP settings to securely
142 // invoke a method on the server. No exception should occur.
144 // The server *is* shutdown by this test.
145 secure_invocation_test (object
.in ());
149 catch (const CORBA::Exception
& ex
)
151 ex
._tao_print_exception ("Caught exception:");
155 ACE_DEBUG ((LM_DEBUG
,
157 "Secure_Invocation test passed.\n"));