diff --git a/plugins/Google.py b/plugins/Google.py index fb104e2a9..9e1892be8 100644 --- a/plugins/Google.py +++ b/plugins/Google.py @@ -42,6 +42,7 @@ import getopt import socket import urllib2 +import SOAP import google import conf @@ -119,6 +120,9 @@ def search(*args, **kwargs): return 'Connection timed out to Google.com.' else: raise + except SOAP.faultType, e: + debug.msg(debug.exnToString(e)) + raise callbacks.Error, 'Invalid Google license key.' class Google(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable): threaded = True @@ -168,6 +172,9 @@ class Google(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable): is necessary before you can do any searching with this module. """ key = privmsgs.getArgs(args) + if len(key) != 32: + irc.error(msg, 'That doesn\'t seem to be a valid license key.') + return google.setLicense(key) irc.reply(msg, conf.replySuccess) licensekey = privmsgs.checkCapability(licensekey, 'admin') diff --git a/test/test_Google.py b/test/test_Google.py index 2925557f8..46710eb3f 100644 --- a/test/test_Google.py +++ b/test/test_Google.py @@ -66,6 +66,12 @@ class GoogleTestCase(ChannelPluginTestCase, PluginDocumentation): 'lr=lang_en&ie=UTF-8&oe=UTF-8&selm=698f09f8.' '0310132012.738e22fc%40posting.google.com') + def testInvalidKeyCaught(self): + self.assertNotError( + 'google licensekey abcdefghijklmnopqrstuvwxyz123456') + self.assertNotRegexp('google foobar', 'faultType') + self.assertNotRegexp('google foobar', 'SOAP') + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: