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.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
28 using namespace opensaml::saml1p;
29 using namespace opensaml::saml2p;
30 using namespace opensaml;
33 class SAMLArtifactCreationTest : public CxxTest::TestSuite
40 providerIdStr = "https://idp.org/SAML";
41 SAMLConfig::getConfig().generateRandomBytes(handle,SAMLArtifactType0001::HANDLE_LENGTH);
44 void testSAMLArtifactType0001(void) {
45 SAMLConfig& conf=SAMLConfig::getConfig();
47 conf.generateRandomBytes(sourceId,SAMLArtifactType0001::SOURCEID_LENGTH);
48 SAMLArtifactType0001 artifact1(sourceId,handle);
49 //printResults(artifact1);
51 SAMLArtifactType0001 artifact2(
52 SecurityHelper::doHash("SHA1", providerIdStr.data(), providerIdStr.length(), false), handle
54 //printResults(artifact2,providerIdStr.c_str());
57 void testSAMLArtifactType0002(void) {
58 SAMLArtifactType0002 artifact(providerIdStr,handle);
59 //printResults(artifact,providerIdStr.c_str());
62 void testSAMLArtifactType0004(void) {
63 SAML2ArtifactType0004 artifact(
64 SecurityHelper::doHash("SHA1", providerIdStr.data(), providerIdStr.length(), false), 666, handle
66 //printResults(artifact,providerIdStr.c_str());
69 void printResults(SAMLArtifact& artifact, const char* str=nullptr) {
71 cout << "Artifact Type " << SAMLArtifact::toHex(artifact.getTypeCode());
72 cout << " (size = " << artifact.getBytes().size() << ")" << endl;
76 cout << "URI: " << str << endl;
79 cout << "URI: NONE" << endl;
82 // print hex-encoded artifact:
83 cout << "Hex: " << SAMLArtifact::toHex(artifact.getBytes()) << endl;
85 // print base64-encoded artifact:
86 cout << "Base64: " << artifact.encode() << endl;
89 cout << " ----------------------------------------------------------------------" << endl;
90 cout << " 1234567890123456789012345678901234567890123456789012345678901234567890" << endl;
91 cout << " 1 2 3 4 5 6 7" << endl;
92 cout << " ----------------------------------------------------------------------" << endl;