2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <saml/SAMLConfig.h>
20 #include <saml/binding/SecurityPolicyRule.h>
21 #include <saml/saml1/core/Assertions.h>
23 using namespace opensaml;
25 class SAML1PolicyTest : public CxxTest::TestSuite {
26 SecurityPolicy* m_policy;
27 SecurityPolicyRule* m_rule;
32 m_rule = SAMLConfig::getConfig().SecurityPolicyRuleManager.newPlugin(CONDITIONS_POLICY_RULE, NULL);
33 m_policy = new SecurityPolicy();
34 m_policy->getRules().push_back(m_rule);
42 void testSAML1Policy() {
44 // Read assertion to use from file.
45 string path = data_path + "saml1/profile/SAML1Assertion.xml";
46 ifstream in(path.c_str());
47 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
48 XercesJanitor<DOMDocument> janitor(doc);
49 auto_ptr<saml1::Assertion> assertion(
50 dynamic_cast<saml1::Assertion*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))
54 TSM_ASSERT_THROWS("Policy should have tripped on AudienceRestriction", m_policy->evaluate(*assertion.get()), SecurityPolicyException);
56 auto_ptr_XMLCh recipient("https://sp.example.org");
57 m_policy->setRecipient(recipient.get());
58 m_policy->evaluate(*assertion.get());
60 catch (exception& ex) {