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 247<br />

Specific Security <strong>Test</strong>s<br />

Specific aspects of each application block were also tested to see if they followed<br />

security best practices. This section discusses security issues that were found in the<br />

Data Access Application Block and the Cryptography Application Block.<br />

<strong>Test</strong>ing the Data Access Application Block<br />

This test case determined whether the Data Access Application Block violated security<br />

best practices by returning the password that is stored in the ConnectionString<br />

property to the user. It is important to ensure that this does not happen because it can<br />

give malicious users access to sensitive information.<br />

<strong>Test</strong> Case<br />

The test case checked to see if the application block returned the password to the<br />

user. If it did, the test case failed. The following code implemented the test case.<br />

[<strong>Test</strong>Method]<br />

public void <strong>Test</strong>PasswordInConnectionStringWithDAAB()<br />

{<br />

Database db =DatabaseFactory.CreateDatabase("PasswordProtectedConnectionString<br />

Instance");<br />

db.Connection.Open();<br />

string connectionString = db.ConnectionString;<br />

db.Connection.Close();<br />

if (connectionString.Contains("password=test"))<br />

{<br />

Assert.Fail();<br />

}<br />

}<br />

Problem<br />

The test case failed because the Database class exposed the ConnectionString property<br />

as a public member. This allowed a user to read the password. The following<br />

code caused the problem.<br />

public string ConnectionString<br />

{<br />

get<br />

{<br />

return this.connectionString.ToString();<br />

}<br />

}<br />

Solution<br />

The Database class was modified so that the ConnectionString property was<br />

changed from a public member to a protected internal member. A new public property<br />

named ConnectionStringWithoutCredentials was added. This property returns

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

Saved successfully!

Ooh no, something went wrong!