Added tests

Also refactored some code in apache SSO
Fix for .encode(to, from)
Make sure valid_encoding? is not run on ruby 1.8 and force_encoding is always run.