os/security/authorisation/userpromptservice/test/tups/src/tupsclientstep.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2007-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 
    20 #include "tupsclientstep.h"  
    21 #include "tupsintegdefs.h"
    22 #include "tupsproperty.h"
    23 #include <e32property.h>
    24 
    25 
    26 TServiceRequestParameters::TServiceRequestParameters() 
    27 	:iServiceUID(0), iServerName(0),iDestination(0), iExpectedError(0),
    28 	 iOpaqueData(0), iSelectDialogOption(0), iButtonsDisplayed(0),
    29 	 iDialogCreatorInvoked(0), iPolicyEvaluatorInvoked(0), iAccessGranted(0),
    30 	 iCloseSession(EFalse), iHoldEvaluatorOpen(EFalse), iHoldPrepareDialogOpen(EFalse), iHoldDisplayDialogOpen(EFalse),
    31 	 iRequestDurationThreshold(0), iLeaveDialog(EFalse), iLeaveEvaluator(EFalse), iCancelUpsRequest(EFalse),
    32 	 iPlatSecPass(EFalse),iForcePrompt(EFalse),iExpectedEvaluatorInfo(0),iSelectFingerprint(0),
    33 	 iWaitUntilFileAppears(0)	 	 	 	 
    34 	{	
    35 	};   
    36 
    37 COpenSession* COpenSession::NewL(const TPtrC& aServerName)
    38 	{
    39 	COpenSession * self = new (ELeave) COpenSession(); 
    40 	CleanupStack::PushL(self);
    41 	self->ConstructL(aServerName);
    42 	CleanupStack::Pop(self);
    43 	return(self);
    44 	} // End of function
    45 	
    46 void COpenSession::ConstructL(const TPtrC& aServerName)
    47 	{
    48 	iServerName = aServerName;
    49 	iPointerToServer = new RUpsTestServ;
    50 	User::LeaveIfError(iPointerToServer->Connect(iServerName, ETrue));
    51     iPointerToSession = new RUpsTestSession;
    52 	User::LeaveIfError(iPointerToSession->Open(*iPointerToServer));
    53 	} // End of function
    54 	
    55 COpenSession::~COpenSession() 
    56 	{	
    57 	if (iPointerToSession)
    58 		iPointerToSession->Close();
    59 	if (iPointerToServer)
    60 		iPointerToServer->Close();
    61 	delete iPointerToSession;
    62     delete iPointerToServer;
    63     }  // End of function
    64 
    65 CUpsClientStep::~CUpsClientStep()
    66 /**
    67  * Destructor
    68  */
    69 	{
    70 	iArraySersToRequest.Close();   
    71   
    72 	CloseAllOpenSessions();
    73 	delete iPropertyReader;
    74   	__UHEAP_MARKEND;
    75 	} // End of function
    76 
    77 
    78 CUpsClientStep::CUpsClientStep()
    79 /**
    80  * Constructor
    81  */
    82 	{
    83 	SetTestStepName(KUPSClientStep);
    84 	} // End of function
    85 
    86 
    87 TVerdict CUpsClientStep::doTestStepPreambleL()
    88 /**
    89  * @return - TVerdict code
    90  * Override of base class virtual
    91  */
    92 	{
    93 	
    94  	__UHEAP_MARK;
    95  	
    96 	// Read values to config servers from INI file. (ARRAY of values)
    97  	
    98     // Read how many times the test step needs to be repeated.
    99     TName fStepRepeat(_L("StepRepeat"));
   100     TInt  repeats;
   101     
   102     if(GetIntFromConfig(ConfigSection(),fStepRepeat,repeats))
   103 	    {
   104 	   	iStepRepeat=repeats;
   105 	    }
   106 	else
   107 		{
   108 		iStepRepeat=1;		
   109 		}
   110     
   111     // Read values for test sequence from INI file. (ARRAY of values)
   112 	TInt index=0;
   113 	TName fUseServiceUID;
   114 	fUseServiceUID.Format(_L("UseServiceUID_%d"),index);
   115 	TName fUseServerName;
   116 	fUseServerName.Format(_L("UseServerName_%d"),index);
   117 	TName fDestination;
   118 	fDestination.Format(_L("Destination_%d"),index);
   119 	TName fExpectedError;
   120 	fExpectedError.Format(_L("ExpectedError_%d"),index);
   121 	TName fUseOpaqueData;
   122 	fUseOpaqueData.Format(_L("UseOpaqueData_%d"),index);
   123 	TName fSelectDialogOption;
   124 	fSelectDialogOption.Format(_L("SelectDialogOption_%d"),index); 
   125 	TName fButtonsDisplayed;
   126 	fButtonsDisplayed.Format(_L("ButtonsDisplayed_%d"),index);
   127 	TName fDialogCreatorInvoked;
   128 	fDialogCreatorInvoked.Format(_L("DialogCreatorInvoked_%d"),index);
   129 	TName fPolicyEvaluatorInvoked;
   130 	fPolicyEvaluatorInvoked.Format(_L("PolicyEvaluatorInvoked_%d"),index);
   131 	TName fAccessGranted;
   132 	fAccessGranted.Format(_L("AccessGranted_%d"), index);
   133 	TName fCloseSession;
   134 	fCloseSession.Format(_L("CloseSession_%d"), index);
   135 	TName fHoldEvaluatorOpen;
   136 	fHoldEvaluatorOpen.Format(_L("HoldEvaluatorOpen_%d"), index);
   137 	TName fHoldPrepareDialogOpen;
   138 	fHoldPrepareDialogOpen.Format(_L("HoldPrepareDialogOpen_%d"), index);
   139 	TName fHoldDisplayDialogOpen;
   140 	fHoldDisplayDialogOpen.Format(_L("HoldDisplayDialogOpen_%d"), index);
   141 	TName fRequestDurationThreshold;
   142 	fRequestDurationThreshold.Format(_L("RequestDurationThreshold_%d"), index);
   143 	TName fLeaveDialog;
   144 	fLeaveDialog.Format(_L("LeaveDialog_%d"), index);
   145 	TName fLeaveEvaluator;
   146 	fLeaveEvaluator.Format(_L("LeaveEvaluator_%d"), index);
   147 	TName fCancelUpsRequest;
   148 	fCancelUpsRequest.Format(_L("CancelUpsRequest_%d"), index);
   149 	TName fPlatSecPass;
   150 	fPlatSecPass.Format(_L("PlatSecPass_%d"), index);
   151 	TName fForcePrompt;
   152 	fForcePrompt.Format(_L("ForcePrompt_%d"), index);
   153 	TName fExpectedEvaInfo;
   154 	fExpectedEvaInfo.Format(_L("ExpectedEvaluatorInfo_%d"), index);
   155 	TName fSelectFingerprint;
   156 	fSelectFingerprint.Format(_L("SelectFingerprint_%d"), index);
   157 	TName fWaitUntilFileAppears;
   158 	fWaitUntilFileAppears.Format(_L("WaitUntilFileAppears_%d"), index);
   159 	
   160 	TInt	useServiceUID;
   161 	TPtrC   useServerName;
   162 	TPtrC   destination;
   163 	TInt	expectedError;
   164 	TPtrC   useOpaqueData;
   165     TPtrC	selectDialogOption;
   166 	TInt	buttonsDisplayed;
   167 	TInt    dialogCreatorInvoked;
   168 	TInt	policyEvaluatorInvoked;
   169 	TPtrC	accessGranted;
   170 	TBool	closeSession;
   171 	TBool   holdEvaluatorOpen;
   172 	TBool   holdPrepareDialogOpen;
   173 	TBool   holdDisplayDialogOpen;
   174 	TInt 	requestDurationThreshold;
   175 	TBool   leaveDialog;
   176 	TBool   leaveEvaluator;
   177 	TBool   cancelUpsRequest;
   178 	TBool   platSecPass;
   179 	TBool   forcePrompt;
   180 	TInt    expectedEvaInfo;
   181 	TInt	selectFingerprint;
   182 	TPtrC   waitUntilFileAppears;	
   183 	
   184 	while (GetHexFromConfig(ConfigSection(), fUseServiceUID,useServiceUID)
   185 		&& GetStringFromConfig(ConfigSection(),fUseServerName,useServerName)
   186 		&& GetStringFromConfig(ConfigSection(),fDestination,destination)
   187 	  	&& GetStringFromConfig(ConfigSection(),fAccessGranted,accessGranted))
   188 		{
   189 	    TServiceRequestParameters newSerReq;
   190 	    newSerReq.iServiceUID = useServiceUID; 
   191 	    newSerReq.iServerName = useServerName;
   192 	    newSerReq.iDestination = destination;
   193 	    newSerReq.iAccessGranted = accessGranted;
   194 	    
   195         // Close session is optional.
   196         if(GetBoolFromConfig(ConfigSection(),fCloseSession,closeSession))
   197 	    	{
   198 	    	newSerReq.iCloseSession = closeSession;
   199 	    	}
   200 	    
   201 	    // use of dialog creator is optional.
   202 	    if(GetStringFromConfig(ConfigSection(),fSelectDialogOption,selectDialogOption)
   203 		&& GetIntFromConfig(ConfigSection(),fButtonsDisplayed,buttonsDisplayed)
   204 		&& GetIntFromConfig(ConfigSection(),fDialogCreatorInvoked,dialogCreatorInvoked))
   205 	    	{
   206 		    newSerReq.iSelectDialogOption = selectDialogOption;
   207 		    newSerReq.iButtonsDisplayed	= buttonsDisplayed;
   208 		    newSerReq.iDialogCreatorInvoked	= dialogCreatorInvoked;
   209 	    	} 
   210 	    
   211 	    // use of policy evaluator is optional.
   212 	    if(GetIntFromConfig(ConfigSection(),fPolicyEvaluatorInvoked,policyEvaluatorInvoked))
   213 	    	{
   214 	       	newSerReq.iPolicyEvaluatorInvoked = policyEvaluatorInvoked;
   215 	    	}
   216 	    	    
   217 	    // Opaque data is optional
   218 	    if(GetStringFromConfig(ConfigSection(),fUseOpaqueData,useOpaqueData))
   219 	    	{
   220 	       	HBufC8* converter = HBufC8::NewLC(useOpaqueData.Length());
   221 			converter->Des().Copy(useOpaqueData);	
   222              
   223 	       	newSerReq.iOpaqueData = converter->Ptr() ;	
   224 	       	CleanupStack::PopAndDestroy(); //converter 
   225 	    	}
   226 	    
   227 	    // Expected error is optional.
   228 	    if(GetIntFromConfig(ConfigSection(),fExpectedError,expectedError))
   229 	    	{
   230 			newSerReq.iExpectedError = expectedError;
   231 	    	}
   232 	    	
   233 	    // hold policy evaluator open is optional.
   234 	    if(GetBoolFromConfig(ConfigSection(),fHoldEvaluatorOpen, holdEvaluatorOpen))
   235 	    	{
   236 			newSerReq.iHoldEvaluatorOpen =	holdEvaluatorOpen;
   237 	    	}
   238 	    
   239 	    // hold prepare dialog open is optional.
   240 	    if(GetBoolFromConfig(ConfigSection(),fHoldPrepareDialogOpen, holdPrepareDialogOpen))
   241 	    	{
   242 			newSerReq.iHoldPrepareDialogOpen =	holdPrepareDialogOpen;
   243 	    	}
   244 	    	
   245 	    // hold display dialog open is optional.
   246 	    if(GetBoolFromConfig(ConfigSection(),fHoldDisplayDialogOpen, holdDisplayDialogOpen))
   247 	    	{
   248 			newSerReq.iHoldDisplayDialogOpen =	holdDisplayDialogOpen;
   249 	    	}
   250 	    
   251 	    // request duration threshold - if a request takes 
   252 	    // longer than this threshold it will fail the test
   253 	    if(GetIntFromConfig(ConfigSection(),fRequestDurationThreshold, requestDurationThreshold))
   254 	    	{
   255 	       	newSerReq.iRequestDurationThreshold = requestDurationThreshold;
   256 	    	}
   257 
   258 	    // leave dialog is optional.
   259 	    if(GetBoolFromConfig(ConfigSection(),fLeaveDialog,leaveDialog))
   260 	    	{
   261 	    	newSerReq.iLeaveDialog = leaveDialog;
   262 	   		}
   263 	    
   264 	    // leave Evaluator is optional.
   265 	    if(GetBoolFromConfig(ConfigSection(),fLeaveEvaluator,leaveEvaluator))
   266 	    	{
   267 			newSerReq.iLeaveEvaluator = leaveEvaluator;	
   268 	    	}
   269 		       
   270 	    // Cancel ups request is optional.
   271 	    if(GetBoolFromConfig(ConfigSection(),fCancelUpsRequest,cancelUpsRequest))
   272 	    	{
   273 	  		newSerReq.iCancelUpsRequest = cancelUpsRequest;		
   274 	    	}
   275     
   276 	    // plat sec pass is optional.
   277 	    if(GetBoolFromConfig(ConfigSection(),fPlatSecPass,platSecPass))
   278 	    	{
   279 			newSerReq.iPlatSecPass = platSecPass;
   280 	    	}
   281 	    
   282 	    // Force prompt is optional.
   283 	    if(GetBoolFromConfig(ConfigSection(),fForcePrompt,forcePrompt))
   284 	    	{
   285 			newSerReq.iForcePrompt = forcePrompt;
   286 	    	}
   287 	    
   288 	    // use of policy evaluator is optional.
   289 	    if(GetIntFromConfig(ConfigSection(),fExpectedEvaInfo,expectedEvaInfo))
   290 	    	{
   291 	       	newSerReq.iExpectedEvaluatorInfo = expectedEvaInfo;
   292 	    	}
   293 	    
   294 	    // Fingerprint selection is optional.
   295 	    if(GetIntFromConfig(ConfigSection(),fSelectFingerprint,selectFingerprint))
   296 	    	{
   297 	       	newSerReq.iSelectFingerprint = selectFingerprint;
   298 	    	}
   299 	    
   300 	    // iRepeatUntilFileAppears is optional.
   301 	    if(GetStringFromConfig(ConfigSection(),fWaitUntilFileAppears,waitUntilFileAppears))
   302 	    	{
   303 	    	newSerReq.iWaitUntilFileAppears = waitUntilFileAppears;
   304 	    	}
   305 	    
   306 	    // Add the new service to be requested to array.
   307 	    iArraySersToRequest.Append(newSerReq);
   308 	       
   309 	    index++;
   310 	    fUseServiceUID.Format(_L("UseServiceUID_%d"),index);
   311 	    fUseServerName.Format(_L("UseServerName_%d"),index);
   312 	    fDestination.Format(_L("Destination_%d"),index);
   313 	    fExpectedError.Format(_L("ExpectedError_%d"),index);
   314 	    fUseOpaqueData.Format(_L("UseOpaqueData_%d"),index);
   315 	    fSelectDialogOption.Format(_L("SelectDialogOption_%d"),index);
   316 	    fButtonsDisplayed.Format(_L("ButtonsDisplayed_%d"),index);
   317 	    fDialogCreatorInvoked.Format(_L("DialogCreatorInvoked_%d"),index); 
   318 	    fPolicyEvaluatorInvoked.Format(_L("PolicyEvaluatorInvoked_%d"),index);
   319 	    fAccessGranted.Format(_L("AccessGranted_%d"), index);  
   320 	    fCloseSession.Format(_L("CloseSession_%d"), index);
   321 	    fHoldEvaluatorOpen.Format(_L("HoldEvaluatorOpen_%d"), index);
   322 	    fHoldPrepareDialogOpen.Format(_L("HoldPrepareDialogOpen_%d"), index);
   323 	    fHoldDisplayDialogOpen.Format(_L("HoldDisplayDialogOpen_%d"), index);
   324 		fRequestDurationThreshold.Format(_L("RequestDurationThreshold_%d"), index);
   325 	    fLeaveDialog.Format(_L("LeaveDialog_%d"), index);
   326 	    fLeaveEvaluator.Format(_L("LeaveEvaluator_%d"), index);
   327 	    fCancelUpsRequest.Format(_L("CancelUpsRequest_%d"), index);
   328 	    fPlatSecPass.Format(_L("PlatSecPass_%d"), index);
   329 	    fForcePrompt.Format(_L("ForcePrompt_%d"), index);
   330 	   	fExpectedEvaInfo.Format(_L("ExpectedEvaluatorInfo_%d"), index);
   331 	   	fSelectFingerprint.Format(_L("SelectFingerprint_%d"), index);
   332 	   	fWaitUntilFileAppears.Format(_L("WaitUntilFileAppears_%d"), index);
   333 	   	}	
   334 
   335 	// now try for some clientStep specific stuff
   336 	// this ini file entry specifies the property key value for the hold flag
   337 	// If the hold flag property is true then monitor it until it becomes false
   338 	// then continue
   339 	TInt holdKey;
   340     if(GetIntFromConfig(ConfigSection(),_L("HoldClientStepKey"), holdKey))
   341 	    {
   342 		iHoldClientStepKey = holdKey;
   343 
   344 		// as this property is present then set it to true using a direct call to p&s api because
   345 		// the ups p&s api only handles policy evaluators and dialog creators and not test steps
   346 		User::LeaveIfError(RProperty::Set(KPropertyCreatorUid, iHoldClientStepKey, 2));
   347 	    }
   348 
   349 	// Instantiates property reader and seter
   350 	iPropertyReader= CUpsProperty::NewL(KPropertyCreatorUid); 
   351 
   352 	// reads client name and SID
   353 	TParse clientFullName;
   354 	RThread client;
   355 	clientFullName.Set(client.FullName(),NULL, NULL);
   356 	iTEFServerName=clientFullName.Name();
   357 	iExpectedClientSid = client.SecureId() ;
   358 	client.Close();
   359 			
   360 	SetTestStepResult(EPass);
   361 	return TestStepResult();
   362 	}
   363 
   364 
   365 TVerdict CUpsClientStep::doTestStepL()
   366 	{
   367 	// loop to request for different test services.
   368 	TVerdict testResult= EPass;
   369 	TInt numServicesToRequest = iArraySersToRequest.Count();
   370 
   371 	if(numServicesToRequest > 0) 
   372 		{
   373 		// check if the test step needs to hold until another step allows it to continue
   374 		if (iHoldClientStepKey)
   375 			{
   376 			HoldClientL();
   377 			}
   378 
   379 		// repeats the sequence of test services request as many times as specified in iStepRepeat
   380 		for(TInt repeatTimes = 0;repeatTimes<iStepRepeat;++repeatTimes)
   381 			{
   382 			INFO_PRINTF3(_L("%S: Repeat number: %d"),&iTEFServerName,repeatTimes);
   383 		
   384 			for(TInt index=0;index < numServicesToRequest; ++index )
   385 				{
   386 				INFO_PRINTF6(_L("%S: Service request: %d. SysServer: %S Destination: %S  ServiceUID: %X "),&iTEFServerName, index, &iArraySersToRequest[index].iServerName ,&iArraySersToRequest[index].iDestination, iArraySersToRequest[index].iServiceUID);
   387 				RUpsTestSession * sessionToBeUsed; 
   388 
   389 				sessionToBeUsed = GetSessionToServerL(iArraySersToRequest[index].iServerName);			    
   390 
   391 				SetTestDataL(index);
   392 				
   393 				sessionToBeUsed->UseTestService(iRequestData,iReturnData); 
   394 
   395 				iServerId=sessionToBeUsed->GetServerSid();
   396 				// Check results.
   397 				if(CheckResultsL(index) == EFalse)
   398 					{
   399 					ERR_PRINTF2(_L("%S: Incorrect results"),&iTEFServerName);
   400 					User::Leave(KErrGeneral);
   401 					}
   402 
   403 				// Checks from config value if session need to be closed.
   404 				if(iArraySersToRequest[index].iCloseSession)
   405 					{
   406 					INFO_PRINTF3(_L("%S :Closing session to server: %S"),&iTEFServerName, &iArraySersToRequest[index].iServerName );    
   407 					CloseSessionL(iArraySersToRequest[index].iServerName);
   408 					}   
   409 				}  // End of second loop
   410 			}// End of first loop
   411 		
   412 		// Sets the status of the first instance of policy evaluator and dialog creator to
   413 		// completed so that the coordinator step can progress in concurrent mode 	
   414 		SetClientStatusCompleteL();
   415 		}
   416 	else
   417 		{
   418 		testResult= EFail;
   419 		ERR_PRINTF2(_L("%S :Problem reading ini file"),&iTEFServerName);
   420 		User::Leave(KErrGeneral);	
   421 		}  
   422 		
   423 	return testResult;	
   424 	}  // End of function
   425 
   426 
   427 TVerdict CUpsClientStep::doTestStepPostambleL()
   428 	{
   429 	return TestStepResult();
   430 	}
   431 
   432 
   433 void CUpsClientStep::HoldClientL(void)
   434 	{
   435 	RProperty checkIfStillNeedtoHold;
   436 	User::LeaveIfError(checkIfStillNeedtoHold.Attach(KPropertyCreatorUid, iHoldClientStepKey));
   437 	CleanupClosePushL(checkIfStillNeedtoHold);
   438 	checkIfStillNeedtoHold.Set(KPropertyCreatorUid, iHoldClientStepKey, 1);
   439     TRequestStatus holdStatus;
   440  	checkIfStillNeedtoHold.Subscribe(holdStatus);
   441  	
   442 	TInt holdState;
   443 
   444 	checkIfStillNeedtoHold.Get(KPropertyCreatorUid, iHoldClientStepKey, holdState);
   445 	if(!holdState)
   446  		{
   447  		checkIfStillNeedtoHold.Cancel();
   448  		}
   449  	else
   450  		{
   451  		User::WaitForRequest(holdStatus);
   452  		}
   453 
   454 	RDebug::Printf("[UPS ClientStep 0x%x] HoldClient() stopped holding\n", this);
   455 	
   456 	// set the hold state back to 1 for future holds
   457 	checkIfStillNeedtoHold.Set(KPropertyCreatorUid, iHoldClientStepKey, 2);
   458 	CleanupStack::PopAndDestroy(&checkIfStillNeedtoHold);
   459 	}
   460 
   461 
   462 TBool CUpsClientStep::FindOpenSession(const TDesC& aServerName,TInt &position)
   463 	{
   464 	TBool sessionFound = EFalse;
   465 	TInt sessionsCount = iArraySessionsInUse.Count();
   466 	for(TInt index = 0;index < sessionsCount; ++index)
   467 		{
   468 		if(!aServerName.CompareF(iArraySessionsInUse[index]->iServerName))
   469 			{
   470 			position = index;
   471 			sessionFound = ETrue;
   472 			break;
   473 			}
   474 		} 
   475 	return sessionFound;
   476 	} // End of function
   477 
   478 
   479 RUpsTestSession* CUpsClientStep::GetSessionToServerL(const TDesC& aServerName) 
   480 	{
   481 	// Finds out if a session is already open for server requested
   482 	TInt foundPos;
   483 	RUpsTestSession* sessionToReturn;
   484 	if(!FindOpenSession(aServerName,foundPos))
   485 		{
   486 		// if open session for intended server not found it creates a new one
   487 		COpenSession* sessionToAppend=COpenSession::NewL(aServerName);
   488 		iArraySessionsInUse.AppendL(sessionToAppend);		
   489 		foundPos = iArraySessionsInUse.Count()-1; // position of new session is last one in array. 
   490 		}
   491 	sessionToReturn = iArraySessionsInUse[foundPos]->iPointerToSession;
   492 	
   493 	return sessionToReturn;
   494 	} // End of function
   495 	
   496 	
   497 void CUpsClientStep::CloseSessionL(const TDesC& aServerName) 
   498 	{
   499 	// Finds out if a session is already open for server requested
   500 	TInt foundPos;
   501 	
   502 	if(!FindOpenSession(aServerName,foundPos))
   503 		{
   504 		// if a session for this server was not found it leaves.
   505 		ERR_PRINTF2(_L("%S: The server to be closed was not found"),&iTEFServerName);
   506 		User::Leave(KErrGeneral); 
   507 		}
   508 	delete iArraySessionsInUse[foundPos];  // deletes instance.
   509 	iArraySessionsInUse.Remove(foundPos);  // removes empty slot
   510 
   511 	} // End of function
   512 
   513 
   514 void CUpsClientStep::CloseAllOpenSessions()
   515 	{
   516 	while(iArraySessionsInUse.Count()>0)
   517 		{   // delete and remove first session of array.
   518 		delete iArraySessionsInUse[0];
   519 	    iArraySessionsInUse.Remove(0);	
   520 		}
   521 	iArraySessionsInUse.Close();
   522 	} // End of function
   523 
   524 
   525 void CUpsClientStep::SetTestDataL(TInt aIndex)
   526 	{
   527 	// Set data for request.
   528 	iReturnData.iError=KErrNone;
   529 	iServerId=0;
   530 	iRequestData.iMeasureResponceTime = EFalse;
   531 	iRequestData.iServiceUid = TUid::Uid(iArraySersToRequest[aIndex].iServiceUID);
   532 
   533 	if(iArraySersToRequest[aIndex].iOpaqueData.CompareF(_L8(""))==0)
   534 		{
   535 		iRequestData.iOpaquePresent = EFalse;
   536 		}
   537 	else
   538 		{
   539 		iRequestData.iOpaquePresent = ETrue;
   540 		iRequestData.iOpaqueData =iArraySersToRequest[aIndex].iOpaqueData;	
   541 		}
   542 		
   543 	iRequestData.iDestination = iArraySersToRequest[aIndex].iDestination;
   544 	iRequestData.iCancelRequest = iArraySersToRequest[aIndex].iCancelUpsRequest;
   545 	iRequestData.iPlatSecPass = iArraySersToRequest[aIndex].iPlatSecPass;
   546 	
   547 	// set properties for policy evaluator.
   548 	if (iArraySersToRequest[aIndex].iPolicyEvaluatorInvoked != 0)
   549 		{
   550 		//Reset various publisher and suscribe properties for policy evaluator.
   551 		TInt instance = iArraySersToRequest[aIndex].iPolicyEvaluatorInvoked;
   552 	  	iPropertyReader->SetL(instance,KPe_Status,CUpsProperty::EPolicyEvaluator, KUpsPeStatusReset);
   553 	  	iPropertyReader->SetL(instance,KPe_ClientSid,CUpsProperty::EPolicyEvaluator, 0);
   554 	  	iPropertyReader->SetL(instance,KPe_ServerSid,CUpsProperty::EPolicyEvaluator, 0);
   555 	  	TBool leaveEvaluator = iArraySersToRequest[aIndex].iLeaveEvaluator; 
   556 	  	iPropertyReader->SetL(instance,KPe_Leave,CUpsProperty::EPolicyEvaluator, leaveEvaluator);
   557 	  	iPropertyReader->SetL(instance,KPe_Error,CUpsProperty::EPolicyEvaluator, KErrNone);
   558 	  	TBool holdEvaluatorOpen = iArraySersToRequest[aIndex].iHoldEvaluatorOpen;
   559 	  	iPropertyReader->SetL(instance,KPe_HoldEvaluatorOpen,CUpsProperty::EPolicyEvaluator, holdEvaluatorOpen);
   560 	  	TBool forcePrompt = iArraySersToRequest[aIndex].iForcePrompt; 
   561 	  	iPropertyReader->SetL(instance,KPe_ForcePrompt,CUpsProperty::EPolicyEvaluator, forcePrompt);
   562 	  	iPropertyReader->SetL(instance,KPe_EvaluatorInfo,CUpsProperty::EPolicyEvaluator, 0);
   563 		}
   564 		
   565 	// set properties for dialog creator.
   566 	if (iArraySersToRequest[aIndex].iDialogCreatorInvoked != 0)
   567 		{
   568 		//Reset various publisher and suscribe properties for dialog creator.
   569 		TInt instance = iArraySersToRequest[aIndex].iDialogCreatorInvoked;
   570 	  	iPropertyReader->SetL(instance,KDc_Status,CUpsProperty::EDialogCreator, KUpsDcStatusReset);
   571 	  	iPropertyReader->SetL(instance,KDc_ClientSid,CUpsProperty::EDialogCreator, 0);
   572 	  	iPropertyReader->SetL(instance,KDc_ServerSid,CUpsProperty::EDialogCreator, 0);
   573 	  	TBool dialogLeave = iArraySersToRequest[aIndex].iLeaveDialog ;
   574 	  	iPropertyReader->SetL(instance,KDc_Leave,CUpsProperty::EDialogCreator, dialogLeave);
   575 	  	iPropertyReader->SetL(instance,KDc_Error,CUpsProperty::EDialogCreator, KErrNone);
   576 	  	iPropertyReader->SetL(instance,KDc_UpsRequestedButtons,CUpsProperty::EDialogCreator, 0);
   577 	    TInt buttonToPress = ButtonToInt(iArraySersToRequest[aIndex].iSelectDialogOption);
   578 	  	iPropertyReader->SetL(instance,KDc_WhichButtonToPress,CUpsProperty::EDialogCreator, buttonToPress);
   579 	  	TBool holdPrepareDialogOpen = iArraySersToRequest[aIndex].iHoldPrepareDialogOpen;
   580 	  	iPropertyReader->SetL(instance,KDc_HoldPrepareDialogOpen,CUpsProperty::EDialogCreator, holdPrepareDialogOpen);
   581 	  	TBool holdDisplayDialogOpen = iArraySersToRequest[aIndex].iHoldDisplayDialogOpen;
   582 	  	iPropertyReader->SetL(instance,KDc_HoldDisplayDialogOpen,CUpsProperty::EDialogCreator, holdDisplayDialogOpen);
   583 	  	TBool selectFingerprint = iArraySersToRequest[aIndex].iSelectFingerprint ;
   584 	  	iPropertyReader->SetL(instance,KDc_SelectFingerprint,CUpsProperty::EDialogCreator, selectFingerprint);
   585 		}
   586 
   587 	}  // End of function.
   588 
   589 
   590 void CUpsClientStep::SetClientStatusCompleteL()
   591 /**
   592  * Sets the status of the first policy evaluator invoked by the client to "KUpsClientCompleted" so that
   593  * the coordinator step can determine when the step has completely finish and progress in Concurrent mode
   594  *
   595  * NOTE: When using the Coordinator in this manner, ALL requests made to UPS must invoke the same instance
   596  * of the Policy Evaluator and Dialog Creator! e.g. Policy Evalutor 1 and Dialog Creator 1
   597  */	
   598  	{
   599 	TInt requestCount = iArraySersToRequest.Count();
   600 		
   601 	for(TInt i=0; i<requestCount; ++i)
   602 		{
   603 		if (iArraySersToRequest[i].iPolicyEvaluatorInvoked != 0)
   604 			{	 
   605 			TInt instance = iArraySersToRequest[i].iPolicyEvaluatorInvoked;
   606 			iPropertyReader->SetL(instance,KPe_Status,CUpsProperty::EPolicyEvaluator, KUpsClientCompleted);
   607 			iPropertyReader->SetL(instance,KDc_Status,CUpsProperty::EDialogCreator, KUpsClientCompleted);
   608 			break;
   609 			}	
   610 		}
   611 	}
   612 	
   613 	
   614 TUpsDecision CUpsClientStep::StringToTUpsDecision(const TPtrC& aString)
   615 	{
   616 	if(aString.CompareF(_L("Yes"))==0)
   617 		{
   618 		return TUpsDecision(EUpsDecYes);
   619 		}
   620 	else if(aString.CompareF(_L("No"))==0)
   621 		{
   622 		return TUpsDecision(EUpsDecNo);
   623 		}
   624 	else if(aString.CompareF(_L("SessionYes"))==0)
   625 		{
   626 		return TUpsDecision(EUpsDecSessionYes);
   627 		}
   628 	else
   629 		{
   630 		return TUpsDecision(EUpsDecSessionNo);
   631 		}	
   632 	} // End of function.
   633 
   634 
   635 TPtrC	CUpsClientStep::TUpsDecisionToString(TUpsDecision aDecision)
   636 	{
   637 	if(aDecision == EUpsDecYes)
   638 		{
   639 		return _L("Yes");
   640 		}
   641 	else if(aDecision == EUpsDecNo)
   642 		{
   643 		return _L("No");
   644 		}
   645 	else if(aDecision == EUpsDecSessionYes)
   646 		{
   647 		return _L("SessionYes");
   648 		}
   649 	else if(aDecision == EUpsDecSessionNo)
   650 		{
   651 		return _L("SessionNo");
   652 		}
   653 	else 
   654 		{
   655 		return _L("Undefined");
   656 		}
   657 	} // End of function.
   658 
   659 
   660 TInt CUpsClientStep::ButtonToInt(const TPtrC& aButton)
   661 	{
   662 	if(aButton.CompareF(_L("Yes"))==0)
   663 		{
   664 		return KYes;
   665 		}
   666 	else if(aButton.CompareF(_L("No"))==0)
   667 		{
   668 		return KNo;
   669 		}
   670 	else if(aButton.CompareF(_L("Always"))==0)
   671 		{
   672 		return KAlways;
   673 		}
   674 	else if(aButton.CompareF(_L("SessionYes"))==0)
   675 		{
   676 		return KSessionYes;
   677 		}
   678 	else if(aButton.CompareF(_L("SessionNo"))==0)
   679 		{
   680 		return KSessionNo;
   681 		}
   682 	else if(aButton.CompareF(_L("Never"))==0)
   683 		{
   684 		return KNever;
   685 		}
   686 	else return KNone;
   687 				
   688 	}  // End of function.
   689 
   690 
   691 TBool CUpsClientStep::CheckResultsL(TInt aIndex)
   692 	{
   693 	TBool theReturn = ETrue; 
   694 	
   695 	if(iArraySersToRequest[aIndex].iExpectedError == KErrNone)   
   696 		{
   697 		TUpsDecision expectedDecision = StringToTUpsDecision(iArraySersToRequest[aIndex].iAccessGranted);
   698 		if(expectedDecision != iReturnData.iDecision)
   699 	 		{
   700 	 		TPtrC decisionReceived(TUpsDecisionToString(iReturnData.iDecision));
   701 	 		ERR_PRINTF4(_L("%S: Decision expected: %S ,Decision received: %S"),&iTEFServerName, &iArraySersToRequest[aIndex].iAccessGranted, &decisionReceived);  
   702 	 		theReturn=EFalse;	
   703 	 		}		
   704 		}
   705 
   706  	if(iArraySersToRequest[aIndex].iExpectedError != iReturnData.iError) 
   707  		{
   708  		// Incorrect error code returned.
   709  		theReturn=EFalse;
   710  		ERR_PRINTF3(_L("%S: Error code expected: %d"),&iTEFServerName,iArraySersToRequest[aIndex].iExpectedError);
   711  		ERR_PRINTF3(_L("%S: Error code Received: %d"),&iTEFServerName,iReturnData.iError);
   712  		}
   713  	
   714  	// checks returned properties from dialog creator & policy evaluator.
   715  	if ( CheckDialogCreatorResultsL(aIndex) == EFalse || CheckPolicyEvaluatorResultsL(aIndex) == EFalse)
   716  		{
   717  			theReturn = EFalse;
   718  		}
   719 
   720  	// display the request duration and check against the ini file value, if supplied
   721 	INFO_PRINTF3(_L("%S: UPS decision request duration: %u milliseconds"),&iTEFServerName, iReturnData.iRequestDuration);
   722 	if (iArraySersToRequest[aIndex].iRequestDurationThreshold > 0)
   723 		{
   724 		// check whether the request duration was too long
   725 		if (static_cast<TInt>(iReturnData.iRequestDuration) > iArraySersToRequest[aIndex].iRequestDurationThreshold)
   726 			{
   727 	 		ERR_PRINTF3(_L("%S: UPS decision request took too long: %u"), &iTEFServerName, iArraySersToRequest[aIndex].iRequestDurationThreshold);
   728 	 		theReturn = EFalse;
   729 			}
   730 		}
   731 
   732 	return theReturn;
   733 	}  // End of function.
   734 
   735 
   736 TBool CUpsClientStep::CheckDialogCreatorResultsL(TInt aIndex)
   737 	{
   738 	TBool checkPassed = ETrue;
   739 	
   740 	// checks return properties from dialog creator.
   741  	if (iArraySersToRequest[aIndex].iDialogCreatorInvoked != 0)
   742 		{
   743 		TInt instanceDia = iArraySersToRequest[aIndex].iDialogCreatorInvoked;
   744 		TInt dialogError = 0;
   745 		iPropertyReader->GetL(instanceDia,KDc_Error,CUpsProperty::EDialogCreator, dialogError);
   746 		
   747 		// Checks that any error encountered by dialog creator is transmited by UPS to system server
   748 		if(dialogError != iReturnData.iError && dialogError!=KErrNone)
   749 			{
   750 			ERR_PRINTF3(_L("%S: Dialog creator found an error: %d"),&iTEFServerName,dialogError);
   751 			checkPassed = EFalse; 	
   752 			}
   753 		
   754 		TInt clientSidDia=0;
   755 		iPropertyReader->GetL(instanceDia,KDc_ClientSid,CUpsProperty::EDialogCreator, clientSidDia);
   756 	     
   757 	    if(iExpectedClientSid != clientSidDia)
   758 		    {
   759 		    ERR_PRINTF2(_L("%S: Client SID returned by dialog creator is not what is expected"),&iTEFServerName);
   760 			checkPassed = EFalse;
   761 		    }
   762 	    
   763 	    TInt buttonsDisplayed=0;
   764 		iPropertyReader->GetL(instanceDia,KDc_UpsRequestedButtons,CUpsProperty::EDialogCreator, buttonsDisplayed);
   765 	    TInt32 expectedButtonsDisplayed=iArraySersToRequest[aIndex].iButtonsDisplayed;
   766 	    if(expectedButtonsDisplayed != buttonsDisplayed)
   767 		    {
   768 		   	ERR_PRINTF2(_L("%S: Incorrect buttons displayed."),&iTEFServerName);
   769 		   	ERR_PRINTF3(_L("%S: Buttons displayed expected: %d"),&iTEFServerName,expectedButtonsDisplayed);
   770 		   	ERR_PRINTF3(_L("%S: Buttons displayed received: %d"),&iTEFServerName,buttonsDisplayed);
   771 			checkPassed = EFalse;
   772 		    }
   773 	    
   774 	    TInt serverSidDia=0;
   775 		iPropertyReader->GetL(instanceDia,KDc_ServerSid,CUpsProperty::EDialogCreator, serverSidDia);
   776 	     
   777 	    if(iServerId != serverSidDia)
   778 		    {
   779 		   	ERR_PRINTF2(_L("%S: Server SID returned by dialog creator is not what is expected"),&iTEFServerName);
   780 			checkPassed = EFalse;
   781 		    } 
   782 	    
   783 	    TInt serviceSidDia=0;
   784 		iPropertyReader->GetL(instanceDia,KDc_ServiceId,CUpsProperty::EDialogCreator, serviceSidDia);
   785 		if(serviceSidDia != iArraySersToRequest[aIndex].iServiceUID)
   786 		    {
   787 		   	ERR_PRINTF3(_L("%S: Service ID reported by dialog creator is not what is expected: %d"),&iTEFServerName,serviceSidDia);
   788 			checkPassed = EFalse;
   789 		    }  
   790 		}
   791 	
   792 	return checkPassed;
   793 	}  // End of function.
   794 
   795 
   796 TBool CUpsClientStep::CheckPolicyEvaluatorResultsL(TInt aIndex)
   797 	{
   798 	TBool checkPassed = ETrue;
   799 	
   800 	if (iArraySersToRequest[aIndex].iPolicyEvaluatorInvoked != 0)
   801 		{
   802 		TInt instanceEva = iArraySersToRequest[aIndex].iPolicyEvaluatorInvoked;
   803 		TInt evaluatorError = 0;
   804 		
   805 		// Checks that any error encountered by policy evaluator is transmited by UPS to system server
   806 		iPropertyReader->GetL(instanceEva,KPe_Error,CUpsProperty::EPolicyEvaluator, evaluatorError);
   807 		if(evaluatorError != iReturnData.iError && evaluatorError!=KErrNone)
   808 			{
   809 			ERR_PRINTF3(_L("%S: Policy evaluator found an error: %d"),&iTEFServerName,evaluatorError);
   810 			checkPassed = EFalse; 	
   811 			}
   812 		
   813 		TInt clientSidEva=0;
   814 		iPropertyReader->GetL(instanceEva,KPe_ClientSid,CUpsProperty::EPolicyEvaluator, clientSidEva);
   815 	     
   816 	    if(iExpectedClientSid != clientSidEva)
   817 		    {
   818 		   	ERR_PRINTF2(_L("%S: Client SID returned by policy evaluator is not what is expected"),&iTEFServerName);
   819 			checkPassed = EFalse;
   820 		    }
   821 	    
   822 	    TInt serverSidEva=0;
   823 		iPropertyReader->GetL(instanceEva,KPe_ServerSid,CUpsProperty::EPolicyEvaluator, serverSidEva);
   824 	     
   825 	    if(iServerId != serverSidEva)
   826 		    {
   827 		   	ERR_PRINTF2(_L("%S: Server SID returned by policy evaluator is not what is expected"),&iTEFServerName);
   828 			checkPassed = EFalse;
   829 		    } 
   830 	    
   831 	    TInt serviceSidEva = 0;
   832 		iPropertyReader->GetL(instanceEva,KPe_ServiceId,CUpsProperty::EPolicyEvaluator, serviceSidEva);
   833 		if(serviceSidEva != iArraySersToRequest[aIndex].iServiceUID)
   834 		    {
   835 		   	ERR_PRINTF3(_L("%S: Service ID reported by policy evaluator is not what is expected: %d"),&iTEFServerName,serviceSidEva);
   836 			checkPassed = EFalse;
   837 		    }
   838 	    if( iArraySersToRequest[aIndex].iForcePrompt)
   839 		    {
   840 	    	// Read evaluator info
   841 	    	TInt evaluatorInfo = 0;
   842 			iPropertyReader->GetL(instanceEva,KPe_EvaluatorInfo,CUpsProperty::EPolicyEvaluator, evaluatorInfo);
   843 	    	if(evaluatorInfo != iArraySersToRequest[aIndex].iExpectedEvaluatorInfo)
   844 	    		{
   845 	    		ERR_PRINTF4(_L("%S: incorrect evaluator info:Expected: %d Received: %d"),&iTEFServerName,iArraySersToRequest[aIndex].iExpectedEvaluatorInfo,evaluatorInfo);
   846 	    		checkPassed = EFalse;
   847 	    		}
   848 		    }
   849 		}
   850 		
   851 	return checkPassed;
   852 	}  // End of function.