Bump lib version.
[shibboleth/cpp-opensaml.git] / samltest / SAMLArtifactCreationTest.h
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "internal.h"
18 #include <saml/SAMLConfig.h>
19 #include <saml/saml1/binding/SAMLArtifactType0001.h>
20 #include <saml/saml1/binding/SAMLArtifactType0002.h>
21 #include <saml/saml2/binding/SAML2ArtifactType0004.h>
22
23 using namespace opensaml::saml1p;
24 using namespace opensaml::saml2p;
25 using namespace opensaml;
26 using namespace std;
27
28 class SAMLArtifactCreationTest : public CxxTest::TestSuite
29 {
30 public:
31     string providerIdStr;
32     string handle;
33     void setUp() {
34         if (handle.empty()) {
35             providerIdStr = "https://idp.org/SAML";
36             SAMLConfig::getConfig().generateRandomBytes(handle,SAMLArtifactType0001::HANDLE_LENGTH);
37         }
38     }
39     void testSAMLArtifactType0001(void) {
40         SAMLConfig& conf=SAMLConfig::getConfig();
41         string sourceId;
42         conf.generateRandomBytes(sourceId,SAMLArtifactType0001::SOURCEID_LENGTH);
43         SAMLArtifactType0001 artifact1(sourceId,handle);
44         //printResults(artifact1);
45
46         SAMLArtifactType0001 artifact2(conf.hashSHA1(providerIdStr.c_str()),handle);
47         //printResults(artifact2,providerIdStr.c_str());
48     }
49
50     void testSAMLArtifactType0002(void) {
51         SAMLArtifactType0002 artifact(providerIdStr,handle);
52         //printResults(artifact,providerIdStr.c_str());
53     }
54
55     void testSAMLArtifactType0004(void) {
56         SAML2ArtifactType0004 artifact(SAMLConfig::getConfig().hashSHA1(providerIdStr.c_str()),666,handle);
57         //printResults(artifact,providerIdStr.c_str());
58     }
59
60     void printResults(SAMLArtifact& artifact, const char* str=NULL) {
61         // print heading:
62         cout << "Artifact Type " << SAMLArtifact::toHex(artifact.getTypeCode());
63         cout << " (size = " << artifact.getBytes().size() << ")" << endl;
64     
65         // print URI:
66         if (str) { 
67           cout << "URI:     " << str << endl; 
68         }
69         else {
70           cout << "URI:     NONE" << endl; 
71         }
72     
73         // print hex-encoded artifact:
74         cout << "Hex:     " << SAMLArtifact::toHex(artifact.getBytes()) << endl;
75     
76         // print base64-encoded artifact:
77         cout << "Base64:  " << artifact.encode() << endl;
78     
79         // print ruler:
80         cout <<  "         ----------------------------------------------------------------------" << endl;
81         cout <<  "         1234567890123456789012345678901234567890123456789012345678901234567890" << endl;
82         cout <<  "                  1         2         3         4         5         6         7" << endl;
83         cout <<  "         ----------------------------------------------------------------------" << endl;
84     }
85 };