sl@0
|
1 |
// Copyright (c) 2006-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 |
// t_sqlsecurity4 application has capabilities allowing read/write access to the test database
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32test.h>
|
sl@0
|
19 |
#include <bautils.h>
|
sl@0
|
20 |
#include <sqldb.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
23 |
//The test database has:
|
sl@0
|
24 |
// SCHEMA database policy: ECapabilityReadDeviceData, ECapabilityWriteUserData, ECapabilityReadUserData
|
sl@0
|
25 |
// WRITE database policy: ECapabilityWriteUserData
|
sl@0
|
26 |
// READ database policy: ECapabilityReadUserData
|
sl@0
|
27 |
//
|
sl@0
|
28 |
//Database tables:
|
sl@0
|
29 |
// TABLE A(F1 INTEGER, B1 BLOB)
|
sl@0
|
30 |
// TABLE B(F2 INTEGER, F3 TEXT, B2 BLOB)
|
sl@0
|
31 |
//
|
sl@0
|
32 |
//Database data:
|
sl@0
|
33 |
// TABLE A: {1, x'41414141414141414141'}, {2, x'42424242424242424242'}, {3, x'43434343434343434343'}, {4, x'44444444444444444444'}
|
sl@0
|
34 |
// TABLE B: {2, "ABC", x'45454545454545454545'}, {4, "DEF", x'46464646464646464646'}
|
sl@0
|
35 |
|
sl@0
|
36 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
37 |
|
sl@0
|
38 |
#define UNUSED_VAR(a) (a) = (a)
|
sl@0
|
39 |
|
sl@0
|
40 |
RSqlDatabase TheDb;
|
sl@0
|
41 |
RTest TheTest(_L("t_sqlsecurity4 test"));
|
sl@0
|
42 |
|
sl@0
|
43 |
_LIT(KTestDbName, "c:[21212125]t_ab.db");
|
sl@0
|
44 |
_LIT(KTestDbName2, "c:\\test\\t_sqlsecurity4_2.db");
|
sl@0
|
45 |
|
sl@0
|
46 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
47 |
//Restore original test database function
|
sl@0
|
48 |
void RestoreOriginalDb()
|
sl@0
|
49 |
{
|
sl@0
|
50 |
TheDb.Close();
|
sl@0
|
51 |
TheDb.Open(KTestDbName);
|
sl@0
|
52 |
|
sl@0
|
53 |
// Delete and restore the content of table A (unconditional DELETE, no READ operations)
|
sl@0
|
54 |
TheDb.Exec(_L("DELETE FROM A"));
|
sl@0
|
55 |
TheDb.Exec(_L("INSERT INTO A(F1,B1) VALUES(1,x'41414141414141414141');INSERT INTO A(F1,B1) VALUES(2,x'42424242424242424242');INSERT INTO A(F1,B1) VALUES(3,x'43434343434343434343');INSERT INTO A(F1,B1) VALUES(4,x'44444444444444444444');"));
|
sl@0
|
56 |
|
sl@0
|
57 |
// Delete and restore the content of table B (unconditional DELETE, no READ operations)
|
sl@0
|
58 |
TheDb.Exec(_L("DELETE FROM B"));
|
sl@0
|
59 |
TheDb.Exec(_L("INSERT INTO B(F2,F3,B2) VALUES(2, 'ABC',x'45454545454545454545');INSERT INTO B(F2,F3,B2) VALUES(4,'DEF',x'46464646464646464646');"));
|
sl@0
|
60 |
|
sl@0
|
61 |
TheDb.Close();
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
65 |
//Test macros and functions
|
sl@0
|
66 |
void Check1(TInt aValue, TInt aLine)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
if(!aValue)
|
sl@0
|
69 |
{
|
sl@0
|
70 |
RestoreOriginalDb();
|
sl@0
|
71 |
RDebug::Print(_L("*** Line %d\r\n"), aLine);
|
sl@0
|
72 |
TheTest(EFalse, aLine);
|
sl@0
|
73 |
}
|
sl@0
|
74 |
}
|
sl@0
|
75 |
void Check2(TInt aValue, TInt aExpected, TInt aLine)
|
sl@0
|
76 |
{
|
sl@0
|
77 |
if(aValue != aExpected)
|
sl@0
|
78 |
{
|
sl@0
|
79 |
RestoreOriginalDb();
|
sl@0
|
80 |
RDebug::Print(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue);
|
sl@0
|
81 |
TheTest(EFalse, aLine);
|
sl@0
|
82 |
}
|
sl@0
|
83 |
}
|
sl@0
|
84 |
#define TEST(arg) ::Check1((arg), __LINE__)
|
sl@0
|
85 |
#define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
|
sl@0
|
86 |
|
sl@0
|
87 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
88 |
|
sl@0
|
89 |
//This functnion is called while there is an open secure connection.
|
sl@0
|
90 |
//The function will create a new, non-secure connection and check that the non-secure database schema can be modified,
|
sl@0
|
91 |
//while there is another alive, secure database connection.
|
sl@0
|
92 |
void NonSecureDbTest()
|
sl@0
|
93 |
{
|
sl@0
|
94 |
(void)RSqlDatabase::Delete(KTestDbName2);
|
sl@0
|
95 |
RSqlDatabase db;
|
sl@0
|
96 |
TInt err = db.Create(KTestDbName2);
|
sl@0
|
97 |
TEST2(err, KErrNone);
|
sl@0
|
98 |
|
sl@0
|
99 |
err = db.Exec(_L("CREATE TABLE A(I1 INTEGER, I2 INTEGER)"));
|
sl@0
|
100 |
TEST(err >= 0);
|
sl@0
|
101 |
err = db.Exec(_L("CREATE TEMP TABLE B(I1 INTEGER, I2 INTEGER)"));
|
sl@0
|
102 |
TEST(err >= 0);
|
sl@0
|
103 |
|
sl@0
|
104 |
//"CREATE VIRTUAL TABLE" statement not supported
|
sl@0
|
105 |
err = db.Exec(_L("CREATE VIRTUAL TABLE V1 USING FTS3(ColOne TEXT, ColTwo DATETIME)"));
|
sl@0
|
106 |
TPtrC msg = db.LastErrorMessage();
|
sl@0
|
107 |
TheTest.Printf(_L("*** \"CREATE VIRTUAL TABLE\" expected failure, msg=\"%S\", err=%d\r\n"), &msg, err);
|
sl@0
|
108 |
TEST(err != KErrNone);
|
sl@0
|
109 |
|
sl@0
|
110 |
err = db.Exec(_L("CREATE TRIGGER T1 AFTER INSERT ON A BEGIN INSERT INTO B VALUES(new.I1, new.I2); END;"));
|
sl@0
|
111 |
TEST(err >= 0);
|
sl@0
|
112 |
err = db.Exec(_L("DROP TRIGGER T1"));
|
sl@0
|
113 |
TEST(err >= 0);
|
sl@0
|
114 |
err = db.Exec(_L("CREATE TEMP TRIGGER T2 AFTER UPDATE OF I1 ON A BEGIN UPDATE B SET I1 = new.I1; END;"));
|
sl@0
|
115 |
TEST(err >= 0);
|
sl@0
|
116 |
err = db.Exec(_L("DROP TRIGGER T2"));
|
sl@0
|
117 |
TEST(err >= 0);
|
sl@0
|
118 |
|
sl@0
|
119 |
err = db.Exec(_L("CREATE VIEW V1 AS SELECT * FROM A"));
|
sl@0
|
120 |
TEST(err >= 0);
|
sl@0
|
121 |
err = db.Exec(_L("DROP VIEW V1"));
|
sl@0
|
122 |
TEST(err >= 0);
|
sl@0
|
123 |
err = db.Exec(_L("CREATE TEMP VIEW V2 AS SELECT * FROM A"));
|
sl@0
|
124 |
TEST(err >= 0);
|
sl@0
|
125 |
err = db.Exec(_L("DROP VIEW V2"));
|
sl@0
|
126 |
TEST(err >= 0);
|
sl@0
|
127 |
|
sl@0
|
128 |
err = db.Exec(_L("CREATE INDEX Idx1 ON A(I1)"));
|
sl@0
|
129 |
TEST(err >= 0);
|
sl@0
|
130 |
err = db.Exec(_L("ANALYZE A"));
|
sl@0
|
131 |
TEST(err >= 0);
|
sl@0
|
132 |
err = db.Exec(_L("DROP INDEX Idx1"));
|
sl@0
|
133 |
TEST(err >= 0);
|
sl@0
|
134 |
err = db.Exec(_L("CREATE INDEX Idx2 ON B(I1)"));
|
sl@0
|
135 |
TEST(err >= 0);
|
sl@0
|
136 |
err = db.Exec(_L("DROP INDEX Idx2"));
|
sl@0
|
137 |
TEST(err >= 0);
|
sl@0
|
138 |
|
sl@0
|
139 |
err = db.Exec(_L("DROP TABLE B"));
|
sl@0
|
140 |
TEST(err >= 0);
|
sl@0
|
141 |
err = db.Exec(_L("DROP TABLE A"));
|
sl@0
|
142 |
TEST(err >= 0);
|
sl@0
|
143 |
|
sl@0
|
144 |
db.Close();
|
sl@0
|
145 |
(void)RSqlDatabase::Delete(KTestDbName2);
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
/**
|
sl@0
|
149 |
@SYMTestCaseID SYSLIB-SQL-CT-1646
|
sl@0
|
150 |
@SYMTestCaseDesc Testing database operations on a secure database.
|
sl@0
|
151 |
The test application's capabilities allow read/write access to the test secure database.
|
sl@0
|
152 |
Verify that any other kind of a database operation will fail with KErrPermissionDenied error.
|
sl@0
|
153 |
@SYMTestPriority High
|
sl@0
|
154 |
@SYMTestActions Testing database operations on a secure database.
|
sl@0
|
155 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
156 |
@SYMREQ REQ5792
|
sl@0
|
157 |
REQ5793
|
sl@0
|
158 |
*/
|
sl@0
|
159 |
void ReadWriteDatabaseTest()
|
sl@0
|
160 |
{
|
sl@0
|
161 |
RSqlDatabase db;
|
sl@0
|
162 |
TInt err = TheDb.Open(KTestDbName);
|
sl@0
|
163 |
TEST2(err, KErrNone);
|
sl@0
|
164 |
|
sl@0
|
165 |
//Attempt to modify the database schema
|
sl@0
|
166 |
err = TheDb.Exec(_L("CREATE TABLE C(FFF TEXT)"));
|
sl@0
|
167 |
TEST2(err, KErrPermissionDenied);
|
sl@0
|
168 |
err = TheDb.Exec(_L("CREATE TEMP TABLE TBL1(COL1 INTEGER, COL2 INTEGER)"));
|
sl@0
|
169 |
TEST(err >= 0);
|
sl@0
|
170 |
err = TheDb.Exec(_L("CREATE TEMP TRIGGER del1 AFTER DELETE ON TBL1 BEGIN DELETE FROM A; END;"));
|
sl@0
|
171 |
TEST(err >= 0);
|
sl@0
|
172 |
err = TheDb.Exec(_L("DROP TRIGGER del1"));
|
sl@0
|
173 |
TEST(err >= 0);
|
sl@0
|
174 |
err = TheDb.Exec(_L("CREATE TEMP VIEW V1 AS SELECT * FROM TBL1"));
|
sl@0
|
175 |
TEST(err >= 0);
|
sl@0
|
176 |
err = TheDb.Exec(_L("DROP VIEW V1"));
|
sl@0
|
177 |
TEST(err >= 0);
|
sl@0
|
178 |
err = TheDb.Exec(_L("CREATE INDEX I1 ON TBL1(COL2)"));
|
sl@0
|
179 |
TEST(err >= 0);
|
sl@0
|
180 |
err = TheDb.Exec(_L("DROP INDEX I1"));
|
sl@0
|
181 |
TEST(err >= 0);
|
sl@0
|
182 |
err = TheDb.Exec(_L("DROP TABLE TBL1"));
|
sl@0
|
183 |
TEST(err >= 0);
|
sl@0
|
184 |
err = TheDb.Exec(_L("ANALYZE A"));
|
sl@0
|
185 |
TEST2(err, KErrPermissionDenied);
|
sl@0
|
186 |
err = TheDb.Exec(_L("CREATE VIEW V2 AS SELECT * FROM A"));
|
sl@0
|
187 |
TEST2(err, KErrPermissionDenied);
|
sl@0
|
188 |
//Attempt to update the user data (but it includes a READ operation)
|
sl@0
|
189 |
err = TheDb.Exec(_L("UPDATE A SET F1 = 11 WHERE F1 = 1"));
|
sl@0
|
190 |
TEST(err >= 0);
|
sl@0
|
191 |
//Attempt to update the user data (unconditional UPDATE, no READ operations)
|
sl@0
|
192 |
err = TheDb.Exec(_L("UPDATE A SET F1 = 11"));
|
sl@0
|
193 |
TEST(err >= 0);
|
sl@0
|
194 |
//Attempt to delete the user data (but it includes a READ operation)
|
sl@0
|
195 |
err = TheDb.Exec(_L("DELETE FROM B WHERE F2 = 2"));
|
sl@0
|
196 |
TEST(err >= 0);
|
sl@0
|
197 |
//Attempt to delete the user data (unconditional DELETE, no READ operations)
|
sl@0
|
198 |
err = TheDb.Exec(_L("DELETE FROM A"));
|
sl@0
|
199 |
TEST(err >= 0);
|
sl@0
|
200 |
//Restore the deleted table A
|
sl@0
|
201 |
err = TheDb.Exec(_L("INSERT INTO A(F1,B1) VALUES(1,x'41414141414141414141');INSERT INTO A(F1,B1) VALUES(2,x'42424242424242424242');INSERT INTO A(F1,B1) VALUES(3,x'43434343434343434343');INSERT INTO A(F1,B1) VALUES(4,x'44444444444444444444');"));
|
sl@0
|
202 |
TEST(err >= 0);
|
sl@0
|
203 |
//Restore the deleted record in table B
|
sl@0
|
204 |
err = TheDb.Exec(_L("INSERT INTO B(F2, F3, B2) VALUES(2, 'ABC', x'45454545454545454545');"));
|
sl@0
|
205 |
TEST2(err, 1);
|
sl@0
|
206 |
//Attempt to insert new user data
|
sl@0
|
207 |
err = TheDb.Exec(_L("INSERT INTO B(F2, F3, B2) VALUES(6, 'GHI', x'47474747474747474747');"));
|
sl@0
|
208 |
TEST2(err, 1);
|
sl@0
|
209 |
//Attempt to read the user data
|
sl@0
|
210 |
RSqlStatement stmt;
|
sl@0
|
211 |
err = stmt.Prepare(TheDb, _L("SELECT A.F1 FROM B,A WHERE A.F1 = B.F2"));
|
sl@0
|
212 |
TEST2(err, KErrNone);
|
sl@0
|
213 |
//ColumnCount() has no capabilities assigned
|
sl@0
|
214 |
TInt colCnt = stmt.ColumnCount();
|
sl@0
|
215 |
TEST2(colCnt, 1);
|
sl@0
|
216 |
//DeclaredColumnType() has no capabilities assigned
|
sl@0
|
217 |
TSqlColumnType colType;
|
sl@0
|
218 |
err = stmt.DeclaredColumnType(0, colType);
|
sl@0
|
219 |
TEST2(err, KErrNone);
|
sl@0
|
220 |
TEST2(colType, ESqlInt);
|
sl@0
|
221 |
err = stmt.Next();
|
sl@0
|
222 |
TEST2(err, KSqlAtRow);
|
sl@0
|
223 |
RDebug::Print(_L("Value=%d\r\n"), stmt.ColumnInt(0));
|
sl@0
|
224 |
err = stmt.Next();
|
sl@0
|
225 |
TEST2(err, KSqlAtRow);
|
sl@0
|
226 |
RDebug::Print(_L("Value=%d\r\n"), stmt.ColumnInt(0));
|
sl@0
|
227 |
stmt.Close();
|
sl@0
|
228 |
//Attempt to read the system data
|
sl@0
|
229 |
err = stmt.Prepare(TheDb, _L("SELECT * FROM SQLITE_MASTER"));
|
sl@0
|
230 |
TEST2(err, KErrNone);
|
sl@0
|
231 |
err = stmt.Next();
|
sl@0
|
232 |
TEST2(err, KSqlAtRow);
|
sl@0
|
233 |
TPtrC p;
|
sl@0
|
234 |
err = stmt.ColumnText(0, p);
|
sl@0
|
235 |
TEST2(err, KErrNone);
|
sl@0
|
236 |
RDebug::Print(_L("Value=%S\r\n"), &p);
|
sl@0
|
237 |
stmt.Close();
|
sl@0
|
238 |
|
sl@0
|
239 |
NonSecureDbTest();
|
sl@0
|
240 |
|
sl@0
|
241 |
TheDb.Close();
|
sl@0
|
242 |
}
|
sl@0
|
243 |
|
sl@0
|
244 |
/**
|
sl@0
|
245 |
@SYMTestCaseID SYSLIB-SQL-UT-4097
|
sl@0
|
246 |
@SYMTestCaseDesc Testing incremental blob reads and writes on a secure database.
|
sl@0
|
247 |
The test application's capabilities allow read and write access to the blobs.
|
sl@0
|
248 |
Verify that both reads and writes are allowed.
|
sl@0
|
249 |
@SYMTestPriority Medium
|
sl@0
|
250 |
@SYMTestActions Testing incremental blob reads and writes on a secure database.
|
sl@0
|
251 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
252 |
@SYMREQ REQ5794
|
sl@0
|
253 |
*/
|
sl@0
|
254 |
void ReadWriteBlobTestL()
|
sl@0
|
255 |
{
|
sl@0
|
256 |
// Current database data:
|
sl@0
|
257 |
// TABLE A: {1, x'41414141414141414141'}, {2, x'42424242424242424242'}, {3, x'43434343434343434343'}, {4, x'44444444444444444444'}
|
sl@0
|
258 |
// TABLE B: {4, "DEF", x'46464646464646464646'} <- ROWID = 2, {2, "ABC", x'45454545454545454545'} <- ROWID = 3, {6, "GHI", x'47474747474747474747'} <- ROWID = 4
|
sl@0
|
259 |
|
sl@0
|
260 |
RSqlDatabase db;
|
sl@0
|
261 |
TInt err = TheDb.Open(KTestDbName);
|
sl@0
|
262 |
TEST2(err, KErrNone);
|
sl@0
|
263 |
|
sl@0
|
264 |
// Attempt to read the blobs in tables A and B
|
sl@0
|
265 |
RSqlBlobReadStream rdStrm;
|
sl@0
|
266 |
CleanupClosePushL(rdStrm);
|
sl@0
|
267 |
TBuf8<20> data;
|
sl@0
|
268 |
TRAP(err, rdStrm.OpenL(TheDb, _L("A"), _L("B1"), 1));
|
sl@0
|
269 |
TEST2(err, KErrNone);
|
sl@0
|
270 |
TRAP(err, rdStrm.ReadL(data, 3));
|
sl@0
|
271 |
TEST2(err, KErrNone);
|
sl@0
|
272 |
TEST(data.Compare(_L8("AAA")) == 0);
|
sl@0
|
273 |
rdStrm.Close();
|
sl@0
|
274 |
TRAP(err, rdStrm.OpenL(TheDb, _L("B"), _L("B2"), 3));
|
sl@0
|
275 |
TEST2(err, KErrNone);
|
sl@0
|
276 |
TRAP(err, rdStrm.ReadL(data, 10));
|
sl@0
|
277 |
TEST2(err, KErrNone);
|
sl@0
|
278 |
TEST(data.Compare(_L8("EEEEEEEEEE")) == 0);
|
sl@0
|
279 |
CleanupStack::PopAndDestroy(&rdStrm);
|
sl@0
|
280 |
|
sl@0
|
281 |
HBufC8* wholeBuf = TSqlBlob::GetLC(TheDb, _L("A"), _L("B1"), 4);
|
sl@0
|
282 |
TEST(wholeBuf->Des().Compare(_L8("DDDDDDDDDD")) == 0);
|
sl@0
|
283 |
CleanupStack::PopAndDestroy(wholeBuf);
|
sl@0
|
284 |
wholeBuf = TSqlBlob::GetLC(TheDb, _L("B"), _L("B2"), 2);
|
sl@0
|
285 |
TEST(wholeBuf->Des().Compare(_L8("FFFFFFFFFF")) == 0);
|
sl@0
|
286 |
CleanupStack::PopAndDestroy(wholeBuf);
|
sl@0
|
287 |
|
sl@0
|
288 |
HBufC8* buf = HBufC8::NewLC(10);
|
sl@0
|
289 |
TPtr8 bufPtr(buf->Des());
|
sl@0
|
290 |
err = TSqlBlob::Get(TheDb, _L("A"), _L("B1"), bufPtr, 2);
|
sl@0
|
291 |
TEST2(err, KErrNone);
|
sl@0
|
292 |
TEST(bufPtr.Compare(_L8("BBBBBBBBBB")) == 0);
|
sl@0
|
293 |
err = TSqlBlob::Get(TheDb, _L("B"), _L("B2"), bufPtr, 4);
|
sl@0
|
294 |
TEST2(err, KErrNone);
|
sl@0
|
295 |
TEST(bufPtr.Compare(_L8("GGGGGGGGGG")) == 0);
|
sl@0
|
296 |
CleanupStack::PopAndDestroy(buf);
|
sl@0
|
297 |
|
sl@0
|
298 |
// Attempt to write the blobs in tables A and B
|
sl@0
|
299 |
RSqlBlobWriteStream wrStrm;
|
sl@0
|
300 |
CleanupClosePushL(wrStrm);
|
sl@0
|
301 |
TRAP(err, wrStrm.OpenL(TheDb, _L("A"), _L("B1"), 1));
|
sl@0
|
302 |
TEST2(err, KErrNone);
|
sl@0
|
303 |
TRAP(err, wrStrm.WriteL(_L8("ZZZ")));
|
sl@0
|
304 |
TEST2(err, KErrNone);
|
sl@0
|
305 |
wrStrm.Close();
|
sl@0
|
306 |
TRAP(err, wrStrm.OpenL(TheDb, _L("B"), _L("B2"), 2));
|
sl@0
|
307 |
TEST2(err, KErrNone);
|
sl@0
|
308 |
TRAP(err, wrStrm.WriteL(_L8("XXXXXXXXX")));
|
sl@0
|
309 |
TEST2(err, KErrNone);
|
sl@0
|
310 |
CleanupStack::PopAndDestroy(&wrStrm);
|
sl@0
|
311 |
|
sl@0
|
312 |
TRAP(err, TSqlBlob::SetL(TheDb, _L("A"), _L("B1"), _L8("UUUUUUUU"), 4));
|
sl@0
|
313 |
TEST2(err, KErrNone);
|
sl@0
|
314 |
TRAP(err, TSqlBlob::SetL(TheDb, _L("B"), _L("B2"), _L8("TT"), 2));
|
sl@0
|
315 |
TEST2(err, KErrNone);
|
sl@0
|
316 |
|
sl@0
|
317 |
// SQLite and system tables
|
sl@0
|
318 |
|
sl@0
|
319 |
// Attempt to read from and write to the SQLite master table -
|
sl@0
|
320 |
// reads should be permitted because read capability is enough for this,
|
sl@0
|
321 |
// writes should not be permitted because schema capability is required for this
|
sl@0
|
322 |
CleanupClosePushL(rdStrm);
|
sl@0
|
323 |
TRAP(err, rdStrm.OpenL(TheDb, _L("sqlite_master"), _L("tbl_name"), 1)); // TEXT column
|
sl@0
|
324 |
TEST2(err, KErrNone);
|
sl@0
|
325 |
TRAP(err, rdStrm.ReadL(data, 1));
|
sl@0
|
326 |
TEST2(err, KErrNone);
|
sl@0
|
327 |
CleanupStack::PopAndDestroy(&rdStrm);
|
sl@0
|
328 |
|
sl@0
|
329 |
wholeBuf = TSqlBlob::GetLC(TheDb, _L("sqlite_master"), _L("tbl_name"), 1);
|
sl@0
|
330 |
TEST(wholeBuf->Length() > 0);
|
sl@0
|
331 |
CleanupStack::PopAndDestroy(wholeBuf);
|
sl@0
|
332 |
|
sl@0
|
333 |
buf = HBufC8::NewLC(100);
|
sl@0
|
334 |
bufPtr.Set(buf->Des());
|
sl@0
|
335 |
err = TSqlBlob::Get(TheDb, _L("sqlite_master"), _L("tbl_name"), bufPtr, 1);
|
sl@0
|
336 |
TEST2(err, KErrNone);
|
sl@0
|
337 |
TEST(bufPtr.Length() > 0);
|
sl@0
|
338 |
CleanupStack::PopAndDestroy(buf);
|
sl@0
|
339 |
|
sl@0
|
340 |
CleanupClosePushL(wrStrm);
|
sl@0
|
341 |
TRAP(err, wrStrm.OpenL(TheDb, _L("sqlite_master"), _L("tbl_name"), 1));
|
sl@0
|
342 |
TEST2(err, KErrPermissionDenied);
|
sl@0
|
343 |
CleanupStack::PopAndDestroy(&wrStrm);
|
sl@0
|
344 |
|
sl@0
|
345 |
TRAP(err, TSqlBlob::SetL(TheDb, _L("sqlite_master"), _L("tbl_name"), _L8("VVVV"), 1));
|
sl@0
|
346 |
TEST2(err, KErrPermissionDenied);
|
sl@0
|
347 |
|
sl@0
|
348 |
// Attempt to read from and write to the system tables - neither reads nor writes should be permitted
|
sl@0
|
349 |
CleanupClosePushL(rdStrm);
|
sl@0
|
350 |
TRAP(err, rdStrm.OpenL(TheDb, _L("symbian_security"), _L("PolicyData"), 1)); // BLOB column
|
sl@0
|
351 |
TEST2(err, KErrPermissionDenied);
|
sl@0
|
352 |
CleanupStack::PopAndDestroy(&rdStrm);
|
sl@0
|
353 |
|
sl@0
|
354 |
TRAP(err, wholeBuf = TSqlBlob::GetLC(TheDb, _L("symbian_security"), _L("PolicyData"), 1));
|
sl@0
|
355 |
TEST2(err, KErrPermissionDenied);
|
sl@0
|
356 |
|
sl@0
|
357 |
buf = HBufC8::NewLC(100);
|
sl@0
|
358 |
bufPtr.Set(buf->Des());
|
sl@0
|
359 |
err = TSqlBlob::Get(TheDb, _L("symbian_security"), _L("PolicyData"), bufPtr, 1);
|
sl@0
|
360 |
TEST2(err, KErrPermissionDenied);
|
sl@0
|
361 |
CleanupStack::PopAndDestroy(buf);
|
sl@0
|
362 |
|
sl@0
|
363 |
CleanupClosePushL(wrStrm);
|
sl@0
|
364 |
TRAP(err, wrStrm.OpenL(TheDb, _L("symbian_security"), _L("PolicyData"), 1));
|
sl@0
|
365 |
TEST2(err, KErrPermissionDenied);
|
sl@0
|
366 |
CleanupStack::PopAndDestroy(&wrStrm);
|
sl@0
|
367 |
|
sl@0
|
368 |
TRAP(err, TSqlBlob::SetL(TheDb, _L("symbian_security"), _L("PolicyData"), _L8("VVVV"), 1));
|
sl@0
|
369 |
TEST2(err, KErrPermissionDenied);
|
sl@0
|
370 |
|
sl@0
|
371 |
TheDb.Close();
|
sl@0
|
372 |
}
|
sl@0
|
373 |
|
sl@0
|
374 |
void DoTestsL()
|
sl@0
|
375 |
{
|
sl@0
|
376 |
TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1646 Read-write database access test "));
|
sl@0
|
377 |
ReadWriteDatabaseTest();
|
sl@0
|
378 |
|
sl@0
|
379 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4097 Read-write blob access test"));
|
sl@0
|
380 |
ReadWriteBlobTestL();
|
sl@0
|
381 |
|
sl@0
|
382 |
RestoreOriginalDb(); // the same db is used by the other t_security test exe's
|
sl@0
|
383 |
}
|
sl@0
|
384 |
|
sl@0
|
385 |
TInt E32Main()
|
sl@0
|
386 |
{
|
sl@0
|
387 |
TheTest.Title();
|
sl@0
|
388 |
|
sl@0
|
389 |
CTrapCleanup* tc = CTrapCleanup::New();
|
sl@0
|
390 |
|
sl@0
|
391 |
__UHEAP_MARK;
|
sl@0
|
392 |
|
sl@0
|
393 |
TRAPD(err, DoTestsL());
|
sl@0
|
394 |
TEST2(err, KErrNone);
|
sl@0
|
395 |
|
sl@0
|
396 |
__UHEAP_MARKEND;
|
sl@0
|
397 |
|
sl@0
|
398 |
TheTest.End();
|
sl@0
|
399 |
TheTest.Close();
|
sl@0
|
400 |
|
sl@0
|
401 |
delete tc;
|
sl@0
|
402 |
|
sl@0
|
403 |
User::Heap().Check();
|
sl@0
|
404 |
return KErrNone;
|
sl@0
|
405 |
}
|