/*
- * Copyright 2001-2006 Internet2
+ * Copyright 2001-2009 Internet2
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <saml/SAMLConfig.h>
#include <saml/binding/MessageDecoder.h>
#include <saml/binding/MessageEncoder.h>
-#include <saml/binding/URLEncoder.h>
+#include <saml/binding/SecurityPolicy.h>
+#include <saml/binding/SecurityPolicyRule.h>
+#include <saml/saml2/metadata/Metadata.h>
#include <saml/saml2/metadata/MetadataProvider.h>
-#include <saml/security/X509TrustEngine.h>
+#include <xmltooling/io/HTTPRequest.h>
+#include <xmltooling/io/HTTPResponse.h>
+#include <xmltooling/security/Credential.h>
+#include <xmltooling/security/CredentialCriteria.h>
+#include <xmltooling/security/TrustEngine.h>
+#include <xmltooling/util/URLEncoder.h>
-using namespace saml2md;
+using namespace opensaml::saml2md;
+using namespace opensaml;
using namespace xmlsignature;
-class SAMLBindingBaseTestCase : public MessageDecoder::HTTPRequest, public MessageEncoder::HTTPResponse
+class SAMLBindingBaseTestCase : public HTTPRequest, public HTTPResponse
{
protected:
CredentialResolver* m_creds;
MetadataProvider* m_metadata;
- opensaml::X509TrustEngine* m_trust;
+ TrustEngine* m_trust;
map<string,string> m_fields;
map<string,string> m_headers;
- string m_method,m_url;
+ string m_method,m_url,m_query;
+ vector<XSECCryptoX509*> m_clientCerts;
+ vector<const SecurityPolicyRule*> m_rules;
public:
void setUp() {
m_headers.clear();
m_method.erase();
m_url.erase();
+ m_query.erase();
try {
string config = data_path + "binding/ExampleMetadataProvider.xml";
doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
m_metadata = SAMLConfig::getConfig().MetadataProviderManager.newPlugin(
- FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement()
+ XML_METADATA_PROVIDER,doc->getDocumentElement()
);
m_metadata->init();
FILESYSTEM_CREDENTIAL_RESOLVER,doc2->getDocumentElement()
);
- m_trust = dynamic_cast<X509TrustEngine*>(
- SAMLConfig::getConfig().TrustEngineManager.newPlugin(EXPLICIT_KEY_SAMLTRUSTENGINE, NULL)
- );
+ m_trust = XMLToolingConfig::getConfig().TrustEngineManager.newPlugin(EXPLICIT_KEY_TRUSTENGINE, NULL);
+
+ m_rules.push_back(SAMLConfig::getConfig().SecurityPolicyRuleManager.newPlugin(MESSAGEFLOW_POLICY_RULE,NULL));
+ m_rules.push_back(SAMLConfig::getConfig().SecurityPolicyRuleManager.newPlugin(SIMPLESIGNING_POLICY_RULE,NULL));
+ m_rules.push_back(SAMLConfig::getConfig().SecurityPolicyRuleManager.newPlugin(XMLSIGNING_POLICY_RULE,NULL));
}
catch (XMLToolingException& ex) {
TS_TRACE(ex.what());
}
void tearDown() {
+ for_each(m_rules.begin(), m_rules.end(), xmltooling::cleanup<SecurityPolicyRule>());
+ m_rules.clear();
delete m_creds;
delete m_metadata;
delete m_trust;
m_headers.clear();
m_method.erase();
m_url.erase();
+ m_query.erase();
}
// HTTPRequest methods
const char* getMethod() const {
return m_method.c_str();
- }
+ }
+
+ const char* getScheme() const {
+ return "https";
+ }
+
+ const char* getHostname() const {
+ return "localhost";
+ }
+
+ int getPort() const {
+ return 443;
+ }
+
+ string getContentType() const {
+ return "application/x-www-form-urlencoded";
+ }
+
+ long getContentLength() const {
+ return -1;
+ }
+
+ const char* getRequestURI() const {
+ return "/";
+ }
const char* getRequestURL() const {
return m_url.c_str();
}
const char* getQueryString() const {
- return NULL;
+ return m_query.c_str();
}
string getRemoteUser() const {
return "";
}
+ string getRemoteAddr() const {
+ return "127.0.0.1";
+ }
+
+ const std::vector<XSECCryptoX509*>& getClientCertificates() const {
+ return m_clientCerts;
+ }
+
string getHeader(const char* name) const {
map<string,string>::const_iterator i=m_headers.find(name);
return i==m_headers.end() ? "" : i->second;
// HTTPResponse methods
- void setHeader(const char* name, const char* value) {
+ void setResponseHeader(const char* name, const char* value) {
m_headers[name] = value ? value : "";
}
-
- void setCookie(const char* name, const char* value) {
- m_headers["Set-Cookie"] = string(name) + "=" + (value ? value : "");
- }
-
+
// The amount of error checking missing from this is incredible, but as long
// as the test data isn't unexpected or malformed, it should work.
char* pch = strchr(dup,'?');
if (pch) {
*pch++=0;
+ m_query = pch;
char* name=pch;
while (name && *name) {
pch=strchr(pch,'=');
pch=strchr(pch,'&');
if (pch)
*pch++=0;
- SAMLConfig::getConfig().getURLEncoder()->decode(value);
+ XMLToolingConfig::getConfig().getURLEncoder()->decode(value);
m_fields[name] = value;
name = pch;
}
return decoded;
}
- long sendResponse(std::istream& inputStream, int status = 200, const char* contentType = "text/html") {
+ using HTTPResponse::sendResponse;
+
+ long sendResponse(std::istream& inputStream, long status) {
m_method="POST";
string page,line;
while (getline(inputStream,line))