sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // DBMS security policy - testing new APIs - database level. sl@0: // All tests assume that drive C is presented in the system and is not a ROM drive. sl@0: // sl@0: // sl@0: sl@0: #include "t_dbplatsecutl.h" sl@0: #include "t_dbplatsecdef.h" sl@0: #include "t_dbplatsecdb.h" sl@0: sl@0: static TColDef const KColumns[]= sl@0: { sl@0: {_S("ID"), EDbColInt32, TDbCol::ENotNull | TDbCol::EAutoIncrement}, sl@0: {_S("DATA1"), EDbColInt32, TDbCol::ENotNull}, sl@0: {_S("DATA2"), EDbColInt32, TDbCol::ENotNull}, sl@0: {0} sl@0: }; sl@0: sl@0: sl@0: //Open database tests sl@0: static void OpenTestL() sl@0: { sl@0: RFs fileSess; sl@0: CleanupClosePushL(fileSess); sl@0: TEST2(fileSess.Connect(), KErrNone); sl@0: sl@0: TBuf<32> fmt; sl@0: fmt.Copy(KSecure); sl@0: fmt.Append(KSecureDbUid.Name()); sl@0: sl@0: TheTest.Printf(_L("Open secure shared database\n")); sl@0: TInt err = TheDb1.Open(TheDbs, KDb1Name, fmt); sl@0: TheDb1.Close(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: sl@0: TheTest.Printf(_L("An attempt to open it as a secure shared database - no format string\n")); sl@0: err = TheDb1.Open(TheDbs, KDb1Name); sl@0: TheDb1.Close(); sl@0: TEST2(err, KErrNotFound);//Treated as a non-secure, not found database. sl@0: sl@0: TheTest.Printf(_L("An attempt to open it as a non-secure shared database\n")); sl@0: _LIT(KNSDbName, "C:\\PRiVatE\\100012A5\\A.dB"); sl@0: err = TheDb1.Open(TheDbs, KNSDbName); sl@0: TheDb1.Close(); sl@0: TEST2(err, KErrPermissionDenied); sl@0: _LIT(KNSDbName2, "C:\\PRiVatE\\100012A5\\DBS_11335577_A.Db"); sl@0: if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) && sl@0: PlatSec::IsCapabilityEnforced(ECapabilityAllFiles)) sl@0: { sl@0: err = TheDb1.Open(fileSess, KNSDbName2); sl@0: TheDb1.Close(); sl@0: TEST2(err, KErrPermissionDenied); sl@0: sl@0: TheTest.Printf(_L("An attempt to create it as a non-secure shared database\n")); sl@0: err = TheDb1.Create(fileSess, KNSDbName2); sl@0: TheDb1.Close(); sl@0: TEST2(err, KErrPermissionDenied); sl@0: } sl@0: sl@0: TheTest.Printf(_L("--An attempt to open a database, which security policy cannot be satisfied by the current test application\n")); sl@0: fmt.Copy(KSecure); sl@0: fmt.Append(KSecureDbUid2.Name()); sl@0: err = TheDb1.Open(TheDbs, KProtDb3CName, fmt); sl@0: TheDb1.Close(); sl@0: TEST2(err, KErrPermissionDenied); sl@0: sl@0: CleanupStack::PopAndDestroy(&fileSess); sl@0: } sl@0: sl@0: //RDbDatabase method calls test. All calls have to pass with KErrNone, sl@0: //because the test application has enough rights to do any R/W/S database operation. sl@0: static void DbCallTestL() sl@0: { sl@0: TBuf<32> fmt; sl@0: fmt.Copy(KSecure); sl@0: fmt.Append(KSecureDbUid.Name()); sl@0: sl@0: TheTest.Printf(_L("Open()\n")); sl@0: TInt err = TheDb1.Open(TheDbs, KDb1Name, fmt); sl@0: sl@0: TheTest.Printf(_L("IsDamaged()\n")); sl@0: TBool res = TheDb1.IsDamaged(); sl@0: TEST(!res); sl@0: sl@0: TheTest.Printf(_L("Recover()\n")); sl@0: err = TheDb1.Recover(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTest.Printf(_L("UpdateStats()\n")); sl@0: err = TheDb1.UpdateStats(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTest.Printf(_L("Size()\n")); sl@0: RDbDatabase::TSize size = TheDb1.Size(); sl@0: sl@0: TheTest.Printf(_L("Compact()\n")); sl@0: err = TheDb1.Compact(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: sl@0: TheTest.Printf(_L("Begin()/Commit()\n")); sl@0: err = TheDb1.Begin(); sl@0: TEST2(err, KErrNone); sl@0: res = TheDb1.InTransaction(); sl@0: TEST(res); sl@0: err = TheDb1.Commit(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTest.Printf(_L("Begin()/Rollback()\n")); sl@0: err = TheDb1.Begin(); sl@0: TEST2(err, KErrNone); sl@0: res = TheDb1.InTransaction(); sl@0: TEST(res); sl@0: TheDb1.Rollback(); sl@0: sl@0: TheTest.Printf(_L("CreateTable()\n")); sl@0: CDbColSet* colset = TDBSCUtils::CreateColSetLC(KColumns); sl@0: _LIT(KTblName1, "A1"); sl@0: err = TheDb1.CreateTable(KTblName1, *colset); sl@0: TEST2(err, KErrNone); sl@0: _LIT(KTblName2, "A2"); sl@0: err = TheDb1.CreateTable(KTblName2, *colset); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTest.Printf(_L("DropTable()\n")); sl@0: err = TheDb1.DropTable(KTblName2); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTest.Printf(_L("AlterTable()\n")); sl@0: err = TheDb1.AlterTable(KTblName1, *colset); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTest.Printf(_L("CreateIndex()\n")); sl@0: CDbKey* key = TDBSCUtils::CreateKeyLC(KCol2); sl@0: err = TheDb1.CreateIndex(KCol2, KTblName1, *key); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTest.Printf(_L("DropIndex()\n")); sl@0: err = TheDb1.DropIndex(KCol2, KTblName1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTest.Printf(_L("TableNamesL()\n")); sl@0: _LIT(KTblName3, "DdD"); sl@0: _LIT(KTblName4, "FFf"); sl@0: _LIT(KTblName5, "Ggg"); sl@0: TDBSCUtils::CreateTableL(TheDb1, KTblName3, KColumns); sl@0: TDBSCUtils::CreateTableL(TheDb1, KTblName4, KColumns); sl@0: TDBSCUtils::CreateTableL(TheDb1, KTblName5, KColumns); sl@0: CDbTableNames* tblNames = TheDb1.TableNamesL(); sl@0: TInt cnt = tblNames->Count(); sl@0: TEST(cnt == 4); sl@0: TInt i; sl@0: for(i=0;iCount(); sl@0: for(i=0;iCount(); sl@0: for(i=0;i 0); sl@0: sl@0: TheTest.Printf(_L("Update\n")); sl@0: cnt = TheDb1.Execute(_L("UPDATe A SeT DAtA2=56 WheRE iD = 0")); sl@0: TEST(cnt > 0); sl@0: sl@0: TheTest.Printf(_L("Delete\n")); sl@0: cnt = TheDb1.Execute(_L("INSErt INtO B (DATA2) VALUES(100)")); sl@0: TEST(cnt > 0); sl@0: cnt = TheDb1.Execute(_L("INSERT INTo b (DATA2) VALUES(200)")); sl@0: TEST(cnt > 0); sl@0: cnt = TheDb1.Execute(_L("delete FROM B where ID = 1")); sl@0: TEST(cnt > 0); sl@0: sl@0: TheDb1.Close(); sl@0: } sl@0: sl@0: static void TwoDatabasesTestL() sl@0: { sl@0: TBuf<32> fmt; sl@0: fmt.Copy(KSecure); sl@0: fmt.Append(KSecureDbUid.Name()); sl@0: sl@0: RDbNamedDatabase db1; sl@0: TheTest.Printf(_L("Open secure shared database-1\n")); sl@0: TInt err = db1.Open(TheDbs, KDb1Name, fmt); sl@0: TEST2(err, KErrNone); sl@0: sl@0: RDbNamedDatabase db2; sl@0: TheTest.Printf(_L("Open secure shared database-2\n")); sl@0: err = db2.Open(TheDbs, KDb1Name, fmt); sl@0: TEST2(err, KErrNone); sl@0: sl@0: db2.Close(); sl@0: db1.Close(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-DBMS-CT-0019 sl@0: @SYMTestCaseDesc RDbNamedDatabase method calls test for a secure shared database. sl@0: Every method of RDbNamedDatabase class and its base class too, is called sl@0: and the result - asserted. sl@0: @SYMTestPriority High sl@0: @SYMTestActions RDbNamedDatabase method calls test. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ2429 sl@0: DBMS shall provide an API to apply security policies to database tables. sl@0: */ sl@0: void DoDbTestL() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0019 ")); sl@0: TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDb1Name); sl@0: TheDb1 = TDBSCUtils::CreateDatabase(TheDbs, KSecureDbUid, KDb1Name); sl@0: TheDb1.Close(); sl@0: sl@0: TheTest.Next(_L("Open secure database test")); sl@0: ::OpenTestL(); sl@0: sl@0: TheTest.Next(_L("Secure Database calls test")); sl@0: ::DbCallTestL(); sl@0: sl@0: TheTest.Next(_L("SQL test")); sl@0: ::SQLTestL(); sl@0: sl@0: TheTest.Next(_L("Two databases test")); sl@0: ::TwoDatabasesTestL(); sl@0: }