Improved error handling of CredentialStore, added basic tests