From db09100772f958fb247e265bff75d50a8f5ac7a2 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 18 May 2015 13:01:12 +0200 Subject: [PATCH] GPG: Fix previous commit. --- plugins/GPG/config.py | 10 ++++++++++ plugins/GPG/plugin.py | 12 +++++++++--- plugins/GPG/test.py | 14 ++++++++------ plugins/User/config.py | 9 --------- plugins/User/plugin.py | 2 -- plugins/User/test.py | 1 - 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/plugins/GPG/config.py b/plugins/GPG/config.py index 8c374ba12..4c74d20da 100644 --- a/plugins/GPG/config.py +++ b/plugins/GPG/config.py @@ -53,5 +53,15 @@ GPG = conf.registerPlugin('GPG') # conf.registerGlobalValue(GPG, 'someConfigVariableName', # registry.Boolean(False, _("""Help for someConfigVariableName."""))) +conf.registerGroup(GPG, 'auth') +conf.registerGroup(GPG.auth, 'sign') + +conf.registerGlobalValue(GPG.auth.sign, 'enable', + registry.Boolean(True, """Determines whether or not users are + allowed to use GPG signing for authentication.""")) +conf.registerGlobalValue(GPG.auth.sign, 'TokenTimeout', + registry.PositiveInteger(60*10, """Determines the lifetime of a GPG + signature authentication token (in seconds).""")) + # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/plugins/GPG/plugin.py b/plugins/GPG/plugin.py index d6dff5a7f..49c6e5603 100644 --- a/plugins/GPG/plugin.py +++ b/plugins/GPG/plugin.py @@ -29,8 +29,14 @@ ### import re +import sys +import time +import uuid +import supybot.gpg as gpg +import supybot.conf as conf import supybot.utils as utils +import supybot.ircdb as ircdb from supybot.commands import * import supybot.plugins as plugins import supybot.ircutils as ircutils @@ -103,9 +109,9 @@ class GPG(callbacks.Plugin): irc.reply(format('%L', keyids)) list = wrap(list, ['user']) - class sign(callbacks.Commands): + class signing(callbacks.Commands): def __init__(self, *args): - super(User.gpg, self).__init__(*args) + super(GPG.signing, self).__init__(*args) self._tokens = {} def _expire_tokens(self): @@ -119,7 +125,7 @@ class GPG(callbacks.Plugin): Send you a token that you'll have to sign with your key.""" self._expire_tokens() token = '{%s}' % str(uuid.uuid4()) - lifetime = conf.supybot.plugins.User.gpg.TokenTimeout() + lifetime = conf.supybot.plugins.GPG.auth.sign.TokenTimeout() self._tokens.update({token: (msg.prefix, time.time()+lifetime)}) irc.reply(_('Your token is: %s. Please sign it with your ' 'GPG key, paste it somewhere, and call the \'auth\' ' diff --git a/plugins/GPG/test.py b/plugins/GPG/test.py index eaaaaf82f..f883e25d3 100644 --- a/plugins/GPG/test.py +++ b/plugins/GPG/test.py @@ -28,6 +28,8 @@ ### +from cStringIO import StringIO + from supybot.test import * import supybot.gpg as gpg @@ -75,7 +77,7 @@ FINGERPRINT = '2CF3E41500218D30F0B654F5C9D3323C20AF012B' class GPGTestCase(PluginTestCase): - plugins = ('GPG',) + plugins = ('GPG', 'User') def setUp(self): super(GPGTestCase, self).setUp() @@ -100,7 +102,7 @@ class GPGTestCase(PluginTestCase): gpg.keyring.import_keys(PRIVATE_KEY).__dict__ (id, user) = ircdb.users.items()[0] user.gpgkeys.append(FINGERPRINT) - msg = self.getMsg('gpg gettoken').args[-1] + msg = self.getMsg('gpg signing gettoken').args[-1] match = re.search('is: ({.*}).', msg) assert match, repr(msg) token = match.group(1) @@ -112,25 +114,25 @@ class GPGTestCase(PluginTestCase): fd = StringIO() fd.write('foo') fd.seek(0) - self.assertResponse('gpg sign auth http://foo.bar/baz.gpg', + self.assertResponse('gpg signing auth http://foo.bar/baz.gpg', 'Error: Signature or token not found.') fd = StringIO() fd.write(token) fd.seek(0) - self.assertResponse('gpg sign auth http://foo.bar/baz.gpg', + self.assertResponse('gpg signing auth http://foo.bar/baz.gpg', 'Error: Signature or token not found.') fd = StringIO() fd.write(WRONG_TOKEN_SIGNATURE) fd.seek(0) - self.assertRegexp('gpg sign auth http://foo.bar/baz.gpg', + self.assertRegexp('gpg signing auth http://foo.bar/baz.gpg', 'Error: Unknown token.*') fd = StringIO() fd.write(str(gpg.keyring.sign(token))) fd.seek(0) - self.assertResponse('gpg sign auth http://foo.bar/baz.gpg', + self.assertResponse('gpg signing auth http://foo.bar/baz.gpg', 'You are now authenticated as spam.') utils.web.getUrlFd = realGetUrlFd diff --git a/plugins/User/config.py b/plugins/User/config.py index 0a45a80ab..758ac70cb 100644 --- a/plugins/User/config.py +++ b/plugins/User/config.py @@ -47,13 +47,4 @@ User = conf.registerPlugin('User') # conf.registerGlobalValue(User, 'someConfigVariableName', # registry.Boolean(False, """Help for someConfigVariableName.""")) -conf.registerGroup(User, 'gpg') - -conf.registerGlobalValue(User.gpg, 'enable', - registry.Boolean(True, """Determines whether or not users are - allowed to use GPG for authentication.""")) -conf.registerGlobalValue(User.gpg, 'TokenTimeout', - registry.PositiveInteger(60*10, """Determines the lifetime of a GPG - authentication token (in seconds).""")) - # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/plugins/User/plugin.py b/plugins/User/plugin.py index 6f998bdaf..a62102361 100644 --- a/plugins/User/plugin.py +++ b/plugins/User/plugin.py @@ -29,8 +29,6 @@ import re import sys -import uuid -import time import fnmatch import supybot.conf as conf diff --git a/plugins/User/test.py b/plugins/User/test.py index 038dfd16c..850c6c02b 100644 --- a/plugins/User/test.py +++ b/plugins/User/test.py @@ -28,7 +28,6 @@ ### import re -from cStringIO import StringIO from supybot.test import PluginTestCase, network