Set fourth file version digit to signify rebuild.
[shibboleth/cpp-opensaml.git] / samltest / saml1 / profile / SAML1PolicyTest.h
1 /**
2  * Licensed to the University Corporation for Advanced Internet
3  * Development, Inc. (UCAID) under one or more contributor license
4  * agreements. See the NOTICE file distributed with this work for
5  * additional information regarding copyright ownership.
6  *
7  * UCAID licenses this file to you under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17  * either express or implied. See the License for the specific
18  * language governing permissions and limitations under the License.
19  */
20
21 #include "internal.h"
22
23 #include <saml/SAMLConfig.h>
24 #include <saml/binding/SecurityPolicy.h>
25 #include <saml/binding/SecurityPolicyRule.h>
26 #include <saml/saml1/core/Assertions.h>
27
28 using namespace opensaml;
29
30 class SAML1PolicyTest : public CxxTest::TestSuite {
31     SecurityPolicy* m_policy;
32     vector<SecurityPolicyRule*> m_rules;
33 public:
34     void setUp() {
35         m_policy = nullptr;
36         m_rules.push_back(SAMLConfig::getConfig().SecurityPolicyRuleManager.newPlugin(CONDITIONS_POLICY_RULE, nullptr));
37         m_rules.push_back(SAMLConfig::getConfig().SecurityPolicyRuleManager.newPlugin(SAML1BROWSERSSO_POLICY_RULE, nullptr));
38         m_policy = new SecurityPolicy();
39         m_policy->getRules().assign(m_rules.begin(), m_rules.end());
40     }
41
42     void tearDown() {
43         for_each(m_rules.begin(), m_rules.end(), xmltooling::cleanup<SecurityPolicyRule>());
44         delete m_policy;
45     }
46
47     void testSAML1Policy() {
48         try {
49             // Read assertion to use from file.
50             string path = data_path + "saml1/profile/SAML1Assertion.xml";
51             ifstream in(path.c_str());
52             DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
53             XercesJanitor<DOMDocument> janitor(doc);
54             auto_ptr<saml1::Assertion> assertion(
55                 dynamic_cast<saml1::Assertion*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))
56                 );
57             janitor.release();
58
59             TSM_ASSERT_THROWS("Policy should have tripped on AudienceRestriction", m_policy->evaluate(*assertion.get()), SecurityPolicyException);
60
61             auto_ptr_XMLCh recipient("https://sp.example.org");
62             m_policy->getAudiences().push_back(recipient.get());
63             m_policy->evaluate(*assertion.get());
64         }
65         catch (exception& ex) {
66             TS_TRACE(ex.what());
67             throw;
68         }
69     }
70 };