X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=samltest%2FSAMLArtifactCreationTest.h;h=e0c47ff6b9ccd77898ee071c48d80a894b931388;hb=4f13d41e6fb5c89be08b56afd964c9972f234b36;hp=104e7b199c5424574a251d3d7d7233bcbb4814c4;hpb=0d4d73adf7fa522e14d34932c0bd56e2907481cb;p=shibboleth%2Fcpp-opensaml.git diff --git a/samltest/SAMLArtifactCreationTest.h b/samltest/SAMLArtifactCreationTest.h index 104e7b1..e0c47ff 100644 --- a/samltest/SAMLArtifactCreationTest.h +++ b/samltest/SAMLArtifactCreationTest.h @@ -1,84 +1,85 @@ -/* - * Copyright 2001-2005 Internet2 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "internal.h" -#include -#include -#include - -using namespace opensaml::saml1p; -using namespace opensaml::saml2p; -using namespace opensaml; -using namespace std; - -class SAMLArtifactCreationTest : public CxxTest::TestSuite -{ -public: - string providerIdStr; - string handle; - void setUp() { - if (handle.empty()) { - providerIdStr = "https://idp.org/SAML"; - SAMLConfig::getConfig().generateRandomBytes(handle,SAMLArtifactType0001::HANDLE_LENGTH); - } - } - void testSAMLArtifactType0001(void) { - SAMLConfig& conf=SAMLConfig::getConfig(); - string sourceId; - conf.generateRandomBytes(sourceId,SAMLArtifactType0001::SOURCEID_LENGTH); - SAMLArtifactType0001 artifact1(sourceId,handle); - //printResults(artifact1); - - SAMLArtifactType0001 artifact2(conf.hashSHA1(providerIdStr.c_str()),handle); - //printResults(artifact2,providerIdStr.c_str()); - } - - void testSAMLArtifactType0002(void) { - SAMLArtifactType0002 artifact(providerIdStr,handle); - //printResults(artifact,providerIdStr.c_str()); - } - - void testSAMLArtifactType0004(void) { - SAML2ArtifactType0004 artifact(SAMLConfig::getConfig().hashSHA1(providerIdStr.c_str()),666,handle); - //printResults(artifact,providerIdStr.c_str()); - } - - void printResults(SAMLArtifact& artifact, const char* str=NULL) { - // print heading: - cout << "Artifact Type " << SAMLArtifact::toHex(artifact.getTypeCode()); - cout << " (size = " << artifact.getBytes().size() << ")" << endl; - - // print URI: - if (str) { - cout << "URI: " << str << endl; - } - else { - cout << "URI: NONE" << endl; - } - - // print hex-encoded artifact: - cout << "Hex: " << SAMLArtifact::toHex(artifact.getBytes()) << endl; - - // print base64-encoded artifact: - cout << "Base64: " << artifact.encode() << endl; - - // print ruler: - cout << " ----------------------------------------------------------------------" << endl; - cout << " 1234567890123456789012345678901234567890123456789012345678901234567890" << endl; - cout << " 1 2 3 4 5 6 7" << endl; - cout << " ----------------------------------------------------------------------" << endl; - } -}; +/* + * Copyright 2001-2007 Internet2 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "internal.h" +#include +#include +#include +#include + +using namespace opensaml::saml1p; +using namespace opensaml::saml2p; +using namespace opensaml; +using namespace std; + +class SAMLArtifactCreationTest : public CxxTest::TestSuite +{ +public: + string providerIdStr; + string handle; + void setUp() { + if (handle.empty()) { + providerIdStr = "https://idp.org/SAML"; + SAMLConfig::getConfig().generateRandomBytes(handle,SAMLArtifactType0001::HANDLE_LENGTH); + } + } + void testSAMLArtifactType0001(void) { + SAMLConfig& conf=SAMLConfig::getConfig(); + string sourceId; + conf.generateRandomBytes(sourceId,SAMLArtifactType0001::SOURCEID_LENGTH); + SAMLArtifactType0001 artifact1(sourceId,handle); + //printResults(artifact1); + + SAMLArtifactType0001 artifact2(conf.hashSHA1(providerIdStr.c_str()),handle); + //printResults(artifact2,providerIdStr.c_str()); + } + + void testSAMLArtifactType0002(void) { + SAMLArtifactType0002 artifact(providerIdStr,handle); + //printResults(artifact,providerIdStr.c_str()); + } + + void testSAMLArtifactType0004(void) { + SAML2ArtifactType0004 artifact(SAMLConfig::getConfig().hashSHA1(providerIdStr.c_str()),666,handle); + //printResults(artifact,providerIdStr.c_str()); + } + + void printResults(SAMLArtifact& artifact, const char* str=NULL) { + // print heading: + cout << "Artifact Type " << SAMLArtifact::toHex(artifact.getTypeCode()); + cout << " (size = " << artifact.getBytes().size() << ")" << endl; + + // print URI: + if (str) { + cout << "URI: " << str << endl; + } + else { + cout << "URI: NONE" << endl; + } + + // print hex-encoded artifact: + cout << "Hex: " << SAMLArtifact::toHex(artifact.getBytes()) << endl; + + // print base64-encoded artifact: + cout << "Base64: " << artifact.encode() << endl; + + // print ruler: + cout << " ----------------------------------------------------------------------" << endl; + cout << " 1234567890123456789012345678901234567890123456789012345678901234567890" << endl; + cout << " 1 2 3 4 5 6 7" << endl; + cout << " ----------------------------------------------------------------------" << endl; + } +};