Update gitignore to account for subdirs / missing files.
[shibboleth/cpp-opensaml.git] / samltest / SAMLArtifactCreationTest.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 #include <saml/SAMLConfig.h>
23 #include <saml/saml1/binding/SAMLArtifactType0001.h>
24 #include <saml/saml1/binding/SAMLArtifactType0002.h>
25 #include <saml/saml2/binding/SAML2ArtifactType0004.h>
26 #include <xmltooling/security/SecurityHelper.h>
27
28 using namespace opensaml::saml1p;
29 using namespace opensaml::saml2p;
30 using namespace opensaml;
31 using namespace std;
32
33 class SAMLArtifactCreationTest : public CxxTest::TestSuite
34 {
35 public:
36     string providerIdStr;
37     string handle;
38     void setUp() {
39         if (handle.empty()) {
40             providerIdStr = "https://idp.org/SAML";
41             SAMLConfig::getConfig().generateRandomBytes(handle,SAMLArtifactType0001::HANDLE_LENGTH);
42         }
43     }
44     void testSAMLArtifactType0001(void) {
45         SAMLConfig& conf=SAMLConfig::getConfig();
46         string sourceId;
47         conf.generateRandomBytes(sourceId,SAMLArtifactType0001::SOURCEID_LENGTH);
48         SAMLArtifactType0001 artifact1(sourceId,handle);
49         //printResults(artifact1);
50
51         SAMLArtifactType0001 artifact2(
52             SecurityHelper::doHash("SHA1", providerIdStr.data(), providerIdStr.length(), false), handle
53             );
54         //printResults(artifact2,providerIdStr.c_str());
55     }
56
57     void testSAMLArtifactType0002(void) {
58         SAMLArtifactType0002 artifact(providerIdStr,handle);
59         //printResults(artifact,providerIdStr.c_str());
60     }
61
62     void testSAMLArtifactType0004(void) {
63         SAML2ArtifactType0004 artifact(
64             SecurityHelper::doHash("SHA1", providerIdStr.data(), providerIdStr.length(), false), 666, handle
65             );
66         //printResults(artifact,providerIdStr.c_str());
67     }
68
69     void printResults(SAMLArtifact& artifact, const char* str=nullptr) {
70         // print heading:
71         cout << "Artifact Type " << SAMLArtifact::toHex(artifact.getTypeCode());
72         cout << " (size = " << artifact.getBytes().size() << ")" << endl;
73     
74         // print URI:
75         if (str) { 
76           cout << "URI:     " << str << endl; 
77         }
78         else {
79           cout << "URI:     NONE" << endl; 
80         }
81     
82         // print hex-encoded artifact:
83         cout << "Hex:     " << SAMLArtifact::toHex(artifact.getBytes()) << endl;
84     
85         // print base64-encoded artifact:
86         cout << "Base64:  " << artifact.encode() << endl;
87     
88         // print ruler:
89         cout <<  "         ----------------------------------------------------------------------" << endl;
90         cout <<  "         1234567890123456789012345678901234567890123456789012345678901234567890" << endl;
91         cout <<  "                  1         2         3         4         5         6         7" << endl;
92         cout <<  "         ----------------------------------------------------------------------" << endl;
93     }
94 };