[cpp-sp] branch main updated: Sample unit test.

Scott Cantor cantor.2 at osu.edu
Tue Nov 5 20:27:33 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=b00e55cfec0a7b7fedf84ac21925a03494ffd1b4

The following commit(s) were added to refs/heads/main by this push:
     new b00e55cf Sample unit test.
b00e55cf is described below

commit b00e55cfec0a7b7fedf84ac21925a03494ffd1b4
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Nov 5 15:27:29 2024 -0500

    Sample unit test.
---
 .gitignore                              | 22 +--------------
 tests/PropertyTreeTests.cpp             | 47 ++++++++++++++++++++++++++++++---
 tests/data/propertytree/requestmap1.xml |  6 +++++
 3 files changed, 50 insertions(+), 25 deletions(-)

diff --git a/.gitignore b/.gitignore
index 4f55bdd2..4d077a30 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,7 +19,6 @@
 *.suo
 *.aps
 shibsp.pc
-shibsp-lite.pc
 *~
 *.#*
 .*.swp
@@ -46,8 +45,8 @@ x64
 /libtool
 /*.opt
 /*.ncb
-/shibboleth.spec
 /.settings
+/.vscode
 /Portfile
 /pkginfo
 /*.gz
@@ -56,12 +55,6 @@ x64
 /build-aux
 /build
 /Build
-/Projects/VC??/adfs/adfs-lite-Debug/
-/Projects/VC??/adfs/adfs-lite-Release/
-/Projects/VC??/apache/mod_shib_20-Debug/
-/Projects/VC??/apache/mod_shib_20-Release/
-/Projects/VC??/apache/mod_shib_22-Debug/
-/Projects/VC??/apache/mod_shib_22-Release/
 /Projects/VC??/apache/mod_shib_24-Debug/
 /Projects/VC??/apache/mod_shib_24-Release/
 /Projects/VC??/fastcgi/shibauthorizer-Debug/
@@ -70,33 +63,20 @@ x64
 /Projects/VC??/fastcgi/shibresponder-Release/
 /Projects/VC??/ipch/
 /Projects/VC??/.vs
-/Projects/VC??/plugins/plugins-lite-Debug/
-/Projects/VC??/plugins/plugins-lite-Release/
-/Projects/VC??/shibsp/shibsp-lite-Debug/
-/Projects/VC??/shibsp/shibsp-lite-Release/
 /Projects/VC??/Shibboleth.*.opendb
 /Projects/VC??/Shibboleth.*.db
-/configs/apache.config
-/configs/apache2.config
-/configs/apache22.config
 /configs/apache24.config
 /configs/shibboleth.xml
 /configs/shibd-*
 /configs/*.logger
-/doc/api
 /m4/ltversion.m4
 /m4/ltoptions.m4
 /m4/lt~obsolete.m4
 /m4/ltsugar.m4
 /m4/libtool.m4
 /schemas/catalog.xml
-/shibd/shibd
 /shibsp/config_pub.h
 /shibsp/paths.h
 /shibsp/stamp-h2
-/util/mdquery
-/util/resolvertest
-/unittests/*.cpp
-/unittests/shibsptest
 .deps
 .dirstamp
diff --git a/tests/PropertyTreeTests.cpp b/tests/PropertyTreeTests.cpp
index b74c27d3..dbb4e86a 100644
--- a/tests/PropertyTreeTests.cpp
+++ b/tests/PropertyTreeTests.cpp
@@ -18,11 +18,50 @@
  * Unit tests for property tree usage.
  */
 
+#include <iostream>
 #include <boost/test/unit_test.hpp>
+#include <boost/property_tree/xml_parser.hpp>
 
-BOOST_AUTO_TEST_CASE(test1)
+using namespace std;
+namespace pt = boost::property_tree;
+
+#define DATA_PATH "data/propertytree/"
+
+struct PT_Fixture {
+    PT_Fixture() : data_path(DATA_PATH) {}
+    string data_path;
+};
+
+BOOST_FIXTURE_TEST_CASE(PropertyTree_RequestMap_simple, PT_Fixture)
 {
-    int i = 2;
-    BOOST_CHECK( i*i == 1 );
-}
+    pt::ptree tree;
+    pt::read_xml(data_path + "requestmap1.xml", tree);
 
+    BOOST_CHECK_EQUAL(tree.size(), 1);
+
+    const pt::ptree& requestMap = tree.get_child("RequestMap");
+    BOOST_CHECK(requestMap.size() == 2);
+
+    for (const pair<string,pt::ptree>& child : requestMap) {
+        BOOST_CHECK_EQUAL(child.first, "Host");
+
+        BOOST_CHECK_GE(child.second.size(), 1);
+        const pt::ptree& attrs = child.second.get_child("<xmlattr>");
+        string name = attrs.get<string>("name");
+        if (name == "sp.example.org") {
+            BOOST_CHECK_EQUAL(child.second.size(), 2);
+            BOOST_CHECK_EQUAL(attrs.size(), 1);
+            BOOST_CHECK_EQUAL(child.second.get<string>("Path.<xmlattr>.name"), "secure");
+            BOOST_CHECK_EQUAL(child.second.get<string>("Path.<xmlattr>.requireSession"), "true");
+        } else if (name == "admin.example.org") {
+            // Nothing in Host element except the <xmlattr> tree.
+            BOOST_CHECK_EQUAL(child.second.size(), 1);
+            // Three XML attributes, including name.
+            BOOST_CHECK_EQUAL(attrs.size(), 3);
+            BOOST_CHECK_EQUAL(attrs.get<string>("applicationId"), "admin");
+            BOOST_CHECK_EQUAL(attrs.get<string>("requireSession"), "true");
+        } else {
+            BOOST_ERROR("Unexpected Host name: " << name);
+        }
+    }
+}
diff --git a/tests/data/propertytree/requestmap1.xml b/tests/data/propertytree/requestmap1.xml
new file mode 100644
index 00000000..bb0ff14b
--- /dev/null
+++ b/tests/data/propertytree/requestmap1.xml
@@ -0,0 +1,6 @@
+<RequestMap>
+    <Host name="sp.example.org">
+        <Path name="secure" requireSession="true" />
+    </Host>
+    <Host name="admin.example.org" applicationId="admin" requireSession="true" />
+</RequestMap>

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list