installationservices/swinstallationfw/test/securitytests/source/scrfilepathprotection.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
child 27 e8965914fac7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /**
       
    20  @file
       
    21  @test
       
    22 */
       
    23 
       
    24 #include "scrfilepathprotection.h"
       
    25 
       
    26 #include <usif/scr/scr.h>
       
    27 #include <scs/cleanuputils.h>
       
    28 #include <e32def.h>
       
    29 
       
    30 _LIT(KScrPrivatePathSecName, "SCR private path file registration APIs test");
       
    31 
       
    32 using namespace Usif;
       
    33 
       
    34 // Throughout the tests we assume that at least one component is present, i.e. that component id 1 is valid
       
    35 const TComponentId KExistingComponentId = 1;
       
    36 
       
    37 void CScrPathProtectionSecTest::TestFileApisL(RSoftwareComponentRegistry& aScrSession, const TDesC& aFilename, const TDesC& aLogHeader)
       
    38 	{
       
    39 	TBuf<256> debugHeader;
       
    40 	
       
    41 	TInt err(0);
       
    42 	
       
    43 	TRAP(err, aScrSession.RegisterComponentFileL(KExistingComponentId, aFilename));
       
    44 	debugHeader.Format(_L("RegisterComponentFileL - %S"), &aLogHeader);
       
    45 	CheckFailL(err, debugHeader);	
       
    46 			
       
    47 	TRAP(err, aScrSession.SetFilePropertyL(KExistingComponentId, aFilename, _L("IntName"), 1));
       
    48 	debugHeader.Format(_L("SetFilePropertyL - int - %S"), &aLogHeader);
       
    49 	CheckFailL(err, debugHeader);	
       
    50 			
       
    51 	TRAP(err, aScrSession.SetFilePropertyL(KExistingComponentId, aFilename, _L("StringName"), _L8("PropertyValue")));
       
    52 	debugHeader.Format(_L("SetFilePropertyL - string - %S"), &aLogHeader);
       
    53 	CheckFailL(err, debugHeader);	
       
    54 	
       
    55 	TRAP(err, aScrSession.DeleteFilePropertyL(KExistingComponentId, aFilename, _L("StringName")));
       
    56 	debugHeader.Format(_L("DeleteFilePropertyL - %S"), &aLogHeader);
       
    57 	CheckFailL(err, debugHeader);
       
    58 	
       
    59 	TRAP(err, aScrSession.UnregisterComponentFileL(KExistingComponentId, aFilename));
       
    60 	debugHeader.Format(_L("UnregisterComponentFileL - %S"), &aLogHeader);
       
    61 	CheckFailL(err, debugHeader);		
       
    62 	}
       
    63 
       
    64 CScrPrivatePathProtectionSecTest* CScrPrivatePathProtectionSecTest::NewL()
       
    65 	{
       
    66 	CScrPrivatePathProtectionSecTest* self=new(ELeave) CScrPrivatePathProtectionSecTest();
       
    67 	CleanupStack::PushL(self);
       
    68 	self->ConstructL();
       
    69 	CleanupStack::Pop(self);
       
    70 	return self;
       
    71 	}
       
    72 
       
    73 CScrPrivatePathProtectionSecTest::CScrPrivatePathProtectionSecTest()
       
    74 	{
       
    75 	SetSidRequired(TUid::Uid(0x12345678)); // Require SID which corresponds to private directory path
       
    76 	}
       
    77 	
       
    78 void CScrPrivatePathProtectionSecTest::ConstructL()
       
    79 	{
       
    80 	SetNameL(KScrPrivatePathSecName);
       
    81 	}
       
    82 
       
    83 void CScrPrivatePathProtectionSecTest::RunTestL()
       
    84 	{
       
    85 	RSoftwareComponentRegistry scrSession;
       
    86 	User::LeaveIfError(scrSession.Connect());
       
    87 	CleanupClosePushL(scrSession);
       
    88 
       
    89 	_LIT(KOwnPrivatePathFilename, "c:\\private\\12345678\\file.txt");
       
    90 
       
    91 	TestFileApisL(scrSession, KOwnPrivatePathFilename, _L("own private path"));	
       
    92 			
       
    93 	// This test should always fail, as we are registering a file in a private directory which does not belong to us
       
    94 	SetExpectPermissionDenied(ETrue); 
       
    95 	_LIT(KOthersPrivatePathFilename, "c:\\private\\99999999\\file.txt");
       
    96 	TestFileApisL(scrSession, KOthersPrivatePathFilename, _L("others' private path"));
       
    97 		
       
    98 	SetExpectPermissionDenied(EFalse);
       
    99 	
       
   100 	// Public and import path should always succeed
       
   101 	_LIT(KOthersImportPrivatePathFilename, "c:\\private\\99999999\\import\\file.txt");
       
   102 	TestFileApisL(scrSession, KOthersImportPrivatePathFilename, _L("others' import path"));
       
   103 	
       
   104 	_LIT(KPublicFilename, "c:\file.txt");
       
   105 	TestFileApisL(scrSession, KPublicFilename, _L("public path"));	
       
   106 	CleanupStack::PopAndDestroy(&scrSession);
       
   107 	}
       
   108 
       
   109 //---------------CScrTCBPathProtectionSecTest------------------
       
   110 
       
   111 _LIT(KScrTCBPathSecName, "SCR TCB path file registration APIs test");
       
   112 
       
   113 CScrTCBPathProtectionSecTest* CScrTCBPathProtectionSecTest::NewL()
       
   114 	{
       
   115 	CScrTCBPathProtectionSecTest* self=new(ELeave) CScrTCBPathProtectionSecTest();
       
   116 	CleanupStack::PushL(self);
       
   117 	self->ConstructL();
       
   118 	CleanupStack::Pop(self);
       
   119 	return self;
       
   120 	}
       
   121 
       
   122 CScrTCBPathProtectionSecTest::CScrTCBPathProtectionSecTest()
       
   123 	{
       
   124 	SetCapabilityRequired(ECapabilityTCB);
       
   125 	}
       
   126 	
       
   127 void CScrTCBPathProtectionSecTest::ConstructL()
       
   128 	{
       
   129 	SetNameL(KScrTCBPathSecName);
       
   130 	}
       
   131 
       
   132 void CScrTCBPathProtectionSecTest::RunTestL()
       
   133 	{
       
   134 	RSoftwareComponentRegistry scrSession;
       
   135 	User::LeaveIfError(scrSession.Connect());
       
   136 	CleanupClosePushL(scrSession);
       
   137 
       
   138 	_LIT(KTcbPathFilename, "c:\\sys\\file.txt");
       
   139 	
       
   140 	TestFileApisL(scrSession, KTcbPathFilename, _L("\\sys path"));
       
   141 	
       
   142 	_LIT(KResourcePathFilename, "c:\\resource\\file.txt");
       
   143 		
       
   144 	TestFileApisL(scrSession, KResourcePathFilename, _L("\\resource path"));
       
   145 		
       
   146 	CleanupStack::PopAndDestroy(&scrSession);
       
   147 	}
       
   148