Don't want generated source checked in.
[shibboleth/cpp-opensaml.git] / samltest / SAMLArtifactCreationTest.h
1 /*\r
2  *  Copyright 2001-2005 Internet2\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 #include "internal.h"\r
18 #include <saml/saml1/core/SAMLArtifactType0001.h>\r
19 #include <saml/saml1/core/SAMLArtifactType0002.h>\r
20 #include <saml/saml2/core/SAML2ArtifactType0004.h>\r
21 \r
22 using namespace opensaml::saml1p;\r
23 using namespace opensaml::saml2p;\r
24 using namespace opensaml;\r
25 using namespace std;\r
26 \r
27 class SAMLArtifactCreationTest : public CxxTest::TestSuite\r
28 {\r
29 public:\r
30     string providerIdStr;\r
31     string handle;\r
32     void setUp() {\r
33         if (handle.empty()) {\r
34             providerIdStr = "https://idp.org/SAML";\r
35             SAMLConfig::getConfig().generateRandomBytes(handle,SAMLArtifactType0001::HANDLE_LENGTH);\r
36         }\r
37     }\r
38     void testSAMLArtifactType0001(void) {\r
39         SAMLConfig& conf=SAMLConfig::getConfig();\r
40         string sourceId;\r
41         conf.generateRandomBytes(sourceId,SAMLArtifactType0001::SOURCEID_LENGTH);\r
42         SAMLArtifactType0001 artifact1(sourceId,handle);\r
43         //printResults(artifact1);\r
44 \r
45         SAMLArtifactType0001 artifact2(conf.hashSHA1(providerIdStr.c_str()),handle);\r
46         //printResults(artifact2,providerIdStr.c_str());\r
47     }\r
48 \r
49     void testSAMLArtifactType0002(void) {\r
50         SAMLArtifactType0002 artifact(providerIdStr,handle);\r
51         //printResults(artifact,providerIdStr.c_str());\r
52     }\r
53 \r
54     void testSAMLArtifactType0004(void) {\r
55         SAML2ArtifactType0004 artifact(SAMLConfig::getConfig().hashSHA1(providerIdStr.c_str()),666,handle);\r
56         //printResults(artifact,providerIdStr.c_str());\r
57     }\r
58 \r
59     void printResults(SAMLArtifact& artifact, const char* str=NULL) {\r
60         // print heading:\r
61         cout << "Artifact Type " << SAMLArtifact::toHex(artifact.getTypeCode());\r
62         cout << " (size = " << artifact.getBytes().size() << ")" << endl;\r
63     \r
64         // print URI:\r
65         if (str) { \r
66           cout << "URI:     " << str << endl; \r
67         }\r
68         else {\r
69           cout << "URI:     NONE" << endl; \r
70         }\r
71     \r
72         // print hex-encoded artifact:\r
73         cout << "Hex:     " << SAMLArtifact::toHex(artifact.getBytes()) << endl;\r
74     \r
75         // print base64-encoded artifact:\r
76         cout << "Base64:  " << artifact.encode() << endl;\r
77     \r
78         // print ruler:\r
79         cout <<  "         ----------------------------------------------------------------------" << endl;\r
80         cout <<  "         1234567890123456789012345678901234567890123456789012345678901234567890" << endl;\r
81         cout <<  "                  1         2         3         4         5         6         7" << endl;\r
82         cout <<  "         ----------------------------------------------------------------------" << endl;\r
83     }\r
84 };\r