Fixes bug 824849 - Fixed and improved middleware testing.