authenticationservices/authenticationserver/test/tauthdb/tauthdbstep.h
changeset 102 deec7e509f66
parent 94 0e6c5a9328b5
child 108 ca9a0fc2f082
equal deleted inserted replaced
94:0e6c5a9328b5 102:deec7e509f66
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef TAUTHDBSTEP_H
       
    20 #define TAUTHDBSTEP_H
       
    21 
       
    22 #include <test/testexecutestepbase.h>
       
    23 #include <test/testexecutelog.h>
       
    24 #include "tauthdbserver.h"
       
    25 #include <f32file.h>
       
    26 
       
    27 #include "authdb.h"
       
    28 #include "encryptedprotectionkey.h"
       
    29 #include "transientkey.h"  
       
    30 #include "transientkey.h"  
       
    31 #include "transientkeyinfo.h"
       
    32 
       
    33 _LIT(KTStepCreateTestDb, "CreateTestDb");
       
    34 _LIT(KTStepPersist2, "PERSIST2");
       
    35 
       
    36 #define KNumPlugins 10
       
    37 
       
    38 
       
    39 class CTAuthDbStepBase : public CTestStep
       
    40 	{
       
    41 protected:
       
    42 	CTAuthDbStepBase() {}
       
    43 	virtual ~CTAuthDbStepBase();
       
    44 	
       
    45 	void CreatePlugins();
       
    46 	void CreateKeyInfo();
       
    47 		
       
    48 	virtual TVerdict doTestStepPreambleL()
       
    49 	   {
       
    50 	   iFs.Connect();
       
    51 	
       
    52 	   CreatePlugins();
       
    53 	   CreateKeyInfo();
       
    54 	   
       
    55 	   return TestStepResult();
       
    56 	   }
       
    57 	virtual TVerdict doTestStepPostambleL()
       
    58     	{
       
    59 		iFs.Close();
       
    60 		return TestStepResult();
       
    61 		}
       
    62 	
       
    63 	void RemoveExistingDbL()
       
    64 	/**
       
    65 		Remove any existing database file.
       
    66 	 */
       
    67 		{
       
    68 		CFileMan* fm = CFileMan::NewL(iFs);
       
    69 		CleanupStack::PushL(fm);
       
    70 
       
    71 		TFileName dbName(AuthServer::KDbName);
       
    72 		dbName[0] = RFs::GetSystemDriveChar();
       
    73 
       
    74 		TInt r = fm->Delete(dbName);
       
    75 		if (r != KErrNotFound)
       
    76 			User::LeaveIfError(r);
       
    77 
       
    78 		CleanupStack::PopAndDestroy(fm);	
       
    79 		}
       
    80 
       
    81 	HBufC* GetNameLC(TInt i);
       
    82 
       
    83 	void PluginData(AuthServer::TIdentityId aId,
       
    84 					AuthServer::TPluginId aPlugin,
       
    85 					TPtr8 aDes) 
       
    86 	{
       
    87 	aDes.Fill(aId*aPlugin);
       
    88 	}
       
    89 protected:
       
    90 	RFs		iFs;
       
    91 
       
    92 
       
    93 	AuthServer::CPluginDesc*       iPlugins[KNumPlugins];
       
    94 	AuthServer::CTransientKeyInfo* iId1Keys[KNumPlugins];
       
    95 	AuthServer::CTransientKeyInfo* iId2Keys[KNumPlugins];
       
    96 	AuthServer::CTransientKeyInfo* iId3Keys[KNumPlugins];
       
    97   };
       
    98 
       
    99 inline CTAuthDbStepBase::~CTAuthDbStepBase() 
       
   100     {
       
   101     for (TInt i = 0 ; i < KNumPlugins ; ++i)
       
   102         {
       
   103         delete iPlugins[i];
       
   104         delete iId1Keys[i];
       
   105         delete iId2Keys[i];
       
   106         delete iId3Keys[i];
       
   107         }
       
   108     }
       
   109 
       
   110 
       
   111 class CTStepCreateTestDb : public CTAuthDbStepBase
       
   112 /**
       
   113 	Creates a test database which tauthcliserv can
       
   114 	use to test the manager later.
       
   115  */
       
   116 	{
       
   117 public:
       
   118 	CTStepCreateTestDb();
       
   119 	
       
   120 	// implement CTestStep
       
   121 	virtual TVerdict doTestStepL();
       
   122 	};
       
   123 
       
   124 
       
   125 class CTStepPersist2 : public CTAuthDbStepBase
       
   126 	{
       
   127 public:
       
   128 	CTStepPersist2();
       
   129 	
       
   130 private:
       
   131 	virtual TVerdict doTestStepL();
       
   132 	
       
   133 	void TestOpenCloseL();
       
   134 	
       
   135 	void TestIdentitiesL();
       
   136 	void TestDescriptionL(AuthServer::CAuthDb2* aDb, AuthServer::TIdentityId aIdentityId, const TDesC& aExpDesc);
       
   137 	
       
   138 	void TestPrefsL();
       
   139 	
       
   140 	void TestTrainedPluginsL();
       
   141 	void TestKeyPresentL(
       
   142 		AuthServer::CAuthDb2* aAuthDb, AuthServer::TIdentityId aIdentityId, AuthServer::TPluginId aPluginId,
       
   143 		const AuthServer::CTransientKeyInfo& aTarget);
       
   144 	
       
   145 	void TestTrainingStatusL();
       
   146 	
       
   147 	void TestRepairL();
       
   148 
       
   149 	void TestCompressL();
       
   150 	TInt DbFileSizeL();
       
   151 	};
       
   152 
       
   153 
       
   154 inline HBufC* CTAuthDbStepBase::GetNameLC(TInt id)
       
   155     {
       
   156     _LIT(nameTmpl, "Plugin_%d");
       
   157 	HBufC* name = HBufC::NewLC(15);
       
   158 	name->Des().Format(nameTmpl, id);
       
   159 	return name;
       
   160     }
       
   161     
       
   162 inline void CTAuthDbStepBase::CreatePlugins()
       
   163 	{
       
   164 	using namespace AuthServer;
       
   165 	
       
   166 	const TAuthPluginType   types[KNumPlugins]
       
   167 		= { EAuthBiometric, EAuthToken, EAuthKnowledge,
       
   168 			EAuthBiometric, EAuthToken, EAuthKnowledge,
       
   169 			EAuthToken, EAuthKnowledge
       
   170 		};
       
   171 	const TAuthTrainingStatus   training[KNumPlugins]
       
   172 		= { EAuthUntrained, EAuthTrained, EAuthFullyTrained,
       
   173 			EAuthUntrained, EAuthTrained, EAuthFullyTrained,
       
   174 			EAuthTrained, EAuthFullyTrained
       
   175 		  };
       
   176 
       
   177 
       
   178 	for (TInt i = 0 ; i < KNumPlugins ; ++i)
       
   179 		{
       
   180 			HBufC* name = GetNameLC(i);
       
   181 			
       
   182 			iPlugins[i] = CPluginDesc::NewL(i,
       
   183 											*name,
       
   184 											types[i],
       
   185 											training[i],
       
   186 											i*10000,
       
   187 											i,
       
   188 											i*4);
       
   189 		    CleanupStack::PopAndDestroy(name);									
       
   190 		}
       
   191 	}
       
   192 inline void CTAuthDbStepBase::CreateKeyInfo()
       
   193 	{
       
   194 	using namespace AuthServer;
       
   195 
       
   196 	CProtectionKey* protKey1 = CProtectionKey::NewLC(8);
       
   197 	CProtectionKey* protKey2 = CProtectionKey::NewLC(8);
       
   198 	CProtectionKey* protKey3 = CProtectionKey::NewLC(8);
       
   199 
       
   200 	HBufC8* data = HBufC8::NewLC(4);
       
   201 	
       
   202 	for (TInt plugin = 0 ; plugin < KNumPlugins ; ++plugin)
       
   203 		{
       
   204 			CTransientKey* transient = 0;
       
   205 			// id 1
       
   206 			iId1Keys[plugin] = CTransientKeyInfo::NewL(plugin);
       
   207 			PluginData(1, plugin, data->Des());
       
   208 			transient = iId1Keys[plugin]->CreateTransientKeyL(data->Des());
       
   209 			CEncryptedProtectionKey* epKey1 =
       
   210 				transient->EncryptL(*protKey1);
       
   211 			delete transient;
       
   212 			iId1Keys[plugin]->SetEncryptedProtectionKeyL(epKey1);
       
   213 			// id 2
       
   214 			PluginData(2, plugin, data->Des());
       
   215 			iId2Keys[plugin] = CTransientKeyInfo::NewL(plugin);
       
   216 			transient = iId2Keys[plugin]->CreateTransientKeyL(data->Des());
       
   217 			CEncryptedProtectionKey* epKey2 =
       
   218 				transient->EncryptL(*protKey2);
       
   219 			delete transient;
       
   220 			iId2Keys[plugin]->SetEncryptedProtectionKeyL(epKey2);
       
   221 			// id 3
       
   222 			PluginData(3, plugin, data->Des());
       
   223 			iId3Keys[plugin] = CTransientKeyInfo::NewL(plugin);
       
   224 			transient = iId3Keys[plugin]->CreateTransientKeyL(data->Des());
       
   225 			CEncryptedProtectionKey* epKey3 =
       
   226 				transient->EncryptL(*protKey3);
       
   227 			delete transient;
       
   228 			iId3Keys[plugin]->SetEncryptedProtectionKeyL(epKey3);
       
   229 		}
       
   230 	CleanupStack::Pop(4, protKey1);
       
   231 	}
       
   232 
       
   233 #endif	/* TAUTHDBSTEP_H */