os/persistentdata/loggingservices/eventlogger/test/src/T_LogSecurity.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2005-2010 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 //
    15 
    16 #include <e32test.h>
    17 #include <f32file.h>
    18 #include "logservsecurity.h"
    19 #include "LogServResourceInterpreter.h"
    20 #include <logeng.h>
    21 #include <logengevents.h>
    22 #include "t_logsecuritypolicy.h"
    23 #include "t_logutil.h"
    24 
    25 RTest TheTest(_L("t_logsecurity"));
    26 static RFs TheFileSess;
    27 
    28 ///////////////////////////////////////////////////////////////////////////////////////
    29 //
    30 
    31 //Check if supplied aPolicy parameter has aCapability capability.
    32 static TBool HasCapability(const TCompiledSecurityPolicy& aPolicy, TCapability aCapability)
    33 	{
    34 	TInt maxCount = 0;
    35 	if(aPolicy.Type() == TSecurityPolicy::ETypeS3 || 
    36 	   aPolicy.Type() == TSecurityPolicy::ETypeV3 ||
    37 	   aPolicy.Type() == TSecurityPolicy::ETypeC3)
    38 		{
    39 		maxCount = 3;	
    40 		}
    41 	else if(aPolicy.Type() == TSecurityPolicy::ETypeC7)
    42 		{
    43 		maxCount = 7;	
    44 		}
    45 	else
    46 		{
    47 		TEST(0);
    48 		}
    49 	for(TInt i=0;i<maxCount;++i)
    50 		{
    51 		if(aPolicy.Capability(i) == aCapability)
    52 			{
    53 			return ETrue;	
    54 			}
    55 		}
    56 	return EFalse;
    57 	}
    58 
    59 ///////////////////////////////////////////////////////////////////////////////////////
    60 //
    61 
    62 //Checks that all supported LogEngServer event types have the expected capabilities.
    63 //See LogWrap.rss file
    64 static void CheckEventSecurityPolicies(CLogServSecurity& aLogServSecurity)
    65 	{
    66 	TSecurityPolicy plc1r = aLogServSecurity.SecurityPolicy(KLogCallEventTypeUid, EReadOp);
    67 	TEST(::HasCapability(plc1r, ECapabilityReadUserData));
    68 	
    69 	TSecurityPolicy plc1w = aLogServSecurity.SecurityPolicy(KLogCallEventTypeUid, EWriteOp);
    70 	TEST(::HasCapability(plc1w, ECapabilityWriteUserData));
    71 	
    72 	TSecurityPolicy plc2r = aLogServSecurity.SecurityPolicy(KLogDataEventTypeUid, EReadOp);
    73 	TEST(::HasCapability(plc2r, ECapabilityReadUserData));
    74 	
    75 	TSecurityPolicy plc2w = aLogServSecurity.SecurityPolicy(KLogDataEventTypeUid, EWriteOp);
    76 	TEST(::HasCapability(plc2w, ECapabilityWriteUserData));
    77 	
    78 	TSecurityPolicy plc3r = aLogServSecurity.SecurityPolicy(KLogFaxEventTypeUid, EReadOp);
    79 	TEST(::HasCapability(plc3r, ECapabilityReadUserData));
    80 	
    81 	TSecurityPolicy plc3w = aLogServSecurity.SecurityPolicy(KLogFaxEventTypeUid, EWriteOp);
    82 	TEST(::HasCapability(plc3w, ECapabilityWriteUserData));
    83 	
    84 	TSecurityPolicy plc4r = aLogServSecurity.SecurityPolicy(KLogShortMessageEventTypeUid, EReadOp);
    85 	TEST(::HasCapability(plc4r, ECapabilityReadUserData));
    86 	
    87 	TSecurityPolicy plc4w = aLogServSecurity.SecurityPolicy(KLogShortMessageEventTypeUid, EWriteOp);
    88 	TEST(::HasCapability(plc4w, ECapabilityWriteUserData));
    89 	
    90 	TSecurityPolicy plc5r = aLogServSecurity.SecurityPolicy(KLogMailEventTypeUid, EReadOp);
    91 	TEST(TCompiledSecurityPolicy(plc5r).Type() == TSecurityPolicy::EAlwaysPass);
    92 	
    93 	TSecurityPolicy plc5w = aLogServSecurity.SecurityPolicy(KLogMailEventTypeUid, EWriteOp);
    94 	TEST(TCompiledSecurityPolicy(plc5w).Type() == TSecurityPolicy::EAlwaysPass);
    95 	
    96 	TSecurityPolicy plc6r = aLogServSecurity.SecurityPolicy(KLogTaskSchedulerEventTypeUid, EReadOp);
    97 	TEST(::HasCapability(plc6r, ECapabilityReadUserData));
    98 	
    99 	TSecurityPolicy plc6w = aLogServSecurity.SecurityPolicy(KLogTaskSchedulerEventTypeUid, EWriteOp);
   100 	TEST(!::HasCapability(plc6w, ECapabilityWriteUserData));
   101 	
   102 	TSecurityPolicy plc7r = aLogServSecurity.SecurityPolicy(KLogPacketDataEventTypeUid, EReadOp);
   103 	TEST(::HasCapability(plc7r, ECapabilityReadUserData));
   104 	
   105 	TSecurityPolicy plc7w = aLogServSecurity.SecurityPolicy(KLogPacketDataEventTypeUid, EWriteOp);
   106 	TEST(::HasCapability(plc7w, ECapabilityWriteUserData));
   107 	
   108 	
   109 	TSecurityPolicy plc8r = aLogServSecurity.SecurityPolicy(KLogLbsSelfLocateEventTypeUid, EReadOp);
   110 	TEST(::HasCapability(plc8r, ECapabilityReadDeviceData));
   111 	
   112 	TSecurityPolicy plc8w = aLogServSecurity.SecurityPolicy(KLogLbsSelfLocateEventTypeUid, EWriteOp);
   113 	TEST(::HasCapability(plc8w, ECapabilityWriteDeviceData));
   114 	
   115 	TSecurityPolicy plc9r = aLogServSecurity.SecurityPolicy(KLogLbsExternalLocateEventTypeUid, EReadOp);
   116 	TEST(::HasCapability(plc9r, ECapabilityReadDeviceData));
   117 	
   118 	TSecurityPolicy plc9w = aLogServSecurity.SecurityPolicy(KLogLbsExternalLocateEventTypeUid, EWriteOp);
   119 	TEST(::HasCapability(plc9w, ECapabilityWriteDeviceData));
   120 	
   121 	TSecurityPolicy plc10r = aLogServSecurity.SecurityPolicy(KLogLbsTransmitLocationEventTypeUid, EReadOp);
   122 	TEST(::HasCapability(plc10r, ECapabilityReadDeviceData));
   123 	
   124 	TSecurityPolicy plc10w = aLogServSecurity.SecurityPolicy(KLogLbsTransmitLocationEventTypeUid, EWriteOp);
   125 	TEST(::HasCapability(plc10w, ECapabilityWriteDeviceData));
   126 	
   127 	TSecurityPolicy plc11r = aLogServSecurity.SecurityPolicy(KLogLbsNetworkLocateEventTypeUid, EReadOp);
   128 	TEST(::HasCapability(plc11r, ECapabilityReadDeviceData));
   129 	
   130 	TSecurityPolicy plc11w = aLogServSecurity.SecurityPolicy(KLogLbsNetworkLocateEventTypeUid, EWriteOp);
   131 	TEST(::HasCapability(plc11w, ECapabilityWriteDeviceData));
   132 	
   133 	TSecurityPolicy plc12r = aLogServSecurity.SecurityPolicy(KLogLbsAssistanceDataEventTypeUid, EReadOp);
   134 	TEST(::HasCapability(plc12r, ECapabilityReadDeviceData));
   135 	
   136 	TSecurityPolicy plc12w = aLogServSecurity.SecurityPolicy(KLogLbsAssistanceDataEventTypeUid, EWriteOp);
   137 	TEST(::HasCapability(plc12w, ECapabilityWriteDeviceData));
   138 	}
   139 
   140 
   141 static void DoOOMTestL()
   142 	{
   143   CLogServResourceInterpreter* logServRsc = CLogServResourceInterpreter::NewL(TheFileSess);
   144 	CleanupStack::PushL(logServRsc);
   145 	
   146 	CLogServSecurity* logServSecurity = CLogServSecurity::NewL(*logServRsc);
   147 	CleanupStack::PushL(logServSecurity);
   148 
   149 	::CheckEventSecurityPolicies(*logServSecurity);
   150 
   151 	CleanupStack::PopAndDestroy(logServSecurity);
   152 	CleanupStack::PopAndDestroy(logServRsc);
   153 	}
   154 
   155 // CLogServSecurity instance creation - OOM test
   156 static void OOMTest()
   157 	{
   158 	for(TInt count=1;;++count)
   159 		{
   160 		__UHEAP_FAILNEXT(count);
   161 		__UHEAP_MARK;
   162 		TRAPD(err, ::DoOOMTestL());
   163 
   164 		if(err == KErrNoMemory)
   165 			{
   166 			__UHEAP_MARKEND;
   167 			}
   168 		else if(err == KErrNone)
   169 			{
   170 			__UHEAP_MARKEND;
   171 			TheTest.Printf(_L("The test succeeded at heap failure rate=%d.\n"), count);
   172 			break;
   173 			}
   174 		else 
   175 			{
   176 			__UHEAP_MARKEND;
   177 			TEST2(err, KErrNone);
   178 			}
   179 		}
   180 	__UHEAP_RESET;
   181 	}
   182 	
   183 ///////////////////////////////////////////////////////////////////////////////////////
   184 //
   185 
   186 static void MainL()
   187 	{
   188 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIBS-LOGENG-LEGACY-T_LOGSECURITY-0001 OOM test "));
   189 	::OOMTest();
   190 	}
   191 
   192 TInt E32Main()
   193 	{
   194 	__UHEAP_MARK;
   195 
   196 	CTrapCleanup* tc = CTrapCleanup::New();
   197 	TEST(tc != NULL);
   198 	
   199 	TEST2(TheFileSess.Connect(), KErrNone);
   200 
   201 	TheTest.Title();
   202 	TRAPD(err, ::MainL());
   203 	TEST2(err, KErrNone);
   204 	
   205 	TheTest.End();
   206 	TheTest.Close();
   207 
   208 	TheFileSess.Close();
   209 	
   210 	delete tc;
   211 
   212 	__UHEAP_MARKEND;
   213 
   214 	User::Heap().Check();
   215 	return KErrNone;
   216 	}