authenticationservices/authenticationserver/test/tauthdb/step_createtestdb.cpp
branchRCL_3
changeset 45 030c4fbc13d7
parent 44 d07aa956024a
child 47 b54b58ee9d58
equal deleted inserted replaced
44:d07aa956024a 45:030c4fbc13d7
     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 #include <bautils.h>
       
    20 #include "tauthdbstep.h"
       
    21 
       
    22 using namespace AuthServer;
       
    23 
       
    24 
       
    25 CTStepCreateTestDb::CTStepCreateTestDb()
       
    26 	{
       
    27 	SetTestStepName(KTStepCreateTestDb);
       
    28 	}
       
    29 
       
    30 
       
    31 TVerdict CTStepCreateTestDb::doTestStepL()
       
    32 /**
       
    33 	Create a test database and copy the file to
       
    34 	authdb0.db to system drive.  This database is used by both
       
    35 	tauthdb and tauthsvr.
       
    36  */
       
    37 	{
       
    38 	TInt r;
       
    39 	
       
    40 	// create the server's private directory.  This happens
       
    41 	// when the server starts up, but some of the tests use
       
    42 	// the server's classes directly.
       
    43 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
    44 	TDriveName sysDriveName (sysDrive.Name());
       
    45 
       
    46 	TBuf<128> dbName(KDbName);
       
    47 	dbName[0] = 'A' + sysDrive;	
       
    48 	
       
    49 	r = iFs.MkDirAll(dbName);			// db name not used
       
    50 	if (r != KErrAlreadyExists)
       
    51 		User::LeaveIfError(r);
       
    52 	
       
    53 	RemoveExistingDbL();
       
    54 	
       
    55 	CAuthDb2* db = CAuthDb2::NewLC(iFs);
       
    56 	
       
    57 	_LIT(kId1Name, "Identity1");
       
    58 	_LIT(kId2Name, "Identity2");
       
    59 	_LIT(kId3Name, "Identity3");
       
    60 	_LIT(kId22Name, "Identity22");
       
    61 	
       
    62 	db->AddIdentityL(1, kId1Name);
       
    63 	const CTransientKeyInfo* tki1 = iId1Keys[0];
       
    64 	db->SetTrainedPluginL(1, tki1->PluginId(), *tki1);
       
    65 	
       
    66 	db->AddIdentityL(2, kId2Name);
       
    67 	const CTransientKeyInfo* tki2 = iId2Keys[0];
       
    68 	db->SetTrainedPluginL(2, tki2->PluginId(), *tki2);
       
    69 	
       
    70 	db->AddIdentityL(3, kId3Name);
       
    71 	const CTransientKeyInfo* tki3 = iId3Keys[0];
       
    72 	db->SetTrainedPluginL(3, tki3->PluginId(), *tki3); 
       
    73 	
       
    74 	// create additional trained plugins
       
    75 	for (TInt i = 1 ; i < KNumPlugins ; ++i)
       
    76 		{
       
    77 		db->SetTrainedPluginL(1, iId1Keys[i]->PluginId(), *iId1Keys[i]);
       
    78 		db->SetTrainedPluginL(2, iId1Keys[i]->PluginId(), *iId2Keys[i]);
       
    79 		db->SetTrainedPluginL(3, iId1Keys[i]->PluginId(), *iId3Keys[i]);
       
    80 		}
       
    81     
       
    82     // Add 1 more id for use with test plugin
       
    83     CProtectionKey* key = CProtectionKey::NewLC(8);
       
    84     
       
    85     CTransientKeyInfo* tki = CTransientKeyInfo::NewLC(0x10274104);
       
    86     
       
    87 	_LIT8(KIdentifyData, "ABABABABABABABABABAB");
       
    88     CTransientKey* tk = tki->CreateTransientKeyL(KIdentifyData);
       
    89     CleanupStack::PushL(tk);
       
    90     
       
    91     CEncryptedProtectionKey* epKey = tk->EncryptL(*key);
       
    92     CleanupStack::PushL(epKey);	// epKey takes ownership
       
    93         
       
    94     tki->SetEncryptedProtectionKeyL(epKey);
       
    95     CleanupStack::Pop(epKey);	// eki takes ownership
       
    96     
       
    97 	db->AddIdentityL(22, kId22Name);
       
    98 	db->SetTrainedPluginL(22, tki->PluginId(), *tki); 
       
    99 
       
   100 	CleanupStack::PopAndDestroy(3, key);
       
   101 	
       
   102 	CleanupStack::PopAndDestroy(db);
       
   103 	
       
   104 	_LIT(KDbTrgFileName ,"\\authdb0.db");
       
   105 	TBuf<128> dbTrgFileName (sysDriveName);
       
   106 	dbTrgFileName.Append(KDbTrgFileName);
       
   107 	
       
   108 	// copy the file to the system drive 
       
   109 	r = BaflUtils::CopyFile(iFs, dbName, dbTrgFileName);
       
   110 	TESTL(r == KErrNone);
       
   111 	
       
   112 	return EPass;
       
   113 	}