|
Test Code-Access Security
Posted March 15, 2004
Programming security is one of the harder development tasks. .NET creates fairly secure code by default, but code-access security (CAS) can be difficult to implement correctly and to verify. Desaware's CAS/Tester, an automated test suite that explores the security fragilities of .NET code, can help you meet this challenge. Think of it as unit testing for CAS.
Like other Desaware products, CAS/Tester is well designed. It loads the assembly you specify through a gamut of tests. More than 80 tests come with the product, and you can add more. Most tests remove one or more .NET permissions from your code and check whether the code raises any exceptions in response. For example, a test checks to see if code that uses the disk file system will fail without the read/write permission. If your code properly demands this permission and fails gracefully without it, it passes the test. If it raises an exception, you've found a CAS issue.
CAS/Tester includes command-line, VS.NET add-in, and standalone-launcher interfaces. The command-line version is useful for including CAS tests in your build suite, and the XML output reports allow automated analysis. The VS.NET add-in runs the standalone launcher but opens windows in the IDE to present reports. Unfortunately, it doesn't list assemblies from the current project automatically for easy selection.
To run CAS/Tester, you specify an assembly or executable to test and either a specific object to test or a test script to run. If you select an object, you can test all methods or a single function. Testing one function is useful if you build test functions into the object; this lets you test far more deeply than CAS/Tester can as an external application. You can also specify whether to run all the default tests or only a selected test, include optional command-line parameters, and set the timeouts for application startup and test duration.
You can go beyond generic testing and write reusable test scripts (in any .NET language) to build your own test harness, which you can incorporate into other test suites. You must understand how CAS works in order to write scripts, then implement a simple interface for CAS/Tester to hook into.
CAS/Tester outputs the test results as XML, providing an Extensible Stylesheet Language Transformations (XSLT) template that displays the XML file as a nicely formatted HTML Web page. The report includes the test's details and options, sections for any test-script errors and test-setup errors, a summary of test results, and detailed results of each test (see Figure 1). The results include a stack trace, so you can locate problems in your code easily.
.NET gives you all the tools to write rock-solid code, but at the cost of complexity. CAS/Tester lets you test your application thoroughly so that you know it can run in a variety of security contexts.
CAS/Tester
Desaware
Web: www.desaware.com
Phone: 408-377-4770
Price: $399
Quick Facts: Automated code-access security (CAS) testing tool.
Pros: Simple, effective interface; flexible options for any internal and external tests; reports that help pinpoint problems.
Cons: Effective use requires an understanding of CAS.
About the Author
Don Kiely is a senior technology consultant. When he isn't writing software, he's writing about it, speaking about it at conferences, and training developers in it. Reach him at .
Back to top
|