secureswitools/swianalysistoolkit/test/tdumpcertstore/testswicertstore.pl
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 #
       
     2 # Copyright (c) 2007-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 # Perl script that test Dumpswicertstore tools
       
    16 #
       
    17 
       
    18 use File::Basename;
       
    19 my $scriptdir= dirname $0;
       
    20 print "Changing dir to $scriptdir\n";
       
    21 chdir $scriptdir;
       
    22 
       
    23 $logFile = "\\epoc32\\winscw\\c\\dumpswicertstore_test.txt";
       
    24 use File::Copy;
       
    25 use Cwd;
       
    26 
       
    27 
       
    28 #
       
    29 #Function to write log into file
       
    30 #
       
    31 sub WriteLog 
       
    32 	{
       
    33 	my ($log) = @_;
       
    34 	unless( open($fh, ">> $logFile")) 
       
    35 		{
       
    36 		printf STDERR "Can\'t open $logfile:$!\n";
       
    37 		return;
       
    38 		}
       
    39 	printf $fh $log;
       
    40 	printf $log;
       
    41 	close $fh;
       
    42 	}
       
    43 
       
    44 #
       
    45 # #
       
    46 sub CertstoreFile 
       
    47 	{
       
    48 	my ($datfile) = @_[0];
       
    49 	my ($expectedResult) = @_[1];
       
    50 	$datfile =~ s/\.dat//;
       
    51 	$neededfolder="";
       
    52 	$neededfile="";
       
    53 	$outputDir = "dumpcertstore-output\\";
       
    54 	if($datfile eq "\\epoc32\\winscw\\c\\resource\\swicertstore\\dat")
       
    55 		{
       
    56 		$writable = "writable.log";
       
    57 		@retval = system("dumpswicertstoretool.exe $datfile > $writable");
       
    58 		$logMsg = sprintf "Expected code:%5d   result Code:%5d\n", $expectedResult, $?;
       
    59 		WriteLog( $logMsg);
       
    60 		$NumberOfTests++;
       
    61 	
       
    62 		if( $? == $expectedResult) 
       
    63 			{
       
    64 			$writableoutput = "$outputDir" ."writable.out";
       
    65 			my $res=`diff "$writableoutput" "writable.log"`;
       
    66 			if(length($res) == 0)
       
    67 				{
       
    68 				$NumberOfPassed++;
       
    69 				WriteLog("Passed\n\n");
       
    70 				}
       
    71 			else
       
    72 				{
       
    73 				$NumberOfFailed++;
       
    74 				WriteLog("Failed: Files $writableoutput and writable.log are not matched\n\n");
       
    75 				}
       
    76 			}
       
    77 		else
       
    78 			{
       
    79 			$NumberOfFailed++;
       
    80 			WriteLog("Failed\n\n");
       
    81 			}
       
    82 		unlink("writable.log");
       
    83 		}
       
    84 	elsif($datfile eq "somecapabilities.dat \\epoc32\\winscw\\c\\resource\\swicertstore\\dat")
       
    85 		{
       
    86 		$both1 = "both1.log";
       
    87 		@retval = system("dumpswicertstoretool.exe $datfile > $both1");
       
    88 		$logMsg = sprintf "Expected code:%5d   result Code:%5d\n", $expectedResult, $?;
       
    89 		WriteLog( $logMsg);
       
    90 		$NumberOfTests++;
       
    91 		if( $? == $expectedResult) 
       
    92 			{
       
    93 			$both1output = "$outputDir" ."both1.out";
       
    94 			my $res=`diff "$both1output" "both1.log"`;
       
    95 			if(length($res) == 0)
       
    96 				{
       
    97 				$NumberOfPassed++;
       
    98 				WriteLog("Passed\n\n");
       
    99 				}
       
   100 			else
       
   101 				{
       
   102 				$NumberOfFailed++;
       
   103 				WriteLog("Failed: Files $both1output  and both1.log are not matched\n\n");
       
   104 				}
       
   105 			}
       
   106 		else
       
   107 			{
       
   108 			$NumberOfFailed++;
       
   109 			WriteLog("Failed\n\n");
       
   110 			}
       
   111 		 unlink("both1.log");
       
   112 		}
       
   113 	elsif($datfile eq "somecapabilities.dat")
       
   114 		{
       
   115 		$Yoption = "capdisplay_yoption.log";
       
   116 		@retval = system("dumpswicertstoretool.exe -y $datfile > $Yoption");
       
   117 		$logMsg = sprintf "Expected code:%5d   result Code:%5d\n", $expectedResult, $?;
       
   118 		WriteLog( $logMsg);
       
   119 		$NumberOfTests++;
       
   120 		if( $? == $expectedResult) 
       
   121 			{
       
   122 			$both1output = "$outputDir" ."capdisplay_yoption.out";
       
   123 			my $res=`diff "$both1output" "capdisplay_yoption.log"`;
       
   124 			if(length($res) == 0)
       
   125 				{
       
   126 				$NumberOfPassed++;
       
   127 				WriteLog("Passed\n\n");
       
   128 				}
       
   129 			else
       
   130 				{
       
   131 				$NumberOfFailed++;
       
   132 				WriteLog("Failed: Files $both1output  and capdisplay_yoption.log are not matched\n\n");
       
   133 				}
       
   134 			}
       
   135 		else
       
   136 			{
       
   137 			$NumberOfFailed++;
       
   138 			WriteLog("Failed\n\n");
       
   139 			}
       
   140 
       
   141 		@retval = system("dumpswicertstoretool.exe -d $datfile > $Yoption");
       
   142 		$logMsg = sprintf "Expected code:%5d   result Code:%5d\n", $expectedResult, $?;
       
   143 		WriteLog( $logMsg);
       
   144 		$NumberOfTests++;
       
   145 		if( $? == $expectedResult) 
       
   146 			{
       
   147 			$both1output = "$outputDir" ."capdisplay_doption.out";
       
   148 			my $res=`diff "$both1output" "capdisplay_doption.log"`;
       
   149 			if(length($res) == 0)
       
   150 				{
       
   151 				$NumberOfPassed++;
       
   152 				WriteLog("Passed\n\n");
       
   153 				}
       
   154 			else
       
   155 				{
       
   156 				$NumberOfFailed++;
       
   157 				WriteLog("Failed: Files $both1output  and capdisplay_doption.log are not matched\n\n");
       
   158 				}
       
   159 			}
       
   160 		else
       
   161 			{
       
   162 			$NumberOfFailed++;
       
   163 			WriteLog("Failed\n\n");
       
   164 			}
       
   165 
       
   166 		 unlink("capdisplay_yoption.log");
       
   167 		}
       
   168 	
       
   169 	elsif($datfile eq "NoMandatory.dat \\epoc32\\winscw\\c\\resource\\swicertstore\\dat")
       
   170 		{
       
   171 		$both2 = "both2.log";
       
   172 		@retval = system("dumpswicertstoretool.exe $datfile > $both2");
       
   173 		$logMsg = sprintf "Expected code:%5d   result Code:%5d\n", $expectedResult, $?;
       
   174 		WriteLog( $logMsg);
       
   175 		$NumberOfTests++;
       
   176 		if( $? == $expectedResult) 
       
   177 			{
       
   178 			$both2output = "$outputDir" ."both2.out";
       
   179 			my $res=`diff "$both2output" "both2.log"`;
       
   180 			if(length($res) == 0)
       
   181 				{
       
   182 				$NumberOfPassed++;
       
   183 				WriteLog("Passed\n\n");
       
   184 				}
       
   185 			else
       
   186 				{
       
   187 				$NumberOfFailed++;
       
   188 				WriteLog("Failed: Files $both2output and both2.log are not matched\n\n");
       
   189 				}
       
   190 				
       
   191 			}
       
   192 		else
       
   193 			{
       
   194 			$NumberOfFailed++;
       
   195 			WriteLog("Failed\n\n");
       
   196 			}
       
   197 		unlink("both2.log");
       
   198 	
       
   199 		}
       
   200 	else
       
   201 		{
       
   202 		@retval = system("dumpswicertstoretool.exe $datfile.dat > $datfile.log");
       
   203 		$logMsg = sprintf "Expected code:%5d   result Code:%5d\n", $expectedResult, $?;
       
   204 		WriteLog( $logMsg);
       
   205 		$NumberOfTests++;
       
   206 		if( $? == $expectedResult) 
       
   207 			{
       
   208 			$outputDat = "$outputDir" ."$datfile.out";
       
   209 			my $res=`diff "$outputDat" "$datfile.log"`;
       
   210 			if(length($res) == 0)
       
   211 				{
       
   212 				$NumberOfPassed++;
       
   213 				WriteLog("Passed\n\n");
       
   214 				}
       
   215 			else
       
   216 				{
       
   217 				$NumberOfFailed++;
       
   218 				WriteLog("Failed: Files $outputDat and $datfile.log are not matched\n\n");
       
   219 				}
       
   220 			if("$pkgfile.dat" eq "AllCapabilities.dat")
       
   221 				{
       
   222 				WriteLog("Test for Extract Certificate\n");
       
   223 				@retval = system("dumpswicertstoretool.exe -c $datfile.dat > $datfile.log");
       
   224 				$logMsg = sprintf "Expected code:%5d   result Code:%5d\n", $expectedResult, $?;
       
   225 				WriteLog( $logMsg);
       
   226 				$NumberOfTests++;
       
   227 				if( $? == $expectedResult) 
       
   228 					{
       
   229 					$neededfile = "Root5CA.der";
       
   230 					if(-e $neededfile && -s $neededfile)
       
   231 						{
       
   232 						$NumberOfPassed++;
       
   233 						WriteLog("Passed\n\n");
       
   234 						}
       
   235 					else
       
   236 						{
       
   237 						$NumberOfFailed++;
       
   238 						WriteLog("Failed\n\n");
       
   239 						}
       
   240 					}
       
   241 				else
       
   242 					{
       
   243 					$NumberOfFailed++;
       
   244 					WriteLog("Failed\n\n");
       
   245 					}
       
   246 				}
       
   247 			
       
   248 				
       
   249 			}
       
   250 		else
       
   251 			{
       
   252 			$NumberOfFailed++;
       
   253 			WriteLog("Failed\n\n");
       
   254 			}
       
   255 	   unlink("$datfile.log");
       
   256 		}
       
   257 
       
   258 	}
       
   259 
       
   260 #
       
   261 # Main
       
   262 #
       
   263 # Create environment and control test flow to testing Dumpswicertstoretool.EXE 
       
   264 #
       
   265 
       
   266 unlink($logFile);
       
   267 WriteLog("DumpSWICertstoreTool test.\n\n");
       
   268 
       
   269 #
       
   270 # Counters for results
       
   271 #
       
   272 $NumberOfTests  = 0;
       
   273 $NUmberOfPassed = 0;
       
   274 $NumberOfFailed = 0;
       
   275 
       
   276 
       
   277 #                file name,   			expected , expected log,            Title
       
   278 #						result     message
       
   279 #               ---------------------------------------------------------------------------------------------------- 
       
   280 @TestItems = (	["somecapabilities.dat", 	0,    , "Created",		"Test for certstore with certificates having some capablities"],
       
   281 		["AllCapabilities.dat", 	0,    , "Created",		"Test for certstore with some certificates granting  all capabilities, some granting no capabilities and some granting few capabilities"],
       
   282 		["somecapabilities.dat", 	0,    , "Created",		"Test for certstore with some certificate (few mandatory flag set and few not set)"],
       
   283 		["\\epoc32\\winscw\\c\\resource\\swicertstore\\dat", 0,    , "Created",		"Test for writable certstore with multiple files(having corrupt file/files)"],
       
   284 		["somecapabilities.dat.dat \\epoc32\\winscw\\c\\resource\\swicertstore\\dat", 0,    , "Created", "Test for certstore with Certificates in C: and not in Z: (Merge)"],
       
   285 		["NoMandatory.dat.dat \\epoc32\\winscw\\c\\resource\\swicertstore\\dat", 0,    , "Created",	"Test for certstore with Certificates in Z: and not in C: (Merge)"],
       
   286 		["somecapabilities.dat.dat \\epoc32\\winscw\\c\\resource\\swicertstore\\dat", 0,    , "Created", "Test for Certificates in both certstore with different settings (capability and mandatory)(Merge))"],
       
   287 		["corrupted.dat", 		1024,    , "Verification failed",		"Corrupted certstore"],
       
   288 		["unicodecertificatename.dat", 	0,    , "Created",		"Test for unicode certificate names"],
       
   289 		["somecapabilities.dat.dat", 	0,    , "Created",		"Test of tool with y and d option for capabilities having text information "],
       
   290 		["suflagsupport.dat", 	0,    , "Created",		"Test for certstore with certificates having su flag set"],
       
   291 	     );
       
   292 
       
   293 
       
   294 
       
   295 
       
   296 #
       
   297 # Do test for each elements of TestItems array
       
   298 #
       
   299 for my $Test ( @TestItems )  
       
   300 	{
       
   301 	$testid = sprintf "SEC-SWI-I-CERTSTORE-000%d\n",$NumberOfTests+1;
       
   302 	WriteLog($testid);
       
   303 	$logMsg = sprintf "%s\n", $Test->[3];
       
   304 	WriteLog($logMsg);
       
   305 	CertstoreFile($Test->[0], $Test->[1]);
       
   306 	}
       
   307 
       
   308 opendir(DIR, ".");
       
   309 while (defined($file=readdir(DIR)))
       
   310 	{
       
   311 	$datfile = $file;
       
   312 	$file =~ s/\.der//;
       
   313 	$datfile= ~ s/\.dat//;
       
   314 	if(-e "$file.der")
       
   315 		{
       
   316 		unlink("$file.der");
       
   317 		}
       
   318 	close(DIR);
       
   319 	}
       
   320 
       
   321 opendir(DIR, ".");
       
   322 while (defined($file=readdir(DIR)))
       
   323 	{
       
   324 	$file =~ s/\.dat//;
       
   325 	if(-e "$file.dat")
       
   326 		{
       
   327 		unlink("$file.dat");
       
   328 		}
       
   329 	close(DIR);
       
   330 	}
       
   331 #
       
   332 # Display the result
       
   333 #
       
   334 WriteLog("\n\nTests completed OK\n");
       
   335 WriteLog(sprintf "Run: %d\n", $NumberOfTests );
       
   336 WriteLog(sprintf "Passed: %d\n", $NumberOfPassed );
       
   337 WriteLog(sprintf "%d tests failed out of %d\n", $NumberOfFailed, $NumberOfTests );