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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Test</strong>ing the Cryptography Application Block 45<br />

Design test case Implemented? Feature that implements design<br />

Verify that the instrumentation<br />

is implemented with loosely<br />

coupled events.<br />

Yes<br />

The methods in the HashAlgorithmInstrumentationProvider<br />

class that raise the<br />

events bind to the methods in the HashAlgorithmInstrumentationListener<br />

class at<br />

run time.<br />

Verify that situations that can<br />

cause exceptions are addressed<br />

and that the application<br />

block logs the exceptions<br />

through the instrumentation.<br />

Verify that the application<br />

block supports custom property<br />

collections for the custom<br />

symmetric key providers and<br />

for custom hash providers.<br />

Yes<br />

Yes<br />

For example, both the HashAlgorithmProvider<br />

class and the SymmetricAlgorithm-<br />

Provider class include the Instrumentation-<br />

Provider property. This property retrieves<br />

the instrumentation provider that defines<br />

the events for the cryptography provider.<br />

The provider logs the events to WMI and<br />

the event log.<br />

The CustomHashProviderData class and<br />

the CustomSymmetricCryptoProviderData<br />

class provides the ability to configure<br />

custom property collections for custom<br />

providers.<br />

After the code is implemented, you can review it to see if it satisfies its test cases.<br />

Table 4 lists the results of a code review for the Cryptography Application Block.<br />

Table 4: Cryptography Application Block Code Verification<br />

Code test case Implemented? Feature that is implemented<br />

Verify that the<br />

Cryptographer<br />

façade exposes<br />

all public members<br />

as static and<br />

supports methods<br />

for encryption,<br />

decryption, and<br />

hashing.<br />

Yes<br />

The Cryptographer class is a façade that exposes<br />

the CreateHash method to compute the hash value of<br />

plain text, the CompareHash method to compare plain<br />

text with a hash value, the EncryptSymmetric method<br />

to encrypt plain text, and the DecryptSymmetric<br />

method to decrypt a symmetrically encrypted secret.<br />

These methods are shown in the following code.<br />

public static byte[] CreateHash(string hash-<br />

Instance, byte[] plaintext) {}<br />

public static bool CompareHash(string hashInstance,<br />

string plaintext, string hashedText)<br />

{}<br />

public static string EncryptSymmetric(string<br />

symmetricInstance, string plaintext) {}<br />

public static string DecryptSymmetric(string<br />

symmetricInstance, string ciphertextBase64)<br />

{}<br />

continued

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

Saved successfully!

Ooh no, something went wrong!