os/persistentdata/persistentstorage/sql/TEST/t_sqlsecurity1.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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
//
sl@0
    15
sl@0
    16
#include <e32test.h>
sl@0
    17
#include <bautils.h>
sl@0
    18
#include <sqldb.h>
sl@0
    19
#include <s32file.h>
sl@0
    20
sl@0
    21
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    22
sl@0
    23
#define UNUSED_VAR(a) (a) = (a)
sl@0
    24
sl@0
    25
RTest TheTest(_L("t_sqlsecurity1 test"));
sl@0
    26
sl@0
    27
_LIT(KTestDir, "c:\\test\\");
sl@0
    28
_LIT(KTestDbName, "c:[98765432]t_sqlsecurity1_1.db");
sl@0
    29
_LIT(KTestDbName2, "c:\\test\\t_sqlsecurity1_2.db");
sl@0
    30
_LIT(KTestDbName3, "c:[98765432]t_sqlsecurity1_3.db");
sl@0
    31
_LIT(KTestDbName4, "c:\\private\\98765432\\t_sqlsecurity1_4.db");
sl@0
    32
_LIT(KTestDbName5, "|00110022|33005500|c:");
sl@0
    33
_LIT(KTestFile, "c:\\test\\policy.strm");
sl@0
    34
sl@0
    35
_LIT(KDb1, "C:[98765432]t_nosettings.db");
sl@0
    36
_LIT(KDb2, "C:[98765432]t_emptysettings.db");
sl@0
    37
_LIT(KDb3, "C:[98765432]t_invversion.db");
sl@0
    38
_LIT(KDb4, "C:[98765432]t_nocollation.db");
sl@0
    39
_LIT(KDb5, "C:[98765432]t_longcollation.db");
sl@0
    40
_LIT(KDb6, "C:[98765432]t_nodefaultpolicy.db");
sl@0
    41
_LIT(KDb7, "C:[98765432]t_invobject.db");
sl@0
    42
_LIT(KDb8, "C:[98765432]t_2defaultpolicies.db");
sl@0
    43
sl@0
    44
const TSecurityPolicy KDefaultPolicy(ECapabilityDRM);
sl@0
    45
const TSecurityPolicy KPolicy1(ECapabilityTrustedUI, ECapabilityDiskAdmin);
sl@0
    46
const TSecurityPolicy KPolicy2(ECapabilityNetworkControl, ECapabilityPowerMgmt, ECapabilityCommDD);
sl@0
    47
const TSecurityPolicy KPolicy3(ECapabilityTCB, ECapabilityWriteUserData, ECapabilityUserEnvironment);
sl@0
    48
sl@0
    49
_LIT(KTableName1, "A-tbl");
sl@0
    50
_LIT(KTableName2, "B-table");
sl@0
    51
_LIT(KTableName3, "T-CCCCCCCCCCCCCC");
sl@0
    52
_LIT(KTableName11, "A-TBL");
sl@0
    53
sl@0
    54
RFs TheFs;
sl@0
    55
sl@0
    56
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    57
sl@0
    58
void DeleteTestFiles()
sl@0
    59
	{
sl@0
    60
	(void)TheFs.Delete(KTestFile);
sl@0
    61
	(void)RSqlDatabase::Delete(KTestDbName4);
sl@0
    62
	(void)RSqlDatabase::Delete(KTestDbName3);
sl@0
    63
	(void)RSqlDatabase::Delete(KTestDbName2);
sl@0
    64
	(void)RSqlDatabase::Delete(KTestDbName);
sl@0
    65
	}
sl@0
    66
sl@0
    67
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    68
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    69
//Test macros and functions
sl@0
    70
void Check1(TInt aValue, TInt aLine, TBool aPrintThreadName = EFalse)
sl@0
    71
	{
sl@0
    72
	if(!aValue)
sl@0
    73
		{
sl@0
    74
		DeleteTestFiles();
sl@0
    75
		if(aPrintThreadName)
sl@0
    76
			{
sl@0
    77
			RThread th;
sl@0
    78
			TName name = th.Name();
sl@0
    79
			RDebug::Print(_L("*** Thread %S, Line %d\r\n"), &name, aLine);
sl@0
    80
			}
sl@0
    81
		else
sl@0
    82
			{
sl@0
    83
			RDebug::Print(_L("*** Line %d\r\n"), aLine);
sl@0
    84
			}
sl@0
    85
		TheTest(EFalse, aLine);
sl@0
    86
		}
sl@0
    87
	}
sl@0
    88
void Check2(TInt aValue, TInt aExpected, TInt aLine, TBool aPrintThreadName = EFalse)
sl@0
    89
	{
sl@0
    90
	if(aValue != aExpected)
sl@0
    91
		{
sl@0
    92
		DeleteTestFiles();
sl@0
    93
		if(aPrintThreadName)
sl@0
    94
			{
sl@0
    95
			RThread th;
sl@0
    96
			TName name = th.Name();
sl@0
    97
			RDebug::Print(_L("*** Thread %S, Line %d Expected error: %d, got: %d\r\n"), &name, aLine, aExpected, aValue);
sl@0
    98
			}
sl@0
    99
		else
sl@0
   100
			{
sl@0
   101
			RDebug::Print(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue);
sl@0
   102
			}
sl@0
   103
		TheTest(EFalse, aLine);
sl@0
   104
		}
sl@0
   105
	}
sl@0
   106
#define TEST(arg) ::Check1((arg), __LINE__)
sl@0
   107
#define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
sl@0
   108
#define TTEST(arg) ::Check1((arg), __LINE__, ETrue)
sl@0
   109
#define TTEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__, ETrue)
sl@0
   110
sl@0
   111
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   112
sl@0
   113
void CreateTestEnv()
sl@0
   114
    {
sl@0
   115
	TInt err = TheFs.Connect();
sl@0
   116
	TEST2(err, KErrNone);
sl@0
   117
sl@0
   118
	err = TheFs.MkDir(KTestDir);
sl@0
   119
	TEST(err == KErrNone || err == KErrAlreadyExists);
sl@0
   120
sl@0
   121
	err = TheFs.CreatePrivatePath(EDriveC);
sl@0
   122
	TEST(err == KErrNone || err == KErrAlreadyExists);
sl@0
   123
	}
sl@0
   124
sl@0
   125
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   126
sl@0
   127
TBool operator==(const TSecurityPolicy& aLeft, const TSecurityPolicy& aRight)
sl@0
   128
	{
sl@0
   129
	return aLeft.Package() == aRight.Package();
sl@0
   130
	}
sl@0
   131
sl@0
   132
void CreateTestSecurityPolicy(RSqlSecurityPolicy& aSecurityPolicy)
sl@0
   133
	{
sl@0
   134
	TInt err = aSecurityPolicy.Create(KDefaultPolicy);
sl@0
   135
	TEST2(err, KErrNone);
sl@0
   136
sl@0
   137
	err = aSecurityPolicy.SetDbPolicy(RSqlSecurityPolicy::ESchemaPolicy, KPolicy1);
sl@0
   138
	TEST2(err, KErrNone);
sl@0
   139
	err = aSecurityPolicy.SetDbPolicy(RSqlSecurityPolicy::EWritePolicy, KPolicy3);
sl@0
   140
	TEST2(err, KErrNone);
sl@0
   141
sl@0
   142
	err = aSecurityPolicy.SetPolicy(RSqlSecurityPolicy::ETable, KTableName1, RSqlSecurityPolicy::EReadPolicy, KPolicy1);
sl@0
   143
	TEST2(err, KErrNone);
sl@0
   144
	err = aSecurityPolicy.SetPolicy(RSqlSecurityPolicy::ETable, KTableName1, RSqlSecurityPolicy::EWritePolicy, KPolicy2);
sl@0
   145
	TEST2(err, KErrNone);
sl@0
   146
sl@0
   147
	err = aSecurityPolicy.SetPolicy(RSqlSecurityPolicy::ETable, KTableName2, RSqlSecurityPolicy::EReadPolicy, KPolicy1);
sl@0
   148
	TEST2(err, KErrNone);
sl@0
   149
	err = aSecurityPolicy.SetPolicy(RSqlSecurityPolicy::ETable, KTableName3, RSqlSecurityPolicy::EReadPolicy, KPolicy2);
sl@0
   150
	TEST2(err, KErrNone);
sl@0
   151
sl@0
   152
	err = aSecurityPolicy.SetPolicy(RSqlSecurityPolicy::ETable, KTableName2, RSqlSecurityPolicy::EWritePolicy, KPolicy1);
sl@0
   153
	TEST2(err, KErrNone);
sl@0
   154
sl@0
   155
	err = aSecurityPolicy.SetPolicy(RSqlSecurityPolicy::ETable, KTableName3, RSqlSecurityPolicy::EWritePolicy, KPolicy3);
sl@0
   156
	TEST2(err, KErrNone);
sl@0
   157
	}
sl@0
   158
sl@0
   159
void CheckTestSecurityPolicy(const RSqlSecurityPolicy& aSecurityPolicy)
sl@0
   160
	{
sl@0
   161
	//Database policies
sl@0
   162
	TSecurityPolicy policy = aSecurityPolicy.DbPolicy(RSqlSecurityPolicy::ESchemaPolicy);
sl@0
   163
	TEST(policy == KPolicy1);
sl@0
   164
	policy = aSecurityPolicy.DbPolicy(RSqlSecurityPolicy::EReadPolicy);
sl@0
   165
	TEST(policy == KDefaultPolicy);
sl@0
   166
	policy = aSecurityPolicy.DbPolicy(RSqlSecurityPolicy::EWritePolicy);
sl@0
   167
	TEST(policy == KPolicy3);
sl@0
   168
	//Table  policies
sl@0
   169
	policy = aSecurityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName11, RSqlSecurityPolicy::EReadPolicy);
sl@0
   170
	TEST(policy == KPolicy1);
sl@0
   171
	policy = aSecurityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName2, RSqlSecurityPolicy::EReadPolicy);
sl@0
   172
	TEST(policy == KPolicy1);
sl@0
   173
	policy = aSecurityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName3, RSqlSecurityPolicy::EReadPolicy);
sl@0
   174
	TEST(policy == KPolicy2);
sl@0
   175
	policy = aSecurityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName1, RSqlSecurityPolicy::EWritePolicy);
sl@0
   176
	TEST(policy == KPolicy2);
sl@0
   177
	policy = aSecurityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName3, RSqlSecurityPolicy::EWritePolicy);
sl@0
   178
	TEST(policy == KPolicy3);
sl@0
   179
	policy = aSecurityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName2, RSqlSecurityPolicy::EWritePolicy);
sl@0
   180
	TEST(policy == KPolicy1);
sl@0
   181
	}
sl@0
   182
sl@0
   183
/**
sl@0
   184
@SYMTestCaseID			SYSLIB-SQL-CT-1635
sl@0
   185
@SYMTestCaseDesc		RSqlSecurityPolicy test.
sl@0
   186
						Tests RSqlSecurityPolicy API.
sl@0
   187
@SYMTestPriority		High
sl@0
   188
@SYMTestActions			RSqlSecurityPolicy test.
sl@0
   189
@SYMTestExpectedResults Test must not fail
sl@0
   190
@SYMREQ					REQ5792
sl@0
   191
                        REQ5793
sl@0
   192
*/
sl@0
   193
void SqlSecurityPolicyTest()
sl@0
   194
	{
sl@0
   195
	RSqlSecurityPolicy securityPolicy;
sl@0
   196
	TInt err = securityPolicy.Create(KDefaultPolicy);
sl@0
   197
	TEST2(err, KErrNone);
sl@0
   198
sl@0
   199
	//Empty RSqlSecurityPolicy object tests
sl@0
   200
		//Database policies
sl@0
   201
	TSecurityPolicy policy = securityPolicy.DbPolicy(RSqlSecurityPolicy::ESchemaPolicy);
sl@0
   202
	TEST(policy == KDefaultPolicy);
sl@0
   203
	policy = securityPolicy.DbPolicy(RSqlSecurityPolicy::EReadPolicy);
sl@0
   204
	TEST(policy == KDefaultPolicy);
sl@0
   205
	policy = securityPolicy.DbPolicy(RSqlSecurityPolicy::EWritePolicy);
sl@0
   206
	TEST(policy == KDefaultPolicy);
sl@0
   207
		//Table policies
sl@0
   208
	policy = securityPolicy.Policy(RSqlSecurityPolicy::ETable, _L("A-Tbl"), RSqlSecurityPolicy::EReadPolicy);
sl@0
   209
	TEST(policy == KDefaultPolicy);
sl@0
   210
	policy = securityPolicy.Policy(RSqlSecurityPolicy::ETable, _L("B-Tbl"), RSqlSecurityPolicy::EWritePolicy);
sl@0
   211
	TEST(policy == KDefaultPolicy);
sl@0
   212
		//
sl@0
   213
	securityPolicy.Close();
sl@0
   214
sl@0
   215
	//Tests with initialized RSqlSecurityPolicy object
sl@0
   216
	CreateTestSecurityPolicy(securityPolicy);
sl@0
   217
	//Check the created and initialized object
sl@0
   218
	CheckTestSecurityPolicy(securityPolicy);
sl@0
   219
sl@0
   220
	//Externalize, then internalize and check the security policy object
sl@0
   221
	RFileWriteStream out;
sl@0
   222
	err = out.Replace(TheFs, KTestFile, EFileRead | EFileWrite);
sl@0
   223
	TEST2(err, KErrNone);
sl@0
   224
	TRAP(err, securityPolicy.ExternalizeL(out));
sl@0
   225
	TEST2(err, KErrNone);
sl@0
   226
	TRAP(err, out.CommitL());
sl@0
   227
	out.Close();
sl@0
   228
	TEST2(err, KErrNone);
sl@0
   229
sl@0
   230
	securityPolicy.Close();
sl@0
   231
	err = securityPolicy.Create(KDefaultPolicy);
sl@0
   232
	TEST2(err, KErrNone);
sl@0
   233
	RFileReadStream in;
sl@0
   234
	err = in.Open(TheFs, KTestFile, EFileRead);
sl@0
   235
	TEST2(err, KErrNone);
sl@0
   236
	TRAP(err, securityPolicy.InternalizeL(in));
sl@0
   237
	in.Close();
sl@0
   238
	TEST2(err, KErrNone);
sl@0
   239
	CheckTestSecurityPolicy(securityPolicy);
sl@0
   240
sl@0
   241
	//Change some security policies and check that the RqlSecurityPolicy content was properly updated
sl@0
   242
	err = securityPolicy.SetPolicy(RSqlSecurityPolicy::ETable, KTableName11, RSqlSecurityPolicy::EReadPolicy, KPolicy3);
sl@0
   243
	TEST2(err, KErrNone);
sl@0
   244
	policy = securityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName1, RSqlSecurityPolicy::EReadPolicy);
sl@0
   245
	TEST(policy == KPolicy3);
sl@0
   246
	policy = securityPolicy.Policy(RSqlSecurityPolicy::ETable, KTableName11, RSqlSecurityPolicy::EWritePolicy);
sl@0
   247
	TEST(policy == KPolicy2);
sl@0
   248
	//
sl@0
   249
	securityPolicy.Close();
sl@0
   250
	}
sl@0
   251
sl@0
   252
/**
sl@0
   253
@SYMTestCaseID			SYSLIB-SQL-CT-1637
sl@0
   254
@SYMTestCaseDesc		RSqlDatabase::Create() test.
sl@0
   255
						Tests RSqlDatabase::Create() call when the request is for creation of a secure database.
sl@0
   256
@SYMTestPriority		High
sl@0
   257
@SYMTestActions			RSqlDatabase::Create() test.
sl@0
   258
@SYMTestExpectedResults Test must not fail
sl@0
   259
@SYMREQ					REQ5792
sl@0
   260
                        REQ5793
sl@0
   261
*/
sl@0
   262
void CreateSecureDatabaseTest()
sl@0
   263
	{
sl@0
   264
	RSqlSecurityPolicy securityPolicy;
sl@0
   265
sl@0
   266
	//Create and initialize RSqlSecurityPolicy object.
sl@0
   267
	CreateTestSecurityPolicy(securityPolicy);
sl@0
   268
sl@0
   269
	//Create secure database using the data from securityPolicy object.
sl@0
   270
	RSqlDatabase db;
sl@0
   271
	TInt err = db.Create(KTestDbName, securityPolicy);
sl@0
   272
	TEST2(err, KErrNone);
sl@0
   273
	securityPolicy.Close();
sl@0
   274
sl@0
   275
	//Check that the database security policy matches the policy used when the database was created.
sl@0
   276
	err = db.GetSecurityPolicy(securityPolicy);
sl@0
   277
	TEST2(err, KErrNone);
sl@0
   278
	CheckTestSecurityPolicy(securityPolicy);
sl@0
   279
	securityPolicy.Close();
sl@0
   280
sl@0
   281
	db.Close();
sl@0
   282
sl@0
   283
	//Reopen the database and check the security policies
sl@0
   284
	err = db.Open(KTestDbName);
sl@0
   285
	TEST2(err, KErrNone);
sl@0
   286
sl@0
   287
	//Check that the database security policy matches the policy used when the database was created.
sl@0
   288
	err = db.GetSecurityPolicy(securityPolicy);
sl@0
   289
	TEST2(err, KErrNone);
sl@0
   290
	CheckTestSecurityPolicy(securityPolicy);
sl@0
   291
	securityPolicy.Close();
sl@0
   292
sl@0
   293
	db.Close();
sl@0
   294
sl@0
   295
	err = RSqlDatabase::Delete(KTestDbName);
sl@0
   296
	TEST2(err, KErrNone);
sl@0
   297
sl@0
   298
	//An attempt to create a secure database specifying the full database path
sl@0
   299
	CreateTestSecurityPolicy(securityPolicy);
sl@0
   300
	err = db.Create(KTestDbName2, securityPolicy);
sl@0
   301
	securityPolicy.Close();
sl@0
   302
	TEST2(err, KErrArgument);
sl@0
   303
sl@0
   304
	//An attempt to create a non-secure database formatting the database file name as <drive:><dbFileName>
sl@0
   305
	err = db.Create(KTestDbName);
sl@0
   306
	TEST2(err, KErrArgument);
sl@0
   307
	}
sl@0
   308
sl@0
   309
/**
sl@0
   310
@SYMTestCaseID			SYSLIB-SQL-CT-1643
sl@0
   311
@SYMTestCaseDesc		SQL server private path in database file name test.
sl@0
   312
						Verify that SQL API returns appropriate error, if an attempt is made to create, open
sl@0
   313
						or delete a secure database, with the full path specified in the database file name.
sl@0
   314
@SYMTestPriority		High
sl@0
   315
@SYMTestActions			SQL server private path in database file name test.
sl@0
   316
@SYMTestExpectedResults Test must not fail
sl@0
   317
@SYMREQ					REQ5792
sl@0
   318
                        REQ5793
sl@0
   319
*/
sl@0
   320
void PrivatePathTest()
sl@0
   321
	{
sl@0
   322
	RSqlSecurityPolicy securityPolicy;
sl@0
   323
	CreateTestSecurityPolicy(securityPolicy);
sl@0
   324
sl@0
   325
	RSqlDatabase db;
sl@0
   326
sl@0
   327
	TInt err = db.Create(_L("C:\\PrIVATE\\10281E17\\[98765432]A.DB"), securityPolicy);
sl@0
   328
	TEST2(err, KErrArgument);
sl@0
   329
	err = db.Create(_L("C:\\PRIVATE\\10281E17\\[98765432]A.DB"));
sl@0
   330
	TEST2(err, KErrArgument);
sl@0
   331
	err = db.Open(_L("C:\\PRIVATE\\10281E17\\[98765432]A.DB"));
sl@0
   332
	TEST2(err, KErrArgument);
sl@0
   333
	err = db.Open(_L("C:\\PRIvaTe\\10281E17\\[98765432]A.DB"));
sl@0
   334
	TEST2(err, KErrArgument);
sl@0
   335
sl@0
   336
	err = db.Create(KTestDbName2);
sl@0
   337
	TEST2(err, KErrNone);
sl@0
   338
	err = db.Attach(_L("C:\\PRIVATe\\10281E17\\[98765432]A.DB"), _L("Db"));
sl@0
   339
	TEST2(err, KErrArgument);
sl@0
   340
	err = db.Attach(_L("C:\\PRIVAtE\\10281E17\\[98765432]A.DB"), _L("Db"));
sl@0
   341
	TEST2(err, KErrArgument);
sl@0
   342
	//This is an attempt to attach a database from the application's private data cage
sl@0
   343
	err = db.Attach(KTestDbName4, _L("Db"));
sl@0
   344
	TEST2(err, KErrNotFound);//There is no "Db" database file in the application's private data cage
sl@0
   345
	db.Close();
sl@0
   346
sl@0
   347
	err = RSqlDatabase::Delete(_L("C:\\pRIVATE\\10281E17\\[98765432]A.DB"));
sl@0
   348
	TEST2(err, KErrArgument);
sl@0
   349
	err = RSqlDatabase::Delete(_L("C:\\PRIvATE\\10281E17\\[98765432]A.DB"));
sl@0
   350
	TEST2(err, KErrArgument);
sl@0
   351
sl@0
   352
	//This is an attempt to create a database in the application's private data cage
sl@0
   353
	err = db.Create(KTestDbName4);
sl@0
   354
	TEST2(err, KErrNone);
sl@0
   355
	db.Close();
sl@0
   356
	err = RSqlDatabase::Delete(KTestDbName4);
sl@0
   357
	TEST2(err, KErrNone);
sl@0
   358
sl@0
   359
	err = db.Create(KTestDbName5);
sl@0
   360
	TEST2(err, KErrArgument);
sl@0
   361
sl@0
   362
	securityPolicy.Close();
sl@0
   363
	}
sl@0
   364
sl@0
   365
//This test is here to check that the construction of the second database object on the server side passes
sl@0
   366
//without problems, if there is already one other secure database object (authorizer callback possible problems
sl@0
   367
//during the construction phase)
sl@0
   368
//Shortly: the test checks how the construction of the secure database object 2 might be influenced by
sl@0
   369
//         the already existing secure database object 1.
sl@0
   370
void TwoSecureDbTest()
sl@0
   371
	{
sl@0
   372
	RSqlSecurityPolicy securityPolicy;
sl@0
   373
	CreateTestSecurityPolicy(securityPolicy);
sl@0
   374
sl@0
   375
	RSqlDatabase db1;
sl@0
   376
	TInt err = db1.Create(KTestDbName, securityPolicy);
sl@0
   377
	TEST2(err, KErrNone);
sl@0
   378
sl@0
   379
	RSqlDatabase db2;
sl@0
   380
	err = db2.Create(KTestDbName3, securityPolicy);
sl@0
   381
	TEST2(err, KErrNone);
sl@0
   382
sl@0
   383
	securityPolicy.Close();
sl@0
   384
	db2.Close();
sl@0
   385
	db1.Close();
sl@0
   386
	}
sl@0
   387
sl@0
   388
/**
sl@0
   389
@SYMTestCaseID			SYSLIB-SQL-UT-3508
sl@0
   390
@SYMTestCaseDesc		Test for DEF109100: SQL, code coverage for TSqlDbSysSettings is low.
sl@0
   391
						The test attempts to create a secure shared database with a security policy
sl@0
   392
						specified for the system tables, which is not allowed.
sl@0
   393
@SYMTestPriority		High
sl@0
   394
@SYMTestActions			Test for DEF109100: SQL, code coverage for TSqlDbSysSettings is low.
sl@0
   395
@SYMTestExpectedResults Test must not fail
sl@0
   396
@SYMDEF					DEF109100
sl@0
   397
*/
sl@0
   398
void StoreSysTableSecurityPolicyTest()
sl@0
   399
	{
sl@0
   400
	_LIT(KSecurityTable, "symbian_security");
sl@0
   401
	_LIT(KSettingsTable, "symbian_settings");
sl@0
   402
sl@0
   403
	//Case 1: "symbian_security" table
sl@0
   404
	RSqlSecurityPolicy sp;
sl@0
   405
	TInt err = sp.Create(KDefaultPolicy);
sl@0
   406
	TEST2(err, KErrNone);
sl@0
   407
	err = sp.SetDbPolicy(RSqlSecurityPolicy::ESchemaPolicy, KPolicy1);
sl@0
   408
	TEST2(err, KErrNone);
sl@0
   409
	err = sp.SetPolicy(RSqlSecurityPolicy::ETable, KSecurityTable, RSqlSecurityPolicy::EReadPolicy, KPolicy1);
sl@0
   410
	TEST2(err, KErrNone);
sl@0
   411
	(void)RSqlDatabase::Delete(KTestDbName);
sl@0
   412
	RSqlDatabase db;
sl@0
   413
	err = db.Create(KTestDbName, sp);
sl@0
   414
	TEST2(err, KErrArgument);
sl@0
   415
	sp.Close();
sl@0
   416
sl@0
   417
	//Case 2: "symbian_settings" table
sl@0
   418
	err = sp.Create(KDefaultPolicy);
sl@0
   419
	TEST2(err, KErrNone);
sl@0
   420
	err = sp.SetDbPolicy(RSqlSecurityPolicy::ESchemaPolicy, KPolicy1);
sl@0
   421
	TEST2(err, KErrNone);
sl@0
   422
	err = sp.SetPolicy(RSqlSecurityPolicy::ETable, KSettingsTable, RSqlSecurityPolicy::EReadPolicy, KPolicy1);
sl@0
   423
	TEST2(err, KErrNone);
sl@0
   424
	err = RSqlDatabase::Delete(KTestDbName);
sl@0
   425
	TEST2(err, KErrNotFound);
sl@0
   426
	err = db.Create(KTestDbName, sp);
sl@0
   427
	TEST2(err, KErrArgument);
sl@0
   428
	sp.Close();
sl@0
   429
sl@0
   430
	err = RSqlDatabase::Delete(KTestDbName);
sl@0
   431
	TEST2(err, KErrNotFound);
sl@0
   432
	}
sl@0
   433
sl@0
   434
/**
sl@0
   435
@SYMTestCaseID			SYSLIB-SQL-UT-3509
sl@0
   436
@SYMTestCaseDesc		Test for DEF109100: SQL, code coverage for TSqlDbSysSettings is low.
sl@0
   437
						The test has 5 sub-cases, where the test attempts to open
sl@0
   438
						a secure shared database with:
sl@0
   439
						- no settings table;
sl@0
   440
						- empty settings table;
sl@0
   441
						- invalid version number of the settings;
sl@0
   442
						- NULL collation dll name, stored in the settings;
sl@0
   443
						- too long collation dll name, stored in the settings;
sl@0
   444
@SYMTestPriority		High
sl@0
   445
@SYMTestActions			Test for DEF109100: SQL, code coverage for TSqlDbSysSettings is low.
sl@0
   446
@SYMTestExpectedResults Test must not fail
sl@0
   447
@SYMDEF					DEF109100
sl@0
   448
*/
sl@0
   449
void LoadSysSettingsTest()
sl@0
   450
	{
sl@0
   451
	//Case 1: no "symbian_settings" table. No error returned, because the table is recreated.
sl@0
   452
	RSqlDatabase db;
sl@0
   453
	TInt err = db.Open(KDb1);
sl@0
   454
	TEST2(err, KErrNone);
sl@0
   455
	db.Close();
sl@0
   456
sl@0
   457
	//Case 2: "symbian_settings" table is empty.
sl@0
   458
	err = db.Open(KDb2);
sl@0
   459
	TEST2(err, KErrGeneral);
sl@0
   460
	db.Close();
sl@0
   461
sl@0
   462
	//Case 3: Invalid version number in "symbian_settings" table.
sl@0
   463
	err = db.Open(KDb3);
sl@0
   464
	TEST2(err, KErrGeneral);
sl@0
   465
	db.Close();
sl@0
   466
sl@0
   467
	//Case 4: NULL collation dll name in "symbian_settings" table.
sl@0
   468
	err = db.Open(KDb4);
sl@0
   469
	TEST2(err, KErrGeneral);
sl@0
   470
	db.Close();
sl@0
   471
sl@0
   472
	//Case 5: Too long collation dll name in "symbian_settings" table.
sl@0
   473
	err = db.Open(KDb5);
sl@0
   474
	TEST2(err, KErrOverflow);
sl@0
   475
	db.Close();
sl@0
   476
	}
sl@0
   477
sl@0
   478
/**
sl@0
   479
@SYMTestCaseID			SYSLIB-SQL-UT-3510
sl@0
   480
@SYMTestCaseDesc		Test for DEF109100: SQL, code coverage for TSqlDbSysSettings is low.
sl@0
   481
						The test has 3 sub-cases, where the test attempts to open
sl@0
   482
						a secure shared database with:
sl@0
   483
						- missing default policy in the security policy table;
sl@0
   484
						- invalid database object type in the security policy table;
sl@0
   485
						- 2 default policies in the security policy table;
sl@0
   486
@SYMTestPriority		High
sl@0
   487
@SYMTestActions			Test for DEF109100: SQL, code coverage for TSqlDbSysSettings is low.
sl@0
   488
@SYMTestExpectedResults Test must not fail
sl@0
   489
@SYMDEF					DEF109100
sl@0
   490
*/
sl@0
   491
void LoadSecurityPolicyTest()
sl@0
   492
	{
sl@0
   493
	//Case 1: missing default policy.
sl@0
   494
	RSqlDatabase db;
sl@0
   495
	TInt err = db.Open(KDb6);
sl@0
   496
	TEST2(err, KErrGeneral);
sl@0
   497
	db.Close();
sl@0
   498
sl@0
   499
	//Case 2: invalid database object type.
sl@0
   500
	err = db.Open(KDb7);
sl@0
   501
	TEST2(err, KErrGeneral);
sl@0
   502
	db.Close();
sl@0
   503
sl@0
   504
	//Case 3: 2 default policies.
sl@0
   505
	err = db.Open(KDb8);
sl@0
   506
	TEST2(err, KErrGeneral);
sl@0
   507
	db.Close();
sl@0
   508
	}
sl@0
   509
sl@0
   510
void DoTests()
sl@0
   511
	{
sl@0
   512
	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1635 RSqlSecurityPolicy test "));
sl@0
   513
	SqlSecurityPolicyTest();
sl@0
   514
sl@0
   515
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1637 Create secure database test "));
sl@0
   516
	CreateSecureDatabaseTest();
sl@0
   517
sl@0
   518
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1643 Sql server private path in the file name test "));
sl@0
   519
	PrivatePathTest();
sl@0
   520
sl@0
   521
	TheTest.Next(_L("Two secure databases at the same time test"));
sl@0
   522
	TwoSecureDbTest();
sl@0
   523
sl@0
   524
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3508 DEF109100 - 1 - SQL, code coverage for TSqlBufRIterator,TSqlAttachDbRefCounter,TSqlDbSysSettings is low "));
sl@0
   525
	StoreSysTableSecurityPolicyTest();
sl@0
   526
sl@0
   527
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3509 DEF109100 - 2 - SQL, code coverage for TSqlBufRIterator,TSqlAttachDbRefCounter,TSqlDbSysSettings is low "));
sl@0
   528
	LoadSysSettingsTest();
sl@0
   529
sl@0
   530
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3510 DEF109100 - 3 - SQL, code coverage for TSqlBufRIterator,TSqlAttachDbRefCounter,TSqlDbSysSettings is low "));
sl@0
   531
	LoadSecurityPolicyTest();
sl@0
   532
	}
sl@0
   533
sl@0
   534
TInt E32Main()
sl@0
   535
	{
sl@0
   536
	TheTest.Title();
sl@0
   537
sl@0
   538
	CTrapCleanup* tc = CTrapCleanup::New();
sl@0
   539
sl@0
   540
	__UHEAP_MARK;
sl@0
   541
sl@0
   542
	CreateTestEnv();
sl@0
   543
	DeleteTestFiles();
sl@0
   544
	DoTests();
sl@0
   545
	DeleteTestFiles();
sl@0
   546
	TheFs.Close();
sl@0
   547
sl@0
   548
	__UHEAP_MARKEND;
sl@0
   549
sl@0
   550
	TheTest.End();
sl@0
   551
	TheTest.Close();
sl@0
   552
sl@0
   553
	delete tc;
sl@0
   554
sl@0
   555
	User::Heap().Check();
sl@0
   556
	return KErrNone;
sl@0
   557
	}