TEST(HttpClient, SslNoVerification) { HttpClient c; c.SetHttpsVerifyPeers(false); c.SetUrl("https://bitbucket.org/sjodogne/orthanc/raw/Orthanc-0.9.3/Resources/Configuration.json"); Json::Value v; c.Apply(v); ASSERT_TRUE(v.isMember("LuaScripts")); }
bool StorePeerCommand::Apply(ListOfStrings& outputs, const ListOfStrings& inputs) { // Configure the HTTP client HttpClient client; client.SetProxy(Configuration::GetGlobalStringParameter("HttpProxy", "")); if (peer_.GetUsername().size() != 0 && peer_.GetPassword().size() != 0) { client.SetCredentials(peer_.GetUsername().c_str(), peer_.GetPassword().c_str()); } client.SetUrl(peer_.GetUrl() + "instances"); client.SetMethod(HttpMethod_Post); for (ListOfStrings::const_iterator it = inputs.begin(); it != inputs.end(); ++it) { LOG(INFO) << "Sending resource " << *it << " to peer \"" << peer_.GetUrl() << "\""; try { context_.ReadFile(client.AccessPostData(), *it, FileContentType_Dicom); std::string answer; if (!client.Apply(answer)) { LOG(ERROR) << "Unable to send resource " << *it << " to peer \"" << peer_.GetUrl() << "\""; throw OrthancException(ErrorCode_NetworkProtocol); } // Only chain with other commands if this command succeeds outputs.push_back(*it); } catch (OrthancException& e) { LOG(ERROR) << "Unable to forward to an Orthanc peer in a Lua script (instance " << *it << ", peer " << peer_.GetUrl() << "): " << e.What(); if (!ignoreExceptions_) { throw; } } } return true; }
TEST(HttpClient, Basic) { HttpClient c; ASSERT_FALSE(c.IsVerbose()); c.SetVerbose(true); ASSERT_TRUE(c.IsVerbose()); c.SetVerbose(false); ASSERT_FALSE(c.IsVerbose()); #if UNIT_TESTS_WITH_HTTP_CONNEXIONS == 1 Json::Value v; c.SetUrl("http://www.montefiore.ulg.ac.be/~jodogne/Orthanc/Configuration.json"); c.Apply(v); ASSERT_TRUE(v.isMember("StorageDirectory")); #endif }
TEST(HttpClient, Ssl) { Toolbox::WriteFile(BITBUCKET_CERTIFICATES, "UnitTestsResults/bitbucket.cert"); /*{ std::string s; Toolbox::ReadFile(s, "/usr/share/ca-certificates/mozilla/WoSign.crt"); Toolbox::WriteFile(s, "UnitTestsResults/bitbucket.cert"); }*/ HttpClient c; c.SetHttpsVerifyPeers(true); c.SetHttpsCACertificates("UnitTestsResults/bitbucket.cert"); c.SetUrl("https://bitbucket.org/sjodogne/orthanc/raw/Orthanc-0.9.3/Resources/Configuration.json"); Json::Value v; c.Apply(v); ASSERT_TRUE(v.isMember("LuaScripts")); }