adding unit tests, some refactoring

return nil now instead of the crazy array of directories the function
used to return when it couldn't find anything.  make it deterministic
if there's both a 'keyfile' and 'keyfile.pem' present.  also, add some
unit tests for this one function.