Refactor duplicate test code into a run_test subroutine.

Again, this does not touch any of the SSL tests to prevent merge conflicts.