1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/authorisation/userpromptservice/test/tups/src/tupsclientstep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,852 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +
1.23 +#include "tupsclientstep.h"
1.24 +#include "tupsintegdefs.h"
1.25 +#include "tupsproperty.h"
1.26 +#include <e32property.h>
1.27 +
1.28 +
1.29 +TServiceRequestParameters::TServiceRequestParameters()
1.30 + :iServiceUID(0), iServerName(0),iDestination(0), iExpectedError(0),
1.31 + iOpaqueData(0), iSelectDialogOption(0), iButtonsDisplayed(0),
1.32 + iDialogCreatorInvoked(0), iPolicyEvaluatorInvoked(0), iAccessGranted(0),
1.33 + iCloseSession(EFalse), iHoldEvaluatorOpen(EFalse), iHoldPrepareDialogOpen(EFalse), iHoldDisplayDialogOpen(EFalse),
1.34 + iRequestDurationThreshold(0), iLeaveDialog(EFalse), iLeaveEvaluator(EFalse), iCancelUpsRequest(EFalse),
1.35 + iPlatSecPass(EFalse),iForcePrompt(EFalse),iExpectedEvaluatorInfo(0),iSelectFingerprint(0),
1.36 + iWaitUntilFileAppears(0)
1.37 + {
1.38 + };
1.39 +
1.40 +COpenSession* COpenSession::NewL(const TPtrC& aServerName)
1.41 + {
1.42 + COpenSession * self = new (ELeave) COpenSession();
1.43 + CleanupStack::PushL(self);
1.44 + self->ConstructL(aServerName);
1.45 + CleanupStack::Pop(self);
1.46 + return(self);
1.47 + } // End of function
1.48 +
1.49 +void COpenSession::ConstructL(const TPtrC& aServerName)
1.50 + {
1.51 + iServerName = aServerName;
1.52 + iPointerToServer = new RUpsTestServ;
1.53 + User::LeaveIfError(iPointerToServer->Connect(iServerName, ETrue));
1.54 + iPointerToSession = new RUpsTestSession;
1.55 + User::LeaveIfError(iPointerToSession->Open(*iPointerToServer));
1.56 + } // End of function
1.57 +
1.58 +COpenSession::~COpenSession()
1.59 + {
1.60 + if (iPointerToSession)
1.61 + iPointerToSession->Close();
1.62 + if (iPointerToServer)
1.63 + iPointerToServer->Close();
1.64 + delete iPointerToSession;
1.65 + delete iPointerToServer;
1.66 + } // End of function
1.67 +
1.68 +CUpsClientStep::~CUpsClientStep()
1.69 +/**
1.70 + * Destructor
1.71 + */
1.72 + {
1.73 + iArraySersToRequest.Close();
1.74 +
1.75 + CloseAllOpenSessions();
1.76 + delete iPropertyReader;
1.77 + __UHEAP_MARKEND;
1.78 + } // End of function
1.79 +
1.80 +
1.81 +CUpsClientStep::CUpsClientStep()
1.82 +/**
1.83 + * Constructor
1.84 + */
1.85 + {
1.86 + SetTestStepName(KUPSClientStep);
1.87 + } // End of function
1.88 +
1.89 +
1.90 +TVerdict CUpsClientStep::doTestStepPreambleL()
1.91 +/**
1.92 + * @return - TVerdict code
1.93 + * Override of base class virtual
1.94 + */
1.95 + {
1.96 +
1.97 + __UHEAP_MARK;
1.98 +
1.99 + // Read values to config servers from INI file. (ARRAY of values)
1.100 +
1.101 + // Read how many times the test step needs to be repeated.
1.102 + TName fStepRepeat(_L("StepRepeat"));
1.103 + TInt repeats;
1.104 +
1.105 + if(GetIntFromConfig(ConfigSection(),fStepRepeat,repeats))
1.106 + {
1.107 + iStepRepeat=repeats;
1.108 + }
1.109 + else
1.110 + {
1.111 + iStepRepeat=1;
1.112 + }
1.113 +
1.114 + // Read values for test sequence from INI file. (ARRAY of values)
1.115 + TInt index=0;
1.116 + TName fUseServiceUID;
1.117 + fUseServiceUID.Format(_L("UseServiceUID_%d"),index);
1.118 + TName fUseServerName;
1.119 + fUseServerName.Format(_L("UseServerName_%d"),index);
1.120 + TName fDestination;
1.121 + fDestination.Format(_L("Destination_%d"),index);
1.122 + TName fExpectedError;
1.123 + fExpectedError.Format(_L("ExpectedError_%d"),index);
1.124 + TName fUseOpaqueData;
1.125 + fUseOpaqueData.Format(_L("UseOpaqueData_%d"),index);
1.126 + TName fSelectDialogOption;
1.127 + fSelectDialogOption.Format(_L("SelectDialogOption_%d"),index);
1.128 + TName fButtonsDisplayed;
1.129 + fButtonsDisplayed.Format(_L("ButtonsDisplayed_%d"),index);
1.130 + TName fDialogCreatorInvoked;
1.131 + fDialogCreatorInvoked.Format(_L("DialogCreatorInvoked_%d"),index);
1.132 + TName fPolicyEvaluatorInvoked;
1.133 + fPolicyEvaluatorInvoked.Format(_L("PolicyEvaluatorInvoked_%d"),index);
1.134 + TName fAccessGranted;
1.135 + fAccessGranted.Format(_L("AccessGranted_%d"), index);
1.136 + TName fCloseSession;
1.137 + fCloseSession.Format(_L("CloseSession_%d"), index);
1.138 + TName fHoldEvaluatorOpen;
1.139 + fHoldEvaluatorOpen.Format(_L("HoldEvaluatorOpen_%d"), index);
1.140 + TName fHoldPrepareDialogOpen;
1.141 + fHoldPrepareDialogOpen.Format(_L("HoldPrepareDialogOpen_%d"), index);
1.142 + TName fHoldDisplayDialogOpen;
1.143 + fHoldDisplayDialogOpen.Format(_L("HoldDisplayDialogOpen_%d"), index);
1.144 + TName fRequestDurationThreshold;
1.145 + fRequestDurationThreshold.Format(_L("RequestDurationThreshold_%d"), index);
1.146 + TName fLeaveDialog;
1.147 + fLeaveDialog.Format(_L("LeaveDialog_%d"), index);
1.148 + TName fLeaveEvaluator;
1.149 + fLeaveEvaluator.Format(_L("LeaveEvaluator_%d"), index);
1.150 + TName fCancelUpsRequest;
1.151 + fCancelUpsRequest.Format(_L("CancelUpsRequest_%d"), index);
1.152 + TName fPlatSecPass;
1.153 + fPlatSecPass.Format(_L("PlatSecPass_%d"), index);
1.154 + TName fForcePrompt;
1.155 + fForcePrompt.Format(_L("ForcePrompt_%d"), index);
1.156 + TName fExpectedEvaInfo;
1.157 + fExpectedEvaInfo.Format(_L("ExpectedEvaluatorInfo_%d"), index);
1.158 + TName fSelectFingerprint;
1.159 + fSelectFingerprint.Format(_L("SelectFingerprint_%d"), index);
1.160 + TName fWaitUntilFileAppears;
1.161 + fWaitUntilFileAppears.Format(_L("WaitUntilFileAppears_%d"), index);
1.162 +
1.163 + TInt useServiceUID;
1.164 + TPtrC useServerName;
1.165 + TPtrC destination;
1.166 + TInt expectedError;
1.167 + TPtrC useOpaqueData;
1.168 + TPtrC selectDialogOption;
1.169 + TInt buttonsDisplayed;
1.170 + TInt dialogCreatorInvoked;
1.171 + TInt policyEvaluatorInvoked;
1.172 + TPtrC accessGranted;
1.173 + TBool closeSession;
1.174 + TBool holdEvaluatorOpen;
1.175 + TBool holdPrepareDialogOpen;
1.176 + TBool holdDisplayDialogOpen;
1.177 + TInt requestDurationThreshold;
1.178 + TBool leaveDialog;
1.179 + TBool leaveEvaluator;
1.180 + TBool cancelUpsRequest;
1.181 + TBool platSecPass;
1.182 + TBool forcePrompt;
1.183 + TInt expectedEvaInfo;
1.184 + TInt selectFingerprint;
1.185 + TPtrC waitUntilFileAppears;
1.186 +
1.187 + while (GetHexFromConfig(ConfigSection(), fUseServiceUID,useServiceUID)
1.188 + && GetStringFromConfig(ConfigSection(),fUseServerName,useServerName)
1.189 + && GetStringFromConfig(ConfigSection(),fDestination,destination)
1.190 + && GetStringFromConfig(ConfigSection(),fAccessGranted,accessGranted))
1.191 + {
1.192 + TServiceRequestParameters newSerReq;
1.193 + newSerReq.iServiceUID = useServiceUID;
1.194 + newSerReq.iServerName = useServerName;
1.195 + newSerReq.iDestination = destination;
1.196 + newSerReq.iAccessGranted = accessGranted;
1.197 +
1.198 + // Close session is optional.
1.199 + if(GetBoolFromConfig(ConfigSection(),fCloseSession,closeSession))
1.200 + {
1.201 + newSerReq.iCloseSession = closeSession;
1.202 + }
1.203 +
1.204 + // use of dialog creator is optional.
1.205 + if(GetStringFromConfig(ConfigSection(),fSelectDialogOption,selectDialogOption)
1.206 + && GetIntFromConfig(ConfigSection(),fButtonsDisplayed,buttonsDisplayed)
1.207 + && GetIntFromConfig(ConfigSection(),fDialogCreatorInvoked,dialogCreatorInvoked))
1.208 + {
1.209 + newSerReq.iSelectDialogOption = selectDialogOption;
1.210 + newSerReq.iButtonsDisplayed = buttonsDisplayed;
1.211 + newSerReq.iDialogCreatorInvoked = dialogCreatorInvoked;
1.212 + }
1.213 +
1.214 + // use of policy evaluator is optional.
1.215 + if(GetIntFromConfig(ConfigSection(),fPolicyEvaluatorInvoked,policyEvaluatorInvoked))
1.216 + {
1.217 + newSerReq.iPolicyEvaluatorInvoked = policyEvaluatorInvoked;
1.218 + }
1.219 +
1.220 + // Opaque data is optional
1.221 + if(GetStringFromConfig(ConfigSection(),fUseOpaqueData,useOpaqueData))
1.222 + {
1.223 + HBufC8* converter = HBufC8::NewLC(useOpaqueData.Length());
1.224 + converter->Des().Copy(useOpaqueData);
1.225 +
1.226 + newSerReq.iOpaqueData = converter->Ptr() ;
1.227 + CleanupStack::PopAndDestroy(); //converter
1.228 + }
1.229 +
1.230 + // Expected error is optional.
1.231 + if(GetIntFromConfig(ConfigSection(),fExpectedError,expectedError))
1.232 + {
1.233 + newSerReq.iExpectedError = expectedError;
1.234 + }
1.235 +
1.236 + // hold policy evaluator open is optional.
1.237 + if(GetBoolFromConfig(ConfigSection(),fHoldEvaluatorOpen, holdEvaluatorOpen))
1.238 + {
1.239 + newSerReq.iHoldEvaluatorOpen = holdEvaluatorOpen;
1.240 + }
1.241 +
1.242 + // hold prepare dialog open is optional.
1.243 + if(GetBoolFromConfig(ConfigSection(),fHoldPrepareDialogOpen, holdPrepareDialogOpen))
1.244 + {
1.245 + newSerReq.iHoldPrepareDialogOpen = holdPrepareDialogOpen;
1.246 + }
1.247 +
1.248 + // hold display dialog open is optional.
1.249 + if(GetBoolFromConfig(ConfigSection(),fHoldDisplayDialogOpen, holdDisplayDialogOpen))
1.250 + {
1.251 + newSerReq.iHoldDisplayDialogOpen = holdDisplayDialogOpen;
1.252 + }
1.253 +
1.254 + // request duration threshold - if a request takes
1.255 + // longer than this threshold it will fail the test
1.256 + if(GetIntFromConfig(ConfigSection(),fRequestDurationThreshold, requestDurationThreshold))
1.257 + {
1.258 + newSerReq.iRequestDurationThreshold = requestDurationThreshold;
1.259 + }
1.260 +
1.261 + // leave dialog is optional.
1.262 + if(GetBoolFromConfig(ConfigSection(),fLeaveDialog,leaveDialog))
1.263 + {
1.264 + newSerReq.iLeaveDialog = leaveDialog;
1.265 + }
1.266 +
1.267 + // leave Evaluator is optional.
1.268 + if(GetBoolFromConfig(ConfigSection(),fLeaveEvaluator,leaveEvaluator))
1.269 + {
1.270 + newSerReq.iLeaveEvaluator = leaveEvaluator;
1.271 + }
1.272 +
1.273 + // Cancel ups request is optional.
1.274 + if(GetBoolFromConfig(ConfigSection(),fCancelUpsRequest,cancelUpsRequest))
1.275 + {
1.276 + newSerReq.iCancelUpsRequest = cancelUpsRequest;
1.277 + }
1.278 +
1.279 + // plat sec pass is optional.
1.280 + if(GetBoolFromConfig(ConfigSection(),fPlatSecPass,platSecPass))
1.281 + {
1.282 + newSerReq.iPlatSecPass = platSecPass;
1.283 + }
1.284 +
1.285 + // Force prompt is optional.
1.286 + if(GetBoolFromConfig(ConfigSection(),fForcePrompt,forcePrompt))
1.287 + {
1.288 + newSerReq.iForcePrompt = forcePrompt;
1.289 + }
1.290 +
1.291 + // use of policy evaluator is optional.
1.292 + if(GetIntFromConfig(ConfigSection(),fExpectedEvaInfo,expectedEvaInfo))
1.293 + {
1.294 + newSerReq.iExpectedEvaluatorInfo = expectedEvaInfo;
1.295 + }
1.296 +
1.297 + // Fingerprint selection is optional.
1.298 + if(GetIntFromConfig(ConfigSection(),fSelectFingerprint,selectFingerprint))
1.299 + {
1.300 + newSerReq.iSelectFingerprint = selectFingerprint;
1.301 + }
1.302 +
1.303 + // iRepeatUntilFileAppears is optional.
1.304 + if(GetStringFromConfig(ConfigSection(),fWaitUntilFileAppears,waitUntilFileAppears))
1.305 + {
1.306 + newSerReq.iWaitUntilFileAppears = waitUntilFileAppears;
1.307 + }
1.308 +
1.309 + // Add the new service to be requested to array.
1.310 + iArraySersToRequest.Append(newSerReq);
1.311 +
1.312 + index++;
1.313 + fUseServiceUID.Format(_L("UseServiceUID_%d"),index);
1.314 + fUseServerName.Format(_L("UseServerName_%d"),index);
1.315 + fDestination.Format(_L("Destination_%d"),index);
1.316 + fExpectedError.Format(_L("ExpectedError_%d"),index);
1.317 + fUseOpaqueData.Format(_L("UseOpaqueData_%d"),index);
1.318 + fSelectDialogOption.Format(_L("SelectDialogOption_%d"),index);
1.319 + fButtonsDisplayed.Format(_L("ButtonsDisplayed_%d"),index);
1.320 + fDialogCreatorInvoked.Format(_L("DialogCreatorInvoked_%d"),index);
1.321 + fPolicyEvaluatorInvoked.Format(_L("PolicyEvaluatorInvoked_%d"),index);
1.322 + fAccessGranted.Format(_L("AccessGranted_%d"), index);
1.323 + fCloseSession.Format(_L("CloseSession_%d"), index);
1.324 + fHoldEvaluatorOpen.Format(_L("HoldEvaluatorOpen_%d"), index);
1.325 + fHoldPrepareDialogOpen.Format(_L("HoldPrepareDialogOpen_%d"), index);
1.326 + fHoldDisplayDialogOpen.Format(_L("HoldDisplayDialogOpen_%d"), index);
1.327 + fRequestDurationThreshold.Format(_L("RequestDurationThreshold_%d"), index);
1.328 + fLeaveDialog.Format(_L("LeaveDialog_%d"), index);
1.329 + fLeaveEvaluator.Format(_L("LeaveEvaluator_%d"), index);
1.330 + fCancelUpsRequest.Format(_L("CancelUpsRequest_%d"), index);
1.331 + fPlatSecPass.Format(_L("PlatSecPass_%d"), index);
1.332 + fForcePrompt.Format(_L("ForcePrompt_%d"), index);
1.333 + fExpectedEvaInfo.Format(_L("ExpectedEvaluatorInfo_%d"), index);
1.334 + fSelectFingerprint.Format(_L("SelectFingerprint_%d"), index);
1.335 + fWaitUntilFileAppears.Format(_L("WaitUntilFileAppears_%d"), index);
1.336 + }
1.337 +
1.338 + // now try for some clientStep specific stuff
1.339 + // this ini file entry specifies the property key value for the hold flag
1.340 + // If the hold flag property is true then monitor it until it becomes false
1.341 + // then continue
1.342 + TInt holdKey;
1.343 + if(GetIntFromConfig(ConfigSection(),_L("HoldClientStepKey"), holdKey))
1.344 + {
1.345 + iHoldClientStepKey = holdKey;
1.346 +
1.347 + // as this property is present then set it to true using a direct call to p&s api because
1.348 + // the ups p&s api only handles policy evaluators and dialog creators and not test steps
1.349 + User::LeaveIfError(RProperty::Set(KPropertyCreatorUid, iHoldClientStepKey, 2));
1.350 + }
1.351 +
1.352 + // Instantiates property reader and seter
1.353 + iPropertyReader= CUpsProperty::NewL(KPropertyCreatorUid);
1.354 +
1.355 + // reads client name and SID
1.356 + TParse clientFullName;
1.357 + RThread client;
1.358 + clientFullName.Set(client.FullName(),NULL, NULL);
1.359 + iTEFServerName=clientFullName.Name();
1.360 + iExpectedClientSid = client.SecureId() ;
1.361 + client.Close();
1.362 +
1.363 + SetTestStepResult(EPass);
1.364 + return TestStepResult();
1.365 + }
1.366 +
1.367 +
1.368 +TVerdict CUpsClientStep::doTestStepL()
1.369 + {
1.370 + // loop to request for different test services.
1.371 + TVerdict testResult= EPass;
1.372 + TInt numServicesToRequest = iArraySersToRequest.Count();
1.373 +
1.374 + if(numServicesToRequest > 0)
1.375 + {
1.376 + // check if the test step needs to hold until another step allows it to continue
1.377 + if (iHoldClientStepKey)
1.378 + {
1.379 + HoldClientL();
1.380 + }
1.381 +
1.382 + // repeats the sequence of test services request as many times as specified in iStepRepeat
1.383 + for(TInt repeatTimes = 0;repeatTimes<iStepRepeat;++repeatTimes)
1.384 + {
1.385 + INFO_PRINTF3(_L("%S: Repeat number: %d"),&iTEFServerName,repeatTimes);
1.386 +
1.387 + for(TInt index=0;index < numServicesToRequest; ++index )
1.388 + {
1.389 + INFO_PRINTF6(_L("%S: Service request: %d. SysServer: %S Destination: %S ServiceUID: %X "),&iTEFServerName, index, &iArraySersToRequest[index].iServerName ,&iArraySersToRequest[index].iDestination, iArraySersToRequest[index].iServiceUID);
1.390 + RUpsTestSession * sessionToBeUsed;
1.391 +
1.392 + sessionToBeUsed = GetSessionToServerL(iArraySersToRequest[index].iServerName);
1.393 +
1.394 + SetTestDataL(index);
1.395 +
1.396 + sessionToBeUsed->UseTestService(iRequestData,iReturnData);
1.397 +
1.398 + iServerId=sessionToBeUsed->GetServerSid();
1.399 + // Check results.
1.400 + if(CheckResultsL(index) == EFalse)
1.401 + {
1.402 + ERR_PRINTF2(_L("%S: Incorrect results"),&iTEFServerName);
1.403 + User::Leave(KErrGeneral);
1.404 + }
1.405 +
1.406 + // Checks from config value if session need to be closed.
1.407 + if(iArraySersToRequest[index].iCloseSession)
1.408 + {
1.409 + INFO_PRINTF3(_L("%S :Closing session to server: %S"),&iTEFServerName, &iArraySersToRequest[index].iServerName );
1.410 + CloseSessionL(iArraySersToRequest[index].iServerName);
1.411 + }
1.412 + } // End of second loop
1.413 + }// End of first loop
1.414 +
1.415 + // Sets the status of the first instance of policy evaluator and dialog creator to
1.416 + // completed so that the coordinator step can progress in concurrent mode
1.417 + SetClientStatusCompleteL();
1.418 + }
1.419 + else
1.420 + {
1.421 + testResult= EFail;
1.422 + ERR_PRINTF2(_L("%S :Problem reading ini file"),&iTEFServerName);
1.423 + User::Leave(KErrGeneral);
1.424 + }
1.425 +
1.426 + return testResult;
1.427 + } // End of function
1.428 +
1.429 +
1.430 +TVerdict CUpsClientStep::doTestStepPostambleL()
1.431 + {
1.432 + return TestStepResult();
1.433 + }
1.434 +
1.435 +
1.436 +void CUpsClientStep::HoldClientL(void)
1.437 + {
1.438 + RProperty checkIfStillNeedtoHold;
1.439 + User::LeaveIfError(checkIfStillNeedtoHold.Attach(KPropertyCreatorUid, iHoldClientStepKey));
1.440 + CleanupClosePushL(checkIfStillNeedtoHold);
1.441 + checkIfStillNeedtoHold.Set(KPropertyCreatorUid, iHoldClientStepKey, 1);
1.442 + TRequestStatus holdStatus;
1.443 + checkIfStillNeedtoHold.Subscribe(holdStatus);
1.444 +
1.445 + TInt holdState;
1.446 +
1.447 + checkIfStillNeedtoHold.Get(KPropertyCreatorUid, iHoldClientStepKey, holdState);
1.448 + if(!holdState)
1.449 + {
1.450 + checkIfStillNeedtoHold.Cancel();
1.451 + }
1.452 + else
1.453 + {
1.454 + User::WaitForRequest(holdStatus);
1.455 + }
1.456 +
1.457 + RDebug::Printf("[UPS ClientStep 0x%x] HoldClient() stopped holding\n", this);
1.458 +
1.459 + // set the hold state back to 1 for future holds
1.460 + checkIfStillNeedtoHold.Set(KPropertyCreatorUid, iHoldClientStepKey, 2);
1.461 + CleanupStack::PopAndDestroy(&checkIfStillNeedtoHold);
1.462 + }
1.463 +
1.464 +
1.465 +TBool CUpsClientStep::FindOpenSession(const TDesC& aServerName,TInt &position)
1.466 + {
1.467 + TBool sessionFound = EFalse;
1.468 + TInt sessionsCount = iArraySessionsInUse.Count();
1.469 + for(TInt index = 0;index < sessionsCount; ++index)
1.470 + {
1.471 + if(!aServerName.CompareF(iArraySessionsInUse[index]->iServerName))
1.472 + {
1.473 + position = index;
1.474 + sessionFound = ETrue;
1.475 + break;
1.476 + }
1.477 + }
1.478 + return sessionFound;
1.479 + } // End of function
1.480 +
1.481 +
1.482 +RUpsTestSession* CUpsClientStep::GetSessionToServerL(const TDesC& aServerName)
1.483 + {
1.484 + // Finds out if a session is already open for server requested
1.485 + TInt foundPos;
1.486 + RUpsTestSession* sessionToReturn;
1.487 + if(!FindOpenSession(aServerName,foundPos))
1.488 + {
1.489 + // if open session for intended server not found it creates a new one
1.490 + COpenSession* sessionToAppend=COpenSession::NewL(aServerName);
1.491 + iArraySessionsInUse.AppendL(sessionToAppend);
1.492 + foundPos = iArraySessionsInUse.Count()-1; // position of new session is last one in array.
1.493 + }
1.494 + sessionToReturn = iArraySessionsInUse[foundPos]->iPointerToSession;
1.495 +
1.496 + return sessionToReturn;
1.497 + } // End of function
1.498 +
1.499 +
1.500 +void CUpsClientStep::CloseSessionL(const TDesC& aServerName)
1.501 + {
1.502 + // Finds out if a session is already open for server requested
1.503 + TInt foundPos;
1.504 +
1.505 + if(!FindOpenSession(aServerName,foundPos))
1.506 + {
1.507 + // if a session for this server was not found it leaves.
1.508 + ERR_PRINTF2(_L("%S: The server to be closed was not found"),&iTEFServerName);
1.509 + User::Leave(KErrGeneral);
1.510 + }
1.511 + delete iArraySessionsInUse[foundPos]; // deletes instance.
1.512 + iArraySessionsInUse.Remove(foundPos); // removes empty slot
1.513 +
1.514 + } // End of function
1.515 +
1.516 +
1.517 +void CUpsClientStep::CloseAllOpenSessions()
1.518 + {
1.519 + while(iArraySessionsInUse.Count()>0)
1.520 + { // delete and remove first session of array.
1.521 + delete iArraySessionsInUse[0];
1.522 + iArraySessionsInUse.Remove(0);
1.523 + }
1.524 + iArraySessionsInUse.Close();
1.525 + } // End of function
1.526 +
1.527 +
1.528 +void CUpsClientStep::SetTestDataL(TInt aIndex)
1.529 + {
1.530 + // Set data for request.
1.531 + iReturnData.iError=KErrNone;
1.532 + iServerId=0;
1.533 + iRequestData.iMeasureResponceTime = EFalse;
1.534 + iRequestData.iServiceUid = TUid::Uid(iArraySersToRequest[aIndex].iServiceUID);
1.535 +
1.536 + if(iArraySersToRequest[aIndex].iOpaqueData.CompareF(_L8(""))==0)
1.537 + {
1.538 + iRequestData.iOpaquePresent = EFalse;
1.539 + }
1.540 + else
1.541 + {
1.542 + iRequestData.iOpaquePresent = ETrue;
1.543 + iRequestData.iOpaqueData =iArraySersToRequest[aIndex].iOpaqueData;
1.544 + }
1.545 +
1.546 + iRequestData.iDestination = iArraySersToRequest[aIndex].iDestination;
1.547 + iRequestData.iCancelRequest = iArraySersToRequest[aIndex].iCancelUpsRequest;
1.548 + iRequestData.iPlatSecPass = iArraySersToRequest[aIndex].iPlatSecPass;
1.549 +
1.550 + // set properties for policy evaluator.
1.551 + if (iArraySersToRequest[aIndex].iPolicyEvaluatorInvoked != 0)
1.552 + {
1.553 + //Reset various publisher and suscribe properties for policy evaluator.
1.554 + TInt instance = iArraySersToRequest[aIndex].iPolicyEvaluatorInvoked;
1.555 + iPropertyReader->SetL(instance,KPe_Status,CUpsProperty::EPolicyEvaluator, KUpsPeStatusReset);
1.556 + iPropertyReader->SetL(instance,KPe_ClientSid,CUpsProperty::EPolicyEvaluator, 0);
1.557 + iPropertyReader->SetL(instance,KPe_ServerSid,CUpsProperty::EPolicyEvaluator, 0);
1.558 + TBool leaveEvaluator = iArraySersToRequest[aIndex].iLeaveEvaluator;
1.559 + iPropertyReader->SetL(instance,KPe_Leave,CUpsProperty::EPolicyEvaluator, leaveEvaluator);
1.560 + iPropertyReader->SetL(instance,KPe_Error,CUpsProperty::EPolicyEvaluator, KErrNone);
1.561 + TBool holdEvaluatorOpen = iArraySersToRequest[aIndex].iHoldEvaluatorOpen;
1.562 + iPropertyReader->SetL(instance,KPe_HoldEvaluatorOpen,CUpsProperty::EPolicyEvaluator, holdEvaluatorOpen);
1.563 + TBool forcePrompt = iArraySersToRequest[aIndex].iForcePrompt;
1.564 + iPropertyReader->SetL(instance,KPe_ForcePrompt,CUpsProperty::EPolicyEvaluator, forcePrompt);
1.565 + iPropertyReader->SetL(instance,KPe_EvaluatorInfo,CUpsProperty::EPolicyEvaluator, 0);
1.566 + }
1.567 +
1.568 + // set properties for dialog creator.
1.569 + if (iArraySersToRequest[aIndex].iDialogCreatorInvoked != 0)
1.570 + {
1.571 + //Reset various publisher and suscribe properties for dialog creator.
1.572 + TInt instance = iArraySersToRequest[aIndex].iDialogCreatorInvoked;
1.573 + iPropertyReader->SetL(instance,KDc_Status,CUpsProperty::EDialogCreator, KUpsDcStatusReset);
1.574 + iPropertyReader->SetL(instance,KDc_ClientSid,CUpsProperty::EDialogCreator, 0);
1.575 + iPropertyReader->SetL(instance,KDc_ServerSid,CUpsProperty::EDialogCreator, 0);
1.576 + TBool dialogLeave = iArraySersToRequest[aIndex].iLeaveDialog ;
1.577 + iPropertyReader->SetL(instance,KDc_Leave,CUpsProperty::EDialogCreator, dialogLeave);
1.578 + iPropertyReader->SetL(instance,KDc_Error,CUpsProperty::EDialogCreator, KErrNone);
1.579 + iPropertyReader->SetL(instance,KDc_UpsRequestedButtons,CUpsProperty::EDialogCreator, 0);
1.580 + TInt buttonToPress = ButtonToInt(iArraySersToRequest[aIndex].iSelectDialogOption);
1.581 + iPropertyReader->SetL(instance,KDc_WhichButtonToPress,CUpsProperty::EDialogCreator, buttonToPress);
1.582 + TBool holdPrepareDialogOpen = iArraySersToRequest[aIndex].iHoldPrepareDialogOpen;
1.583 + iPropertyReader->SetL(instance,KDc_HoldPrepareDialogOpen,CUpsProperty::EDialogCreator, holdPrepareDialogOpen);
1.584 + TBool holdDisplayDialogOpen = iArraySersToRequest[aIndex].iHoldDisplayDialogOpen;
1.585 + iPropertyReader->SetL(instance,KDc_HoldDisplayDialogOpen,CUpsProperty::EDialogCreator, holdDisplayDialogOpen);
1.586 + TBool selectFingerprint = iArraySersToRequest[aIndex].iSelectFingerprint ;
1.587 + iPropertyReader->SetL(instance,KDc_SelectFingerprint,CUpsProperty::EDialogCreator, selectFingerprint);
1.588 + }
1.589 +
1.590 + } // End of function.
1.591 +
1.592 +
1.593 +void CUpsClientStep::SetClientStatusCompleteL()
1.594 +/**
1.595 + * Sets the status of the first policy evaluator invoked by the client to "KUpsClientCompleted" so that
1.596 + * the coordinator step can determine when the step has completely finish and progress in Concurrent mode
1.597 + *
1.598 + * NOTE: When using the Coordinator in this manner, ALL requests made to UPS must invoke the same instance
1.599 + * of the Policy Evaluator and Dialog Creator! e.g. Policy Evalutor 1 and Dialog Creator 1
1.600 + */
1.601 + {
1.602 + TInt requestCount = iArraySersToRequest.Count();
1.603 +
1.604 + for(TInt i=0; i<requestCount; ++i)
1.605 + {
1.606 + if (iArraySersToRequest[i].iPolicyEvaluatorInvoked != 0)
1.607 + {
1.608 + TInt instance = iArraySersToRequest[i].iPolicyEvaluatorInvoked;
1.609 + iPropertyReader->SetL(instance,KPe_Status,CUpsProperty::EPolicyEvaluator, KUpsClientCompleted);
1.610 + iPropertyReader->SetL(instance,KDc_Status,CUpsProperty::EDialogCreator, KUpsClientCompleted);
1.611 + break;
1.612 + }
1.613 + }
1.614 + }
1.615 +
1.616 +
1.617 +TUpsDecision CUpsClientStep::StringToTUpsDecision(const TPtrC& aString)
1.618 + {
1.619 + if(aString.CompareF(_L("Yes"))==0)
1.620 + {
1.621 + return TUpsDecision(EUpsDecYes);
1.622 + }
1.623 + else if(aString.CompareF(_L("No"))==0)
1.624 + {
1.625 + return TUpsDecision(EUpsDecNo);
1.626 + }
1.627 + else if(aString.CompareF(_L("SessionYes"))==0)
1.628 + {
1.629 + return TUpsDecision(EUpsDecSessionYes);
1.630 + }
1.631 + else
1.632 + {
1.633 + return TUpsDecision(EUpsDecSessionNo);
1.634 + }
1.635 + } // End of function.
1.636 +
1.637 +
1.638 +TPtrC CUpsClientStep::TUpsDecisionToString(TUpsDecision aDecision)
1.639 + {
1.640 + if(aDecision == EUpsDecYes)
1.641 + {
1.642 + return _L("Yes");
1.643 + }
1.644 + else if(aDecision == EUpsDecNo)
1.645 + {
1.646 + return _L("No");
1.647 + }
1.648 + else if(aDecision == EUpsDecSessionYes)
1.649 + {
1.650 + return _L("SessionYes");
1.651 + }
1.652 + else if(aDecision == EUpsDecSessionNo)
1.653 + {
1.654 + return _L("SessionNo");
1.655 + }
1.656 + else
1.657 + {
1.658 + return _L("Undefined");
1.659 + }
1.660 + } // End of function.
1.661 +
1.662 +
1.663 +TInt CUpsClientStep::ButtonToInt(const TPtrC& aButton)
1.664 + {
1.665 + if(aButton.CompareF(_L("Yes"))==0)
1.666 + {
1.667 + return KYes;
1.668 + }
1.669 + else if(aButton.CompareF(_L("No"))==0)
1.670 + {
1.671 + return KNo;
1.672 + }
1.673 + else if(aButton.CompareF(_L("Always"))==0)
1.674 + {
1.675 + return KAlways;
1.676 + }
1.677 + else if(aButton.CompareF(_L("SessionYes"))==0)
1.678 + {
1.679 + return KSessionYes;
1.680 + }
1.681 + else if(aButton.CompareF(_L("SessionNo"))==0)
1.682 + {
1.683 + return KSessionNo;
1.684 + }
1.685 + else if(aButton.CompareF(_L("Never"))==0)
1.686 + {
1.687 + return KNever;
1.688 + }
1.689 + else return KNone;
1.690 +
1.691 + } // End of function.
1.692 +
1.693 +
1.694 +TBool CUpsClientStep::CheckResultsL(TInt aIndex)
1.695 + {
1.696 + TBool theReturn = ETrue;
1.697 +
1.698 + if(iArraySersToRequest[aIndex].iExpectedError == KErrNone)
1.699 + {
1.700 + TUpsDecision expectedDecision = StringToTUpsDecision(iArraySersToRequest[aIndex].iAccessGranted);
1.701 + if(expectedDecision != iReturnData.iDecision)
1.702 + {
1.703 + TPtrC decisionReceived(TUpsDecisionToString(iReturnData.iDecision));
1.704 + ERR_PRINTF4(_L("%S: Decision expected: %S ,Decision received: %S"),&iTEFServerName, &iArraySersToRequest[aIndex].iAccessGranted, &decisionReceived);
1.705 + theReturn=EFalse;
1.706 + }
1.707 + }
1.708 +
1.709 + if(iArraySersToRequest[aIndex].iExpectedError != iReturnData.iError)
1.710 + {
1.711 + // Incorrect error code returned.
1.712 + theReturn=EFalse;
1.713 + ERR_PRINTF3(_L("%S: Error code expected: %d"),&iTEFServerName,iArraySersToRequest[aIndex].iExpectedError);
1.714 + ERR_PRINTF3(_L("%S: Error code Received: %d"),&iTEFServerName,iReturnData.iError);
1.715 + }
1.716 +
1.717 + // checks returned properties from dialog creator & policy evaluator.
1.718 + if ( CheckDialogCreatorResultsL(aIndex) == EFalse || CheckPolicyEvaluatorResultsL(aIndex) == EFalse)
1.719 + {
1.720 + theReturn = EFalse;
1.721 + }
1.722 +
1.723 + // display the request duration and check against the ini file value, if supplied
1.724 + INFO_PRINTF3(_L("%S: UPS decision request duration: %u milliseconds"),&iTEFServerName, iReturnData.iRequestDuration);
1.725 + if (iArraySersToRequest[aIndex].iRequestDurationThreshold > 0)
1.726 + {
1.727 + // check whether the request duration was too long
1.728 + if (static_cast<TInt>(iReturnData.iRequestDuration) > iArraySersToRequest[aIndex].iRequestDurationThreshold)
1.729 + {
1.730 + ERR_PRINTF3(_L("%S: UPS decision request took too long: %u"), &iTEFServerName, iArraySersToRequest[aIndex].iRequestDurationThreshold);
1.731 + theReturn = EFalse;
1.732 + }
1.733 + }
1.734 +
1.735 + return theReturn;
1.736 + } // End of function.
1.737 +
1.738 +
1.739 +TBool CUpsClientStep::CheckDialogCreatorResultsL(TInt aIndex)
1.740 + {
1.741 + TBool checkPassed = ETrue;
1.742 +
1.743 + // checks return properties from dialog creator.
1.744 + if (iArraySersToRequest[aIndex].iDialogCreatorInvoked != 0)
1.745 + {
1.746 + TInt instanceDia = iArraySersToRequest[aIndex].iDialogCreatorInvoked;
1.747 + TInt dialogError = 0;
1.748 + iPropertyReader->GetL(instanceDia,KDc_Error,CUpsProperty::EDialogCreator, dialogError);
1.749 +
1.750 + // Checks that any error encountered by dialog creator is transmited by UPS to system server
1.751 + if(dialogError != iReturnData.iError && dialogError!=KErrNone)
1.752 + {
1.753 + ERR_PRINTF3(_L("%S: Dialog creator found an error: %d"),&iTEFServerName,dialogError);
1.754 + checkPassed = EFalse;
1.755 + }
1.756 +
1.757 + TInt clientSidDia=0;
1.758 + iPropertyReader->GetL(instanceDia,KDc_ClientSid,CUpsProperty::EDialogCreator, clientSidDia);
1.759 +
1.760 + if(iExpectedClientSid != clientSidDia)
1.761 + {
1.762 + ERR_PRINTF2(_L("%S: Client SID returned by dialog creator is not what is expected"),&iTEFServerName);
1.763 + checkPassed = EFalse;
1.764 + }
1.765 +
1.766 + TInt buttonsDisplayed=0;
1.767 + iPropertyReader->GetL(instanceDia,KDc_UpsRequestedButtons,CUpsProperty::EDialogCreator, buttonsDisplayed);
1.768 + TInt32 expectedButtonsDisplayed=iArraySersToRequest[aIndex].iButtonsDisplayed;
1.769 + if(expectedButtonsDisplayed != buttonsDisplayed)
1.770 + {
1.771 + ERR_PRINTF2(_L("%S: Incorrect buttons displayed."),&iTEFServerName);
1.772 + ERR_PRINTF3(_L("%S: Buttons displayed expected: %d"),&iTEFServerName,expectedButtonsDisplayed);
1.773 + ERR_PRINTF3(_L("%S: Buttons displayed received: %d"),&iTEFServerName,buttonsDisplayed);
1.774 + checkPassed = EFalse;
1.775 + }
1.776 +
1.777 + TInt serverSidDia=0;
1.778 + iPropertyReader->GetL(instanceDia,KDc_ServerSid,CUpsProperty::EDialogCreator, serverSidDia);
1.779 +
1.780 + if(iServerId != serverSidDia)
1.781 + {
1.782 + ERR_PRINTF2(_L("%S: Server SID returned by dialog creator is not what is expected"),&iTEFServerName);
1.783 + checkPassed = EFalse;
1.784 + }
1.785 +
1.786 + TInt serviceSidDia=0;
1.787 + iPropertyReader->GetL(instanceDia,KDc_ServiceId,CUpsProperty::EDialogCreator, serviceSidDia);
1.788 + if(serviceSidDia != iArraySersToRequest[aIndex].iServiceUID)
1.789 + {
1.790 + ERR_PRINTF3(_L("%S: Service ID reported by dialog creator is not what is expected: %d"),&iTEFServerName,serviceSidDia);
1.791 + checkPassed = EFalse;
1.792 + }
1.793 + }
1.794 +
1.795 + return checkPassed;
1.796 + } // End of function.
1.797 +
1.798 +
1.799 +TBool CUpsClientStep::CheckPolicyEvaluatorResultsL(TInt aIndex)
1.800 + {
1.801 + TBool checkPassed = ETrue;
1.802 +
1.803 + if (iArraySersToRequest[aIndex].iPolicyEvaluatorInvoked != 0)
1.804 + {
1.805 + TInt instanceEva = iArraySersToRequest[aIndex].iPolicyEvaluatorInvoked;
1.806 + TInt evaluatorError = 0;
1.807 +
1.808 + // Checks that any error encountered by policy evaluator is transmited by UPS to system server
1.809 + iPropertyReader->GetL(instanceEva,KPe_Error,CUpsProperty::EPolicyEvaluator, evaluatorError);
1.810 + if(evaluatorError != iReturnData.iError && evaluatorError!=KErrNone)
1.811 + {
1.812 + ERR_PRINTF3(_L("%S: Policy evaluator found an error: %d"),&iTEFServerName,evaluatorError);
1.813 + checkPassed = EFalse;
1.814 + }
1.815 +
1.816 + TInt clientSidEva=0;
1.817 + iPropertyReader->GetL(instanceEva,KPe_ClientSid,CUpsProperty::EPolicyEvaluator, clientSidEva);
1.818 +
1.819 + if(iExpectedClientSid != clientSidEva)
1.820 + {
1.821 + ERR_PRINTF2(_L("%S: Client SID returned by policy evaluator is not what is expected"),&iTEFServerName);
1.822 + checkPassed = EFalse;
1.823 + }
1.824 +
1.825 + TInt serverSidEva=0;
1.826 + iPropertyReader->GetL(instanceEva,KPe_ServerSid,CUpsProperty::EPolicyEvaluator, serverSidEva);
1.827 +
1.828 + if(iServerId != serverSidEva)
1.829 + {
1.830 + ERR_PRINTF2(_L("%S: Server SID returned by policy evaluator is not what is expected"),&iTEFServerName);
1.831 + checkPassed = EFalse;
1.832 + }
1.833 +
1.834 + TInt serviceSidEva = 0;
1.835 + iPropertyReader->GetL(instanceEva,KPe_ServiceId,CUpsProperty::EPolicyEvaluator, serviceSidEva);
1.836 + if(serviceSidEva != iArraySersToRequest[aIndex].iServiceUID)
1.837 + {
1.838 + ERR_PRINTF3(_L("%S: Service ID reported by policy evaluator is not what is expected: %d"),&iTEFServerName,serviceSidEva);
1.839 + checkPassed = EFalse;
1.840 + }
1.841 + if( iArraySersToRequest[aIndex].iForcePrompt)
1.842 + {
1.843 + // Read evaluator info
1.844 + TInt evaluatorInfo = 0;
1.845 + iPropertyReader->GetL(instanceEva,KPe_EvaluatorInfo,CUpsProperty::EPolicyEvaluator, evaluatorInfo);
1.846 + if(evaluatorInfo != iArraySersToRequest[aIndex].iExpectedEvaluatorInfo)
1.847 + {
1.848 + ERR_PRINTF4(_L("%S: incorrect evaluator info:Expected: %d Received: %d"),&iTEFServerName,iArraySersToRequest[aIndex].iExpectedEvaluatorInfo,evaluatorInfo);
1.849 + checkPassed = EFalse;
1.850 + }
1.851 + }
1.852 + }
1.853 +
1.854 + return checkPassed;
1.855 + } // End of function.