[cpp-sp] branch main updated: Add unit test for AttributeConfiguration

Scott Cantor cantor.2 at osu.edu
Tue Oct 14 14:00: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=3c77a1aa858e6382a35ce785b4d0a0ca2af9cbd4

The following commit(s) were added to refs/heads/main by this push:
     new 3c77a1aa Add unit test for AttributeConfiguration
3c77a1aa is described below

commit 3c77a1aa858e6382a35ce785b4d0a0ca2af9cbd4
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Oct 14 10:00:47 2025 -0400

    Add unit test for AttributeConfiguration
---
 tests/Makefile.am                                  |  1 +
 .../impl/DefaultAttributeConfigurationTests.cpp    | 82 ++++++++++++++++++++++
 tests/data/attribute/impl/attributes-bad.ini       | 11 +++
 tests/data/attribute/impl/attributes.ini           | 11 +++
 tests/data/attribute/impl/console-agent.ini        | 12 ++++
 5 files changed, 117 insertions(+)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 69c9c27d..ea87d224 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,6 +15,7 @@ noinst_HEADERS = \
 shibsptest_SOURCES = \
 	AgentTestSuite.cpp \
 	AgentConfigTests.cpp \
+	attribute/impl/DefaultAttributeConfigurationtests.cpp \
 	impl/XMLAccessControlTests.cpp \
 	impl/XMLRequestMapperTests.cpp \
 	platform/iis/ModuleConfigTests.cpp \
diff --git a/tests/attribute/impl/DefaultAttributeConfigurationTests.cpp b/tests/attribute/impl/DefaultAttributeConfigurationTests.cpp
new file mode 100644
index 00000000..1d1b5daf
--- /dev/null
+++ b/tests/attribute/impl/DefaultAttributeConfigurationTests.cpp
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+
+/**
+ * platform/iis/ModuleConfigTests.cpp
+ *
+ * Unit tests for IIS ModuleConfig class.
+ */
+
+#include "exceptions.h"
+#include "AgentConfig.h"
+#include "RequestMapper.h"
+#include "attribute/AttributeConfiguration.h"
+
+#include <memory>
+
+#include <boost/property_tree/ini_parser.hpp>
+#include <boost/test/unit_test.hpp>
+
+using namespace shibsp;
+using namespace boost::property_tree;
+using namespace std;
+
+#define DATA_PATH "./data/attribute/impl/"
+
+namespace {
+
+class exceptionCheck {
+public:
+    exceptionCheck(const string& msg) : m_msg(msg) {}
+    bool check_message(const exception& e) {
+        cout << e.what() << endl;
+        return m_msg.compare(e.what()) == 0;
+    }
+private:
+    string m_msg;
+};
+
+struct AttributeConfigFixture
+{
+    AttributeConfigFixture() : data_path(DATA_PATH) {
+        AgentConfig::getConfig().init(nullptr, (data_path + "./console-agent.ini").c_str(), true);
+    }
+    ~AttributeConfigFixture() {
+        AgentConfig::getConfig().term();
+    }
+
+    string data_path;
+};
+
+BOOST_FIXTURE_TEST_CASE(AttributeConfigTest_ini_invalid, AttributeConfigFixture)
+{
+    exceptionCheck checker(data_path + "attributes-bad.ini(1): unmatched '['");
+    BOOST_CHECK_EXCEPTION(AttributeConfiguration::newAttributeConfiguration(string(data_path + "attributes-bad.ini").c_str()),
+            ini_parser_error, checker.check_message);
+}
+
+BOOST_FIXTURE_TEST_CASE(AttributeConfigTest_ini, AttributeConfigFixture)
+{
+    unique_ptr<AttributeConfiguration> config(AttributeConfiguration::newAttributeConfiguration(string(data_path + "attributes.ini").c_str()));
+    
+    BOOST_CHECK_EQUAL(config->getString("scopeDelimiter"), "/");
+    BOOST_CHECK(!config->getBool("exportDuplicateValues", true));
+    BOOST_CHECK_EQUAL(config->getString("caseInsensitiveAttributes"), "foo bar");
+    BOOST_CHECK_EQUAL(config->getString("encoding"), "URL");
+    BOOST_CHECK_EQUAL(config->getString(AttributeConfiguration::LEGACY_CLASSREF_ATTRIBUTE_PROP_NAME,
+            AttributeConfiguration::LEGACY_CLASSREF_ATTRIBUTE_PROP_DEFAULT),
+        AttributeConfiguration::LEGACY_CLASSREF_ATTRIBUTE_PROP_DEFAULT);
+}
+
+};
\ No newline at end of file
diff --git a/tests/data/attribute/impl/attributes-bad.ini b/tests/data/attribute/impl/attributes-bad.ini
new file mode 100644
index 00000000..c7d52691
--- /dev/null
+++ b/tests/data/attribute/impl/attributes-bad.ini
@@ -0,0 +1,11 @@
+[settings
+scopeDelimiter = /
+exportDuplicateValues = false
+caseInsensitiveAttributes = foo bar
+#legacyClassRefAttribute = Shib-AuthnContext-Class
+#legacyAuthnTimeAttribute = Shib-Authentication-Instant
+# Set to URL to apply URL encoding on export
+encoding = URL
+
+[mappings]
+foo = foo
diff --git a/tests/data/attribute/impl/attributes.ini b/tests/data/attribute/impl/attributes.ini
new file mode 100644
index 00000000..3e23f37b
--- /dev/null
+++ b/tests/data/attribute/impl/attributes.ini
@@ -0,0 +1,11 @@
+[settings]
+scopeDelimiter = /
+exportDuplicateValues = false
+caseInsensitiveAttributes = foo bar
+#legacyClassRefAttribute = Shib-AuthnContext-Class
+#legacyAuthnTimeAttribute = Shib-Authentication-Instant
+# Set to URL to apply URL encoding on export
+encoding = URL
+
+[mappings]
+foo = foo
diff --git a/tests/data/attribute/impl/console-agent.ini b/tests/data/attribute/impl/console-agent.ini
new file mode 100644
index 00000000..493c1cd3
--- /dev/null
+++ b/tests/data/attribute/impl/console-agent.ini
@@ -0,0 +1,12 @@
+[global]
+agentID = sp.example.org
+skipHandlers = true
+skipAttributes = true
+
+[logging]
+type = console
+defaultLevel = INFO
+
+[logging-categories]
+Shibboleth.AgentConfig = WARN
+Shibboleth.IIS = DEBUG

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


More information about the commits mailing list