⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alltests.cpp

📁 ICE-3.2 一个开源的中间件
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        catch(const LocalException& ex)        {            cerr << ex << endl;            test(false);        }        fact->destroyServer(server);        comm->destroy();    }    cout << "ok" << endl;    cout << "testing CA certificate directory... " << flush;    {        //        // Don't specify CertAuthFile explicitly; we let OpenSSL find the CA        // certificate in the default directory.        //        InitializationData initData;        initData.properties = createClientProps(defaultDir, defaultHost);        initData.properties->setProperty("IceSSL.CertFile", "c_rsa_nopass_ca1_pub.pem");        initData.properties->setProperty("IceSSL.KeyFile", "c_rsa_nopass_ca1_priv.pem");        CommunicatorPtr comm = initialize(initData);        Test::ServerFactoryPrx fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef));        test(fact);        Test::Properties d = createServerProps(defaultDir, defaultHost);        d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_pub.pem";        d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_priv.pem";        Test::ServerPrx server = fact->createServer(d);        try        {            server->ice_ping();        }        catch(const LocalException& ex)        {            cerr << ex << endl;            test(false);        }        fact->destroyServer(server);        comm->destroy();    }    cout << "ok" << endl;    cout << "testing password prompt... " << flush;    {        //        // Use the correct password.        //        InitializationData initData;        initData.properties = createClientProps(defaultDir, defaultHost);        initData.properties->setProperty("IceSSL.CertFile", "c_rsa_pass_ca1_pub.pem");        initData.properties->setProperty("IceSSL.KeyFile", "c_rsa_pass_ca1_priv.pem");        initData.properties->setProperty("Ice.InitPlugins", "0");        CommunicatorPtr comm = initialize(initData);        PluginManagerPtr pm = comm->getPluginManager();        IceSSL::PluginPtr plugin = IceSSL::PluginPtr::dynamicCast(pm->getPlugin("IceSSL"));        test(plugin);        PasswordPromptIPtr prompt = new PasswordPromptI("client");        plugin->setPasswordPrompt(prompt);        pm->initializePlugins();        test(prompt->count() == 1);        Test::ServerFactoryPrx fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef));        test(fact);        Test::Properties d = createServerProps(defaultDir, defaultHost);        d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_pub.pem";        d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_priv.pem";        Test::ServerPrx server = fact->createServer(d);        try        {            server->ice_ping();        }        catch(const LocalException& ex)        {            cerr << ex << endl;            test(false);        }        fact->destroyServer(server);        comm->destroy();        //        // Use an incorrect password and check that retries are attempted.        //        initData.properties = createClientProps(defaultDir, defaultHost);        initData.properties->setProperty("IceSSL.CertFile", "c_rsa_pass_ca1_pub.pem");        initData.properties->setProperty("IceSSL.KeyFile", "c_rsa_pass_ca1_priv.pem");        initData.properties->setProperty("IceSSL.PasswordRetryMax", "4");        initData.properties->setProperty("Ice.InitPlugins", "0");        comm = initialize(initData);        pm = comm->getPluginManager();        plugin = IceSSL::PluginPtr::dynamicCast(pm->getPlugin("IceSSL"));        test(plugin);        prompt = new PasswordPromptI("invalid");        plugin->setPasswordPrompt(prompt);        try        {            pm->initializePlugins();        }        catch(const PluginInitializationException&)        {            // Expected.        }        catch(const LocalException& ex)        {            cerr << ex << endl;            test(false);        }        test(prompt->count() == 4);        comm->destroy();    }    cout << "ok" << endl;    cout << "testing ciphers... " << flush;    {        //        // The server has a certificate but the client doesn't. They should        // negotiate to use ADH since we explicitly enable it.        //        InitializationData initData;        initData.properties = createClientProps(defaultDir, defaultHost);        initData.properties->setProperty("IceSSL.Ciphers", "ADH");        CommunicatorPtr comm = initialize(initData);        Test::ServerFactoryPrx fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef));        test(fact);        Test::Properties d = createServerProps(defaultDir, defaultHost);        d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_pub.pem";        d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_priv.pem";        d["IceSSL.Ciphers"] = "RSA:ADH";        d["IceSSL.VerifyPeer"] = "1";        Test::ServerPrx server = fact->createServer(d);        try        {            string cipherSub = "ADH-";            server->checkCipher(cipherSub);            IceSSL::ConnectionInfo info = IceSSL::getConnectionInfo(server->ice_getConnection());            test(info.cipher.compare(0, cipherSub.size(), cipherSub) == 0);        }        catch(const LocalException&)        {            test(false);        }        fact->destroyServer(server);        comm->destroy();    }    {        //        // Configure a server with RSA and DSA certificates.        //        // First try a client with a DSA certificate.        //        InitializationData initData;        initData.properties = createClientProps(defaultDir, defaultHost);        initData.properties->setProperty("IceSSL.CertFile", "c_dsa_nopass_ca1_pub.pem");        initData.properties->setProperty("IceSSL.KeyFile", "c_dsa_nopass_ca1_priv.pem");        initData.properties->setProperty("IceSSL.Ciphers", "DEFAULT:DSS");        CommunicatorPtr comm = initialize(initData);        Test::ServerFactoryPrx fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef));        test(fact);        Test::Properties d = createServerProps(defaultDir, defaultHost);        d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_pub.pem" + sep + "s_dsa_nopass_ca1_pub.pem";        d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_priv.pem" + sep + "s_dsa_nopass_ca1_priv.pem";        d["IceSSL.Ciphers"] = "DEFAULT:DSS";        d["IceSSL.VerifyPeer"] = "1";        Test::ServerPrx server = fact->createServer(d);        try        {            server->ice_ping();        }        catch(const LocalException&)        {            test(false);        }        fact->destroyServer(server);        comm->destroy();        //        // Next try a client with an RSA certificate.        //        initData.properties = createClientProps(defaultDir, defaultHost);        initData.properties->setProperty("IceSSL.CertFile", "c_rsa_nopass_ca1_pub.pem");        initData.properties->setProperty("IceSSL.KeyFile", "c_rsa_nopass_ca1_priv.pem");        comm = initialize(initData);        fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef));        test(fact);        d = createServerProps(defaultDir, defaultHost);        d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_pub.pem" + sep + "s_dsa_nopass_ca1_pub.pem";        d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_priv.pem" + sep + "s_dsa_nopass_ca1_priv.pem";        d["IceSSL.Ciphers"] = "DEFAULT:DSS";        d["IceSSL.VerifyPeer"] = "1";        server = fact->createServer(d);        try        {            server->ice_ping();        }        catch(const LocalException&)        {            test(false);        }        fact->destroyServer(server);        comm->destroy();        //        // Next try a client with ADH. This should fail.        //        initData.properties = createClientProps(defaultDir, defaultHost);        initData.properties->setProperty("IceSSL.Ciphers", "ADH");        comm = initialize(initData);        fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef));        test(fact);        d = createServerProps(defaultDir, defaultHost);        d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_pub.pem" + sep + "s_dsa_nopass_ca1_pub.pem";        d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_priv.pem" + sep + "s_dsa_nopass_ca1_priv.pem";        d["IceSSL.Ciphers"] = "DEFAULT:DSS";        d["IceSSL.VerifyPeer"] = "1";        server = fact->createServer(d);        try        {            server->ice_ping();            test(false);        }        catch(const ProtocolException&)        {            // Expected.        }        catch(const LocalException&)        {            test(false);        }        fact->destroyServer(server);        comm->destroy();    }    {        //        // Configure a server with RSA and a client with DSA. This should fail.        //        InitializationData initData;        initData.properties = createClientProps(defaultDir, defaultHost);        initData.properties->setProperty("IceSSL.CertFile", "c_dsa_nopass_ca1_pub.pem");        initData.properties->setProperty("IceSSL.KeyFile", "c_dsa_nopass_ca1_priv.pem");        initData.properties->setProperty("IceSSL.Ciphers", "DSS");        CommunicatorPtr comm = initialize(initData);        Test::ServerFactoryPrx fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef));        test(fact);        Test::Properties d = createServerProps(defaultDir, defaultHost);        d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_pub.pem";        d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_priv.pem";        Test::ServerPrx server = fact->createServer(d);        try        {            server->ice_ping();            test(false);        }        catch(const ProtocolException&)        {            // Expected.        }#ifdef _WIN32        catch(const ConnectionLostException&)        {            // Expected.        }#endif        catch(const LocalException& ex)        {            cerr << ex << endl;            test(false);        }        fact->destroyServer(server);        comm->destroy();    }    cout << "ok" << endl;    cout << "testing IceSSL.TrustOnly... " << flush;    {        InitializationData initData;        initData.properties = createClientProps(defaultDir, defaultHost);        initData.properties->setProperty("IceSSL.CertAuthFile", "cacert1.pem");        initData.properties->setProperty("IceSSL.CertFile", "c_rsa_nopass_ca1_pub.pem");        initData.properties->setProperty("IceSSL.KeyFile", "c_rsa_nopass_ca1_priv.pem");        initData.properties->setProperty("IceSSL.TrustOnly", "C=US, ST=Florida, O=ZeroC\\, Inc.,"                                         "OU=Ice, emailAddress=info@zeroc.com, CN=Server");        CommunicatorPtr comm = initialize(initData);        IceSSL::PluginPtr plugin = IceSSL::PluginPtr::dynamicCast(comm->getPluginManager()->getPlugin("IceSSL"));        test(plugin);        Test::ServerFactoryPrx fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef));        test(fact);        Test::Properties d = createServerProps(defaultDir, defaultHost);        d["IceSSL.CertAuthFile"] = "cacert1.pem";        d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_pub.pem";        d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_priv.pem";        Test::ServerPrx server = fact->createServer(d);        try        {            server->ice_ping();        }        catch(const LocalException&)        {            test(false);        }        fact->destroyServer(server);        comm->destroy();    }    {        InitializationData initData;        initData.properties = createClientProps(defaultDir, defaultHost);        initData.properties->setProperty("IceSSL.CertAuthFile", "cacert1.pem");        initData.properties->setProperty("IceSSL.CertFile", "c_rsa_nopass_ca1_pub.pem");        initData.properties->setProperty("IceSSL.KeyFile", "c_rsa_nopass_ca1_priv.pem");        initData.properties->setProperty("IceSSL.TrustOnly", "C=US, ST=Florida, O=\"ZeroC, Inc.\","                                         "OU=Ice, emailAddress=info@zeroc.com, CN=Server");        CommunicatorPtr comm = initialize(initData);        IceSSL::PluginPtr plugin = IceSSL::PluginPtr::dynamicCast(comm->getPluginManager()->getPlugin("IceSSL"));        test(plugin);        Test::ServerFactoryPrx fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef));        test(fact);        Test::Properties d = createServerProps(defaultDir, defaultHost);        d["IceSSL.CertAuthFile"] = "cacert1.pem";        d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_pub.pem";        d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_priv.pem";        Test::ServerPrx server = fact->createServer(d);        try        {            server->ice_ping();        }        catch(const LocalException&)        {            test(false);        }        fact->destroyServer(server);        comm->destroy();    }    {        InitializationData initData;        initData.properties = createClientProps(defaultDir, defaultHost);        initData.properties->setProperty("IceSSL.CertAuthFile", "cacert1.pem");        initData.properties->setProperty("IceSSL.CertFile", "c_rsa_nopass_ca1_pub.pem");        initData.properties->setProperty("IceSSL.KeyFile", "c_rsa_nopass_ca1_priv.pem");        CommunicatorPtr comm = initialize(initData);        IceSSL::PluginPtr plugin = IceSSL::PluginPtr::dynamicCast(comm->getPluginManager()->getPlugin("IceSSL"));        test(plugin);        Test::ServerFactoryPrx fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef));        test(fact);        Test::Properties d = createServerProps(defaultDir, defaultHost);        d["IceSSL.CertAuthFile"] = "cacert1.pem";        d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_pub.pem";        d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_priv.pem";        d["IceSSL.TrustOnly"] = "C=US, ST=Florida, O=ZeroC\\, Inc., OU=Ice, emailAddress=info@zeroc.com,"                                "CN=Client";        Test::ServerPrx server = fact->createServer(d);        try        {            server->ice_ping();        }        catch(const LocalException&)        {            test(false);        }        fact->destroyServer(server);        comm->destroy();    }    {        InitializationData initData;        initData.properties = createClientProps(defaultDir, defaultHost);        initData.properties->setProperty("IceSSL.CertAuthFile", "cacert1.pem");        initData.properties->setProperty("IceSSL.CertFile", "c_rsa_nopass_ca1_pub.pem");        initData.properties->setProperty("IceSSL.KeyFile", "c_rsa_nopass_ca1_priv.pem");        initData.properties->setProperty("IceSSL.TrustOnly", "CN=Server");        CommunicatorPtr comm = initialize(initData);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -