[cpp-sp] branch main updated: Additional test and fixes to plugins and ptree usage.

Scott Cantor cantor.2 at osu.edu
Wed Dec 18 15:20:47 UTC 2024


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=498d4afddeb9238eb6b8c70440fb71823e661322

The following commit(s) were added to refs/heads/main by this push:
     new 498d4afd Additional test and fixes to plugins and ptree usage.
498d4afd is described below

commit 498d4afddeb9238eb6b8c70440fb71823e661322
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Dec 18 10:20:42 2024 -0500

    Additional test and fixes to plugins and ptree usage.
---
 apache/mod_shib_24.cpp                   |  7 +++++--
 shibsp/impl/XMLAccessControl.cpp         |  4 +++-
 shibsp/impl/XMLRequestMapper.cpp         |  6 ++++--
 tests/Makefile.am                        |  3 ++-
 tests/data/impl/acl-badtype.xml          |  1 -
 tests/data/impl/internal-acl-invalid.xml |  3 +++
 tests/impl/XMLAccessControlTests.cpp     | 23 +++++++++++++++--------
 tests/util/ReloadableXMLFileTests.cpp    |  4 ++++
 8 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/apache/mod_shib_24.cpp b/apache/mod_shib_24.cpp
index 641df6e0..69544ca4 100644
--- a/apache/mod_shib_24.cpp
+++ b/apache/mod_shib_24.cpp
@@ -850,10 +850,13 @@ AccessControl::aclresult_t htAccessControl::doAccessControl(const ShibTargetApac
     try {
         ptree pt;
         xml_parser::read_xml(plugin, pt, xml_parser::no_comments|xml_parser::trim_whitespace);
-        string t = pt.get("<xmlattr>.type", "");
+        if (pt.size() != 1)
+            throw ConfigurationException("AccessControl plugin configuration did not contain the expected XML document.");
+        ptree& pt_root = pt.front().second;
+        string t = pt_root.get("<xmlattr>.type", "");
         if (t.empty())
             throw ConfigurationException("Missing type attribute in AccessControl plugin configuration.");
-        unique_ptr<AccessControl> aclplugin(AgentConfig::getConfig().AccessControlManager.newPlugin(t.c_str(), pt, true));
+        unique_ptr<AccessControl> aclplugin(AgentConfig::getConfig().AccessControlManager.newPlugin(t.c_str(), pt_root, true));
 #ifdef HAVE_CXX14
         shared_lock<AccessControl> acllock(*aclplugin);
 #endif
diff --git a/shibsp/impl/XMLAccessControl.cpp b/shibsp/impl/XMLAccessControl.cpp
index 372bf20c..de627ee8 100644
--- a/shibsp/impl/XMLAccessControl.cpp
+++ b/shibsp/impl/XMLAccessControl.cpp
@@ -102,7 +102,9 @@ namespace {
     public:
         XMLAccessControl(const ptree& pt)
             : ReloadableXMLFile(ACCESS_CONTROL_PROP_PATH, pt, Category::getInstance(SHIBSP_LOGCAT ".AccessControl.XML")) {
-            load(); // guarantees an exception or the policy is loaded
+            if (!load().second) {
+                throw ConfigurationException("Initial AccessControl configuration was invalid.");
+            }
         }
 
         ~XMLAccessControl() {}
diff --git a/shibsp/impl/XMLRequestMapper.cpp b/shibsp/impl/XMLRequestMapper.cpp
index 6bc52407..99f587fe 100644
--- a/shibsp/impl/XMLRequestMapper.cpp
+++ b/shibsp/impl/XMLRequestMapper.cpp
@@ -110,7 +110,9 @@ namespace {
     public:
         XMLRequestMapper(const ptree& pt)
             : ReloadableXMLFile(REQUEST_MAP_PROP_PATH, pt, Category::getInstance(SHIBSP_LOGCAT ".RequestMapper")) {
-            load(); // guarantees an exception or the map is loaded
+            if (!load().second) {
+                throw ConfigurationException("Initial ReqyestMapper configuration was invalid.");
+            }
         }
 
         ~XMLRequestMapper() {}
@@ -661,7 +663,7 @@ pair<bool,ptree*> XMLRequestMapper::load() noexcept
         unique_lock<ReloadableXMLFile> locker(*this);
 #endif
         m_impl.swap(impl);
-        
+
         return make_pair(false, raw.second);
     }
     catch (exception& e) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d66b43f2..af4c671d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -4,7 +4,7 @@ TESTS = shibsptest
 check_PROGRAMS = shibsptest
 
 shibsptest_CPPFLAGS = \
-	$(BOOST_CPPFLAGS)
+	$(BOOST_CPPFLAGS) -DSHIBSP_LITE
 
 shibsptest_CXXFLAGS = \
 	$(AM_CXXFLAGS)
@@ -12,6 +12,7 @@ shibsptest_CXXFLAGS = \
 shibsptest_SOURCES = \
 	AgentTestSuite.cpp \
 	AgentConfigTests.cpp \
+	impl/XMLAccessControlTests.cpp \
 	util/PropertyTreeTests.cpp \
 	util/BoostPropertySetTests.cpp \
 	util/ReloadableXMLFileTests.cpp
diff --git a/tests/data/impl/acl-badtype.xml b/tests/data/impl/acl-badtype.xml
deleted file mode 100644
index f0ea0ed2..00000000
--- a/tests/data/impl/acl-badtype.xml
+++ /dev/null
@@ -1 +0,0 @@
-<AccessControlProvider type="Invalid" />
diff --git a/tests/data/impl/internal-acl-invalid.xml b/tests/data/impl/internal-acl-invalid.xml
new file mode 100644
index 00000000..c7ab7874
--- /dev/null
+++ b/tests/data/impl/internal-acl-invalid.xml
@@ -0,0 +1,3 @@
+<AccessControlProvider type="XML">
+	<Access/>
+</AccessControlProvider>
diff --git a/tests/impl/XMLAccessControlTests.cpp b/tests/impl/XMLAccessControlTests.cpp
index 938da869..d7608123 100644
--- a/tests/impl/XMLAccessControlTests.cpp
+++ b/tests/impl/XMLAccessControlTests.cpp
@@ -117,6 +117,8 @@ struct BaseFixture
     string data_path;
 };
 
+/////////////
+// File pointing to external ACL file that's invalid XML.
 /////////////
 
 struct External_Invalid_Fixture : public BaseFixture
@@ -135,18 +137,19 @@ BOOST_FIXTURE_TEST_CASE(XMLAccessControl_external_invalid, External_Invalid_Fixt
     BOOST_CHECK_EQUAL(tree.size(), 1);
 
     exceptionCheck checker("Initial AccessControl configuration was invalid.");
-    BOOST_CHECK_EXCEPTION(AgentConfig::getConfig().AccessControlManager.newPlugin(XML_ACCESS_CONTROL, tree.front().second, true),
-        ConfigurationException, checker.check_message);
+    BOOST_CHECK_EXCEPTION(AgentConfig::getConfig().AccessControlManager.newPlugin(
+        tree.front().second.get<string>("<xmlattr>.type").c_str(), tree.front().second, true),
+            ConfigurationException, checker.check_message);
 }
 
 /////////////
-
-/*
+// Inline ACL content that has the wrong child element.
+/////////////
 
 struct Inline_Invalid_Fixture : public BaseFixture
 {
     Inline_Invalid_Fixture() {
-        xml_parser::read_xml(data_path + "inline-invalid.xml", tree, xml_parser::no_comments|xml_parser::trim_whitespace);
+        xml_parser::read_xml(data_path + "internal-acl-invalid.xml", tree, xml_parser::no_comments|xml_parser::trim_whitespace);
     }
     ~Inline_Invalid_Fixture() {
     }
@@ -154,16 +157,20 @@ struct Inline_Invalid_Fixture : public BaseFixture
     ptree tree;
 };
 
-BOOST_FIXTURE_TEST_CASE(ReloadableFileTest_inline_invalid, Inline_Invalid_Fixture)
+BOOST_FIXTURE_TEST_CASE(XMLAccessControl_inline_invalid, Inline_Invalid_Fixture)
 {
     BOOST_CHECK_EQUAL(tree.size(), 1);
 
-    exceptionCheck checker("Invalid configuration.");
-    BOOST_CHECK_EXCEPTION(DummyXMLFile dummy(tree.front().second), domain_error, checker.check_message);
+    exceptionCheck checker("Initial AccessControl configuration was invalid.");
+    BOOST_CHECK_EXCEPTION(AgentConfig::getConfig().AccessControlManager.newPlugin(
+        tree.front().second.get<string>("<xmlattr>.type").c_str(), tree.front().second, true),
+            ConfigurationException, checker.check_message);
 }
 
 /////////////
 
+/*
+
 struct Inline_Valid_Fixture : public BaseFixture
 {
     Inline_Valid_Fixture() {
diff --git a/tests/util/ReloadableXMLFileTests.cpp b/tests/util/ReloadableXMLFileTests.cpp
index 62e85f10..8befae50 100644
--- a/tests/util/ReloadableXMLFileTests.cpp
+++ b/tests/util/ReloadableXMLFileTests.cpp
@@ -31,6 +31,8 @@ using namespace std;
 
 #define DATA_PATH "./data/util/reloadablefile/"
 
+namespace {
+
 class DummyXMLFile : virtual public ReloadableXMLFile
 {
 public:
@@ -223,3 +225,5 @@ BOOST_FIXTURE_TEST_CASE(ReloadableFileTest_external_valid, External_Valid_Fixtur
     BOOST_CHECK_GT(ts2, ts1);
     dummy.unlock();
 }
+
+};
\ 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