authenticationservices/authenticationserver/test/tAuthSvr/src/step_authenticate.cpp
changeset 29 ece3df019add
equal deleted inserted replaced
19:cd501b96611d 29:ece3df019add
       
     1 /*
       
     2 * Copyright (c) 2006-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 * CTestStep derived implementation
       
    16 *
       
    17 */
       
    18 
       
    19  
       
    20 #include "tAuthSvrStep.h"
       
    21 
       
    22 #include "authserver/authclient.h"
       
    23 #include "authserver/authmgrclient.h"
       
    24 #include "authrepository.h"
       
    25 #include "testutilclient.h"
       
    26 
       
    27 using namespace AuthServer;
       
    28 
       
    29 
       
    30 class CAuthActive2 : public CActive
       
    31     {
       
    32     public:
       
    33     CAuthActive2(RAuthMgrClient& aClient, CAuthExpression* aExpression,
       
    34 				 TInt aFresh, TBool aClientSpecific, TBool aAuthViaAlias, const TDesC& aClientMessage, TBool aStop = ETrue) : 
       
    35          CActive(EPriorityNormal),
       
    36          iClient(aClient),
       
    37 		 iResult(EFail),
       
    38          iRunCount(0),
       
    39          iAe(aExpression),
       
    40          iStop(aStop),
       
    41          iFresh(aFresh),
       
    42          iIdToStore(0), 
       
    43          iClientSpecific(aClientSpecific),
       
    44          iAuthViaAlias(aAuthViaAlias),
       
    45          iClientMessage(aClientMessage)
       
    46         {
       
    47         CActiveScheduler::Add(this);
       
    48         }
       
    49     
       
    50    void doAuth() 
       
    51         {
       
    52         SetActive();		
       
    53 		TRequestStatus* status = &iStatus;
       
    54 		User::RequestComplete(status, KErrNone);
       
    55 		iRunCount = 0;
       
    56         }
       
    57 	void DoCancel() 
       
    58         {
       
    59         }
       
    60         
       
    61     TInt RunError(TInt aError)
       
    62     	{
       
    63     	iErr = aError;
       
    64 	   	CActiveScheduler::Stop();
       
    65     	return KErrNone;
       
    66     	}
       
    67     	
       
    68     void RunL() 
       
    69         {
       
    70         iErr = iStatus.Int();
       
    71        
       
    72 		switch (iRunCount)
       
    73 		  {
       
    74 		  case 0:
       
    75 		  	{
       
    76 		  	iId = 0;
       
    77 			TUid clientSid = {0};
       
    78 			iClient.AuthenticateL(*iAe, iFresh, iClientSpecific, clientSid, EFalse, iClientMessage, iId, iStatus);
       
    79 		
       
    80 			SetActive();
       
    81 
       
    82 			break;
       
    83 		  	}
       
    84             
       
    85 		  case 1:
       
    86 			if (0 != iId)
       
    87 				{
       
    88 				iIdToStore = iId->Id();
       
    89 				delete iId;
       
    90 				iId = NULL;
       
    91 				}
       
    92 			
       
    93 			iResult = iStatus == KErrNone ? EPass : EFail;
       
    94             iErr = iStatus.Int();
       
    95 			if (iStop)
       
    96                 {
       
    97                 CActiveScheduler::Stop();
       
    98                 }
       
    99 
       
   100 			break;
       
   101 			
       
   102      	  default:
       
   103 			iResult = EFail;
       
   104 			
       
   105 			if (iStop)
       
   106 			    {
       
   107 			    CActiveScheduler::Stop();
       
   108 			    }
       
   109 		    }
       
   110 		  ++iRunCount;
       
   111           }
       
   112 
       
   113 	~CAuthActive2()
       
   114 		{
       
   115 		if(iId != NULL)
       
   116 			delete iId;
       
   117 		}
       
   118           
       
   119    		
       
   120 	RAuthMgrClient& iClient;
       
   121 	TVerdict iResult;
       
   122 	TInt iRunCount;
       
   123 	CAuthExpression* iAe;
       
   124 	CIdentity* iId;
       
   125     TBool iStop;
       
   126     TInt iErr;
       
   127     TInt iFresh;
       
   128     TIdentityId iIdToStore;
       
   129     TBool iClientSpecific;
       
   130     TBool iAuthViaAlias;
       
   131     const TDesC& iClientMessage;
       
   132     };
       
   133     
       
   134 //====================================================================================================    
       
   135 CTAuthenticate::CTAuthenticate(CTAuthSvrServer& aParent): iParent(aParent)
       
   136 /**
       
   137   Constructor
       
   138  */
       
   139 	{
       
   140 	// Call base class method to set up the human readable name for logging
       
   141 	SetTestStepName(KTAuthenticate);
       
   142 	}
       
   143 
       
   144 CTAuthenticate::~CTAuthenticate()
       
   145 /**
       
   146   Destructor
       
   147  */
       
   148 	{}
       
   149 	
       
   150 TVerdict CTAuthenticate::doTestStepPreambleL()
       
   151 /**
       
   152   @return - TVerdict code
       
   153   Override of base class virtual
       
   154  */
       
   155 	{
       
   156 	//Call the parent class preamble, setting up the file server, etc
       
   157 	CTStepActSch::doTestStepPreambleL();
       
   158 
       
   159 	return TestStepResult();
       
   160 	}
       
   161 
       
   162 TVerdict CTAuthenticate::doTestStepL()
       
   163 /**
       
   164   @return - TVerdict code
       
   165   Override of base class pure virtual
       
   166   
       
   167  */
       
   168 	{	
       
   169 	SetTestStepResult(EFail);
       
   170 
       
   171 __UHEAP_MARK;		// Check for memory leaks
       
   172 	 	
       
   173 	//-----------------------------------------------------------------------------------------------------
       
   174 	TPtrC displayMessage;
       
   175 	TBool messageSent = (GetStringFromConfig(ConfigSection(),_L("DisplayMessage"), displayMessage) != EFalse);
       
   176 	TBuf<100> message(displayMessage);
       
   177 	ClientMessage(messageSent, displayMessage);
       
   178 	if(!messageSent)
       
   179 		{
       
   180 		message = KNullDesC();
       
   181 		}
       
   182 	InitAuthServerFromFileL();	// Set things like 'iSupportsDefaultData' and 'DefaultPlugin'
       
   183 	
       
   184 	// this method creates the dat file from where the test implementation
       
   185 	// of pin plugin notifier reads user input.
       
   186 	// as the pin plugin fails without this data it has been included 
       
   187 	// in the code as a default step for initializing the pin plugin
       
   188 	// data.
       
   189 	// the pin value generate through the reference plugin is a random 
       
   190 	// value which should be retrieved from the output file and given 
       
   191 	// as an input back for creation of the input file again.
       
   192 	// If the ini file specified a pin use that instead
       
   193 	TPtrC pin;
       
   194 	if (GetStringFromConfig(ConfigSection(),_L("pinvalue"), pin))
       
   195 		{
       
   196 		TPinValue pinValue;
       
   197 		pinValue.Copy(pin);
       
   198 		//pinValue.
       
   199 		CreatePinPluginInputFileL(EPinPluginIdentify, pinValue);
       
   200 		}
       
   201 	else
       
   202 		{
       
   203 		TPinValue pinValue = GetPinFromOutputFileL();
       
   204 		CreatePinPluginInputFileL(EPinPluginIdentify, pinValue);
       
   205 		}
       
   206 
       
   207 	CActiveScheduler::Install(iActSchd);
       
   208 	//Connect to the AuthServer	
       
   209 	AuthServer::RAuthMgrClient authMgrClient1;	
       
   210 	TInt connectVal = authMgrClient1.Connect();
       
   211 	if (KErrNotFound == connectVal)
       
   212 		{
       
   213 		//Retry after a delay
       
   214 		TTimeIntervalMicroSeconds32 timeInterval = 2000;	//2 Milliseconds
       
   215 		User::After(timeInterval);
       
   216 		connectVal = authMgrClient1.Connect();
       
   217 		}
       
   218 	if (KErrNone != connectVal)
       
   219 		{
       
   220 		ERR_PRINTF2(_L("Unable to start a session or other connection error. Err = %d"), connectVal);
       
   221 		User::LeaveIfError(connectVal);		
       
   222 		}	
       
   223 	
       
   224 	CleanupClosePushL(authMgrClient1);
       
   225 
       
   226 	//-----------------------------------------------------------------------------------------------------
       
   227 	// Authenticate by reading the user input
       
   228 	
       
   229 	//Check that alias or pluginId is quoted in the ini file
       
   230 	TPtrC exprString;
       
   231 	TBool authViaAlias = GetStringFromConfig(ConfigSection(),_L("alias"), exprString);
       
   232 	TBool authViaExpr = EFalse;
       
   233 	if(!authViaAlias)
       
   234 		{
       
   235 		authViaExpr = GetStringFromConfig(ConfigSection(),_L("plugin1Id"), exprString);
       
   236 		}
       
   237 	
       
   238 	if(	! authViaAlias && ! authViaExpr)
       
   239 		{
       
   240 		INFO_PRINTF1(_L("Neither plugin1Id nor alias was specified in the ini file"));	
       
   241 		}
       
   242 	else
       
   243 		{
       
   244 	  	TInt freshnessVal = 0;	//Default value
       
   245 	 	//Retrieve the value of 'freshness' from the ini file, but if it's absent use the default value
       
   246 	 	if(GetIntFromConfig(ConfigSection(),_L("freshness"), freshnessVal) == EFalse)
       
   247 	 		{
       
   248 	 		freshnessVal = 10;
       
   249 	 		}
       
   250 	 		
       
   251 	 	TBool clientSpecificKeyVal = EFalse;	 	
       
   252 	 	//Retrieve the value of 'clientSpecificKey' from the ini file, but if it's absent use the default value
       
   253 	 	if(GetBoolFromConfig(ConfigSection(),_L("clientSpecificKey"), clientSpecificKeyVal) == EFalse)
       
   254 	 		{
       
   255 	 		clientSpecificKeyVal = EFalse;
       
   256 	 		}
       
   257 	 	
       
   258 	 	TBool defaultpluginusage = EFalse;
       
   259 	 	if(GetBoolFromConfig(ConfigSection(),_L("defaultpluginusage"), defaultpluginusage ) == EFalse)
       
   260 	 		 {
       
   261 	 		defaultpluginusage  = EFalse;
       
   262 	 		 }
       
   263 	 		
       
   264 	 	TBool isSynchronous = EFalse;
       
   265 	 	//Retrieve the value of 'synchronous' from the ini file, but if it's absent use the default value
       
   266 	 	if(GetBoolFromConfig(ConfigSection(),_L("synchronous"), isSynchronous) != EFalse)
       
   267 	 		{
       
   268 	 		CallSyncAuthenticateL(authMgrClient1, exprString, freshnessVal, clientSpecificKeyVal, authViaAlias, defaultpluginusage, message);
       
   269 	 		}
       
   270 	 	else
       
   271 	 		{
       
   272 	 		CallAsyncAuthenticateL(authMgrClient1, exprString, freshnessVal, clientSpecificKeyVal, authViaAlias, defaultpluginusage, message);
       
   273 	 		}
       
   274 
       
   275 	  	}
       
   276 
       
   277 	CleanupStack::PopAndDestroy(&authMgrClient1);	// authClient1	
       
   278 	//Garbage collect the last previously destroyed implementation 
       
   279 	// and close the REComSession if no longer in use
       
   280 	REComSession::FinalClose(); 
       
   281 __UHEAP_MARKEND;
       
   282 	return TestStepResult();
       
   283 	}
       
   284 
       
   285 
       
   286 TVerdict CTAuthenticate::doTestStepPostambleL()
       
   287 /**
       
   288   @return - TVerdict code
       
   289   Override of base class virtual
       
   290  */
       
   291 	{
       
   292 	//Call the parent postamble, releasing the file handle, etc
       
   293 	CTStepActSch::doTestStepPostambleL();
       
   294 	return TestStepResult();
       
   295 	}
       
   296 
       
   297 
       
   298 void CTAuthenticate::setLastAuthIdL(AuthServer::TIdentityId idToStore)
       
   299 /**
       
   300   Utility function that stores the most recently authenticated identity in the GlobalDb file
       
   301   This should only be called by the Authenticate test step  class
       
   302  */
       
   303 	{	
       
   304 	TBuf<100> bufToWrite;
       
   305 	_LIT16(KFormatLastAuth,"%u");
       
   306 	
       
   307 	bufToWrite.Format(KFormatLastAuth, idToStore); //generates:
       
   308 	
       
   309 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
   310 	TBuf<128> authSvrPolicyFile (sysDrive.Name());
       
   311 	authSvrPolicyFile.Append(KAuthSvrPolicyFile);
       
   312 
       
   313 	CIniData* policyFile=NULL;
       
   314 	TRAP_IGNORE(policyFile=CIniData::NewL(authSvrPolicyFile));
       
   315 	CleanupStack::PushL(policyFile);
       
   316 
       
   317 	TInt ret = writeToNamedConfig(policyFile, KLastAuthIdTag, bufToWrite);
       
   318 
       
   319 	policyFile->WriteToFileL();
       
   320 	CleanupStack::PopAndDestroy(policyFile);
       
   321 
       
   322 	if (KErrNotFound == ret)
       
   323 		{
       
   324 		ERR_PRINTF3(_L("Error while setting last AuthId. Tag %S not found in %S file"), KLastAuthIdTag, &authSvrPolicyFile);
       
   325 		}
       
   326 	else
       
   327 		{
       
   328 		INFO_PRINTF2(_L("Setting last AuthId was successful. Id = %S"), &bufToWrite);
       
   329 		}
       
   330 	}
       
   331 	
       
   332 void CTAuthenticate::CallSyncAuthenticateL(RAuthMgrClient& aAuthMgrClient, const TDesC& aInputString, TInt aFreshness, TBool aClientSpecificKey, TBool aIsAlias, TBool aIsDefault, const TDesC& aClientMessage )
       
   333 	{
       
   334 	CIdentity* id = 0;
       
   335 	TInt error;
       
   336 	TUid val = TUid::Uid(0);
       
   337 	
       
   338 	CAuthExpression* expr = NULL;
       
   339 	
       
   340 	if(!aIsAlias)
       
   341 		{
       
   342 		if(!aIsDefault)
       
   343 			{
       
   344 			CAuthExpression* expr = CreateAuthExprLC(aInputString);			
       
   345 			TRAP(error, id = aAuthMgrClient.AuthenticateL(*expr, aFreshness, aClientSpecificKey, val, EFalse, aClientMessage));
       
   346 			CleanupStack::PopAndDestroy(expr);
       
   347 			}
       
   348 		else
       
   349 			{
       
   350 			CAuthExpression* expr = CreateAuthExprLC(KNullDesC());			
       
   351 			TRAP(error, id = aAuthMgrClient.AuthenticateL(*expr, aFreshness, aClientSpecificKey, val, EFalse, aClientMessage));
       
   352 			CleanupStack::PopAndDestroy(expr);
       
   353 			}
       
   354 		}
       
   355 	
       
   356 	else
       
   357 		{
       
   358 		TRAPD(err,expr = aAuthMgrClient.CreateAuthExpressionL(aInputString));
       
   359 			if(err != KErrNone)
       
   360 				{
       
   361 				SetTestStepError(err);
       
   362 				return;
       
   363 				}
       
   364 				
       
   365 		CleanupStack::PushL(expr);
       
   366 		TUid clientSid = {0};
       
   367 		TRAP(error, id = aAuthMgrClient.AuthenticateL(*expr, aFreshness, aClientSpecificKey, clientSid, EFalse, KNullDesC));
       
   368 		CleanupStack::PopAndDestroy(expr);
       
   369 		}
       
   370 		
       
   371 	if(error != KErrNone)
       
   372 	 	{
       
   373 	 	ERR_PRINTF2(_L("Authentication Result error = %d"), error);	
       
   374 	 	SetTestStepError(error);
       
   375 	 	return;	
       
   376 		}
       
   377 	 	
       
   378 	//Main check
       
   379 	if (0 == id->Id())
       
   380 		{
       
   381 		ERR_PRINTF1(_L("Authentication failed. No identity returned"));
       
   382 		delete id;
       
   383 		}
       
   384 	
       
   385 	else
       
   386 		{
       
   387 		INFO_PRINTF1(_L("Authentication successful."));
       
   388 		CleanupStack::PushL(id);
       
   389 		//Store the id in the Global Db file		
       
   390 		setLastAuthIdL(id->Id());
       
   391 		CleanupStack::PopAndDestroy(id);
       
   392 		SetTestStepResult(EPass);
       
   393 		}
       
   394 	}
       
   395 	
       
   396 void CTAuthenticate::CallAsyncAuthenticateL(RAuthMgrClient& aAuthMgrClient, TDesC& aInputString, TInt aFreshness, TBool aClientSpecificKey, TBool aIsAlias, TBool aIsDefault, const TDesC& aClientMessage)
       
   397 	{
       
   398 	CAuthExpression* expr = 0;
       
   399 	if(!aIsAlias)
       
   400 		{
       
   401 		if(!aIsDefault)
       
   402 			{	
       
   403 			expr = CreateAuthExprLC(aInputString);
       
   404 			}
       
   405 		else
       
   406 			{
       
   407 			expr = CreateAuthExprLC(KNullDesC());
       
   408 			}
       
   409 		}
       
   410 	else
       
   411 		{
       
   412 		TRAPD(err,expr = aAuthMgrClient.CreateAuthExpressionL(aInputString));
       
   413 		if(err != KErrNone)
       
   414 			{
       
   415 			SetTestStepError(err);
       
   416 			return;
       
   417 			}
       
   418 		CleanupStack::PushL(expr);
       
   419 		}
       
   420 	
       
   421 	CAuthActive2 active1(aAuthMgrClient, expr, aFreshness, aClientSpecificKey, aIsAlias, aClientMessage);
       
   422 	active1.doAuth();		
       
   423 	CActiveScheduler::Start();
       
   424 		
       
   425 	if(expr)
       
   426 		{
       
   427 		CleanupStack::PopAndDestroy(expr);
       
   428 		}
       
   429 	
       
   430 	 		
       
   431 	if(EPass != active1.iResult)
       
   432 		{
       
   433 		ERR_PRINTF3(_L("Authentication Result error = %d, iResult = %d\n"), active1.iErr, active1.iResult);			
       
   434 		SetTestStepError(active1.iErr);
       
   435 		}
       
   436 	
       
   437 	else if ((KErrNone == active1.iErr) && (EPass == active1.iResult))
       
   438 		{
       
   439 		INFO_PRINTF1(_L("No Authentication Errors."));
       
   440 		}
       
   441 		
       
   442 	else
       
   443 		{
       
   444 		ERR_PRINTF3(_L("Unexpected Authentication Result. error = %d, iResult = %d\n"), active1.iErr, active1.iResult);
       
   445 		}
       
   446 		
       
   447 	//Main check
       
   448 	if (0 == active1.iIdToStore)
       
   449 		{
       
   450 		ERR_PRINTF1(_L("Authentication failed. No identity returned"));
       
   451 		}
       
   452 	
       
   453 	else
       
   454 		{
       
   455 		INFO_PRINTF1(_L("Authentication successful."));
       
   456 		//Store the id in the Global Db file		
       
   457 		setLastAuthIdL(active1.iIdToStore);
       
   458 		SetTestStepResult(EPass);
       
   459 		}	
       
   460 	}
       
   461 	
       
   462 //---------------------------------------------------------------------------------------------------------------------------------
       
   463 
       
   464 CTInitCenRep::CTInitCenRep(CTAuthSvrServer& aParent): iParent(aParent)
       
   465 /**
       
   466  Constructor
       
   467 */
       
   468 	{
       
   469 	// Call base class method to set up the human readable name for logging
       
   470 	SetTestStepName(KTInitCenRep);
       
   471 	}
       
   472 
       
   473 
       
   474  CTInitCenRep::~CTInitCenRep()
       
   475 /**
       
   476  Destructor
       
   477 */
       
   478 	{}
       
   479  	
       
   480 TVerdict CTInitCenRep::doTestStepPreambleL()
       
   481 /**
       
   482  @return - TVerdict code
       
   483  Override of base class virtual
       
   484 */
       
   485 	{
       
   486 	//Call the parent class preamble, setting up the file server, etc
       
   487 	CTStepActSch::doTestStepPreambleL();
       
   488 	return TestStepResult();
       
   489 	}
       
   490 
       
   491 TVerdict CTInitCenRep::doTestStepL()
       
   492 /**
       
   493  @return - TVerdict code
       
   494  Override of base class pure virtual
       
   495   
       
   496  */
       
   497 	{	
       
   498 
       
   499  __UHEAP_MARK;		// Check for memory leaks
       
   500 
       
   501 	//Initialize the repository
       
   502 	CRepository* repository = CRepository::NewL(KUidAuthServerRepository);
       
   503 	CleanupStack::PushL(repository);
       
   504 	
       
   505 	//If default plugin is specified, set it
       
   506 	TPtrC defaultPluginFromFile;
       
   507 	if(GetStringFromConfig(ConfigSection(),_L("default"), defaultPluginFromFile) != EFalse)
       
   508 		{
       
   509 		TLex pluginIdString = TLex(defaultPluginFromFile);
       
   510 		TPluginId defaultPluginId(0);
       
   511 		
       
   512 		pluginIdString.Val(defaultPluginId, EHex );
       
   513 		SetDefaultPluginIdL(defaultPluginId);
       
   514 	 		
       
   515 		//Retrieve the value
       
   516 		TInt value(0);
       
   517 		User::LeaveIfError(repository->Get(KAuthDefaultPlugin, value));
       
   518 		CleanupStack::PopAndDestroy(repository);
       
   519 		SetTestStepResult(EPass);
       
   520 		return TestStepResult();
       
   521 		}
       
   522 	TInt aliasCount = 0;
       
   523 	
       
   524 	// Retrieve the value of 'aliasCount' from the ini file, but if it's absent use the default value.
       
   525 	// This value is used for validation of cenrep file.
       
   526 	if(GetIntFromConfig(ConfigSection(),_L("aliasCount"), aliasCount) != EFalse)
       
   527 		{
       
   528 		User::LeaveIfError(repository->Set(EAuthAliasesCount, aliasCount));
       
   529 		CleanupStack::PopAndDestroy(repository);
       
   530 		SetTestStepResult(EPass);
       
   531 		return TestStepResult();
       
   532 		}
       
   533 	
       
   534 	User::LeaveIfError(repository->Get(EAuthAliasesCount, aliasCount));
       
   535 	// since we will only have four aliases in the cenrep file.
       
   536 	__ASSERT_DEBUG(aliasCount == 4, User::Leave(KErrArgument));
       
   537 	
       
   538 	// Retrieve the value of 'unicode' from the ini file, but if it's absent use the default value.
       
   539 	// For unicode tests we need to set the aliases in addition to thier corresponding alias string.
       
   540 	TBool isUnicode = EFalse;
       
   541 	if(GetBoolFromConfig(ConfigSection(),_L("unicode"), isUnicode) != EFalse)
       
   542 		{
       
   543 		TBuf<24> alias;
       
   544 		TPtrC aliasValue;
       
   545 	
       
   546 		for(TInt i = 0; i < aliasCount; ++i)
       
   547 			{
       
   548 			alias.Format(_L("alias%d"), i);
       
   549 			if (GetStringFromConfig(ConfigSection(), alias, aliasValue) != EFalse)
       
   550 				{
       
   551 				User::LeaveIfError(repository->Set(EAuthAliases+i, aliasValue));
       
   552 				}
       
   553 			}
       
   554 		}
       
   555 	
       
   556 	// for each alias ,set the corresponding alias string expression.
       
   557 	TBuf<24> aliasString;
       
   558 	TPtrC aliasStringValue;
       
   559 	
       
   560 	for(TInt i = 0; i < aliasCount; ++i)
       
   561 		{
       
   562 		aliasString.Format(_L("aliasString%d"), i);
       
   563 		if (GetStringFromConfig(ConfigSection(), aliasString, aliasStringValue) != EFalse)
       
   564 			{
       
   565 			User::LeaveIfError(repository->Set(EAuthAliasesExpr+i, aliasStringValue));
       
   566 			}
       
   567 		}
       
   568 	
       
   569 	CleanupStack::PopAndDestroy(repository);
       
   570 	SetTestStepResult(EPass);
       
   571 	
       
   572 __UHEAP_MARKEND;
       
   573 	return TestStepResult();
       
   574 	}
       
   575 	
       
   576 TVerdict CTInitCenRep::doTestStepPostambleL()
       
   577 /**
       
   578   @return - TVerdict code
       
   579   Override of base class virtual
       
   580  */
       
   581 	{
       
   582  	//Call the parent postamble, releasing the file handle, etc
       
   583  	CTStepActSch::doTestStepPostambleL();
       
   584 	return TestStepResult();
       
   585 	}
       
   586 
       
   587 //====================================================================================================
       
   588 
       
   589 CTSysTimeUpdate::CTSysTimeUpdate(CTAuthSvrServer& aParent): iParent(aParent)
       
   590 /**
       
   591   Constructor
       
   592  */
       
   593 	{
       
   594 	// Call base class method to set up the human readable name for logging
       
   595 	SetTestStepName(KTUpdateSysTime);
       
   596 	}
       
   597 
       
   598 
       
   599 CTSysTimeUpdate::~CTSysTimeUpdate()
       
   600 /**
       
   601   Destructor
       
   602  */
       
   603 	{}
       
   604 	
       
   605 TVerdict CTSysTimeUpdate::doTestStepPreambleL()
       
   606 /**
       
   607   @return - TVerdict code
       
   608   Override of base class virtual
       
   609  */
       
   610 	{
       
   611 	//Call the parent class preamble, setting up the file server, etc
       
   612 	CTStepActSch::doTestStepPreambleL();
       
   613 
       
   614 	return TestStepResult();
       
   615 	}
       
   616 
       
   617 TVerdict CTSysTimeUpdate::doTestStepL()
       
   618 /**
       
   619   @return - TVerdict code
       
   620   Override of base class pure virtual
       
   621   
       
   622  */
       
   623 	{	
       
   624 	SetTestStepResult(EFail);
       
   625 
       
   626 __UHEAP_MARK;		// Check for memory leaks
       
   627 	
       
   628 	//Get the "time" which must be added to the system time.
       
   629 	TInt timeVal(0);
       
   630 	GetIntFromConfig(ConfigSection(), _L("time"), timeVal);
       
   631 
       
   632 	TTime currentTime;
       
   633 	currentTime.UniversalTime();
       
   634 	
       
   635 	if(timeVal == 0 )
       
   636 		{
       
   637 		//Set the secure clock time.
       
   638 		RTestUtilSession session;
       
   639 		session.Connect();
       
   640 		CleanupClosePushL(session);
       
   641 		TInt ret = session.SetSecureClock(0);
       
   642 		INFO_PRINTF2(_L("Set the secure clock --- %d"), ret);
       
   643 		CleanupStack::PopAndDestroy(&session);
       
   644 		}
       
   645 	else
       
   646 		{
       
   647 		//Increment the time only if secure clock is present
       
   648 		TInt err = currentTime.UniversalTimeSecure();
       
   649 		INFO_PRINTF2(_L("Getting the secure clock time returned %d"), err );
       
   650 		if(!err)
       
   651 			{
       
   652 			INFO_PRINTF1(_L("Secure clock found !"));
       
   653 			TTimeIntervalSeconds increment(timeVal);
       
   654 			currentTime += increment;
       
   655 			User::LeaveIfError(User::SetUTCTime(currentTime));
       
   656 			}
       
   657 		else
       
   658 			{
       
   659 			INFO_PRINTF1(_L("Secure clock not found !"));
       
   660 			}
       
   661 	
       
   662 		}
       
   663 
       
   664 
       
   665 	SetTestStepResult(EPass);
       
   666 
       
   667 __UHEAP_MARKEND;
       
   668 	return TestStepResult();
       
   669 	}
       
   670 
       
   671 
       
   672 TVerdict CTSysTimeUpdate::doTestStepPostambleL()
       
   673 /**
       
   674   @return - TVerdict code
       
   675   Override of base class virtual
       
   676  */
       
   677 	{
       
   678 	//Call the parent postamble, releasing the file handle, etc
       
   679 	CTStepActSch::doTestStepPostambleL();
       
   680 	return TestStepResult();
       
   681 	}