Back to index

nordugrid-arc-nox  1.1.0~rc6
DelegationInterfaceTest.cpp
Go to the documentation of this file.
00001 #include <sstream>
00002 
00003 #include <cppunit/extensions/HelperMacros.h>
00004 
00005 #include <arc/message/PayloadSOAP.h>
00006 #include <arc/delegation/DelegationInterface.h>
00007        
00008 class DelegationInterfaceTest
00009   : public CppUnit::TestFixture {
00010 
00011   CPPUNIT_TEST_SUITE(DelegationInterfaceTest);
00012   CPPUNIT_TEST(TestDelegationInterfaceDELEGATE);
00013   CPPUNIT_TEST_SUITE_END();
00014 
00015 public:
00016   void setUp();
00017   void tearDown();
00018 
00019   void TestDelegationInterfaceDELEGATE();
00020 
00021 private:
00022   std::string credentials;
00023 };
00024 
00025 class DirectMCC: public Arc::MCCInterface {
00026   private:
00027     Arc::DelegationContainerSOAP& container_;
00028   public:
00029     DirectMCC(Arc::DelegationContainerSOAP& container):container_(container) {};
00030     Arc::MCC_Status process(Arc::Message& in,Arc::Message& out);
00031 };
00032 
00033 Arc::MCC_Status DirectMCC::process(Arc::Message& in,Arc::Message& out) {
00034   if(!in.Payload()) return Arc::MCC_Status();
00035   Arc::PayloadSOAP* in_payload = NULL;
00036   try {
00037     in_payload = dynamic_cast<Arc::PayloadSOAP*>(in.Payload());
00038   } catch(std::exception& e) { };
00039   if(!in_payload) return Arc::MCC_Status();
00040   Arc::MCC_Status r;
00041   Arc::NS ns;
00042   Arc::PayloadSOAP* out_payload = new Arc::PayloadSOAP(ns);
00043   out.Payload(out_payload);
00044   if((*in_payload)["DelegateCredentialsInit"]) {
00045     if(!container_.DelegateCredentialsInit(*in_payload,*out_payload)) return Arc::MCC_Status();
00046   } else if((*in_payload)["UpdateCredentials"]) {
00047     std::string cred;
00048     if(!container_.UpdateCredentials(cred,*in_payload,*out_payload)) return Arc::MCC_Status();
00049     if(cred.empty()) return Arc::MCC_Status();
00050   };
00051   return Arc::MCC_Status(Arc::STATUS_OK);
00052 }
00053 
00054 void DelegationInterfaceTest::setUp() {
00055   credentials.assign("\
00056 -----BEGIN CERTIFICATE-----\n\
00057 MIIBxjCCAS8CARAwDQYJKoZIhvcNAQEFBQAwKzENMAsGA1UEChMER3JpZDENMAsG\n\
00058 A1UEChMEVGVzdDELMAkGA1UEAxMCQ0EwHhcNMDkwMTA1MTExNzQ2WhcNMDkwMjA0\n\
00059 MTExNzQ2WjAsMQswCQYDVQQGEwJYWDEOMAwGA1UEChMFRHVtbXkxDTALBgNVBAMT\n\
00060 BFRlc3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMPRUsusZTJG5tph8EUv\n\
00061 s8Lvsv8+JRyoMuNhxcg5sy2MtxKvs1LBG8uBIeiI5vDHEyaA+kM3RP6/RvBD9Uru\n\
00062 /qZRkmMlYwWDNyhU2Ft/7//M8jVIXl8pagWEwEAFwUPcdBX5OSPe5GFpeJnGtyWu\n\
00063 0vLTrxDammqIDtdyrJM8c8AvAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAMNxlpMJo\n\
00064 vo/2Mdwib+DLLyALm7HT0PbAFupj+QIyAntqqqQKaQqZwD4WeQf4jk2Vx9gGzFLV\n\
00065 gEt3slFV2uxcuLf8BNQdPcv5rFwvwYu5AlExVZDUCQ06oR+RWiktekDWTAsx/PEt\n\
00066 AjVVi0njg0Iev5AN7zWqxCOPjSW2yePNzCE=\n\
00067 -----END CERTIFICATE-----\n\
00068 -----BEGIN RSA PRIVATE KEY-----\n\
00069 MIICXQIBAAKBgQDD0VLLrGUyRubaYfBFL7PC77L/PiUcqDLjYcXIObMtjLcSr7NS\n\
00070 wRvLgSHoiObwxxMmgPpDN0T+v0bwQ/VK7v6mUZJjJWMFgzcoVNhbf+//zPI1SF5f\n\
00071 KWoFhMBABcFD3HQV+Tkj3uRhaXiZxrclrtLy068Q2ppqiA7XcqyTPHPALwIDAQAB\n\
00072 AoGAMuSPeUH4FyYYT7/Om5y3Qr3brrzvFlCc0T4TEmP0rqz409F4cNShrbWFI5OZ\n\
00073 OhDzaDlzUc7mjrMV89IlyXDuG8WJJApCvd5fkZcigxa+cmrcGKRO/BOq5Zit0yKM\n\
00074 ebE9csJKfj5WeXyjtQSWmAXlJJ5Y9bKO+PuVUaav5V/W/QkCQQDi33mOaf99o1o1\n\
00075 jjnSUl5TgbqAtE4LXgnOgVl+Sazq3dVHBBhaFTzFYfa57YlvN8i6nYF8SfegpFJa\n\
00076 Pt7BdSFlAkEA3PUrZgZDQDdrIFrqk12tW7P4YGqPkSjGrbuLTwGxhTiWhPL7Tej7\n\
00077 Up/z8zpahDbGEXhNUgKKw0AOwHtZ2wssAwJBAJyPr2jyCRgApH4U2h4kLWffPH8Y\n\
00078 7kq16HqTlNirqyKhV08cqllwEnH7+rGwFImlq2Xsz7Cfsr0u6I3SmRJT7GkCQQCJ\n\
00079 v8q7gyH/8cy2Uhe1oYwHBI7OxQAV9f7OpoH10k9yh1HHNpgW/S1ZWGDEfNebX25h\n\
00080 y8cgXndVvCS2OPBOz4szAkBWx+6KgpQ+Xdx5Jv7IoGRdE9GdIGMtTaHOnUxSsdlj\n\
00081 buEHRt+0Gp5Rod9S6w9Ppl6CphSPq5HRCo49SBBRgAWm\n\
00082 -----END RSA PRIVATE KEY-----\n\
00083 ");
00084 }
00085 
00086 void DelegationInterfaceTest::tearDown() {
00087 }
00088 
00089 void DelegationInterfaceTest::TestDelegationInterfaceDELEGATE() {
00090   Arc::DelegationContainerSOAP c;
00091   Arc::DelegationProviderSOAP p(credentials);
00092   DirectMCC m(c);
00093   Arc::MessageContext context;
00094 
00095   CPPUNIT_ASSERT((bool)p.DelegateCredentialsInit(m,&context));
00096 #ifdef HAVE_OPENSSL_PROXY
00097   CPPUNIT_ASSERT((bool)p.UpdateCredentials(m,&context));
00098 #endif
00099 }
00100 
00101 CPPUNIT_TEST_SUITE_REGISTRATION(DelegationInterfaceTest);
00102 
00103