diff options
Diffstat (limited to 'cpp/test/IceSSL/configuration/Configuration.cpp')
-rw-r--r-- | cpp/test/IceSSL/configuration/Configuration.cpp | 222 |
1 files changed, 222 insertions, 0 deletions
diff --git a/cpp/test/IceSSL/configuration/Configuration.cpp b/cpp/test/IceSSL/configuration/Configuration.cpp new file mode 100644 index 00000000000..3707d31d85d --- /dev/null +++ b/cpp/test/IceSSL/configuration/Configuration.cpp @@ -0,0 +1,222 @@ +// **********************************************************************
+//
+// Copyright (c) 2002
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#include <Ice/Ice.h>
+#include <TestCommon.h>
+#include <Ice/SslException.h>
+#include <Ice/System.h>
+
+// Note: This test must have a valid Ice.SSL.Client.CertPath
+// and Ice.SSL.Server.CertPath specified.
+
+using namespace std;
+using namespace Ice;
+
+void testContextWithConfig(const Ice::CommunicatorPtr&, IceSSL::ContextType, const std::string&,
+ const std::string&, bool expectFailure = true);
+
+void
+testContextNoConfig(const Ice::CommunicatorPtr& communicator, IceSSL::ContextType contextType)
+{
+ testContextWithConfig(communicator, contextType, "", "");
+}
+
+void
+testContextWithConfig(const Ice::CommunicatorPtr& communicator,
+ IceSSL::ContextType contextType,
+ const std::string& clientFile,
+ const std::string& serverFile,
+ bool expectFailure)
+{
+ PropertiesPtr properties = communicator->getProperties();
+ IceSSL::SystemPtr sslSystem = communicator->getSslSystem();
+
+ std::string contextString;
+
+ std::string clientPropertyString = "Ice.SSL.Client.Config";
+ std::string serverPropertyString = "Ice.SSL.Server.Config";
+
+ switch (contextType)
+ {
+ case IceSSL::Client:
+ {
+ contextString = "Client";
+ break;
+ }
+
+ case IceSSL::Server:
+ {
+ contextString = "Server";
+ break;
+ }
+
+ case IceSSL::ClientServer:
+ {
+ contextString = "ClientServer";
+ break;
+ }
+ }
+
+ std::string configFileDesc = "";
+
+ if (!clientFile.empty() && !serverFile.empty())
+ {
+ configFileDesc = "client and server configuration files";
+ }
+ else if (!clientFile.empty())
+ {
+ configFileDesc = "client configuration file";
+ }
+ else if (!serverFile.empty())
+ {
+ configFileDesc = "server configuration file";
+ }
+ else
+ {
+ configFileDesc = "no configuration file";
+ }
+
+ std::cout << contextString << " with " << configFileDesc << "... " << std::flush;
+
+ try
+ {
+ properties->setProperty(clientPropertyString, clientFile);
+ properties->setProperty(serverPropertyString, serverFile);
+ sslSystem->configure(contextType);
+
+ if (expectFailure)
+ {
+ test(false);
+ }
+ else
+ {
+ std::cout << "ok" << std::endl;
+ }
+ }
+ catch (const IceSSL::ConfigurationLoadingException&)
+ {
+ //
+ // Depending on the context type, and if we supplied
+ // a configuration file, this might be a valid response.
+ //
+
+ switch (contextType)
+ {
+ case IceSSL::Client:
+ {
+ if (clientFile.empty())
+ {
+ std::cout << "ok" << std::endl;
+ }
+ else
+ {
+ test(false);
+ }
+ break;
+ }
+
+ case IceSSL::Server:
+ {
+ if (serverFile.empty())
+ {
+ std::cout << "ok" << std::endl;
+ }
+ else
+ {
+ test(false);
+ }
+ break;
+ }
+
+ case IceSSL::ClientServer:
+ {
+ if (clientFile.empty() || serverFile.empty())
+ {
+ std::cout << "ok" << std::endl;
+ }
+ else
+ {
+ test(false);
+ }
+ break;
+ }
+ }
+ }
+ catch (const LocalException&)
+ {
+ //
+ // Any other exception is bad.
+ //
+
+ test(false);
+ }
+ catch (...)
+ {
+ //
+ // Unknown exceptions are always bad.
+ //
+
+ test(false);
+ }
+}
+
+int
+run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator)
+{
+ // Testing Client context.
+ testContextNoConfig(communicator, IceSSL::Client);
+ testContextWithConfig(communicator, IceSSL::Client,"client_sslconfig.xml","", false);
+
+ // Testing Server context.
+ testContextNoConfig(communicator, IceSSL::Server);
+ testContextWithConfig(communicator, IceSSL::Server,"","server_sslconfig.xml", false);
+
+ // Testing ClientServer context.
+ testContextNoConfig(communicator, IceSSL::ClientServer);
+ testContextWithConfig(communicator, IceSSL::ClientServer, "client_sslconfig.xml", "");
+ testContextWithConfig(communicator, IceSSL::ClientServer, "", "server_sslconfig.xml");
+ testContextWithConfig(communicator, IceSSL::ClientServer, "client_sslconfig.xml", "server_sslconfig.xml", false);
+ testContextWithConfig(communicator, IceSSL::ClientServer, "sslconfig.xml", "sslconfig.xml", false);
+
+ return EXIT_SUCCESS;
+}
+
+int
+main(int argc, char* argv[])
+{
+ int status;
+ Ice::CommunicatorPtr communicator;
+
+ try
+ {
+ communicator = Ice::initialize(argc, argv);
+ status = run(argc, argv, communicator);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ status = EXIT_FAILURE;
+ }
+
+ if (communicator)
+ {
+ try
+ {
+ communicator->destroy();
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ status = EXIT_FAILURE;
+ }
+ }
+
+ return status;
+}
|