07.11.2014 Views

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Using the <strong>Test</strong> Cases 245<br />

This is the code that caused the problems.<br />

public static ProtectedKey Read(string protectedKeyFileName, DataProtectionScope<br />

dpapiProtectionScope)<br />

{<br />

using (FileStream stream = new FileStream(protectedKeyFileName, FileMode.<br />

Open))<br />

{<br />

return Read(stream, dpapiProtectionScope);<br />

}<br />

}<br />

Solution<br />

To solve the first problem, the Read method was modified so that it read the symmetric<br />

key only once from the file and then cached the key in a static collection. Subsequent<br />

reads retrieved the file from the cache, which greatly reduced the performance<br />

overhead.<br />

To solve the second problem, the Read method was modified to use constructors that<br />

included the FileShare.Read enumeration. This allowed multiple users to concurrently<br />

read the file. The following is the code that solved both the performance problem<br />

and the concurrency problem.<br />

public static ProtectedKey Read(string protectedKeyFileName, DataProtectionScope<br />

dpapiProtectionScope)<br />

{<br />

string completeFileName = Path.GetFullPath(protectedKeyFileName);<br />

if (cache[completeFileName] != null)<br />

return cache[completeFileName];<br />

using (FileStream stream = new FileStream(protectedKeyFileName, FileMode.Open,<br />

FileAccess.Read, FileShare.Read))<br />

{<br />

ProtectedKey protectedKey = Read(stream, dpapiProtectionScope);<br />

cache[completeFileName] = protectedKey;<br />

return protectedKey;<br />

}<br />

}<br />

Verification<br />

Running the test case again after applying the preceding code verified that the cost of<br />

reading a key from a file was within acceptable limits. In addition, concurrent users<br />

could now read the file.<br />

Security <strong>Test</strong>ing<br />

The goals of security testing are the following:<br />

●<br />

●<br />

●<br />

Identify the potential threats to the application blocks.<br />

Identify the vulnerabilities of the application blocks.<br />

Provide counter measures to these threats and vulnerabilities.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!