PageRenderTime 220ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/tests/llsecapi_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 122 lines | 68 code | 14 blank | 40 comment | 3 complexity | 17ae155d746e58d10ff1d30b68603fb4 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llsecapi_test.cpp
  3. * @author Roxie
  4. * @date 2009-02-10
  5. * @brief Test the sec api functionality
  6. *
  7. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. #include "../llviewerprecompiledheaders.h"
  29. #include "../llviewernetwork.h"
  30. #include "../test/lltut.h"
  31. #include "../llsecapi.h"
  32. #include "../llsechandler_basic.h"
  33. #include "../../llxml/llcontrol.h"
  34. //----------------------------------------------------------------------------
  35. // Mock objects for the dependencies of the code we're testing
  36. LLControlGroup::LLControlGroup(const std::string& name)
  37. : LLInstanceTracker<LLControlGroup, std::string>(name) {}
  38. LLControlGroup::~LLControlGroup() {}
  39. BOOL LLControlGroup::declareString(const std::string& name,
  40. const std::string& initial_val,
  41. const std::string& comment,
  42. BOOL persist) {return TRUE;}
  43. void LLControlGroup::setString(const std::string& name, const std::string& val){}
  44. std::string LLControlGroup::getString(const std::string& name)
  45. {
  46. return "";
  47. }
  48. LLControlGroup gSavedSettings("test");
  49. LLSecAPIBasicHandler::LLSecAPIBasicHandler() {}
  50. void LLSecAPIBasicHandler::init() {}
  51. LLSecAPIBasicHandler::~LLSecAPIBasicHandler() {}
  52. LLPointer<LLCertificate> LLSecAPIBasicHandler::getCertificate(const std::string& pem_cert) { return NULL; }
  53. LLPointer<LLCertificate> LLSecAPIBasicHandler::getCertificate(X509* openssl_cert) { return NULL; }
  54. LLPointer<LLCertificateChain> LLSecAPIBasicHandler::getCertificateChain(const X509_STORE_CTX* chain) { return NULL; }
  55. LLPointer<LLCertificateStore> LLSecAPIBasicHandler::getCertificateStore(const std::string& store_id) { return NULL; }
  56. void LLSecAPIBasicHandler::setProtectedData(const std::string& data_type, const std::string& data_id, const LLSD& data) {}
  57. LLSD LLSecAPIBasicHandler::getProtectedData(const std::string& data_type, const std::string& data_id) { return LLSD(); }
  58. void LLSecAPIBasicHandler::deleteProtectedData(const std::string& data_type, const std::string& data_id) {}
  59. LLPointer<LLCredential> LLSecAPIBasicHandler::createCredential(const std::string& grid, const LLSD& identifier, const LLSD& authenticator) { return NULL; }
  60. LLPointer<LLCredential> LLSecAPIBasicHandler::loadCredential(const std::string& grid) { return NULL; }
  61. void LLSecAPIBasicHandler::saveCredential(LLPointer<LLCredential> cred, bool save_authenticator) {}
  62. void LLSecAPIBasicHandler::deleteCredential(LLPointer<LLCredential> cred) {}
  63. // -------------------------------------------------------------------------------------------
  64. // TUT
  65. // -------------------------------------------------------------------------------------------
  66. namespace tut
  67. {
  68. // Test wrapper declaration : wrapping nothing for the moment
  69. struct secapiTest
  70. {
  71. secapiTest()
  72. {
  73. }
  74. ~secapiTest()
  75. {
  76. }
  77. };
  78. // Tut templating thingamagic: test group, object and test instance
  79. typedef test_group<secapiTest> secapiTestFactory;
  80. typedef secapiTestFactory::object secapiTestObject;
  81. tut::secapiTestFactory tut_test("LLSecAPI");
  82. // ---------------------------------------------------------------------------------------
  83. // Test functions
  84. // ---------------------------------------------------------------------------------------
  85. // registration
  86. template<> template<>
  87. void secapiTestObject::test<1>()
  88. {
  89. // retrieve an unknown handler
  90. ensure("'Unknown' handler should be NULL", !(BOOL)getSecHandler("unknown"));
  91. LLPointer<LLSecAPIHandler> test1_handler = new LLSecAPIBasicHandler();
  92. registerSecHandler("sectest1", test1_handler);
  93. ensure("'Unknown' handler should be NULL", !(BOOL)getSecHandler("unknown"));
  94. LLPointer<LLSecAPIHandler> retrieved_test1_handler = getSecHandler("sectest1");
  95. ensure("Retrieved sectest1 handler should be the same",
  96. retrieved_test1_handler == test1_handler);
  97. // insert a second handler
  98. LLPointer<LLSecAPIHandler> test2_handler = new LLSecAPIBasicHandler();
  99. registerSecHandler("sectest2", test2_handler);
  100. ensure("'Unknown' handler should be NULL", !(BOOL)getSecHandler("unknown"));
  101. retrieved_test1_handler = getSecHandler("sectest1");
  102. ensure("Retrieved sectest1 handler should be the same",
  103. retrieved_test1_handler == test1_handler);
  104. LLPointer<LLSecAPIHandler> retrieved_test2_handler = getSecHandler("sectest2");
  105. ensure("Retrieved sectest1 handler should be the same",
  106. retrieved_test2_handler == test2_handler);
  107. }
  108. }