sl@0
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <schinfo.h>
|
sl@0
|
17 |
#include <schinfointernal.h>
|
sl@0
|
18 |
#include <schtask.h>
|
sl@0
|
19 |
#include <s32file.h>
|
sl@0
|
20 |
#include <e32math.h>
|
sl@0
|
21 |
#include <e32cons.h>
|
sl@0
|
22 |
#include <e32test.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
#include "platsectaskcommon.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
|
sl@0
|
27 |
// Constants
|
sl@0
|
28 |
_LIT(KConsoleName, "PlatSecTaskHandler");
|
sl@0
|
29 |
|
sl@0
|
30 |
static void SignalTestExe()
|
sl@0
|
31 |
{
|
sl@0
|
32 |
_LIT(KSchSemaphoreName, "SCHMinimalTaskHandler");
|
sl@0
|
33 |
RSemaphore sem;
|
sl@0
|
34 |
TInt ret = sem.OpenGlobal(KSchSemaphoreName);
|
sl@0
|
35 |
if (ret == KErrNone)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
sem.Signal();
|
sl@0
|
38 |
sem.Close();
|
sl@0
|
39 |
}
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
//***********************************************************************************
|
sl@0
|
43 |
LOCAL_C TInt GetRandomNumber(const TInt aLow, const TInt aHigh, TInt64& aSeed)
|
sl@0
|
44 |
{
|
sl@0
|
45 |
TReal initialRand = (Math::FRand(aSeed) * (aHigh - aLow));
|
sl@0
|
46 |
TInt32 rand;
|
sl@0
|
47 |
|
sl@0
|
48 |
// Round to 0 decimal places, ie. the nearest whole numer
|
sl@0
|
49 |
Math::Round(initialRand, initialRand, 0);
|
sl@0
|
50 |
Math::Int(rand, initialRand);
|
sl@0
|
51 |
|
sl@0
|
52 |
return (aLow + rand);
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
//***********************************************************************************
|
sl@0
|
56 |
LOCAL_C void DestroyArray(TAny* aArray)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
static_cast<RArray<TCapability>*>(aArray)->Reset();
|
sl@0
|
59 |
}
|
sl@0
|
60 |
/**
|
sl@0
|
61 |
@SYMTestCaseID SYSLIB-SCHSVR-CT-1345
|
sl@0
|
62 |
@SYMTestCaseDesc Platform security Task handler test
|
sl@0
|
63 |
@SYMTestPriority High
|
sl@0
|
64 |
@SYMTestActions Attempt to test the contents of a task file.
|
sl@0
|
65 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
66 |
@SYMREQ REQ0000
|
sl@0
|
67 |
*/
|
sl@0
|
68 |
LOCAL_C void ConstructConsoleL(RFile& aTaskFile, RTest& aTest)
|
sl@0
|
69 |
{
|
sl@0
|
70 |
|
sl@0
|
71 |
CConsoleBase* console=Console::NewL(KConsoleName, TSize(KConsFullScreen, KConsFullScreen));
|
sl@0
|
72 |
CleanupStack::PushL(console);
|
sl@0
|
73 |
console->Printf(_L(" contents of task file\n"));
|
sl@0
|
74 |
|
sl@0
|
75 |
RArray<TCapability> enforcedCaps;
|
sl@0
|
76 |
CleanupStack::PushL(TCleanupItem(&DestroyArray,&enforcedCaps));
|
sl@0
|
77 |
|
sl@0
|
78 |
for (TInt i=0; i<ECapability_Limit; i++)
|
sl@0
|
79 |
{
|
sl@0
|
80 |
// we're checking here to see which capabilities are enforced, skipping
|
sl@0
|
81 |
// ECapabilityMultimediaDD and ECapabilityWriteDeviceData as it is
|
sl@0
|
82 |
// needed to write persistent schedules upon which this test relies.
|
sl@0
|
83 |
|
sl@0
|
84 |
if (i == KPlatSecTestCapability)
|
sl@0
|
85 |
continue;
|
sl@0
|
86 |
else if (i == ECapabilityWriteDeviceData)
|
sl@0
|
87 |
continue;
|
sl@0
|
88 |
else if (PlatSec::IsCapabilityEnforced((TCapability)i))
|
sl@0
|
89 |
enforcedCaps.Append((TCapability)i);
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
TBool isTestCapabilityEnforced = PlatSec::IsCapabilityEnforced(KPlatSecTestCapability);
|
sl@0
|
93 |
|
sl@0
|
94 |
CFileStore* store;
|
sl@0
|
95 |
store = CDirectFileStore::FromLC(aTaskFile);
|
sl@0
|
96 |
|
sl@0
|
97 |
RStoreReadStream instream;
|
sl@0
|
98 |
instream.OpenLC(*store,store->Root());
|
sl@0
|
99 |
|
sl@0
|
100 |
TInt count = instream.ReadInt32L();
|
sl@0
|
101 |
for (TInt i=0;i<count;i++)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
CScheduledTask* task = CScheduledTask::NewLC(instream);
|
sl@0
|
104 |
|
sl@0
|
105 |
aTest(task->Info().iName.CompareF(KPlatSecTaskName)==0);
|
sl@0
|
106 |
aTest(task->Data().CompareF(KPlatSecTaskData)==0);
|
sl@0
|
107 |
aTest(task->SecurityInfo().iSecureId==KPlatSecTestSid); //This is the SID of tschsvrplatsec
|
sl@0
|
108 |
|
sl@0
|
109 |
// check that client has capability it should have
|
sl@0
|
110 |
if(isTestCapabilityEnforced)
|
sl@0
|
111 |
aTest(task->SecurityInfo().iCaps.HasCapability(KPlatSecTestCapability));
|
sl@0
|
112 |
|
sl@0
|
113 |
// check that the client has ECapabilityWriteDeviceData
|
sl@0
|
114 |
aTest(task->SecurityInfo().iCaps.HasCapability(ECapabilityWriteDeviceData));
|
sl@0
|
115 |
|
sl@0
|
116 |
// check that client doesn't have any other capabilities
|
sl@0
|
117 |
for (TInt j=enforcedCaps.Count()-1; j>=0; --j)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
aTest(!task->SecurityInfo().iCaps.HasCapability(enforcedCaps[j]));
|
sl@0
|
120 |
}
|
sl@0
|
121 |
|
sl@0
|
122 |
|
sl@0
|
123 |
CleanupStack::PopAndDestroy(task);
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|
sl@0
|
126 |
console->Printf(_L("Pausing for a one second..."));
|
sl@0
|
127 |
User::After(1000000);
|
sl@0
|
128 |
|
sl@0
|
129 |
CleanupStack::PopAndDestroy(4); // instream, store, enforcedCaps, console
|
sl@0
|
130 |
}
|
sl@0
|
131 |
|
sl@0
|
132 |
|
sl@0
|
133 |
//***********************************************************************************
|
sl@0
|
134 |
LOCAL_C TInt Execute()
|
sl@0
|
135 |
{
|
sl@0
|
136 |
TInt err = KErrNoMemory;
|
sl@0
|
137 |
CTrapCleanup* cleanup=CTrapCleanup::New(); //can fail
|
sl@0
|
138 |
if (cleanup)
|
sl@0
|
139 |
{
|
sl@0
|
140 |
_LIT(KPlatSecTestName, "PlatSectTaskHandlerTest");
|
sl@0
|
141 |
RTest theTest(KPlatSecTestName);
|
sl@0
|
142 |
theTest.Start(KPlatSecTestName);
|
sl@0
|
143 |
theTest.Title();
|
sl@0
|
144 |
|
sl@0
|
145 |
RFile file;
|
sl@0
|
146 |
|
sl@0
|
147 |
// Adopt the task file from the Task Scheduler
|
sl@0
|
148 |
err = file.AdoptFromCreator(TScheduledTaskFile::FsHandleIndex(),
|
sl@0
|
149 |
TScheduledTaskFile::FileHandleIndex());
|
sl@0
|
150 |
if (err != KErrNone)
|
sl@0
|
151 |
return err;
|
sl@0
|
152 |
|
sl@0
|
153 |
// The aParam is the name of a file where the relevant CTaskExCmdLine is
|
sl@0
|
154 |
// do the executing
|
sl@0
|
155 |
theTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1345 "));
|
sl@0
|
156 |
TRAPD(err, ConstructConsoleL(file, theTest));
|
sl@0
|
157 |
if(err == KErrNone)
|
sl@0
|
158 |
{
|
sl@0
|
159 |
// Sometimes we want to return a bogus error value,
|
sl@0
|
160 |
// sometimes we don't.
|
sl@0
|
161 |
TTime now;
|
sl@0
|
162 |
now.HomeTime();
|
sl@0
|
163 |
TInt64 seed = now.Int64();
|
sl@0
|
164 |
err = GetRandomNumber(-50, 200, seed); //20% chance of error being returned
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
file.Close();// Close the file
|
sl@0
|
168 |
|
sl@0
|
169 |
theTest.End();
|
sl@0
|
170 |
theTest.Close();
|
sl@0
|
171 |
|
sl@0
|
172 |
delete cleanup;
|
sl@0
|
173 |
}
|
sl@0
|
174 |
SignalTestExe();
|
sl@0
|
175 |
return err;
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
|
sl@0
|
179 |
//***********************************************************************************
|
sl@0
|
180 |
GLDEF_C TInt E32Main()
|
sl@0
|
181 |
{
|
sl@0
|
182 |
return Execute();
|
sl@0
|
183 |
}
|