1 /* |
|
2 * Copyright (c) 2008-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 @file |
|
21 @test |
|
22 */ |
|
23 |
|
24 #include "stsfilepathprotection.h" |
|
25 |
|
26 #include <usif/sts/sts.h> |
|
27 #include <scs/cleanuputils.h> |
|
28 #include <e32def.h> |
|
29 #include <f32file.h> |
|
30 |
|
31 _LIT(KStsPrivatePathSecName, "STS private path file registration APIs test"); |
|
32 |
|
33 using namespace Usif; |
|
34 |
|
35 CStsPrivatePathProtectionSecTest* CStsPrivatePathProtectionSecTest::NewL() |
|
36 { |
|
37 CStsPrivatePathProtectionSecTest* self=new(ELeave) CStsPrivatePathProtectionSecTest(); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 CStsPrivatePathProtectionSecTest::CStsPrivatePathProtectionSecTest() |
|
45 { |
|
46 SetSidRequired(TUid::Uid(0x10285DDF)); //this ID must match the one used in the file path below |
|
47 } |
|
48 |
|
49 void CStsPrivatePathProtectionSecTest::ConstructL() |
|
50 { |
|
51 SetNameL(KStsPrivatePathSecName); |
|
52 } |
|
53 |
|
54 void CStsPrivatePathProtectionSecTest::RunTestL() |
|
55 { |
|
56 RStsSession stsSession; |
|
57 TInt32 transactionId(stsSession.CreateTransactionL()); |
|
58 CleanupClosePushL(stsSession); |
|
59 TInt err(0); |
|
60 TUint newFileMode(EFileShareExclusive | EFileWrite); |
|
61 |
|
62 _LIT(KOwnPrivatePathFilename, "c:\\private\\10285DDF\\file.txt"); |
|
63 |
|
64 TRAP(err, stsSession.RegisterNewL(KOwnPrivatePathFilename)); |
|
65 CheckFailL(err, _L("RegisterNewL - own private path c:\\private\\10285DDF")); |
|
66 |
|
67 RFile dummyFileHandle; |
|
68 CleanupClosePushL(dummyFileHandle); |
|
69 |
|
70 TRAP(err, stsSession.CreateNewL(KOwnPrivatePathFilename, dummyFileHandle, newFileMode)); |
|
71 dummyFileHandle.Close(); |
|
72 CheckFailL(err, _L("CreateNewL - own private path c:\\private\\10285DDF")); |
|
73 |
|
74 TRAP(err, stsSession.RemoveL(KOwnPrivatePathFilename)); |
|
75 CheckFailL(err, _L("RemoveL - own private path c:\\private\\10285DDF")); |
|
76 |
|
77 TRAP(err, stsSession.RegisterTemporaryL(KOwnPrivatePathFilename)); |
|
78 CheckFailL(err, _L("RegisterTemporaryL - own private path c:\\private\\10285DDF")); |
|
79 |
|
80 TRAP(err, stsSession.CreateTemporaryL(KOwnPrivatePathFilename, dummyFileHandle, newFileMode)); |
|
81 dummyFileHandle.Close(); |
|
82 CheckFailL(err, _L("CreateTemporaryL - own private path c:\\private\\10285DDF")); |
|
83 |
|
84 TRAP(err, stsSession.OverwriteL(KOwnPrivatePathFilename, dummyFileHandle, newFileMode)); |
|
85 dummyFileHandle.Close(); |
|
86 CheckFailL(err, _L("OverwriteL - own private path c:\\private\\10285DDF")); |
|
87 |
|
88 //--------------------------------------------------------------------------------- |
|
89 |
|
90 // This test should always pass, as we are registering a file in an import directory which can be accessed regardless of the SID |
|
91 SetExpectPermissionDenied(EFalse); |
|
92 _LIT(KOthersImportPrivatePathFilename, "c:\\private\\99999999\\import\\file.txt"); |
|
93 |
|
94 |
|
95 TRAP(err, stsSession.RegisterNewL(KOthersImportPrivatePathFilename)); |
|
96 CheckFailL(err, _L("RegisterNewL - others import path c:\\private\\99999999\\import")); |
|
97 |
|
98 TRAP(err, stsSession.CreateNewL(KOthersImportPrivatePathFilename, dummyFileHandle, newFileMode)); |
|
99 dummyFileHandle.Close(); |
|
100 CheckFailL(err, _L("CreateNewL - others import path c:\\private\\99999999\\import")); |
|
101 |
|
102 TRAP(err, stsSession.RemoveL(KOthersImportPrivatePathFilename)); |
|
103 CheckFailL(err, _L("RemoveL - others import path c:\\private\\99999999\\import")); |
|
104 |
|
105 TRAP(err, stsSession.RegisterTemporaryL(KOthersImportPrivatePathFilename)); |
|
106 CheckFailL(err, _L("RegisterTemporaryL - others import path c:\\private\\99999999\\import")); |
|
107 |
|
108 TRAP(err, stsSession.CreateTemporaryL(KOthersImportPrivatePathFilename, dummyFileHandle, newFileMode)); |
|
109 dummyFileHandle.Close(); |
|
110 CheckFailL(err, _L("CreateTemporaryL - others import path c:\\private\\99999999\\import")); |
|
111 |
|
112 TRAP(err, stsSession.OverwriteL(KOthersImportPrivatePathFilename, dummyFileHandle, newFileMode)); |
|
113 dummyFileHandle.Close(); |
|
114 CheckFailL(err, _L("OverwriteL - others import path c:\\private\\99999999\\import")); |
|
115 |
|
116 //--------------------------------------------------------------------------------- |
|
117 |
|
118 // This test should always fail, as we are registering a file in a private directory which does not belong to us |
|
119 SetExpectPermissionDenied(ETrue); |
|
120 _LIT(KOthersPrivatePathFilename, "c:\\private\\99999999\\file.txt"); |
|
121 |
|
122 TRAP(err, stsSession.RegisterNewL(KOthersPrivatePathFilename)); |
|
123 CheckFailL(err, _L("RegisterNewL - others private path c:\\private\\99999999")); |
|
124 |
|
125 TRAP(err, stsSession.CreateNewL(KOthersPrivatePathFilename, dummyFileHandle, newFileMode)); |
|
126 dummyFileHandle.Close(); |
|
127 CheckFailL(err, _L("CreateNewL - others private path c:\\private\\99999999")); |
|
128 |
|
129 TRAP(err, stsSession.RemoveL(KOthersPrivatePathFilename)); |
|
130 CheckFailL(err, _L("RemoveL - others private path c:\\private\\99999999")); |
|
131 |
|
132 TRAP(err, stsSession.RegisterTemporaryL(KOthersPrivatePathFilename)); |
|
133 CheckFailL(err, _L("RegisterTemporaryL - others private path c:\\private\\99999999")); |
|
134 |
|
135 TRAP(err, stsSession.CreateTemporaryL(KOthersPrivatePathFilename, dummyFileHandle, newFileMode)); |
|
136 dummyFileHandle.Close(); |
|
137 CheckFailL(err, _L("CreateTemporaryL - others private path c:\\private\\99999999")); |
|
138 |
|
139 TRAP(err, stsSession.OverwriteL(KOthersPrivatePathFilename, dummyFileHandle, newFileMode)); |
|
140 dummyFileHandle.Close(); |
|
141 CheckFailL(err, _L("OverwriteL - others private path c:\\private\\99999999")); |
|
142 |
|
143 CleanupStack::PopAndDestroy(&dummyFileHandle); |
|
144 CleanupStack::PopAndDestroy(&stsSession); |
|
145 } |
|
146 |
|
147 //---------------CStsTCBPathProtectionSecTest------------------ |
|
148 |
|
149 _LIT(KStsTCBPathSecName, "STS TCB path file registration APIs test"); |
|
150 |
|
151 CStsTCBPathProtectionSecTest* CStsTCBPathProtectionSecTest::NewL() |
|
152 { |
|
153 CStsTCBPathProtectionSecTest* self=new(ELeave) CStsTCBPathProtectionSecTest(); |
|
154 CleanupStack::PushL(self); |
|
155 self->ConstructL(); |
|
156 CleanupStack::Pop(self); |
|
157 return self; |
|
158 } |
|
159 |
|
160 CStsTCBPathProtectionSecTest::CStsTCBPathProtectionSecTest() |
|
161 { |
|
162 SetCapabilityRequired(ECapabilityTCB); |
|
163 } |
|
164 |
|
165 void CStsTCBPathProtectionSecTest::ConstructL() |
|
166 { |
|
167 SetNameL(KStsTCBPathSecName); |
|
168 } |
|
169 |
|
170 void CStsTCBPathProtectionSecTest::RunTestL() |
|
171 { |
|
172 RStsSession stsSession; |
|
173 TInt32 transactionId(stsSession.CreateTransactionL()); |
|
174 CleanupClosePushL(stsSession); |
|
175 TInt err(0); |
|
176 |
|
177 _LIT(KTcbPathFilename, "c:\\sys\\file.txt"); |
|
178 |
|
179 TRAP(err, stsSession.RegisterNewL(KTcbPathFilename)); |
|
180 CheckFailL(err, _L("RegisterNewL - \\sys path")); |
|
181 |
|
182 TUint newFileMode(EFileShareExclusive | EFileWrite); |
|
183 RFile dummyFileHandle; |
|
184 CleanupClosePushL(dummyFileHandle); |
|
185 |
|
186 TRAP(err, stsSession.CreateNewL(KTcbPathFilename, dummyFileHandle, newFileMode)); |
|
187 dummyFileHandle.Close(); |
|
188 CheckFailL(err, _L("CreateNewL - \\sys path")); |
|
189 |
|
190 TRAP(err, stsSession.RemoveL(KTcbPathFilename)); |
|
191 CheckFailL(err, _L("RemoveL - \\sys path")); |
|
192 |
|
193 TRAP(err, stsSession.RegisterTemporaryL(KTcbPathFilename)); |
|
194 CheckFailL(err, _L("RegisterTemporaryL - \\sys path")); |
|
195 |
|
196 TRAP(err, stsSession.CreateTemporaryL(KTcbPathFilename, dummyFileHandle, newFileMode)); |
|
197 dummyFileHandle.Close(); |
|
198 CheckFailL(err, _L("CreateTemporaryL - \\sys path")); |
|
199 |
|
200 TRAP(err, stsSession.OverwriteL(KTcbPathFilename, dummyFileHandle, newFileMode)); |
|
201 dummyFileHandle.Close(); |
|
202 CheckFailL(err, _L("OverwriteL - \\sys path")); |
|
203 |
|
204 |
|
205 _LIT(KResourcePathFilename, "c:\\resource\\file.txt"); |
|
206 |
|
207 TRAP(err, stsSession.RegisterNewL(KResourcePathFilename)); |
|
208 CheckFailL(err, _L("RegisterNewL - \\resource path")); |
|
209 |
|
210 TRAP(err, stsSession.CreateNewL(KResourcePathFilename, dummyFileHandle, newFileMode)); |
|
211 dummyFileHandle.Close(); |
|
212 CheckFailL(err, _L("CreateNewL - \\resource path")); |
|
213 |
|
214 TRAP(err, stsSession.RemoveL(KResourcePathFilename)); |
|
215 CheckFailL(err, _L("RemoveL - \\resource path")); |
|
216 |
|
217 TRAP(err, stsSession.RegisterTemporaryL(KResourcePathFilename)); |
|
218 CheckFailL(err, _L("RegisterTemporaryL - \\resource path")); |
|
219 |
|
220 TRAP(err, stsSession.CreateTemporaryL(KResourcePathFilename, dummyFileHandle, newFileMode)); |
|
221 dummyFileHandle.Close(); |
|
222 CheckFailL(err, _L("CreateTemporaryL - \\resource path")); |
|
223 |
|
224 TRAP(err, stsSession.OverwriteL(KResourcePathFilename, dummyFileHandle, newFileMode)); |
|
225 dummyFileHandle.Close(); |
|
226 CheckFailL(err, _L("OverwriteL - \\resource path")); |
|
227 |
|
228 CleanupStack::PopAndDestroy(&dummyFileHandle); |
|
229 CleanupStack::PopAndDestroy(&stsSession); |
|
230 } |
|
231 |
|
232 |
|
233 //---------------CStsPublicPathSecTest------------------ |
|
234 |
|
235 _LIT(KStsPublicPathSecName, "STS public path file registration APIs test"); |
|
236 |
|
237 CStsPublicPathSecTest* CStsPublicPathSecTest::NewL() |
|
238 { |
|
239 CStsPublicPathSecTest* self=new(ELeave) CStsPublicPathSecTest(); |
|
240 CleanupStack::PushL(self); |
|
241 self->ConstructL(); |
|
242 CleanupStack::Pop(self); |
|
243 return self; |
|
244 } |
|
245 |
|
246 CStsPublicPathSecTest::CStsPublicPathSecTest() |
|
247 { |
|
248 } |
|
249 |
|
250 void CStsPublicPathSecTest::ConstructL() |
|
251 { |
|
252 SetNameL(KStsPublicPathSecName); |
|
253 } |
|
254 |
|
255 void CStsPublicPathSecTest::RunTestL() |
|
256 { |
|
257 RStsSession stsSession; |
|
258 TInt32 transactionId(stsSession.CreateTransactionL()); |
|
259 CleanupClosePushL(stsSession); |
|
260 TInt err(0); |
|
261 |
|
262 TUint newFileMode(EFileShareExclusive | EFileWrite); |
|
263 |
|
264 //this test must always pass |
|
265 SetExpectPermissionDenied(EFalse); |
|
266 _LIT(KPublicPathFilename, "c:\\publicdir\\file.txt"); |
|
267 |
|
268 TRAP(err, stsSession.RegisterNewL(KPublicPathFilename)); |
|
269 CheckFailL(err, _L("RegisterNewL - \\publicdir path")); |
|
270 |
|
271 RFile dummyFileHandle; |
|
272 CleanupClosePushL(dummyFileHandle); |
|
273 |
|
274 TRAP(err, stsSession.CreateNewL(KPublicPathFilename, dummyFileHandle, newFileMode)); |
|
275 dummyFileHandle.Close(); |
|
276 CheckFailL(err, _L("CreateNewL - \\publicdir path")); |
|
277 |
|
278 TRAP(err, stsSession.RemoveL(KPublicPathFilename)); |
|
279 CheckFailL(err, _L("RemoveL - \\publicdir path")); |
|
280 |
|
281 TRAP(err, stsSession.RegisterTemporaryL(KPublicPathFilename)); |
|
282 CheckFailL(err, _L("RegisterTemporaryL - \\publicdir path")); |
|
283 |
|
284 TRAP(err, stsSession.CreateTemporaryL(KPublicPathFilename, dummyFileHandle, newFileMode)); |
|
285 dummyFileHandle.Close(); |
|
286 CheckFailL(err, _L("CreateTemporaryL - \\publicdir path")); |
|
287 |
|
288 TRAP(err, stsSession.OverwriteL(KPublicPathFilename, dummyFileHandle, newFileMode)); |
|
289 dummyFileHandle.Close(); |
|
290 CheckFailL(err, _L("OverwriteL - \\publicdir path")); |
|
291 |
|
292 CleanupStack::PopAndDestroy(&dummyFileHandle); |
|
293 CleanupStack::PopAndDestroy(&stsSession); |
|
294 } |
|