sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "platsectaskcommon.h" sl@0: sl@0: sl@0: // Constants sl@0: _LIT(KConsoleName, "PlatSecTaskHandler"); sl@0: sl@0: static void SignalTestExe() sl@0: { sl@0: _LIT(KSchSemaphoreName, "SCHMinimalTaskHandler"); sl@0: RSemaphore sem; sl@0: TInt ret = sem.OpenGlobal(KSchSemaphoreName); sl@0: if (ret == KErrNone) sl@0: { sl@0: sem.Signal(); sl@0: sem.Close(); sl@0: } sl@0: } sl@0: sl@0: //*********************************************************************************** sl@0: LOCAL_C TInt GetRandomNumber(const TInt aLow, const TInt aHigh, TInt64& aSeed) sl@0: { sl@0: TReal initialRand = (Math::FRand(aSeed) * (aHigh - aLow)); sl@0: TInt32 rand; sl@0: sl@0: // Round to 0 decimal places, ie. the nearest whole numer sl@0: Math::Round(initialRand, initialRand, 0); sl@0: Math::Int(rand, initialRand); sl@0: sl@0: return (aLow + rand); sl@0: } sl@0: sl@0: //*********************************************************************************** sl@0: LOCAL_C void DestroyArray(TAny* aArray) sl@0: { sl@0: static_cast*>(aArray)->Reset(); sl@0: } sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-1345 sl@0: @SYMTestCaseDesc Platform security Task handler test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Attempt to test the contents of a task file. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void ConstructConsoleL(RFile& aTaskFile, RTest& aTest) sl@0: { sl@0: sl@0: CConsoleBase* console=Console::NewL(KConsoleName, TSize(KConsFullScreen, KConsFullScreen)); sl@0: CleanupStack::PushL(console); sl@0: console->Printf(_L(" contents of task file\n")); sl@0: sl@0: RArray enforcedCaps; sl@0: CleanupStack::PushL(TCleanupItem(&DestroyArray,&enforcedCaps)); sl@0: sl@0: for (TInt i=0; iRoot()); sl@0: sl@0: TInt count = instream.ReadInt32L(); sl@0: for (TInt i=0;iInfo().iName.CompareF(KPlatSecTaskName)==0); sl@0: aTest(task->Data().CompareF(KPlatSecTaskData)==0); sl@0: aTest(task->SecurityInfo().iSecureId==KPlatSecTestSid); //This is the SID of tschsvrplatsec sl@0: sl@0: // check that client has capability it should have sl@0: if(isTestCapabilityEnforced) sl@0: aTest(task->SecurityInfo().iCaps.HasCapability(KPlatSecTestCapability)); sl@0: sl@0: // check that the client has ECapabilityWriteDeviceData sl@0: aTest(task->SecurityInfo().iCaps.HasCapability(ECapabilityWriteDeviceData)); sl@0: sl@0: // check that client doesn't have any other capabilities sl@0: for (TInt j=enforcedCaps.Count()-1; j>=0; --j) sl@0: { sl@0: aTest(!task->SecurityInfo().iCaps.HasCapability(enforcedCaps[j])); sl@0: } sl@0: sl@0: sl@0: CleanupStack::PopAndDestroy(task); sl@0: } sl@0: sl@0: console->Printf(_L("Pausing for a one second...")); sl@0: User::After(1000000); sl@0: sl@0: CleanupStack::PopAndDestroy(4); // instream, store, enforcedCaps, console sl@0: } sl@0: sl@0: sl@0: //*********************************************************************************** sl@0: LOCAL_C TInt Execute() sl@0: { sl@0: TInt err = KErrNoMemory; sl@0: CTrapCleanup* cleanup=CTrapCleanup::New(); //can fail sl@0: if (cleanup) sl@0: { sl@0: _LIT(KPlatSecTestName, "PlatSectTaskHandlerTest"); sl@0: RTest theTest(KPlatSecTestName); sl@0: theTest.Start(KPlatSecTestName); sl@0: theTest.Title(); sl@0: sl@0: RFile file; sl@0: sl@0: // Adopt the task file from the Task Scheduler sl@0: err = file.AdoptFromCreator(TScheduledTaskFile::FsHandleIndex(), sl@0: TScheduledTaskFile::FileHandleIndex()); sl@0: if (err != KErrNone) sl@0: return err; sl@0: sl@0: // The aParam is the name of a file where the relevant CTaskExCmdLine is sl@0: // do the executing sl@0: theTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1345 ")); sl@0: TRAPD(err, ConstructConsoleL(file, theTest)); sl@0: if(err == KErrNone) sl@0: { sl@0: // Sometimes we want to return a bogus error value, sl@0: // sometimes we don't. sl@0: TTime now; sl@0: now.HomeTime(); sl@0: TInt64 seed = now.Int64(); sl@0: err = GetRandomNumber(-50, 200, seed); //20% chance of error being returned sl@0: } sl@0: sl@0: file.Close();// Close the file sl@0: sl@0: theTest.End(); sl@0: theTest.Close(); sl@0: sl@0: delete cleanup; sl@0: } sl@0: SignalTestExe(); sl@0: return err; sl@0: } sl@0: sl@0: sl@0: //*********************************************************************************** sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: return Execute(); sl@0: }