[cpp-sp] branch main updated: Initial working ACL test, adjust SPRequest logging.
Scott Cantor
cantor.2 at osu.edu
Wed Dec 18 20:10:37 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=e1f5b9693f2215ac2904b9819855b93d9e45184f
The following commit(s) were added to refs/heads/main by this push:
new e1f5b969 Initial working ACL test, adjust SPRequest logging.
e1f5b969 is described below
commit e1f5b9693f2215ac2904b9819855b93d9e45184f
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Dec 18 15:10:33 2024 -0500
Initial working ACL test, adjust SPRequest logging.
---
shibsp/AbstractSPRequest.cpp | 33 +++++------
shibsp/AbstractSPRequest.h | 3 +-
tests/data/impl/console-shibboleth.ini | 1 +
.../impl/{acl-simple.xml => inline-ac-acl.xml} | 0
tests/impl/XMLAccessControlTests.cpp | 68 +++++++++++++++-------
5 files changed, 64 insertions(+), 41 deletions(-)
diff --git a/shibsp/AbstractSPRequest.cpp b/shibsp/AbstractSPRequest.cpp
index 68f65ce9..c14ac6e1 100644
--- a/shibsp/AbstractSPRequest.cpp
+++ b/shibsp/AbstractSPRequest.cpp
@@ -24,6 +24,7 @@
#include "Application.h"
#include "ServiceProvider.h"
#include "SessionCache.h"
+#include "logging/Category.h"
#include "util/CGIParser.h"
#include <boost/lexical_cast.hpp>
@@ -41,11 +42,11 @@ SPRequest::~SPRequest()
AbstractSPRequest::AbstractSPRequest(const char* category)
- : m_sp(SPConfig::getConfig().getServiceProvider()),
- m_mapper(nullptr), m_app(nullptr), m_sessionTried(false), m_session(nullptr),
- m_log(nullptr)
+ : m_log(Category::getInstance(category)), m_sp(SPConfig::getConfig().getServiceProvider()),
+ m_mapper(nullptr), m_app(nullptr), m_sessionTried(false), m_session(nullptr)
{
- m_sp->lock();
+ if (m_sp)
+ m_sp->lock();
}
AbstractSPRequest::~AbstractSPRequest()
@@ -343,25 +344,21 @@ void AbstractSPRequest::setCookie(const char* name, const char* value, time_t ex
void AbstractSPRequest::log(SPLogLevel level, const std::string& msg) const
{
- /*
- reinterpret_cast<Category*>(m_log)->log(
- (level == SPDebug ? Priority::DEBUG :
- (level == SPInfo ? Priority::INFO :
- (level == SPWarn ? Priority::WARN :
- (level == SPError ? Priority::ERROR : Priority::CRIT)))),
+ m_log.log(
+ (level == SPDebug ? Priority::SHIB_DEBUG :
+ (level == SPInfo ? Priority::SHIB_INFO :
+ (level == SPWarn ? Priority::SHIB_WARN :
+ (level == SPError ? Priority::SHIB_ERROR : Priority::SHIB_CRIT)))),
msg
);
- */
}
bool AbstractSPRequest::isPriorityEnabled(SPLogLevel level) const
{
- /*
- return reinterpret_cast<Category*>(m_log)->isPriorityEnabled(
- (level == SPDebug ? Priority::DEBUG :
- (level == SPInfo ? Priority::INFO :
- (level == SPWarn ? Priority::WARN :
- (level == SPError ? Priority::ERROR : Priority::CRIT))))
+ return m_log.isPriorityEnabled(
+ (level == SPDebug ? Priority::SHIB_DEBUG :
+ (level == SPInfo ? Priority::SHIB_INFO :
+ (level == SPWarn ? Priority::SHIB_WARN :
+ (level == SPError ? Priority::SHIB_ERROR : Priority::SHIB_CRIT))))
);
- */
}
diff --git a/shibsp/AbstractSPRequest.h b/shibsp/AbstractSPRequest.h
index 79c7b0a0..132d3e16 100644
--- a/shibsp/AbstractSPRequest.h
+++ b/shibsp/AbstractSPRequest.h
@@ -27,6 +27,7 @@
namespace shibsp {
class SHIBSP_API CGIParser;
+ class SHIBSP_API Category;
#if defined (_MSC_VER)
#pragma warning( push )
@@ -76,6 +77,7 @@ namespace shibsp {
bool isPriorityEnabled(SPLogLevel level) const;
private:
+ Category& m_log;
ServiceProvider* m_sp;
mutable RequestMapper* m_mapper;
mutable RequestMapper::Settings m_settings;
@@ -84,7 +86,6 @@ namespace shibsp {
mutable Session* m_session;
std::string m_uri;
mutable std::string m_url;
- void* m_log; // declared void* to avoid log4cpp header conflicts in Apache
mutable std::string m_handlerURL;
mutable boost::scoped_ptr<CGIParser> m_parser;
};
diff --git a/tests/data/impl/console-shibboleth.ini b/tests/data/impl/console-shibboleth.ini
index 13810d39..bc3fb129 100644
--- a/tests/data/impl/console-shibboleth.ini
+++ b/tests/data/impl/console-shibboleth.ini
@@ -5,3 +5,4 @@ default-level = INFO
[logging-categories]
Shibboleth.AgentConfig = WARN
Shibboleth.AccessControl = DEBUG
+Shibboleth.DummyRequest = DEBUG
diff --git a/tests/data/impl/acl-simple.xml b/tests/data/impl/inline-ac-acl.xml
similarity index 100%
rename from tests/data/impl/acl-simple.xml
rename to tests/data/impl/inline-ac-acl.xml
diff --git a/tests/impl/XMLAccessControlTests.cpp b/tests/impl/XMLAccessControlTests.cpp
index f7d12fa9..e1cf144f 100644
--- a/tests/impl/XMLAccessControlTests.cpp
+++ b/tests/impl/XMLAccessControlTests.cpp
@@ -19,6 +19,7 @@
*/
#include "exceptions.h"
+#include "AbstractSPRequest.h"
#include "AccessControl.h"
#include "AgentConfig.h"
#include "SessionCache.h"
@@ -37,7 +38,7 @@ using namespace std;
namespace {
/** Open structure for testing manipulation. */
-struct DummySession : public Session
+struct DummySession : public Session, public NoOpBasicLockable
{
public:
DummySession() {}
@@ -94,6 +95,28 @@ public:
mutable multimap<string,const Attribute*> m_attributeIndex;
};
+class DummyRequest : public AbstractSPRequest {
+public:
+ DummyRequest() : AbstractSPRequest(SHIBSP_LOGCAT ".DummyRequest") {}
+ const char* getMethod() const { return nullptr; }
+ const char* getScheme() const { return nullptr; }
+ const char* getHostname() const { return nullptr; }
+ int getPort() const { return 0; }
+ string getContentType() const { return ""; }
+ long getContentLength() const { return -1; }
+ const char* getQueryString() const { return nullptr; }
+ const char* getRequestBody() const { return nullptr; }
+ string getHeader(const char*) const { return nullptr; }
+ string getRemoteUser() const { return nullptr; }
+ string getAuthType() const { return nullptr; }
+ long sendResponse(istream&, long status) { return status; }
+ void clearHeader(const char*, const char*) {}
+ void setHeader(const char*, const char*) {}
+ void setRemoteUser(const char*) {}
+ long returnDecline() { return 200; }
+ long returnOK() { return 200; }
+};
+
class exceptionCheck {
public:
exceptionCheck(const string& msg) : m_msg(msg) {}
@@ -185,45 +208,46 @@ BOOST_FIXTURE_TEST_CASE(XMLAccessControl_inline_invalid_internal, Inline_Invalid
ConfigurationException, checker.check_message);
}
-/*
-struct Inline_Valid_Fixture : public BaseFixture
+/////////////
+// Inline ACL test for authnContextClassRef rule.
+/////////////
+
+struct Inline_ACRule_Fixture : public BaseFixture
{
- Inline_Valid_Fixture() {
- xml_parser::read_xml(data_path + "inline.xml", tree, xml_parser::no_comments|xml_parser::trim_whitespace);
- }
- ~Inline_Valid_Fixture() {
+ Inline_ACRule_Fixture() {
+ xml_parser::read_xml(data_path + "inline-ac-acl.xml", tree, xml_parser::no_comments|xml_parser::trim_whitespace);
}
ptree tree;
};
-BOOST_FIXTURE_TEST_CASE(ReloadableFileTest_inline_valid, Inline_Valid_Fixture)
+BOOST_FIXTURE_TEST_CASE(ReloadableFileTest_inline_ACRule, Inline_ACRule_Fixture)
{
BOOST_CHECK_EQUAL(tree.size(), 1);
- DummyXMLFile dummy(tree.front().second);
- dummy.lock_shared();
- time_t ts1 = dummy.getLastModified();
- BOOST_CHECK_EQUAL(ts1, 0);
- dummy.unlock();
+ unique_ptr<AccessControl> acl(AgentConfig::getConfig().AccessControlManager.newPlugin(
+ tree.front().second.get<string>("<xmlattr>.type").c_str(), tree.front().second, true));
- // No-op since there's no locking internally.
- dummy.forceReload();
- sleep(2);
+ acl->lock_shared();
- dummy.lock_shared();
- time_t ts2 = dummy.getLastModified();
- BOOST_CHECK_EQUAL(ts2, 0);
- dummy.unlock();
+ DummyRequest request;
+ DummySession session;
+ session.m_ac = "Foo";
+
+ BOOST_CHECK_EQUAL(acl->authorized(request, &session), AccessControl::shib_acl_false);
+
+ session.m_ac = "urn:oasis:names:tc:SAML:2.0:ac:classes:TimeSyncToken";
+ BOOST_CHECK_EQUAL(acl->authorized(request, &session), AccessControl::shib_acl_true);
+
+ acl->unlock_shared();
}
+/*
struct External_Valid_Fixture : public BaseFixture
{
External_Valid_Fixture() {
xml_parser::read_xml(data_path + "external.xml", tree, xml_parser::no_comments|xml_parser::trim_whitespace);
}
- ~External_Valid_Fixture() {
- }
ptree tree;
};
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list