[cpp-sp] branch main updated: Curl fixes, conditionally enabled tests.
Scott Cantor
cantor.2 at osu.edu
Thu Jan 23 21:03:14 UTC 2025
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository cpp-sp.
View the commit online:
http://git.shibboleth.net/view/?p=cpp-sp.git;a=commit;h=a9e09e8d201b20506a549dc6af71ef8a0a008864
The following commit(s) were added to refs/heads/main by this push:
new a9e09e8d Curl fixes, conditionally enabled tests.
a9e09e8d is described below
commit a9e09e8d201b20506a549dc6af71ef8a0a008864
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Jan 23 16:03:07 2025 -0500
Curl fixes, conditionally enabled tests.
---
shibsp/Makefile.am | 10 +----
.../remoting/impl/AbstractHTTPRemotingService.cpp | 13 ++++++
shibsp/remoting/impl/AbstractRemotingService.h | 3 +-
shibsp/remoting/impl/CurlHTTPRemotingService.cpp | 47 +++++++++++++---------
tests/data/remoting/impl/shibboleth.ini | 3 +-
tests/data/remoting/impl/trustfile.pem | 21 ++++++++++
tests/remoting/impl/RemotingServiceTests.cpp | 35 ++++++++++++++--
7 files changed, 99 insertions(+), 33 deletions(-)
diff --git a/shibsp/Makefile.am b/shibsp/Makefile.am
index b31b25b1..96a918c5 100644
--- a/shibsp/Makefile.am
+++ b/shibsp/Makefile.am
@@ -153,16 +153,10 @@ libshibsp_la_CXXFLAGS = -DSHIBSP_LITE \
$(AM_CXXFLAGS) \
$(BOOST_CPPFLAGS) \
$(PTHREAD_CFLAGS) \
- $(gss_CFLAGS) $(gnu_gss_CFLAGS) \
- $(log4shib_CFLAGS) $(log4cpp_CFLAGS) \
- $(xerces_CFLAGS) \
- $(xmltooling_lite_CFLAGS)
+ $(libcurl_CFLAGS)
libshibsp_la_LIBADD = \
$(PTHREAD_LIBS) \
- $(gss_LIBS) $(gnu_gss_LIBS) \
- $(log4shib_LIBS) $(log4cpp_LIBS) \
- $(xerces_LIBS) \
- $(xmltooling_lite_LIBS)
+ $(libcurl_LIBS)
pkgsysconfdir = $(sysconfdir)/@PACKAGE_NAME@
pkgxmldir = $(datadir)/xml/@PACKAGE_NAME@
diff --git a/shibsp/remoting/impl/AbstractHTTPRemotingService.cpp b/shibsp/remoting/impl/AbstractHTTPRemotingService.cpp
index 34ea5158..ee1ee77a 100644
--- a/shibsp/remoting/impl/AbstractHTTPRemotingService.cpp
+++ b/shibsp/remoting/impl/AbstractHTTPRemotingService.cpp
@@ -27,6 +27,8 @@
#include "util/BoostPropertySet.h"
#include "util/PathResolver.h"
+#include <sys/stat.h>
+
#include <stdexcept>
#include <boost/property_tree/ptree.hpp>
@@ -76,6 +78,17 @@ AbstractHTTPRemotingService::AbstractHTTPRemotingService(ptree& pt)
m_caFile = props.getString(CA_FILE_PROP_NAME, CA_FILE_PROP_DEFAULT);
if (!m_caFile.empty()) {
AgentConfig::getConfig().getPathResolver().resolve(m_caFile, PathResolver::SHIBSP_CFG_FILE);
+#ifdef WIN32
+ struct _stat stat_buf;
+ if (_stat(m_caFile.c_str(), &stat_buf) != 0) {
+#else
+ struct stat stat_buf;
+ if (stat(m_caFile.c_str(), &stat_buf) != 0) {
+#endif
+ throw ConfigurationException("Unable to access CA file.");
+ } else if (stat_buf.st_size == 0) {
+ throw ConfigurationException("CA file is empty.");
+ }
}
m_authCachingCookie = props.getString(AUTH_CACHING_COOKIE_PROP_NAME, AUTH_CACHING_COOKIE_PROP_DEFAULT);
diff --git a/shibsp/remoting/impl/AbstractRemotingService.h b/shibsp/remoting/impl/AbstractRemotingService.h
index 9e8dbe39..380f1b3f 100644
--- a/shibsp/remoting/impl/AbstractRemotingService.h
+++ b/shibsp/remoting/impl/AbstractRemotingService.h
@@ -54,9 +54,8 @@ namespace shibsp {
* @param path URL path to append to base URL to construct request
* @param input input data to stream to hub
* @param output output stream to capture response
- * @return HTTP status code
*/
- virtual long send(const char* path, std::istream& input, std::ostream& output) const=0;
+ virtual void send(const char* path, std::istream& input, std::ostream& output) const=0;
};
};
diff --git a/shibsp/remoting/impl/CurlHTTPRemotingService.cpp b/shibsp/remoting/impl/CurlHTTPRemotingService.cpp
index 4321e501..d8f7c4e3 100644
--- a/shibsp/remoting/impl/CurlHTTPRemotingService.cpp
+++ b/shibsp/remoting/impl/CurlHTTPRemotingService.cpp
@@ -27,6 +27,7 @@
#include "util/BoostPropertySet.h"
#include <stdexcept>
+#include <boost/algorithm/string.hpp>
#include <boost/property_tree/ptree.hpp>
using namespace shibsp;
@@ -65,7 +66,7 @@ namespace {
return m_chunked;
}
- long send(const char* path, istream& input, ostream& output) const;
+ void send(const char* path, istream& input, ostream& output) const;
CURL* checkout() const;
void checkin(CURL* handle) const;
@@ -74,6 +75,7 @@ namespace {
private:
Category& m_log;
Category& m_curllog;
+ bool m_curlInit;
mutable list<CURL*> m_pool;
mutable int m_poolsize;
mutable mutex m_lock;
@@ -108,15 +110,7 @@ namespace {
curl_easy_getinfo(m_handle, CURLINFO_CONTENT_TYPE, &content_type);
return content_type ? content_type : "";
}
-
- long getStatusCode() const {
- long code = 200;
- if (curl_easy_getinfo(m_handle, CURLINFO_RESPONSE_CODE, &code) != CURLE_OK)
- code = 200;
- return code;
- }
-
-
+
bool setRequestHeader(const char* name, const char* val) {
string temp(name);
temp = temp + ": " + val;
@@ -124,7 +118,7 @@ namespace {
return true;
}
- long send(const char* path, istream& in, ostream& out);
+ void send(const char* path, istream& in, ostream& out);
private:
// per-call state
@@ -175,8 +169,16 @@ CurlHTTPRemotingService::CurlHTTPRemotingService(ptree& pt)
: AbstractHTTPRemotingService(pt), AbstractRemotingService(pt),
m_log(Category::getInstance(SHIBSP_LOGCAT ".RemotingService")),
m_curllog(Category::getInstance(SHIBSP_LOGCAT ".libcurl")),
- m_poolsize(20), m_chunked(true)
+ m_curlInit(false), m_poolsize(20), m_chunked(true)
{
+
+ CURLcode status = curl_global_init(CURL_GLOBAL_ALL);
+ if (status != CURLE_OK) {
+ m_log.crit("libcurl initialization failure: %d", status);
+ throw runtime_error("libcurl failed to initialize");
+ }
+ m_curlInit = true;
+
static const char CIPHER_LIST_PROP_NAME[] = "tlsCipherList";
static const char CHUNKED_PROP_NAME[] = "chunkedEncoding";
@@ -204,6 +206,10 @@ CurlHTTPRemotingService::~CurlHTTPRemotingService()
curl_easy_cleanup(handle);
}
m_pool.clear();
+
+ if (m_curlInit) {
+ curl_global_cleanup();
+ }
}
#define SHIB_CURL_SET(opt, val) \
@@ -311,20 +317,25 @@ void CurlHTTPRemotingService::attachCachedAuthentication(CURL* m_handle) const
if (name) {
string val(getAuthCachingCookieValue());
if (!val.empty()) {
- val = name + '=' + val;
- SHIB_CURL_SET(CURLOPT_COOKIE, val.c_str());
+ string cookie(name);
+ cookie += '=' + val;
+ SHIB_CURL_SET(CURLOPT_COOKIE, cookie.c_str());
}
}
}
-long CurlHTTPRemotingService::send(const char* path, istream& input, ostream& output) const
+void CurlHTTPRemotingService::send(const char* path, istream& input, ostream& output) const
{
CurlOperation op(*this);
- return op.send(path, input, output);
+ op.send(path, input, output);
+ string content_type(op.getContentType());
+ if (content_type != "text/plain" && !boost::starts_with(content_type, "text/plain;")) {
+ throw RemotingException("Response had unsupported content type.");
+ }
}
-long CurlOperation::send(const char* path, istream& in, ostream& out)
+void CurlOperation::send(const char* path, istream& in, ostream& out)
{
// Append call path to base URL.
string url(m_service.getBaseURL());
@@ -382,7 +393,5 @@ long CurlOperation::send(const char* path, istream& in, ostream& out)
// This won't prevent every possible failed connection from being kept, but it's something.
m_keepHandle = true;
-
- return getStatusCode();
}
diff --git a/tests/data/remoting/impl/shibboleth.ini b/tests/data/remoting/impl/shibboleth.ini
index 0f0317b5..d868cac8 100644
--- a/tests/data/remoting/impl/shibboleth.ini
+++ b/tests/data/remoting/impl/shibboleth.ini
@@ -9,7 +9,8 @@ secretEnv = SHIBSP_AGENT_SECRET
[logging]
type = console
-defaultLevel = WARN
+defaultLevel = INFO
[logging-categories]
Shibboleth.RemotingService = DEBUG
+Shibboleth.libcurl = DEBUG
diff --git a/tests/data/remoting/impl/trustfile.pem b/tests/data/remoting/impl/trustfile.pem
new file mode 100644
index 00000000..e39b0fb0
--- /dev/null
+++ b/tests/data/remoting/impl/trustfile.pem
@@ -0,0 +1,21 @@
+-----BEGIN CERTIFICATE-----
+MIIDZTCCAk2gAwIBAgIUXF3+d21Uzb6Vlg/VYTJGb91/HhowDQYJKoZIhvcNAQEL
+BQAwQTELMAkGA1UEBhMCVVMxHjAcBgNVBAoMFVNoaWJib2xldGggQ29uc29ydGl1
+bTESMBAGA1UEAwwJbG9jYWxob3N0MCAXDTI1MDEyMzIwMTk1M1oYDzIwNTIwNjEw
+MjAxOTUzWjBBMQswCQYDVQQGEwJVUzEeMBwGA1UECgwVU2hpYmJvbGV0aCBDb25z
+b3J0aXVtMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IB
+DwAwggEKAoIBAQCq/CqwZ8b5IJAVM5SM5fRLXs80PCFJ0YnWOE4GES2GmTG4awDE
+PtYZkyBAnVvenW1U3oHteuJ/l1rD+aBCqKfLun6FREFUV5+yLr0xeBqbPKeOUr3M
+igX3R9c710/FHgyNCa1Hi5a0+oHmSwqGQ6v0ULuCe38QniS4c+rtjfROz+qvYabI
+ZGAoLvS5fEW9UL4Eyfp/oukxhY3HdM6oiMS/4fSzdj2SKso+vNDtUq8ATLOoGlnz
+ljhCpjbMGOECx+fXgH3NMPwLim4AS99w0HRbCAzjkxBpMbhsHy8yOoDGdHFK15PH
+bRUpvYsBIfAxUiaiWC+waRnrOe8YfskXWd1lAgMBAAGjUzBRMB0GA1UdDgQWBBTB
+mo0EEgIZZm7fy0Oq4bQZzkm2cjAfBgNVHSMEGDAWgBTBmo0EEgIZZm7fy0Oq4bQZ
+zkm2cjAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQB5DnPK2xvq
+byF4D7t0BYHuEL95WR2y+SSIIzL0pncAj7io2jkHIwEe1tsAIHAi7fbSyghGPLQR
+Rs1SM6pr/hbfTzCoHZ52tO6FvcpcXFlx91Ywyyj1BkKxqxcNQ72dtisAwb/DWD4r
+nIAaLe8CGxk3VwoTtE9/wfMQLtmd8EmOOoSYNAfXJgEwlbrOp1QptY1d2sRFU4Pk
+IgMVa1QW0etB5yrPl5u1zXKHmhaMp18xanIsQD7AHxHjPcXu7HCbK7KOi2iKwH0f
+EZ9qsUNAusD71UGu5dvEV3BHli2xgP/jpvVXv5LakArrWcH3eeokEVZk5EqR9AzC
+LNnMMXBeyNQ+
+-----END CERTIFICATE-----
diff --git a/tests/remoting/impl/RemotingServiceTests.cpp b/tests/remoting/impl/RemotingServiceTests.cpp
index 0387f17b..48c04fb4 100644
--- a/tests/remoting/impl/RemotingServiceTests.cpp
+++ b/tests/remoting/impl/RemotingServiceTests.cpp
@@ -26,16 +26,22 @@
#include <memory>
#include <string>
#include <boost/test/unit_test.hpp>
-#include <boost/property_tree/ptree.hpp>
using namespace shibsp;
-using namespace boost::property_tree;
using namespace std;
#define DATA_PATH "./data/remoting/impl/"
namespace {
+// Used as test decorator for any tests requiring testbed.
+struct testbedRunning {
+ boost::test_tools::assertion_result operator()(boost::unit_test::test_unit_id) {
+ const char* var = getenv("SHIBSP_TESTBED_RUNNING");
+ return var && *var == '1';
+ }
+};
+
struct RemotingFixture
{
RemotingFixture() : data_path(DATA_PATH) {
@@ -52,9 +58,32 @@ struct RemotingFixture
/////////////
-BOOST_FIXTURE_TEST_CASE(RemotingService_test, RemotingFixture)
+BOOST_FIXTURE_TEST_CASE(RemotingService_startup, RemotingFixture)
{
AgentConfig::getConfig().getAgent().getRemotingService();
}
+BOOST_FIXTURE_TEST_CASE(RemotingService_wrong_path, RemotingFixture, * boost::unit_test::precondition(testbedRunning()))
+{
+ const RemotingService* service = AgentConfig::getConfig().getAgent().getRemotingService();
+ DDF input("/missing");
+ DDFJanitor injanitor(input);
+ BOOST_CHECK_THROW(service->send(input), RemotingException);
+}
+
+BOOST_FIXTURE_TEST_CASE(RemotingService_ping, RemotingFixture, * boost::unit_test::precondition(testbedRunning()))
+{
+ const RemotingService* service = AgentConfig::getConfig().getAgent().getRemotingService();
+ DDF input("/ping");
+ DDFJanitor injanitor(input);
+
+ DDF output = service->send(input);
+ DDFJanitor outjanitor(output);
+ BOOST_CHECK_LE(output.getmember("epoch").longinteger(), time(nullptr));
+
+ DDF output2 = service->send(input);
+ DDFJanitor outjanitor2(output2);
+ BOOST_CHECK_LE(output2.getmember("epoch").longinteger(), time(nullptr));
+}
+
};
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list