[cpp-sp] branch main updated: Skeletal tests and some logging for RemotingService.

Scott Cantor cantor.2 at osu.edu
Thu Jan 23 17:46:51 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=375572f1151d42a80eefa67450944374c3be29f2

The following commit(s) were added to refs/heads/main by this push:
     new 375572f1 Skeletal tests and some logging for RemotingService.
375572f1 is described below

commit 375572f1151d42a80eefa67450944374c3be29f2
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Jan 23 12:46:47 2025 -0500

    Skeletal tests and some logging for RemotingService.
---
 shibsp/exceptions.h                                |  1 +
 .../remoting/impl/AbstractHTTPRemotingService.cpp  | 10 ++--
 shibsp/remoting/impl/AbstractRemotingService.cpp   |  8 ++-
 shibsp/remoting/impl/CurlHTTPRemotingService.cpp   |  4 +-
 tests/Makefile.am                                  |  1 +
 tests/data/impl/console-shibboleth.ini             |  2 +-
 tests/data/remoting/impl/shibboleth.ini            | 15 ++++++
 tests/remoting/impl/RemotingServiceTests.cpp       | 60 ++++++++++++++++++++++
 8 files changed, 93 insertions(+), 8 deletions(-)

diff --git a/shibsp/exceptions.h b/shibsp/exceptions.h
index 712a056f..50b3efbd 100644
--- a/shibsp/exceptions.h
+++ b/shibsp/exceptions.h
@@ -132,6 +132,7 @@ namespace shibsp {
     DECL_SHIBSP_EXCEPTION(ConfigurationException,SHIBSP_EXCEPTIONAPI(SHIBSP_API),shibsp::agent_exception);
     DECL_SHIBSP_EXCEPTION(IOException,SHIBSP_EXCEPTIONAPI(SHIBSP_API),shibsp::agent_exception);
     DECL_SHIBSP_EXCEPTION(RemotingException,SHIBSP_EXCEPTIONAPI(SHIBSP_API),shibsp::agent_exception);
+    DECL_SHIBSP_EXCEPTION(OperationException,SHIBSP_EXCEPTIONAPI(SHIBSP_API),shibsp::RemotingException);
     DECL_SHIBSP_EXCEPTION(SessionException,SHIBSP_EXCEPTIONAPI(SHIBSP_API),shibsp::agent_exception);
 
 #if defined (_MSC_VER)
diff --git a/shibsp/remoting/impl/AbstractHTTPRemotingService.cpp b/shibsp/remoting/impl/AbstractHTTPRemotingService.cpp
index ac8fd98f..34ea5158 100644
--- a/shibsp/remoting/impl/AbstractHTTPRemotingService.cpp
+++ b/shibsp/remoting/impl/AbstractHTTPRemotingService.cpp
@@ -45,9 +45,9 @@ const char AbstractHTTPRemotingService::TIMEOUT_PROP_NAME[] = "timeout";
 const char AbstractHTTPRemotingService::CA_FILE_PROP_NAME[] = "tlsCAFile";
 
 const char AbstractHTTPRemotingService::SECRET_SOURCE_TYPE_PROP_DEFAULT[] = "File";
-const char AbstractHTTPRemotingService::BASE_URL_PROP_DEFAULT[] = "http://localhost/idp/profile";
+const char AbstractHTTPRemotingService::BASE_URL_PROP_DEFAULT[] = "http://localhost/idp/profile/sp";
 const char AbstractHTTPRemotingService::AUTH_METHOD_PROP_DEFAULT[] = "basic";
-const char AbstractHTTPRemotingService::AUTH_CACHING_COOKIE_PROP_DEFAULT[] = "JSESSIONID";
+const char AbstractHTTPRemotingService::AUTH_CACHING_COOKIE_PROP_DEFAULT[] = "__Host-JSESSIONID";
 unsigned int AbstractHTTPRemotingService::CONNECT_TIMEOUT_PROP_DEFAULT = 3;
 unsigned int AbstractHTTPRemotingService::TIMEOUT_PROP_DEFAULT = 10;
 const char AbstractHTTPRemotingService::CA_FILE_PROP_DEFAULT[] = "trustlist.pem";
@@ -85,7 +85,7 @@ AbstractHTTPRemotingService::AbstractHTTPRemotingService(ptree& pt)
 #elif defined(HAVE_CXX14)
             m_lock.reset(new shared_timed_mutex());
 #else
-        Category::getInstance(SHIBSP_LOGCAT ".RemotingService.HTTP").warn(
+        Category::getInstance(SHIBSP_LOGCAT ".RemotingService").warn(
             "disabling agent authentication caching due to older C++ compiler");
         m_authCachingCookie.clear();
 #endif
@@ -98,8 +98,8 @@ DDF AbstractHTTPRemotingService::send(const DDF& in) const
     DDF output = AbstractRemotingService::send(in);
     if (!m_authCachingCookie.empty()) {
         // TODO: Check for auth cache cookie value coming back and stash off using a write lock.
-        string latestValue;
-        if (!latestValue.empty()) {
+        const char* latestValue = output.getmember("cached_auth").string();
+        if (latestValue) {
             m_authcachelock->lock_shared();
             if (m_authCachingValue != latestValue) {
                 m_authcachelock->unlock_shared();
diff --git a/shibsp/remoting/impl/AbstractRemotingService.cpp b/shibsp/remoting/impl/AbstractRemotingService.cpp
index 8b76fc9d..59546610 100644
--- a/shibsp/remoting/impl/AbstractRemotingService.cpp
+++ b/shibsp/remoting/impl/AbstractRemotingService.cpp
@@ -19,7 +19,7 @@
  */
 
 #include "internal.h"
-
+#include "exceptions.h"
 #include "remoting/impl/AbstractRemotingService.h"
 
 #include <sstream>
@@ -43,5 +43,11 @@ DDF AbstractRemotingService::send(const DDF& in) const
 
     DDF output;
     outstream >> output;
+
+    const char* event = output.getmember("event").string();
+    if (event && strcmp(event, "success")) {
+        DDFJanitor cleanup(output);
+        throw OperationException(event);
+    }
     return output;
 }
diff --git a/shibsp/remoting/impl/CurlHTTPRemotingService.cpp b/shibsp/remoting/impl/CurlHTTPRemotingService.cpp
index 13d28376..4321e501 100644
--- a/shibsp/remoting/impl/CurlHTTPRemotingService.cpp
+++ b/shibsp/remoting/impl/CurlHTTPRemotingService.cpp
@@ -173,7 +173,7 @@ namespace shibsp {
 
 CurlHTTPRemotingService::CurlHTTPRemotingService(ptree& pt)
     : AbstractHTTPRemotingService(pt), AbstractRemotingService(pt),
-        m_log(Category::getInstance(SHIBSP_LOGCAT ".RemotingService.CurlHTTP")),
+        m_log(Category::getInstance(SHIBSP_LOGCAT ".RemotingService")),
             m_curllog(Category::getInstance(SHIBSP_LOGCAT ".libcurl")),
                 m_poolsize(20), m_chunked(true)
 {
@@ -194,6 +194,8 @@ CurlHTTPRemotingService::CurlHTTPRemotingService(ptree& pt)
         }
         setUserAgent(useragent.c_str());
     }
+
+    m_log.info("CurlHTTP RemotingService installed for agent (%s), baseURL (%s)", getAgentID(), getBaseURL());
 }
 
 CurlHTTPRemotingService::~CurlHTTPRemotingService()
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 98fe165b..7f9994ee 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,6 +15,7 @@ shibsptest_SOURCES = \
 	impl/XMLAccessControlTests.cpp \
 	impl/XMLRequestMapperTests.cpp \
 	platform/iis/ModuleConfigTests.cpp \
+	remoting/impl/RemotingServiceTests.cpp \
 	remoting/impl/SecretSourceTests.cpp \
 	util/PropertyTreeTests.cpp \
 	util/BoostPropertySetTests.cpp \
diff --git a/tests/data/impl/console-shibboleth.ini b/tests/data/impl/console-shibboleth.ini
index f666b523..575185e6 100644
--- a/tests/data/impl/console-shibboleth.ini
+++ b/tests/data/impl/console-shibboleth.ini
@@ -5,6 +5,6 @@ defaultLevel = INFO
 [logging-categories]
 Shibboleth.AgentConfig = WARN
 Shibboleth.AccessControl = DEBUG
-Shibboleth.RequestMapper = DEBUG
+Shibboleth.RequestMapper = INFO
 Shibboleth.DummyRequest = DEBUG
 
diff --git a/tests/data/remoting/impl/shibboleth.ini b/tests/data/remoting/impl/shibboleth.ini
new file mode 100644
index 00000000..0f0317b5
--- /dev/null
+++ b/tests/data/remoting/impl/shibboleth.ini
@@ -0,0 +1,15 @@
+[remoting]
+baseURL = https://localhost/idp/profile/sp
+agentID = sp.example.org
+authMethod = basic
+authCachingCookie = __Host-JSESSIONID
+tlsCAFile = ./data/remoting/impl/trustfile.pem
+secretSourceType = Env
+secretEnv = SHIBSP_AGENT_SECRET
+
+[logging]
+type = console
+defaultLevel = WARN
+
+[logging-categories]
+Shibboleth.RemotingService = DEBUG
diff --git a/tests/remoting/impl/RemotingServiceTests.cpp b/tests/remoting/impl/RemotingServiceTests.cpp
new file mode 100644
index 00000000..0387f17b
--- /dev/null
+++ b/tests/remoting/impl/RemotingServiceTests.cpp
@@ -0,0 +1,60 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * remoting/impl/RemotingServiceTests.cpp
+ *
+ * Unit tests for RemotingService implementations.
+ */
+
+#include "Agent.h"
+#include "AgentConfig.h"
+#include "exceptions.h"
+#include "remoting/RemotingService.h"
+
+#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 {
+
+struct RemotingFixture
+{
+    RemotingFixture() : data_path(DATA_PATH) {
+        setenv("SHIBSP_AGENT_SECRET", "foo", true);
+        AgentConfig::getConfig().init(nullptr, (data_path + "./shibboleth.ini").c_str(), true);
+    }
+    ~RemotingFixture() {
+        AgentConfig::getConfig().term();
+        unsetenv("SHIBSP_AGENT_SECRET");
+    }
+
+    string data_path;
+};
+
+/////////////
+
+BOOST_FIXTURE_TEST_CASE(RemotingService_test, RemotingFixture)
+{
+    AgentConfig::getConfig().getAgent().getRemotingService();
+}
+
+};
\ 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