persistentstorage/dbms/tdbms/t_dbplatsec.cpp
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // DBMS security policy - testing new APIs
       
    15 // All tests assume that drive C is presented in the system and is not a ROM drive.
       
    16 // Please, ensure that t_dbenvcreate test is executed before t_dbplatsec<N>/t_dbplatsecperf tests!
       
    17 // Please, ensure that t_dbenvdestroy test is executed after t_dbplatsec<N>/t_dbplatsecperf tests!
       
    18 // 
       
    19 //
       
    20 
       
    21 #include <d32dbms.h>
       
    22 #include <e32test.h>
       
    23 #include "t_dbplatsecdef.h"
       
    24 #include "t_dbplatsecutl.h"
       
    25 #include "t_dbplatsecdb.h"
       
    26 #include "t_dbplatsectbl.h"
       
    27 
       
    28 //Global definitions
       
    29 RTest 				TheTest(_L("t_dbplatsec : DBMS platform security testing"));
       
    30 RDbs 				TheDbs;
       
    31 RDbNamedDatabase 	TheDb1;
       
    32 RDbNamedDatabase 	TheDb2;
       
    33 RDbTable			TheTbl1;
       
    34 RDbTable			TheTbl2;
       
    35 
       
    36 void 		DeleteDatabases();
       
    37 TDBSCUtils 	TheDbscUtils(TheTest, &DeleteDatabases);
       
    38 
       
    39 void DeleteDatabases()
       
    40 	{
       
    41 	TheTbl1.Close();
       
    42 	TheTbl2.Close();
       
    43 	TheDb2.Close();
       
    44 	TheDb1.Close();
       
    45 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
    46 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb2Name);
       
    47 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb3Name);
       
    48 	}
       
    49 
       
    50 static void GetDatabaseRPolicyTest()
       
    51 	{
       
    52 	TSecurityPolicy policy;
       
    53 	TInt err = TheDbs.GetDatabasePolicy(KSecureDbUid, RDbs::EReadPolicy, policy);
       
    54 	TEST2(err, KErrNone);
       
    55 	TCompiledSecurityPolicy testSecurityPolicy(policy);
       
    56 	TSecurityPolicy::TType type = testSecurityPolicy.Type();
       
    57 	TEST(type == TSecurityPolicy::ETypeC3);
       
    58 	TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityCommDD));
       
    59 	TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityPowerMgmt));
       
    60 	TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityTrustedUI));
       
    61 	}
       
    62 
       
    63 static void GetDatabaseWPolicyTest()
       
    64 	{
       
    65 	TSecurityPolicy policy;
       
    66 	TInt err = TheDbs.GetDatabasePolicy(KSecureDbUid, RDbs::EWritePolicy, policy);
       
    67 	TEST2(err, KErrNone);
       
    68 	TCompiledSecurityPolicy testSecurityPolicy(policy);
       
    69 	TSecurityPolicy::TType type = testSecurityPolicy.Type();
       
    70 	TEST(type == TSecurityPolicy::ETypeC3);
       
    71 	TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityMultimediaDD));
       
    72 	TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityReadDeviceData));
       
    73 	TEST(TDBSCUtils::HasCapability(testSecurityPolicy, static_cast <TCapability> (TUint8(ECapability_None))));
       
    74 	}
       
    75 
       
    76 static void GetDatabaseSPolicyTest()
       
    77 	{
       
    78 	TSecurityPolicy policy;
       
    79 	TInt err = TheDbs.GetDatabasePolicy(KSecureDbUid, RDbs::ESchemaPolicy, policy);
       
    80 	TEST2(err, KErrNone);
       
    81 	TCompiledSecurityPolicy testSecurityPolicy(policy);
       
    82 	TSecurityPolicy::TType type = testSecurityPolicy.Type();
       
    83 	TEST(type == TSecurityPolicy::ETypeC7);
       
    84 	TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityWriteDeviceData));
       
    85 	TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityDRM));
       
    86 	TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityProtServ));
       
    87 	TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityDiskAdmin));
       
    88 	TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityNetworkControl));
       
    89 	TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilityWriteUserData));
       
    90 	TEST(TDBSCUtils::HasCapability(testSecurityPolicy, ECapabilitySwEvent));
       
    91 	}
       
    92 
       
    93 static void GetTablePolicyTest(const TDesC& aTableName,
       
    94 							   RDbs::TPolicyType aPolicyType,
       
    95 							   TSecurityPolicy::TType aType,
       
    96 							   TSecureId aSecureId,
       
    97 							   TVendorId aVendorId,
       
    98 							   const TCapability* aCapabilities, TInt aCapCount)
       
    99 	{
       
   100 	TSecurityPolicy policy;
       
   101 	TInt err = TheDbs.GetTablePolicy(KSecureDbUid, aTableName, aPolicyType, policy);
       
   102 	TEST2(err, KErrNone);
       
   103 	TCompiledSecurityPolicy testSecurityPolicy(policy);
       
   104 	TEST(testSecurityPolicy.Type() == aType);
       
   105 	for(TInt i=0;i<aCapCount;++i)
       
   106 		{
       
   107 		TEST(TDBSCUtils::HasCapability(testSecurityPolicy, aCapabilities[i]));
       
   108 		}
       
   109 	if(testSecurityPolicy.Type() == TSecurityPolicy::ETypeS3)
       
   110 		{
       
   111 		TEST(testSecurityPolicy.SecureId() == aSecureId);
       
   112 		}
       
   113 	else if(testSecurityPolicy.Type() == TSecurityPolicy::ETypeV3)
       
   114 		{
       
   115 		TEST(testSecurityPolicy.VendorId() == aVendorId);
       
   116 		}
       
   117 	}
       
   118 
       
   119 //Tests RDbs::GetDatabasePolicy()/RDbs::GetTablePolicy() with invalid arguments
       
   120 static void InvalidPolicyArgTestsL()
       
   121 	{
       
   122 	TheTest.Printf(_L("--Invalid UID\n"));
       
   123 	const TUid KInvalidUid = {0x490122};
       
   124 	TSecurityPolicy policy;
       
   125 	TInt err = TheDbs.GetDatabasePolicy(KInvalidUid, RDbs::EWritePolicy, policy);
       
   126 	TEST2(err, KErrArgument);
       
   127 	err = TheDbs.GetDatabasePolicy(KNullUid, RDbs::EWritePolicy, policy);
       
   128 	TEST2(err, KErrArgument);
       
   129 	err = TheDbs.GetTablePolicy(KInvalidUid, KTableName1, RDbs::EWritePolicy, policy);
       
   130 	TEST2(err, KErrArgument);
       
   131 	err = TheDbs.GetTablePolicy(KNullUid, KTableName1, RDbs::EWritePolicy, policy);
       
   132 	TEST2(err, KErrArgument);
       
   133 
       
   134 	TheTest.Printf(_L("--Invalid policy type\n"));
       
   135 	err = TheDbs.GetDatabasePolicy(KSecureDbUid, static_cast <RDbs::TPolicyType> (100), policy);
       
   136 	TEST2(err, KErrArgument);
       
   137 	err = TheDbs.GetTablePolicy(KSecureDbUid, KTableName2, static_cast <RDbs::TPolicyType> (101), policy);
       
   138 	TEST2(err, KErrArgument);
       
   139 
       
   140 	TheTest.Printf(_L("--Table name, which is not in the policy file\n"));
       
   141 	_LIT(KMissingTableName, "AAAAAA");
       
   142 	err = TheDbs.GetTablePolicy(KSecureDbUid, KMissingTableName, RDbs::EWritePolicy, policy);
       
   143 	TEST2(err, KErrNone);//This must be the related database policy
       
   144 	TSecurityPolicy dbPolicy;
       
   145 	err = TheDbs.GetDatabasePolicy(KSecureDbUid, RDbs::EWritePolicy, dbPolicy);
       
   146 	TEST2(err, KErrNone);
       
   147 	TCompiledSecurityPolicy sp1(policy);
       
   148 	TCompiledSecurityPolicy sp2(dbPolicy);
       
   149 	TEST(sp1 == sp2);
       
   150 
       
   151 	TheTest.Printf(_L("--Table name - zero length\n"));
       
   152 	_LIT(KInvTableName, "");
       
   153 	err = TheDbs.GetTablePolicy(KSecureDbUid, KInvTableName, RDbs::EWritePolicy, policy);
       
   154 	TEST2(err, KErrArgument);
       
   155 
       
   156 	TheTest.Printf(_L("--Table name - Schema policy request\n"));
       
   157 	err = TheDbs.GetTablePolicy(KSecureDbUid, KTableName3, RDbs::ESchemaPolicy, policy);
       
   158 	TEST2(err, KErrNotSupported);
       
   159 	}
       
   160 
       
   161 //Returns a valid drive number, but not presented in the system
       
   162 static TDriveNumber FirstNotPresentedDriveNumber()
       
   163 	{
       
   164 	RFs fs;
       
   165 	TEST2(fs.Connect(), KErrNone);
       
   166 	TDriveNumber drvNumber = static_cast <TDriveNumber> (1000);
       
   167 	for(TInt i=EDriveA;i<=EDriveZ;++i)
       
   168 		{
       
   169 		TDriveInfo driveInfo;
       
   170 		if(fs.Drive(driveInfo, static_cast <TDriveNumber> (i)) == KErrNone)
       
   171 			{
       
   172 			if(driveInfo.iType == EMediaNotPresent)
       
   173 				{
       
   174 				drvNumber = static_cast <TDriveNumber> (i);
       
   175 				break;
       
   176 				}
       
   177 			}
       
   178 		}
       
   179 	fs.Close();
       
   180 	TEST(drvNumber <= EDriveZ);
       
   181 	return drvNumber;
       
   182 	}
       
   183 
       
   184 //Returns the first valid ROM drive number.
       
   185 static TDriveNumber FirstROMDriveNumber()
       
   186 	{
       
   187 	RFs fs;
       
   188 	TEST2(fs.Connect(), KErrNone);
       
   189 	TDriveNumber drvNumber = static_cast <TDriveNumber> (1000);
       
   190 	for(TInt i=EDriveA;i<=EDriveZ;++i)
       
   191 		{
       
   192 		TDriveInfo driveInfo;
       
   193 		if(fs.Drive(driveInfo, static_cast <TDriveNumber> (i)) == KErrNone)
       
   194 			{
       
   195 			if(driveInfo.iDriveAtt & KDriveAttRom)
       
   196 				{
       
   197 				drvNumber = static_cast <TDriveNumber> (i);
       
   198 				break;
       
   199 				}
       
   200 			}
       
   201 		}
       
   202 	fs.Close();
       
   203 	TEST(drvNumber <= EDriveZ);
       
   204 	return drvNumber;
       
   205 	}
       
   206 
       
   207 //Tests RDbs::DatabaseNamesL() with invalid arguments
       
   208 static void InvalidPolicyArgTests2L()
       
   209 	{
       
   210 	CDbDatabaseNames* dbNames = NULL;
       
   211 
       
   212 	TheTest.Printf(_L("--Invalid UID\n"));
       
   213 	const TUid KInvalidUid = {0x490122};
       
   214 	TRAPD(err, dbNames = TheDbs.DatabaseNamesL(EDriveC, KInvalidUid));
       
   215 	TEST2(err, KErrArgument);
       
   216 	TEST(dbNames == NULL);
       
   217 
       
   218 	TheTest.Printf(_L("--Null UID\n"));
       
   219 	TRAP(err, dbNames = TheDbs.DatabaseNamesL(EDriveC, KNullUid));
       
   220 	TEST2(err, KErrArgument);
       
   221 	TEST(dbNames == NULL);
       
   222 
       
   223 	TheTest.Printf(_L("--Invalid drive\n"));
       
   224 	TRAP(err, dbNames = TheDbs.DatabaseNamesL(static_cast <TDriveNumber> (-1), KSecureDbUid));
       
   225 	TEST2(err, KErrBadName);
       
   226 	TEST(dbNames == NULL);
       
   227 	TRAP(err, TheDbs.DatabaseNamesL(static_cast <TDriveNumber> (1765), KSecureDbUid));
       
   228 	TEST2(err, KErrBadName);
       
   229 	TEST(dbNames == NULL);
       
   230 
       
   231 	TheTest.Printf(_L("--Valid drive number, but not presented in the system\n"));
       
   232 	TDriveNumber driveNumber = ::FirstNotPresentedDriveNumber();
       
   233 	TRAP(err, dbNames = TheDbs.DatabaseNamesL(driveNumber, KSecureDbUid));
       
   234 	TEST2(err, KErrNotReady);
       
   235 	TEST(dbNames == NULL);
       
   236 	}
       
   237 
       
   238 /**
       
   239 @SYMTestCaseID SYSLIB-DBMS-CT-0003
       
   240 @SYMTestCaseDesc Test RDbs::GetDatabasePolicy(), RDbs::GetTablePolicy()
       
   241                  getting database or table security policies.
       
   242 @SYMTestPriority High
       
   243 @SYMTestActions  A call with valid arguments and result check.
       
   244 				 A call with an invalid UID.
       
   245 				 A call with an invalid security policy type.
       
   246 				 A call with a table name, not presented in the policy file.
       
   247 				 A call requesting schema security policy of a table.
       
   248 @SYMTestExpectedResults The test must not fail.
       
   249 @SYMREQ          REQ2429
       
   250                  DBMS shall provide an API to apply security policies to database tables.
       
   251 */
       
   252 static void GetPolicyTestL()
       
   253 	{
       
   254 	TheTest.Printf(_L("--Simple GetDatabasePolicy() tests\n"));
       
   255 	::GetDatabaseRPolicyTest();
       
   256 	::GetDatabaseWPolicyTest();
       
   257 	::GetDatabaseSPolicyTest();
       
   258 
       
   259 	::InvalidPolicyArgTestsL();
       
   260 
       
   261 	TheTest.Printf(_L("--Simple GetTablePolicy() tests\n"));
       
   262 	TCapability caps1[] = {ECapabilityCommDD, ECapabilityPowerMgmt, ECapabilityTrustedUI};
       
   263 	TCapability caps2[] = {ECapabilityMultimediaDD, ECapabilityReadDeviceData};
       
   264 	::GetTablePolicyTest(KTableName1, RDbs::EReadPolicy, TSecurityPolicy::ETypeC3, 0, 0, caps1, 3);
       
   265 	::GetTablePolicyTest(KTableName1, RDbs::EWritePolicy, TSecurityPolicy::ETypeC3, 0, 0, caps2, 2);
       
   266 
       
   267 	TCapability caps3[] = {static_cast <TCapability> (TUint8(ECapability_None))};
       
   268 	::GetTablePolicyTest(KTableName2, RDbs::EReadPolicy, TSecurityPolicy::ETypeC3, 0, 0, caps3, 1);
       
   269 	::GetTablePolicyTest(KTableName2, RDbs::EWritePolicy, TSecurityPolicy::ETypeC3, 0, 0, caps2, 2);
       
   270 
       
   271 	TCapability caps4[] = {ECapabilityReadUserData};
       
   272 	::GetTablePolicyTest(KTableName3, RDbs::EReadPolicy, TSecurityPolicy::ETypeC3, 0, 0, caps1, 3);
       
   273 	::GetTablePolicyTest(KTableName3, RDbs::EWritePolicy, TSecurityPolicy::ETypeC3, 0, 0, caps4, 1);
       
   274 
       
   275 	TCapability caps5[] = {ECapabilityWriteUserData};
       
   276 	::GetTablePolicyTest(KTableName4, RDbs::EReadPolicy, TSecurityPolicy::ETypeC3, 0, 0, caps5, 1);
       
   277 	::GetTablePolicyTest(KTableName4, RDbs::EWritePolicy, TSecurityPolicy::ETypeC3, 0, 0, caps2, 2);
       
   278 	}
       
   279 
       
   280 /**
       
   281 @SYMTestCaseID SYSLIB-DBMS-CT-0004
       
   282 @SYMTestCaseDesc Test RDbs::DatabaseNamesL(TDriveNumber, const TDesC&, TUid) -
       
   283                  getting a list of secure shared databases.
       
   284 @SYMTestPriority High
       
   285 @SYMTestActions  A call with valid arguments and result check
       
   286 				 A call with an invalid drive number.
       
   287 				 A call with a valid, but not presented in the system, drive number.
       
   288 				 A call with an invalid UID.
       
   289 @SYMTestExpectedResults The test must not fail.
       
   290 @SYMREQ          REQ2429
       
   291                  DBMS shall provide an API to apply security policies to database tables.
       
   292 */
       
   293 static void GetDatabaseListTestL()
       
   294 	{
       
   295 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   296 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb2Name);
       
   297 
       
   298 	TheDb1 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   299 	TheDb1.Close();
       
   300 
       
   301 	TheDb2 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb2Name);
       
   302 	TheDb2.Close();
       
   303 
       
   304 	TBuf<32> dbName;
       
   305 	dbName.Copy(KDb1Name().Mid(KDatabaseNamePos));
       
   306 	TEST(TDBSCUtils::IsDatabaseThereL(TheDbs, KSecureDbUid, EDriveC, dbName));
       
   307 	dbName.Copy(KDb2Name().Mid(KDatabaseNamePos));
       
   308 	TEST(TDBSCUtils::IsDatabaseThereL(TheDbs, KSecureDbUid, EDriveC, dbName));
       
   309 
       
   310 	TheTest.Printf(_L("--An attempt to retrieve the list of database names for an UID, which security policy cannot be satisfied by the current test application\n"));
       
   311 	CDbDatabaseNames* dbNames = NULL;
       
   312 	TRAPD(err, dbNames = TheDbs.DatabaseNamesL(EDriveZ, KSecureDbUid2));
       
   313 	delete dbNames;
       
   314 	TEST2(err, KErrNone);
       
   315 
       
   316 	::InvalidPolicyArgTests2L();
       
   317 	}
       
   318 
       
   319 /**
       
   320 @SYMTestCaseID SYSLIB-DBMS-CT-0005
       
   321 @SYMTestCaseDesc Test RDbs::CopyDatabase(const TDesC&, const TDesC&, TUid) -
       
   322                  copying secure shared database .
       
   323 @SYMTestPriority High
       
   324 @SYMTestActions  A call with valid arguments and result check
       
   325                  A call with an invalid source database name.
       
   326 				 A call with an invalid target database name.
       
   327 				 A call with an invalid UID.
       
   328 				 An attempt to copy an opened database.
       
   329 				 An attempt to copy a database, which security policy cannot be satisfied.
       
   330 				 An attempt to copy a database with path specified in the database name.
       
   331 				 An attempt to copy non-existing database.
       
   332 @SYMTestExpectedResults The test must not fail.
       
   333 @SYMREQ          REQ2429
       
   334                  DBMS shall provide an API to apply security policies to database tables.
       
   335 */
       
   336 static void CopyDatabaseTestL()
       
   337 	{
       
   338 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   339 	TheDb1 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   340 	TheDb1.Close();
       
   341 
       
   342 	TheTest.Printf(_L("--Simple copy test\n"));
       
   343 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb3Name);
       
   344 	TInt err = TheDbs.CopyDatabase(KDb1Name, KDb3Name, KSecureDbUid);
       
   345 	TEST2(err, KErrNone);
       
   346 	TBuf<32> dbName;
       
   347 	dbName.Copy(KDb3Name().Mid(KDatabaseNamePos));
       
   348 	TEST(TDBSCUtils::IsDatabaseThereL(TheDbs, KSecureDbUid, EDriveC, dbName));
       
   349 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb3Name);
       
   350 
       
   351 	TheTest.Printf(_L("--An attempt to copy a source database, which security policy cannot be satisfied by the current test application\n"));
       
   352 	err = TheDbs.CopyDatabase(KProtDb1ZName, KDb3Name, KSecureDbUid2);
       
   353 	TEST2(err, KErrPermissionDenied);
       
   354 
       
   355 	TheTest.Printf(_L("--Null source database name\n"));
       
   356 	err = TheDbs.CopyDatabase(KNullDesC, KDb3Name, KSecureDbUid);
       
   357 	TEST2(err, KErrArgument);
       
   358 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb3Name);
       
   359 
       
   360 	TheTest.Printf(_L("--Source database name with not presented drive number\n"));
       
   361 	TDriveNumber driveNumber = ::FirstNotPresentedDriveNumber();
       
   362 	TChar driveChar;
       
   363 	TEST2(RFs::DriveToChar(driveNumber, driveChar), KErrNone);
       
   364 	TBuf<KDatabaseNamePos> drvBuf;
       
   365 	drvBuf.Append(driveChar);
       
   366 	drvBuf.Append(':');
       
   367 	dbName.Copy(drvBuf);
       
   368 	dbName.Append(KDb1Name().Mid(KDatabaseNamePos));
       
   369 	err = TheDbs.CopyDatabase(dbName, KDb3Name, KSecureDbUid);
       
   370 	TEST2(err, KErrNotReady);
       
   371 
       
   372 	TheTest.Printf(_L("--Source database name - only with a drive letter and \":\"\n"));
       
   373 	err = TheDbs.CopyDatabase(drvBuf, KDb3Name, KSecureDbUid);
       
   374 	TEST2(err, KErrNotReady);
       
   375 
       
   376 	TheTest.Printf(_L("--Source database name - only with a drive letter\n"));
       
   377 	drvBuf.SetLength(1);
       
   378 	err = TheDbs.CopyDatabase(drvBuf, KDb3Name, KSecureDbUid);
       
   379 	TEST2(err, KErrArgument);
       
   380 
       
   381 	TheTest.Printf(_L("--Null destination database name\n"));
       
   382 	err = TheDbs.CopyDatabase(KDb1Name, KNullDesC, KSecureDbUid);
       
   383 	TEST2(err, KErrArgument);
       
   384 
       
   385 	TheTest.Printf(_L("--Destination database name with not presented drive number\n"));
       
   386 	drvBuf.Append(':');
       
   387 	dbName.Copy(drvBuf);
       
   388 	dbName.Append(KDb3Name().Mid(KDatabaseNamePos));
       
   389 	err = TheDbs.CopyDatabase(KDb1Name, dbName, KSecureDbUid);
       
   390 	TEST2(err, KErrNotReady);
       
   391 
       
   392 	TheTest.Printf(_L("--Destination database - ROM drive\n"));
       
   393 	TDriveNumber romDriveNumber = ::FirstROMDriveNumber();
       
   394 	TEST2(RFs::DriveToChar(romDriveNumber, driveChar), KErrNone);
       
   395 	drvBuf[0] = static_cast <TText> (driveChar);
       
   396 	dbName.Copy(drvBuf);
       
   397 	dbName.Append(KDb3Name().Mid(KDatabaseNamePos));
       
   398 	err = TheDbs.CopyDatabase(KDb1Name, dbName, KSecureDbUid);
       
   399 	TEST2(err, KErrAccessDenied);
       
   400 
       
   401 	TheTest.Printf(_L("--A source database with a valid name, but not presented in the system\n"));
       
   402 	_LIT(KMissingDb, "C:asdhasfsudfygusdfuierfb.db");
       
   403 	err = TheDbs.CopyDatabase(KMissingDb, KDb3Name, KSecureDbUid);
       
   404 	TEST2(err, KErrNotFound);
       
   405 
       
   406 	TheTest.Printf(_L("--A test with an open source database\n"));
       
   407 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   408 	TheDb2 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   409 	err = TheDbs.CopyDatabase(KDb1Name, KDb3Name, KSecureDbUid);
       
   410 	TheDb2.Close();
       
   411 	TEST2(err, KErrInUse);
       
   412 
       
   413 	TheTest.Printf(_L("--An atempt to copy over an existing database\n"));
       
   414 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb2Name);
       
   415 	TheDb1 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb2Name);
       
   416 	TheDb1.Close();
       
   417 	err = TheDbs.CopyDatabase(KDb1Name, KDb2Name, KSecureDbUid);
       
   418 	TEST2(err, KErrAlreadyExists);
       
   419 
       
   420 	TheTest.Printf(_L("--Too long destination database name > KDbMaxName symbols\n"));
       
   421 	_LIT(KTooLongDbName, "A_0123456789_0123456789_0123456789_0123456789_0123456789_0123456789_0123456789.db");
       
   422 	err = TheDbs.CopyDatabase(KDb1Name, KTooLongDbName, KSecureDbUid);
       
   423 	TEST2(err, KErrArgument);
       
   424 
       
   425 	TheTest.Printf(_L("--Null UID\n"));
       
   426 	err = TheDbs.CopyDatabase(KDb1Name, KDb3Name, KNullUid);
       
   427 	TEST2(err, KErrArgument);
       
   428 
       
   429 	TheTest.Printf(_L("--Invalid UID\n"));
       
   430 	const TUid KInvalidUid = {0x490122};
       
   431 	err = TheDbs.CopyDatabase(KDb1Name, KDb3Name, KInvalidUid);
       
   432 	TEST2(err, KErrArgument);
       
   433 
       
   434 	TheTest.Printf(_L("--An attempt to copy a database with the path specified in the name\n"));
       
   435 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb2Name);
       
   436 	_LIT(KSrcDbName2, "C:\\a.Db");
       
   437 	_LIT(KDestDbName2, "C:\\b.dB");
       
   438 	err = TheDbs.CopyDatabase(KSrcDbName2, KDestDbName2, KSecureDbUid);
       
   439 	TEST2(err, KErrArgument);
       
   440 	}
       
   441 
       
   442 /**
       
   443 @SYMTestCaseID SYSLIB-DBMS-CT-0006
       
   444 @SYMTestCaseDesc Test RDbs::Delete(const TDesC&, TUid) - deleting secure shared database .
       
   445 @SYMTestPriority High
       
   446 @SYMTestActions  A call with valid arguments and result check
       
   447                  A call with an invalid UID.
       
   448 				 A call with an invalid database name.
       
   449 				 An attempt to delete an opened database.
       
   450 				 An attempt to delete a database, which security policy cannot be satisfied.
       
   451 				 An attempt to delete a database with path specified in the database name.
       
   452 				 An attempt to delete non-existing database.
       
   453 @SYMTestExpectedResults The test must not fail.
       
   454 @SYMREQ          REQ2429
       
   455                  DBMS shall provide an API to apply security policies to database tables.
       
   456 */
       
   457 static void DeleteDatabaseTestL()
       
   458 	{
       
   459 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   460 	TheDb1 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   461 	TheDb1.Close();
       
   462 
       
   463 	TheTest.Printf(_L("--Simple delete database test\n"));
       
   464 	TInt err = TheDbs.DeleteDatabase(KDb1Name, KSecureDbUid);
       
   465 	TEST2(err, KErrNone);
       
   466 
       
   467 	TheTest.Printf(_L("--Null UID\n"));
       
   468 	err = TheDbs.DeleteDatabase(KDb1Name, KNullUid);
       
   469 	TEST2(err, KErrArgument);
       
   470 
       
   471 	TheTest.Printf(_L("--Invalid UID\n"));
       
   472 	const TUid KInvalidUid = {0x490122};
       
   473 	err = TheDbs.DeleteDatabase(KDb1Name, KInvalidUid);
       
   474 	TEST2(err, KErrArgument);
       
   475 
       
   476 	TheTest.Printf(_L("--Null database name\n"));
       
   477 	err = TheDbs.DeleteDatabase(KNullDesC, KSecureDbUid);
       
   478 	TEST2(err, KErrArgument);
       
   479 
       
   480 	TheTest.Printf(_L("--Non-existing database - no drive letter (the name is invalid)\n"));
       
   481 	_LIT(KTooLongDbName, "A_0123456789_0123456789_0123456789_0123456789_0123456789_0123456789_0123456789.db");
       
   482 	err = TheDbs.DeleteDatabase(KTooLongDbName, KSecureDbUid);
       
   483 	TEST2(err, KErrArgument);
       
   484 	_LIT(KInvDbName1, "UI789.db");
       
   485 	err = TheDbs.DeleteDatabase(KInvDbName1, KSecureDbUid);
       
   486 	TEST2(err, KErrArgument);
       
   487 
       
   488 	TheTest.Printf(_L("--Non-existing database - valid db name\n"));
       
   489 	_LIT(KMissingDbName1, "C:A0192345.db");
       
   490 	err = TheDbs.DeleteDatabase(KMissingDbName1, KSecureDbUid);
       
   491 	TEST2(err, KErrNotFound);
       
   492 
       
   493 	TheTest.Printf(_L("--An attempt to delete a database with the path specified in the name\n"));
       
   494 	_LIT(KMissingDbName2, "C:\\TEMP\\A0192345.db");
       
   495 	err = TheDbs.DeleteDatabase(KMissingDbName2, KSecureDbUid);
       
   496 	TEST2(err, KErrArgument);
       
   497 
       
   498 	TheTest.Printf(_L("--An attempt to delete a database, which security policy cannot be satisfied by the current test application\n"));
       
   499 	err = TheDbs.DeleteDatabase(KProtDb1CName, KSecureDbUid2);
       
   500 	TEST2(err, KErrPermissionDenied);
       
   501 
       
   502 	TheTest.Printf(_L("--An attempt to delete an open database\n"));
       
   503 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   504 	TheDb1 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   505 	err = TheDbs.DeleteDatabase(KDb1Name, KSecureDbUid);
       
   506 	TEST2(err, KErrInUse);
       
   507 	TheDb1.Close();
       
   508 	}
       
   509 
       
   510 /**
       
   511 @SYMTestCaseID SYSLIB-DBMS-CT-0007
       
   512 @SYMTestCaseDesc Test RDbNamedDatabase::Create(RDbs&, const TDesC&, const TDesC&) -
       
   513                  secure shared database creation.
       
   514 @SYMTestPriority High
       
   515 @SYMTestActions  A call with valid arguments and result check
       
   516                  An attempt to create already existing database.
       
   517 				 An attempt to create already existing and opened database.
       
   518 				 RDbNamedDatabase::Create() called with an invalid format string.
       
   519 				 RDbNamedDatabase::Create() called with a database name containing '\' symbols.
       
   520 				 An attempt to create a database, which security policy cannot be satisfied.
       
   521 @SYMTestExpectedResults The test must not fail.
       
   522 @SYMREQ          REQ2429
       
   523                  DBMS shall provide an API to apply security policies to database tables.
       
   524 */
       
   525 static void CreateDatabaseL()
       
   526 	{
       
   527 	TheTest.Printf(_L("--Simple create database test\n"));
       
   528 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   529 	TBuf<32> format;
       
   530 	format.Copy(KSecure);
       
   531 	format.Append(KSecureDbUid.Name());
       
   532 	TInt err = TheDb1.Create(TheDbs, KDb1Name, format);
       
   533 	TEST2(err, KErrNone);
       
   534 
       
   535 	TheTest.Printf(_L("--An atempt to recreate an open database\n"));
       
   536 	err = TheDb1.Create(TheDbs, KDb1Name, format);
       
   537 	TEST2(err, KErrAlreadyExists);
       
   538 	TheDb1.Close();
       
   539 
       
   540 	TheTest.Printf(_L("--An atempt to recreate an existing database\n"));
       
   541 	err = TheDb1.Create(TheDbs, KDb1Name, format);
       
   542 	TEST2(err, KErrAlreadyExists);
       
   543 
       
   544 	TheTest.Printf(_L("--Format string with \"SECURE\" keyword and some other words too\n"));
       
   545 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   546 	format.Copy(_L("A "));
       
   547 	format.Append(KSecure);
       
   548 	format.Append(_L(" B"));
       
   549 	format.Append(KSecureDbUid.Name());
       
   550 	err = TheDb1.Create(TheDbs, KDb1Name, format);
       
   551 	TheDb1.Close();
       
   552 	TEST2(err, KErrNotSupported);
       
   553 
       
   554 	TheTest.Printf(_L("--Format string with \"SeCuRe\" keyword\n"));
       
   555 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   556 	format.Copy(_L("SeCuRe"));
       
   557 	format.Append(KSecureDbUid.Name());
       
   558 	err = TheDb1.Create(TheDbs, KDb1Name, format);
       
   559 	TheDb1.Close();
       
   560 	TEST2(err, KErrNone);
       
   561 
       
   562 	TheTest.Printf(_L("--Format string with \"SECURED\" keyword\n"));
       
   563 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   564 	format.Copy(_L("SECURED"));
       
   565 	format.Append(KSecureDbUid.Name());
       
   566 	err = TheDb1.Create(TheDbs, KDb1Name, format);
       
   567 	TheDb1.Close();
       
   568 	TEST2(err, KErrNotSupported);
       
   569 
       
   570 	TheTest.Printf(_L("--Format string with a null uid\n"));
       
   571 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   572 	format.Copy(_L("SECURE"));
       
   573 	format.Append(KNullUid.Name());
       
   574 	err = TheDb1.Create(TheDbs, KDb1Name, format);
       
   575 	TheDb1.Close();
       
   576 	TEST2(err, KErrArgument);
       
   577 
       
   578 	TheTest.Printf(_L("--Format string with an invalid uid\n"));
       
   579 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   580 	format.Copy(_L("SECURE"));
       
   581 	const TUid KInvalidUid = {0x490122};
       
   582 	format.Append(KInvalidUid.Name());
       
   583 	err = TheDb1.Create(TheDbs, KDb1Name, format);
       
   584 	TheDb1.Close();
       
   585 	TEST2(err, KErrArgument);
       
   586 
       
   587 	TheTest.Printf(_L("--Format string with a uid only\n"));
       
   588 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   589 	format.Copy(KSecureDbUid.Name());
       
   590 	err = TheDb1.Create(TheDbs, KDb1Name, format);
       
   591 	TheDb1.Close();
       
   592 	TEST2(err, KErrNotSupported);
       
   593 
       
   594 	TheTest.Printf(_L("--Blank format string\n"));
       
   595 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   596 	format.Zero();
       
   597 	err = TheDb1.Create(TheDbs, KDb1Name, format);
       
   598 	TheDb1.Close();
       
   599 	TEST2(err, KErrNotSupported);
       
   600 
       
   601 	TheTest.Printf(_L("--Valid format string + database name with a path\n"));
       
   602 	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name);
       
   603 	format.Copy(KSecure);
       
   604 	format.Append(KSecureDbUid.Name());
       
   605 	_LIT(KSrcDbName2, "C:\\a.Db");
       
   606 	err = TheDb1.Create(TheDbs, KSrcDbName2, format);
       
   607 	TheDb1.Close();
       
   608 	TEST2(err, KErrArgument);
       
   609 
       
   610 	TheTest.Printf(_L("--An attempt to create a database, which security policy cannot be satisfied by the current test application\n"));
       
   611 	format.Copy(KSecure);
       
   612 	format.Append(KSecureDbUid2.Name());
       
   613 	err = TheDb1.Create(TheDbs, KProtDb2CName, format);
       
   614 	TheDb1.Close();
       
   615 	TEST2(err, KErrPermissionDenied);
       
   616 	}
       
   617 
       
   618 static void INC057327L()
       
   619     {
       
   620      TRAPD(err,delete TheDbs.DatabaseNamesL(EDriveZ, TUid::Uid(0x12344321)));
       
   621      TheTest(err == KErrNone);
       
   622     }
       
   623 
       
   624 static void DoRunL()
       
   625 	{
       
   626 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0003 Get database/table policies "));
       
   627 	::GetPolicyTestL();
       
   628 
       
   629 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0004 Get databases list "));
       
   630 	::GetDatabaseListTestL();
       
   631 
       
   632 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0005 Copy database "));
       
   633 	::CopyDatabaseTestL();
       
   634 
       
   635 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0006 Delete database "));
       
   636 	::DeleteDatabaseTestL();
       
   637 
       
   638 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0007 Create database "));
       
   639 	::CreateDatabaseL();
       
   640 
       
   641 	TheTest.Next(_L("Database security"));
       
   642 	::DoDbTestL();
       
   643 
       
   644 	TheTest.Next(_L("Table security"));
       
   645 	::DoTblTestL();
       
   646 
       
   647 	TheTest.Next(_L("Test for INC057327"));
       
   648 	::INC057327L();
       
   649 	}
       
   650 
       
   651 TInt E32Main()
       
   652     {
       
   653 	__UHEAP_MARK;
       
   654 	CTrapCleanup* tc = CTrapCleanup::New();
       
   655 	TEST(tc != NULL);
       
   656 
       
   657 	TInt err = TheDbs.Connect();
       
   658 	TEST2(err, KErrNone);
       
   659 
       
   660 	TRAP(err, ::DoRunL());
       
   661 	TEST2(err, KErrNone);
       
   662 
       
   663 	::DeleteDatabases();
       
   664 	TheDbs.Close();
       
   665 
       
   666 	TheTest.End();
       
   667 	TheTest.Close();
       
   668 
       
   669 	delete tc;
       
   670 
       
   671 	__UHEAP_MARKEND;
       
   672 	User::Heap().Check();
       
   673 	return KErrNone;
       
   674     }