2 #include "ace/Get_Opt.h"
3 #include "ace/SString.h"
4 #include "orbsvcs/SecurityC.h"
8 bool shutdown_server
= true;
17 bool successful
; // set by "run" if actual meets expected
19 Results(bool sec
= false, bool nsec
= false)
20 : secure(sec
), non_secure(nsec
), successful(false) { }
23 ClientTest (CORBA::ORB_ptr orb
, const ACE_TCHAR
* ior
);
26 * Creates a Security::QOPPolicy with the Quality-of-Protection set
27 * to "no protection." It then invokes a method on @c obj_ via a
28 * non-secured transport, which should then result in a @c
29 * CORBA::NO_PERMISSION exception.
31 bool non_secure_invocation ();
32 bool secure_invocation ();
34 Results
run(const Results
& expected_results
);
41 ClientTest::ClientTest (CORBA::ORB_ptr orb
, const ACE_TCHAR
* ior
)
42 : orb_(CORBA::ORB::_duplicate (orb
))
44 CORBA::Object_var o
= this->orb_
->string_to_object (ior
);
45 if (CORBA::is_nil (o
.in()))
46 throw CORBA::INTERNAL ();
48 this->obj_
= Foo::Bar::_narrow (o
.in ());
52 ClientTest::run (const ClientTest::Results
& expected
)
56 actual
.non_secure
= this->non_secure_invocation ();
58 actual
.non_secure
= true;
60 actual
.secure
= this->secure_invocation ();
62 actual
.successful
= (expected
.secure
== actual
.secure
63 && expected
.non_secure
== actual
.non_secure
);
69 ClientTest::non_secure_invocation ()
71 ACE_DEBUG ((LM_DEBUG
, "mixed_security/client: invoking via non-secured means\n"));
72 // Disable protection for this insecure invocation test.
74 Security::QOP qop
= Security::SecQOPNoProtection
;
76 CORBA::Any no_protection
;
77 no_protection
<<= qop
;
79 // Create the Security::QOPPolicy.
80 CORBA::Policy_var policy
=
81 this->orb_
->create_policy (Security::SecQOPPolicy
,
84 CORBA::PolicyList
policy_list (1);
85 policy_list
.length (1);
86 policy_list
[0] = CORBA::Policy::_duplicate (policy
.in ());
88 // Create an object reference that uses plain IIOP (i.e. no
90 CORBA::Object_var object
=
91 this->obj_
->_set_policy_overrides (policy_list
,
95 Foo::Bar::_narrow (object
.in ());
97 if (CORBA::is_nil (server
.in ()))
100 "(%P|%t) ERROR: Failed to narrow override reference to "
101 "Foo::Bar type.\n"));
103 throw CORBA::INTERNAL ();
106 bool invocation_succeeded
= true;
109 // This invocation should result in a CORBA::NO_PERMISSION
112 ACE_DEBUG ((LM_DEBUG
, "mixed_security/client: non-secured invocation succeeded\n"));
114 catch (const CORBA::NO_PERMISSION
& )
116 ACE_DEBUG ((LM_DEBUG
,
117 "ClientTest::non_secure_invocation: got NO_PERMISSION\n"));
118 invocation_succeeded
= false;
121 return invocation_succeeded
;
125 ClientTest::secure_invocation ()
127 ACE_DEBUG ((LM_DEBUG
, "mixed_security/client: invoking via secure means\n"));
129 // In this test, any NO_PERM exception is a failure.
130 bool invocation_succeeded
= true;
133 // This invocation should return successfully.
135 ACE_DEBUG ((LM_DEBUG
, "mixed_security/client: secured invocation succeeded\n"));
137 catch (const CORBA::NO_PERMISSION
&)
139 ACE_DEBUG ((LM_DEBUG
,
140 "ClientTest::secure_invocation: got NO_PERMISSION\n"));
141 invocation_succeeded
= false;
144 return invocation_succeeded
;
148 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
150 // Accomodate deficiencies on Windows that preclude doing this in
152 ACE_CString
env ("SSL_CERT_FILE=");
153 env
+= TAO_Mixed_Security_Test::cert_file
;
154 ACE_OS::putenv (env
.c_str ());
158 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
160 ClientTest
restricted (orb
.in (),
161 TAO_Mixed_Security_Test::restricted_ior
);
163 // Run the restricted test
164 ClientTest::Results restricted_results
=
165 restricted
.run (ClientTest::Results(true, false));
166 ACE_DEBUG ((LM_DEBUG
,
167 ACE_TEXT ("===> Restricted test %C: secure=%d, non-secure=%d\n"),
168 restricted_results
.successful
? "PASSED" : "FAILED",
169 restricted_results
.secure
,
170 restricted_results
.non_secure
));
172 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("mixed_security/client: set up permitted test\n")));
173 // Run the permitted test
174 ClientTest
permitted (orb
.in (),
175 TAO_Mixed_Security_Test::permitted_ior
);
177 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("mixed_security/client: running permitted test\n")));
178 ClientTest::Results permitted_results
=
179 permitted
.run (ClientTest::Results(true, true));
180 ACE_DEBUG ((LM_DEBUG
,
181 ACE_TEXT ("===> Permitted test %C: secure=%d, non-secure=%d\n"),
182 permitted_results
.successful
? "PASSED" : "FAILED",
183 permitted_results
.secure
,
184 permitted_results
.non_secure
));
186 // The server ORB *is* shutdown by this test, if explicitly requested
187 // @@ at this point there's no way to specify this...but I should
190 CORBA::Object_var o
=
191 orb
->string_to_object (TAO_Mixed_Security_Test::permitted_ior
);
192 Foo::Bar_var foo
= Foo::Bar::_narrow (o
.in());
198 catch (const CORBA::Exception
& ex
)
200 ex
._tao_print_exception
201 (ACE_TEXT ("mixed_security/client: caught unexpected exception "));