[cpp-sp] branch main updated: Tests for SecretSource impls.
Scott Cantor
cantor.2 at osu.edu
Tue Jan 21 17:25:56 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=befd9637e4a8e04cbfc1ba27c4c6c5c68e377f85
The following commit(s) were added to refs/heads/main by this push:
new befd9637 Tests for SecretSource impls.
befd9637 is described below
commit befd9637e4a8e04cbfc1ba27c4c6c5c68e377f85
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Jan 21 12:25:51 2025 -0500
Tests for SecretSource impls.
---
shibsp/remoting/SecretSource.h | 2 +-
shibsp/remoting/impl/SecretSource.cpp | 4 +-
tests/Makefile.am | 1 +
tests/data/remoting/impl/env.ini | 1 +
tests/data/remoting/impl/file-missing.ini | 1 +
tests/data/remoting/impl/file.ini | 1 +
tests/data/remoting/impl/invalid.ini | 1 +
tests/data/remoting/impl/secret.txt | 1 +
tests/remoting/impl/SecretSourceTests.cpp | 120 ++++++++++++++++++++++++++++++
9 files changed, 129 insertions(+), 3 deletions(-)
diff --git a/shibsp/remoting/SecretSource.h b/shibsp/remoting/SecretSource.h
index a1288a51..f36646ac 100644
--- a/shibsp/remoting/SecretSource.h
+++ b/shibsp/remoting/SecretSource.h
@@ -48,7 +48,7 @@ namespace shibsp {
*
* @return a secret
*/
- virtual std::string getSecret(const char* key) const=0;
+ virtual std::string getSecret(const char* key=nullptr) const=0;
};
/**
diff --git a/shibsp/remoting/impl/SecretSource.cpp b/shibsp/remoting/impl/SecretSource.cpp
index 8ea9062b..4faf2dd4 100644
--- a/shibsp/remoting/impl/SecretSource.cpp
+++ b/shibsp/remoting/impl/SecretSource.cpp
@@ -38,7 +38,7 @@ namespace {
FileSecretSource(const ptree& pt);
virtual ~FileSecretSource() {}
- string getSecret(const char* key) const;
+ string getSecret(const char* key=nullptr) const;
private:
string m_pathname;
@@ -49,7 +49,7 @@ namespace {
EnvSecretSource(const ptree& pt);
virtual ~EnvSecretSource() {}
- string getSecret(const char* key) const;
+ string getSecret(const char* key=nullptr) const;
private:
string m_envname;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0e857985..98fe165b 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/SecretSourceTests.cpp \
util/PropertyTreeTests.cpp \
util/BoostPropertySetTests.cpp \
util/ReloadableXMLFileTests.cpp
diff --git a/tests/data/remoting/impl/env.ini b/tests/data/remoting/impl/env.ini
new file mode 100644
index 00000000..dfa7a002
--- /dev/null
+++ b/tests/data/remoting/impl/env.ini
@@ -0,0 +1 @@
+secretEnv = SHIB_SECRET
diff --git a/tests/data/remoting/impl/file-missing.ini b/tests/data/remoting/impl/file-missing.ini
new file mode 100644
index 00000000..1ce64e81
--- /dev/null
+++ b/tests/data/remoting/impl/file-missing.ini
@@ -0,0 +1 @@
+secretFile = ./password.txt
diff --git a/tests/data/remoting/impl/file.ini b/tests/data/remoting/impl/file.ini
new file mode 100644
index 00000000..c56c9ebd
--- /dev/null
+++ b/tests/data/remoting/impl/file.ini
@@ -0,0 +1 @@
+secretFile = ./data/remoting/impl/secret.txt
diff --git a/tests/data/remoting/impl/invalid.ini b/tests/data/remoting/impl/invalid.ini
new file mode 100644
index 00000000..d5dd18c1
--- /dev/null
+++ b/tests/data/remoting/impl/invalid.ini
@@ -0,0 +1 @@
+foo = bar
diff --git a/tests/data/remoting/impl/secret.txt b/tests/data/remoting/impl/secret.txt
new file mode 100644
index 00000000..245fcdf2
--- /dev/null
+++ b/tests/data/remoting/impl/secret.txt
@@ -0,0 +1 @@
+password!
diff --git a/tests/remoting/impl/SecretSourceTests.cpp b/tests/remoting/impl/SecretSourceTests.cpp
new file mode 100644
index 00000000..b4b05235
--- /dev/null
+++ b/tests/remoting/impl/SecretSourceTests.cpp
@@ -0,0 +1,120 @@
+/*
+ * 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/SecretSourceTests.cpp
+ *
+ * Unit tests for SecretSource implementations.
+ */
+
+#include "AgentConfig.h"
+#include "exceptions.h"
+#include "remoting/SecretSource.h"
+
+#include <memory>
+#include <string>
+#include <boost/test/unit_test.hpp>
+#include <boost/property_tree/ini_parser.hpp>
+
+using namespace shibsp;
+using namespace boost::property_tree;
+using namespace std;
+
+#define DATA_PATH "./data/remoting/impl/"
+
+namespace {
+
+struct SecretSourceFixture
+{
+ SecretSourceFixture() : data_path(DATA_PATH) {
+ AgentConfig::getConfig().init(nullptr, (data_path + "../../console-shibboleth.ini").c_str(), true);
+ }
+ ~SecretSourceFixture() {
+ AgentConfig::getConfig().term();
+ }
+
+ void parse(const string& filename) {
+ ini_parser::read_ini(data_path + filename, tree);
+ }
+
+ ptree tree;
+ string data_path;
+};
+
+/////////////
+
+BOOST_FIXTURE_TEST_CASE(SecretSourceTest_file_invalid, SecretSourceFixture)
+{
+ parse("invalid.ini");
+
+ BOOST_CHECK_THROW(
+ AgentConfig::getConfig().SecretSourceManager.newPlugin(FILE_SECRET_SOURCE, tree, false),
+ ConfigurationException);
+}
+
+/////////////
+
+BOOST_FIXTURE_TEST_CASE(SecretSourceTest_file_missing, SecretSourceFixture)
+{
+ parse("file-missing.ini");
+
+ BOOST_CHECK_THROW(
+ AgentConfig::getConfig().SecretSourceManager.newPlugin(FILE_SECRET_SOURCE, tree, false),
+ IOException);
+}
+
+/////////////
+
+BOOST_FIXTURE_TEST_CASE(SecretSourceTest_file, SecretSourceFixture)
+{
+ parse("file.ini");
+
+ unique_ptr<SecretSource> source(AgentConfig::getConfig().SecretSourceManager.newPlugin(FILE_SECRET_SOURCE, tree, false));
+ BOOST_CHECK_EQUAL(source->getSecret(), string("password!"));
+}
+
+/////////////
+
+BOOST_FIXTURE_TEST_CASE(SecretSourceTest_env_invalid, SecretSourceFixture)
+{
+ parse("invalid.ini");
+
+ BOOST_CHECK_THROW(
+ AgentConfig::getConfig().SecretSourceManager.newPlugin(ENV_SECRET_SOURCE, tree, false),
+ ConfigurationException);
+}
+
+/////////////
+
+BOOST_FIXTURE_TEST_CASE(SecretSourceTest_env_missing, SecretSourceFixture)
+{
+ parse("env.ini");
+
+ BOOST_CHECK_THROW(
+ AgentConfig::getConfig().SecretSourceManager.newPlugin(ENV_SECRET_SOURCE, tree, false),
+ IOException);
+}
+
+/////////////
+
+BOOST_FIXTURE_TEST_CASE(SecretSourceTest_env, SecretSourceFixture)
+{
+ parse("env.ini");
+
+ setenv("SHIB_SECRET", "password!", true);
+
+ unique_ptr<SecretSource> source(AgentConfig::getConfig().SecretSourceManager.newPlugin(ENV_SECRET_SOURCE, tree, false));
+ BOOST_CHECK_EQUAL(source->getSecret(), string("password!"));
+}
+};
\ 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