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