os/persistentdata/persistentstorage/dbms/tdbms/t_dbbackupsid.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) 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 - Backup&Restore SID test.
sl@0
    15
// The test assume that drive C is presented in the system and is not a ROM drive.
sl@0
    16
// Please, ensure that t_predbsc test is executed before T_DBMSBackupSID test!
sl@0
    17
// Please, ensure that t_postdbsc test is executed after T_DBMSBackupSID test!
sl@0
    18
// 
sl@0
    19
//
sl@0
    20
sl@0
    21
#include <d32dbms.h>
sl@0
    22
#include <e32test.h>
sl@0
    23
sl@0
    24
//Global definitions
sl@0
    25
RTest 				TheTest(_L("t_dbbackupsid"));
sl@0
    26
RDbs 				TheDbs;
sl@0
    27
sl@0
    28
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    29
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    30
//Test macros and functions
sl@0
    31
static void Check(TInt aValue, TInt aLine)
sl@0
    32
	{
sl@0
    33
	if(!aValue)
sl@0
    34
		{
sl@0
    35
		TheTest(EFalse, aLine);
sl@0
    36
		}
sl@0
    37
	}
sl@0
    38
static void Check(TInt aValue, TInt aExpected, TInt aLine)
sl@0
    39
	{
sl@0
    40
	if(aValue != aExpected)
sl@0
    41
		{
sl@0
    42
		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
sl@0
    43
		TheTest(EFalse, aLine);
sl@0
    44
		}
sl@0
    45
	}
sl@0
    46
#define TEST(arg) 					Check((arg), __LINE__)
sl@0
    47
#define TEST2(aValue, aExpected) 	Check(aValue, aExpected, __LINE__)
sl@0
    48
sl@0
    49
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    50
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    51
sl@0
    52
/**
sl@0
    53
@SYMTestCaseID SYSLIB-DBMS-CT-0036
sl@0
    54
@SYMTestCaseDesc Backup&restore Secure ID test.
sl@0
    55
                 This function tests RDbs::GetBackupPath() with different sets of input
sl@0
    56
                 parameters: invalid and valid.
sl@0
    57
@SYMTestPriority High
sl@0
    58
@SYMTestActions  RDbs::GetBackupPath() test.
sl@0
    59
@SYMTestExpectedResults The test must not fail.
sl@0
    60
@SYMPREQ PREQ277
sl@0
    61
*/
sl@0
    62
static void TestBackupSID()
sl@0
    63
	{
sl@0
    64
	TBuf<KMaxPath> backupPath;
sl@0
    65
	//Invalid SID
sl@0
    66
	TSecureId backupSID = 0;
sl@0
    67
	TUid dbUid = {0x1133557A};
sl@0
    68
	_LIT(KDbName, "C:abcd.db");
sl@0
    69
	TheTest.Printf(_L("--Invalid backup SID: 0\n"));
sl@0
    70
	TInt err = TheDbs.GetBackupPath(backupSID, KDbName, dbUid, backupPath);
sl@0
    71
	TEST2(err, KErrArgument);
sl@0
    72
	backupSID = (TUint32)ECapability_None;
sl@0
    73
	TheTest.Printf(_L("--Invalid backup SID: ECapability_None\n"));
sl@0
    74
	err = TheDbs.GetBackupPath(backupSID, KDbName, dbUid, backupPath);
sl@0
    75
	TEST2(err, KErrArgument);
sl@0
    76
	//Invalid UID
sl@0
    77
	backupSID = 0x30003000;
sl@0
    78
	dbUid.iUid = 0xFB34010F;
sl@0
    79
	TheTest.Printf(_L("--Invalid UID: no security policy for it\n"));
sl@0
    80
	err = TheDbs.GetBackupPath(backupSID, KDbName, dbUid, backupPath);
sl@0
    81
	TEST2(err, KErrNotFound);
sl@0
    82
	dbUid.iUid = 0;
sl@0
    83
	TheTest.Printf(_L("--Invalid UID: 0\n"));
sl@0
    84
	err = TheDbs.GetBackupPath(backupSID, KDbName, dbUid, backupPath);
sl@0
    85
	TEST2(err, KErrArgument);
sl@0
    86
	//Invalid database name
sl@0
    87
	dbUid.iUid = 0x1133557A;
sl@0
    88
	TheTest.Printf(_L("--Null database name\n"));
sl@0
    89
	err = TheDbs.GetBackupPath(backupSID, KNullDesC, dbUid, backupPath);
sl@0
    90
	TEST2(err, KErrArgument);
sl@0
    91
	TheTest.Printf(_L("--Database name: no drive\n"));
sl@0
    92
	_LIT(KDbName2, "abcd.db");
sl@0
    93
	err = TheDbs.GetBackupPath(backupSID, KDbName2, dbUid, backupPath);
sl@0
    94
	TEST2(err, KErrArgument);
sl@0
    95
	//Valid arguments
sl@0
    96
	TheTest.Printf(_L("--Valid GetBackupPath() arguments\n"));
sl@0
    97
	err = TheDbs.GetBackupPath(backupSID, KDbName, dbUid, backupPath);
sl@0
    98
	TEST2(err, KErrNone);
sl@0
    99
	TheTest.Printf(_L("--Path: %S\n"), &backupPath);
sl@0
   100
	_LIT(KExpectedPath, "C:\\PRIVATE\\100012A5\\DBS_1133557A_ABCD.DB");
sl@0
   101
	TEST(backupPath.CompareF(KExpectedPath) == 0);
sl@0
   102
    //Valid arguments, but old format security policy file (without "backup" section)
sl@0
   103
	TSecureId backupSID3 = 1;
sl@0
   104
	TUid dbUid3 = {0x11335578};
sl@0
   105
	_LIT(KDbName3, "C:Z.db");
sl@0
   106
	TheTest.Printf(_L("--Valid GetBackupPath() arguments, old format file\n"));
sl@0
   107
	err = TheDbs.GetBackupPath(backupSID3, KDbName3, dbUid3, backupPath);
sl@0
   108
	TEST2(err, KErrPermissionDenied);
sl@0
   109
	}
sl@0
   110
sl@0
   111
//DEF063053  Additional method required on RDbs API for Secure Backup
sl@0
   112
static void DEF063053L()
sl@0
   113
	{
sl@0
   114
	//Invalid SID
sl@0
   115
	TheTest.Printf(_L("--Invalid backup SID: 0\n"));
sl@0
   116
	TSecureId backupSID = 0;
sl@0
   117
	TUid dbUid = {0x1133557A};
sl@0
   118
	CDbStrings* paths = NULL;
sl@0
   119
	TRAPD(err, paths = TheDbs.BackupPathsL(backupSID, dbUid));
sl@0
   120
	TEST2(err, KErrArgument);
sl@0
   121
	TEST(!paths);
sl@0
   122
sl@0
   123
	TheTest.Printf(_L("--Invalid backup SID: ECapability_None\n"));
sl@0
   124
	backupSID = (TUint32)ECapability_None;
sl@0
   125
	TRAP(err, paths = TheDbs.BackupPathsL(backupSID, dbUid));
sl@0
   126
	TEST2(err, KErrArgument);
sl@0
   127
	TEST(!paths);
sl@0
   128
sl@0
   129
	TheTest.Printf(_L("--Invalid backup SID: not matching the SID in security policy\n"));
sl@0
   130
	backupSID = (TUint32)0x109345FF;
sl@0
   131
	TRAP(err, paths = TheDbs.BackupPathsL(backupSID, dbUid));
sl@0
   132
	TEST2(err, KErrPermissionDenied);
sl@0
   133
	TEST(!paths);
sl@0
   134
sl@0
   135
	//Invalid UID
sl@0
   136
	TheTest.Printf(_L("--Invalid UID: no security policy for it\n"));
sl@0
   137
	backupSID = 0x30003000;
sl@0
   138
	dbUid.iUid = 0xFB34010F;
sl@0
   139
	TRAP(err, paths = TheDbs.BackupPathsL(backupSID, dbUid));
sl@0
   140
	TEST2(err, KErrArgument);
sl@0
   141
	TEST(!paths);
sl@0
   142
sl@0
   143
	TheTest.Printf(_L("--Invalid UID: 0\n"));
sl@0
   144
	dbUid.iUid = 0;
sl@0
   145
	TRAP(err, paths = TheDbs.BackupPathsL(backupSID, dbUid));
sl@0
   146
	TEST2(err, KErrArgument);
sl@0
   147
	TEST(!paths);
sl@0
   148
sl@0
   149
	//Valid arguments
sl@0
   150
	TheTest.Printf(_L("--Valid BackupPathL() arguments\n"));
sl@0
   151
	backupSID = 0x30003000;
sl@0
   152
	dbUid.iUid = 0x1133557A;
sl@0
   153
	TRAP(err, paths = TheDbs.BackupPathsL(backupSID, dbUid));
sl@0
   154
	TEST2(err, KErrNone);
sl@0
   155
	TEST(paths != NULL);
sl@0
   156
	for(TInt i=0;i<paths->Count();++i)
sl@0
   157
		{
sl@0
   158
		const TDesC& dd = (*paths)[i];
sl@0
   159
		RDebug::Print(_L("  Database %d: %S\r\n"), i + 1, &dd);
sl@0
   160
		}
sl@0
   161
	delete paths;
sl@0
   162
	paths = NULL;
sl@0
   163
sl@0
   164
	//Valid arguments, but no databases having the supplied security policy UID.
sl@0
   165
	TheTest.Printf(_L("--Valid BackupPathL() arguments, no databases\n"));
sl@0
   166
	backupSID = 0x30003001;
sl@0
   167
	dbUid.iUid = 0x11335577;
sl@0
   168
	TRAP(err, paths = TheDbs.BackupPathsL(backupSID, dbUid));
sl@0
   169
	TEST2(err, KErrNone);
sl@0
   170
	TEST(paths != NULL);
sl@0
   171
	TEST(paths->Count() == 0);
sl@0
   172
	delete paths;
sl@0
   173
	}
sl@0
   174
sl@0
   175
static void DoRunL()
sl@0
   176
	{
sl@0
   177
	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0036 Backup&restore SID "));
sl@0
   178
	::TestBackupSID();
sl@0
   179
sl@0
   180
	TheTest.Next(_L("DEF063053 Additional method required on RDbs API for Secure Backup"));
sl@0
   181
	::DEF063053L();
sl@0
   182
	}
sl@0
   183
sl@0
   184
TInt E32Main()
sl@0
   185
    {
sl@0
   186
	__UHEAP_MARK;
sl@0
   187
	CTrapCleanup* tc = CTrapCleanup::New();
sl@0
   188
	TEST(tc != NULL);
sl@0
   189
sl@0
   190
	TheTest.Title();
sl@0
   191
sl@0
   192
	TInt err = TheDbs.Connect();
sl@0
   193
	TEST2(err, KErrNone);
sl@0
   194
sl@0
   195
	TRAP(err, ::DoRunL());
sl@0
   196
	TEST2(err, KErrNone);
sl@0
   197
sl@0
   198
	TheDbs.Close();
sl@0
   199
sl@0
   200
	TheTest.End();
sl@0
   201
	TheTest.Close();
sl@0
   202
sl@0
   203
	delete tc;
sl@0
   204
sl@0
   205
	__UHEAP_MARKEND;
sl@0
   206
	User::Heap().Check();
sl@0
   207
	return KErrNone;
sl@0
   208
    }