PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 14ms RepoModel.GetById 27ms 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
  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
 36//----------------------------------------------------------------------------               
 37// Mock objects for the dependencies of the code we're testing                               
 38
 39LLControlGroup::LLControlGroup(const std::string& name)
 40: LLInstanceTracker<LLControlGroup, std::string>(name) {}
 41LLControlGroup::~LLControlGroup() {}
 42BOOL LLControlGroup::declareString(const std::string& name,
 43                                   const std::string& initial_val,
 44                                   const std::string& comment,
 45                                   BOOL persist) {return TRUE;}
 46void LLControlGroup::setString(const std::string& name, const std::string& val){}
 47std::string LLControlGroup::getString(const std::string& name)
 48{
 49	return "";
 50}
 51
 52
 53LLControlGroup gSavedSettings("test");
 54
 55LLSecAPIBasicHandler::LLSecAPIBasicHandler() {}
 56void LLSecAPIBasicHandler::init() {}
 57LLSecAPIBasicHandler::~LLSecAPIBasicHandler() {}
 58LLPointer<LLCertificate> LLSecAPIBasicHandler::getCertificate(const std::string& pem_cert) { return NULL; }
 59LLPointer<LLCertificate> LLSecAPIBasicHandler::getCertificate(X509* openssl_cert) { return NULL; }
 60LLPointer<LLCertificateChain> LLSecAPIBasicHandler::getCertificateChain(const X509_STORE_CTX* chain) { return NULL; }
 61LLPointer<LLCertificateStore> LLSecAPIBasicHandler::getCertificateStore(const std::string& store_id) { return NULL; }
 62void LLSecAPIBasicHandler::setProtectedData(const std::string& data_type, const std::string& data_id, const LLSD& data) {}
 63LLSD LLSecAPIBasicHandler::getProtectedData(const std::string& data_type, const std::string& data_id) { return LLSD(); }
 64void LLSecAPIBasicHandler::deleteProtectedData(const std::string& data_type, const std::string& data_id) {}
 65LLPointer<LLCredential> LLSecAPIBasicHandler::createCredential(const std::string& grid, const LLSD& identifier, const LLSD& authenticator) { return NULL; }
 66LLPointer<LLCredential> LLSecAPIBasicHandler::loadCredential(const std::string& grid) { return NULL; }
 67void LLSecAPIBasicHandler::saveCredential(LLPointer<LLCredential> cred, bool save_authenticator) {}
 68void LLSecAPIBasicHandler::deleteCredential(LLPointer<LLCredential> cred) {}
 69
 70// -------------------------------------------------------------------------------------------
 71// TUT
 72// -------------------------------------------------------------------------------------------
 73namespace tut
 74{
 75	// Test wrapper declaration : wrapping nothing for the moment
 76	struct secapiTest
 77	{
 78		
 79		secapiTest()
 80		{
 81		}
 82		~secapiTest()
 83		{
 84		}
 85	};
 86	
 87	// Tut templating thingamagic: test group, object and test instance
 88	typedef test_group<secapiTest> secapiTestFactory;
 89	typedef secapiTestFactory::object secapiTestObject;
 90	tut::secapiTestFactory tut_test("LLSecAPI");
 91	
 92	// ---------------------------------------------------------------------------------------
 93	// Test functions 
 94	// ---------------------------------------------------------------------------------------
 95	// registration
 96	template<> template<>
 97	void secapiTestObject::test<1>()
 98	{
 99		// retrieve an unknown handler
100
101		ensure("'Unknown' handler should be NULL", !(BOOL)getSecHandler("unknown"));
102		LLPointer<LLSecAPIHandler> test1_handler =  new LLSecAPIBasicHandler();
103		registerSecHandler("sectest1", test1_handler);
104		ensure("'Unknown' handler should be NULL", !(BOOL)getSecHandler("unknown"));
105		LLPointer<LLSecAPIHandler> retrieved_test1_handler = getSecHandler("sectest1");
106		ensure("Retrieved sectest1 handler should be the same", 
107			   retrieved_test1_handler == test1_handler);
108		
109		// insert a second handler
110		LLPointer<LLSecAPIHandler> test2_handler =  new LLSecAPIBasicHandler();
111		registerSecHandler("sectest2", test2_handler);
112		ensure("'Unknown' handler should be NULL", !(BOOL)getSecHandler("unknown"));
113		retrieved_test1_handler = getSecHandler("sectest1");
114		ensure("Retrieved sectest1 handler should be the same", 
115			   retrieved_test1_handler == test1_handler);
116
117		LLPointer<LLSecAPIHandler> retrieved_test2_handler = getSecHandler("sectest2");
118		ensure("Retrieved sectest1 handler should be the same", 
119			   retrieved_test2_handler == test2_handler);
120		
121	}
122}