GPG: Fix previous commit.

This commit is contained in:
Valentin Lorentz 2015-05-18 13:01:12 +02:00
parent c6697350b3
commit db09100772
6 changed files with 27 additions and 21 deletions

View File

@ -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:

View File

@ -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\' '

View File

@ -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

View File

@ -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:

View File

@ -29,8 +29,6 @@
import re
import sys
import uuid
import time
import fnmatch
import supybot.conf as conf

View File

@ -28,7 +28,6 @@
###
import re
from cStringIO import StringIO
from supybot.test import PluginTestCase, network