|
1 /* |
|
2 * Copyright (c) 2004-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 * tpolicy.h |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef __TPOLICY_H__ |
|
21 #define __TPOLICY_H__ |
|
22 |
|
23 #include <testhandler2/t_testaction.h> |
|
24 |
|
25 /** |
|
26 * This action is used to test whether security policies are correctly enforced. |
|
27 * This is done by specifying another test action to run, and the security |
|
28 * policy that is under test. The action is then run in a seprate process. |
|
29 * This happens multiple times, to test that it passes when the process has the |
|
30 * required security settings and failes when it does not. |
|
31 * |
|
32 * The action body can contain the the following elements: |
|
33 * |
|
34 * testexe: The path of the executable to use to run the test |
|
35 * excludedcapabilities: Capabilites not to assign to the test executable when performing failure tests |
|
36 * policy: The security policy to be tested for |
|
37 * preactions: Optional, contains test actions to run to perform setup before the test |
|
38 * passaction: The action under test, when expected to pass |
|
39 * failaction: The action under test, when expected to fail |
|
40 * postactions: Optonal, contains test actions to run to perform cleanup after the test |
|
41 * |
|
42 * A new script is created containing the preactions if present, the test action |
|
43 * and the postactions (if present). For failure tests, the testaction's expect |
|
44 * results is changed to KErrPermissionDenied. |
|
45 */ |
|
46 class CPolicyTest : public CTestAction |
|
47 { |
|
48 public: |
|
49 static CPolicyTest* NewL(CConsoleBase& aConsole, Output& aOut, |
|
50 const TTestActionSpec& aTestActionSpec); |
|
51 static CPolicyTest* NewLC(CConsoleBase& aConsole, Output& aOut, |
|
52 const TTestActionSpec& aTestActionSpec); |
|
53 ~CPolicyTest(); |
|
54 |
|
55 private: |
|
56 CPolicyTest(CConsoleBase& aConsole, Output& aOut); |
|
57 void ConstructL(const TTestActionSpec& aTestActionSpec); |
|
58 |
|
59 public: |
|
60 virtual void PerformAction(TRequestStatus& aStatus); |
|
61 |
|
62 private: |
|
63 // Methods overriden from CTestAction |
|
64 virtual void DoReportAction(); |
|
65 virtual void DoCheckResult(TInt aError); |
|
66 virtual void PerformCancel(); |
|
67 virtual void Reset(); |
|
68 |
|
69 // Methods for parsing the test spec |
|
70 void BadUsageL(const TDesC& aMessage); |
|
71 void SetTestExeL(const TDesC8& aPath); |
|
72 void SetPolicyL(const TDesC8& aSpec); |
|
73 void SetTestActionL(const TDesC8& aPassAction, const TDesC8& aFailAction); |
|
74 |
|
75 // Methods for running the test |
|
76 void GetNextTest(); |
|
77 void StartProcessL(const TDesC& aExe, const TDesC& aCommandLine, TRequestStatus& aStatus); |
|
78 void CheckProcessTermintationL(); |
|
79 void SetupTestL(TRequestStatus& aStatus); |
|
80 void SetTestSecurityInfoL(TInt aSecureId, TInt aVendorId, TUint aCapSet, TRequestStatus& aStatus); |
|
81 void CheckSetCapsResultL(); |
|
82 void RunTestL(TRequestStatus& aStatus); |
|
83 void ProcessResultsL(TRequestStatus& aStatus); |
|
84 void WriteScriptFileL(const TDesC& aPath, const TDesC8& aAction); |
|
85 |
|
86 private: |
|
87 enum TState |
|
88 { |
|
89 EInit, |
|
90 ESetupTest, |
|
91 ERunTest, |
|
92 EProcessResults, |
|
93 EFinished |
|
94 }; |
|
95 |
|
96 enum TTestState |
|
97 { |
|
98 ETestNone, |
|
99 ETestFailSID, |
|
100 ETestFailVID, |
|
101 ETestFailCap, |
|
102 ETestPass, |
|
103 ETestFinished |
|
104 }; |
|
105 |
|
106 private: |
|
107 RFs iFs; ///< File server handle |
|
108 TInt iProcessSecureId; ///< The secure id of this process |
|
109 TInt iProcessVendorId; ///< The vendor id of this process |
|
110 |
|
111 HBufC* iTestExe; ///< The path of the test harness to run |
|
112 TCapabilitySet iExcludedCaps; ///< Capabilties to exclude from failure tests |
|
113 TUint iSecureId; ///< The secure id of the policy under test, or zero |
|
114 TUint iVendorId; ///< The secure id of the policy under test, or zero |
|
115 RArray<TCapability> iCapabilities; ///< The capabilities of the policy under test |
|
116 HBufC8* iPreActions; ///< Script fragment for setup test actions |
|
117 HBufC8* iPassAction; ///< The action under test |
|
118 HBufC8* iFailAction; ///< The action under test |
|
119 HBufC8* iPostActions; ///< Script fragment for cleanup test actions |
|
120 |
|
121 TState iState; ///< The state we're in |
|
122 TTestState iTestState; ///< The test we're running when iState is ESetCaps or ERunTest |
|
123 TInt iCapIndex; ///< The capability we're testing when iTestState is ECapFailTests |
|
124 RProcess iProcess; ///< Used for running setcap and test harness |
|
125 TInt iFailCount; ///< Running count of tests failed |
|
126 TBuf16<50> iTestExeTmpNewPath; ///< stores the executable as executable_policytest.exe |
|
127 }; |
|
128 |
|
129 #endif |