[cpp-sp] branch main updated: Start work on file-backed cache.
Scott Cantor
cantor.2 at osu.edu
Wed Jun 4 23:52:49 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=e8baec6f6930f01bab34c3182487c90a804d845c
The following commit(s) were added to refs/heads/main by this push:
new e8baec6f Start work on file-backed cache.
e8baec6f is described below
commit e8baec6f6930f01bab34c3182487c90a804d845c
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Jun 4 19:52:45 2025 -0400
Start work on file-backed cache.
---
shibsp/session/impl/FilesystemSessionCache.cpp | 45 ++++++++++++
tests/Makefile.am | 3 +-
...bboleth.ini => bogus-filesystem-shibboleth.ini} | 5 +-
...ry-shibboleth.ini => filesystem-shibboleth.ini} | 5 +-
tests/data/session/impl/memory-shibboleth.ini | 2 -
tests/session/impl/FilesystemSessionCacheTests.cpp | 80 ++++++++++++++++++++++
6 files changed, 131 insertions(+), 9 deletions(-)
diff --git a/shibsp/session/impl/FilesystemSessionCache.cpp b/shibsp/session/impl/FilesystemSessionCache.cpp
index edd7183e..2d71bc0a 100644
--- a/shibsp/session/impl/FilesystemSessionCache.cpp
+++ b/shibsp/session/impl/FilesystemSessionCache.cpp
@@ -20,8 +20,15 @@
#include "internal.h"
#include "exceptions.h"
+#include "AgentConfig.h"
+#include "csprng/csprng.hpp"
#include "session/AbstractSessionCache.h"
#include "logging/Category.h"
+#include "util/Misc.h"
+#include "util/PathResolver.h"
+
+#include <cstdio>
+#include <fstream>
#include <boost/property_tree/ptree.hpp>
@@ -45,7 +52,14 @@ namespace {
) const;
bool cache_touch(const char* key, unsigned int timeout=0) const;
void cache_remove(const char* key);
+
+ private:
+ string m_dir;
+ duthomhas::csprng m_rng;
};
+
+ static const char CACHE_DIRECTORY_PROP_NAME[] = "cacheDirectory";
+ static const char CACHE_DIRECTORY_PROP_DEFAULT[] = "sessions";
};
namespace shibsp {
@@ -56,6 +70,37 @@ namespace shibsp {
FilesystemSessionCache::FilesystemSessionCache(const ptree& pt) : AbstractSessionCache(pt)
{
+ m_dir = getString(CACHE_DIRECTORY_PROP_NAME, CACHE_DIRECTORY_PROP_DEFAULT);
+ AgentConfig::getConfig().getPathResolver().resolve(m_dir, PathResolver::SHIBSP_CACHE_FILE);
+
+ string testPath = m_dir + '/' + hex_encode(m_rng(string(16,0)));
+
+ bool failed = true;
+
+ DDF obj("test");
+ DDFJanitor objjanitor(obj);
+ ofstream os(testPath);
+ if (os) {
+ os << obj;
+ os.close();
+ ifstream is(testPath);
+ if (is) {
+ DDF obj2(nullptr);
+ DDFJanitor obj2janitor(obj2);
+ is >> obj2;
+ is.close();
+ if (obj2.name() && !strcmp(obj.name(), obj2.name())) {
+ failed = false;
+ }
+ }
+ }
+
+ std::remove(testPath.c_str());
+
+ if (failed) {
+ log().error("could not perform read/write in cache directory (%s), check permissions", m_dir.c_str());
+ throw ConfigurationException("Configured session cache directory was inaccessible to agent process.");
+ }
}
FilesystemSessionCache::~FilesystemSessionCache()
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7fb78448..69c9c27d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -20,7 +20,8 @@ shibsptest_SOURCES = \
platform/iis/ModuleConfigTests.cpp \
remoting/impl/RemotingServiceTests.cpp \
remoting/impl/SecretSourceTests.cpp \
- session/impl/MemorySessionCacheTests.cpp \
+ session/impl/MemorySessionCacheTests.cpp \
+ session/impl/FilesystemSessionCacheTests.cpp \
util/PropertyTreeTests.cpp \
util/BoostPropertySetTests.cpp \
util/ReloadableXMLFileTests.cpp
diff --git a/tests/data/session/impl/memory-shibboleth.ini b/tests/data/session/impl/bogus-filesystem-shibboleth.ini
similarity index 80%
copy from tests/data/session/impl/memory-shibboleth.ini
copy to tests/data/session/impl/bogus-filesystem-shibboleth.ini
index c0a81e95..0e71f6ee 100644
--- a/tests/data/session/impl/memory-shibboleth.ini
+++ b/tests/data/session/impl/bogus-filesystem-shibboleth.ini
@@ -2,8 +2,6 @@
agentID = sp.example.org
skipHandlers = true
skipAttributes = true
-# Use "partial" for partial matching
-regexMatching = full
[logging]
type = console
@@ -13,7 +11,8 @@ defaultLevel = INFO
Shibboleth.SessionCache = DEBUG
[session-cache]
-type = memory
+type = filesystem
+cacheDirectory = /bogus
cleanupInterval = 180
cookieSameSite = None
diff --git a/tests/data/session/impl/memory-shibboleth.ini b/tests/data/session/impl/filesystem-shibboleth.ini
similarity index 80%
copy from tests/data/session/impl/memory-shibboleth.ini
copy to tests/data/session/impl/filesystem-shibboleth.ini
index c0a81e95..281d1621 100644
--- a/tests/data/session/impl/memory-shibboleth.ini
+++ b/tests/data/session/impl/filesystem-shibboleth.ini
@@ -2,8 +2,6 @@
agentID = sp.example.org
skipHandlers = true
skipAttributes = true
-# Use "partial" for partial matching
-regexMatching = full
[logging]
type = console
@@ -13,7 +11,8 @@ defaultLevel = INFO
Shibboleth.SessionCache = DEBUG
[session-cache]
-type = memory
+type = filesystem
+cacheDirectory = ./data
cleanupInterval = 180
cookieSameSite = None
diff --git a/tests/data/session/impl/memory-shibboleth.ini b/tests/data/session/impl/memory-shibboleth.ini
index c0a81e95..548a780f 100644
--- a/tests/data/session/impl/memory-shibboleth.ini
+++ b/tests/data/session/impl/memory-shibboleth.ini
@@ -2,8 +2,6 @@
agentID = sp.example.org
skipHandlers = true
skipAttributes = true
-# Use "partial" for partial matching
-regexMatching = full
[logging]
type = console
diff --git a/tests/session/impl/FilesystemSessionCacheTests.cpp b/tests/session/impl/FilesystemSessionCacheTests.cpp
new file mode 100644
index 00000000..55618995
--- /dev/null
+++ b/tests/session/impl/FilesystemSessionCacheTests.cpp
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+/**
+ * session/impl/MemorySessionCacheTests.cpp
+ *
+ * Unit tests for in-memory SessionCache back-end.
+ */
+
+#include "Agent.h"
+#include "AgentConfig.h"
+#include "exceptions.h"
+#include "remoting/ddf.h"
+#include "session/SessionCache.h"
+
+#include "DummyRequest.h"
+
+#include <map>
+#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/session/impl/"
+
+namespace {
+
+class exceptionCheck {
+public:
+ exceptionCheck(const string& msg) : m_msg(msg) {}
+ bool check_message(const exception& e) {
+ return m_msg.compare(e.what()) == 0;
+ }
+private:
+ string m_msg;
+};
+
+/////////////
+
+BOOST_AUTO_TEST_CASE(BogusFilesystemSessionCache)
+{
+ exceptionCheck checker("Configured session cache directory was inaccessible to agent process.");
+ BOOST_CHECK_EXCEPTION(AgentConfig::getConfig().init(nullptr, (string(DATA_PATH) + "bogus-filesystem-shibboleth.ini").c_str(), true),
+ ConfigurationException, checker.check_message);
+}
+
+/////////////
+
+struct FilesystemFixture
+{
+ FilesystemFixture() : data_path(DATA_PATH) {
+ AgentConfig::getConfig().init(nullptr, (data_path + "filesystem-shibboleth.ini").c_str(), true);
+ }
+ ~FilesystemFixture() {
+ AgentConfig::getConfig().term();
+ }
+
+ string data_path;
+};
+
+BOOST_FIXTURE_TEST_CASE(FilesystemSessionCache_tests, FilesystemFixture)
+{
+}
+
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list