From b0f0f353db9f05a5037dfc4f80e9786f14594595 Mon Sep 17 00:00:00 2001 From: Nick Daly Date: Thu, 10 May 2012 07:20:42 -0500 Subject: [PATCH] Unwrapper.next now returns a gnupg.Verify. --- ugly_hacks/santiago/pgpprocessor.py | 4 ++-- ugly_hacks/santiago/test_pgpprocessor.py | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ugly_hacks/santiago/pgpprocessor.py b/ugly_hacks/santiago/pgpprocessor.py index 04a378396..a8ab14598 100644 --- a/ugly_hacks/santiago/pgpprocessor.py +++ b/ugly_hacks/santiago/pgpprocessor.py @@ -156,9 +156,9 @@ class Unwrapper(object): self.handle_end_conditions(point, msg_type) self.type = msg_type - self.message = "".join(Unwrapper.unwrap(self.body, self.type)) + self.message = "".join(Unwrapper.unwrap(self.body, self.type)).lstrip() - return self.message + return self.gpg_data def handle_end_conditions(self, point, msg_type): """Handle end-conditions of message. diff --git a/ugly_hacks/santiago/test_pgpprocessor.py b/ugly_hacks/santiago/test_pgpprocessor.py index 518b4e5ad..ce948034d 100644 --- a/ugly_hacks/santiago/test_pgpprocessor.py +++ b/ugly_hacks/santiago/test_pgpprocessor.py @@ -23,7 +23,7 @@ def remove_line(string, line, preserve_newlines = True): return str(string.splitlines(preserve_newlines).remove(line)) -class ProcessorCase(unittest.TestCase): +class MessageWrapper(unittest.TestCase): """The superclass for pgpprocessor tests, containing shared setup: - Sign a message several times with a specified key. @@ -32,7 +32,9 @@ class ProcessorCase(unittest.TestCase): MESSAGES = [ str({"host": "somebody"}), ] GPG = gnupg.GPG(use_agent = True) - CONFIG = configparser.ConfigParser({"KEYID": "0928D23A"}) + CONFIG = configparser.ConfigParser( + {"KEYID": + "D95C32042EE54FFDB25EC3489F2733F40928D23A"}) CONFIG.read(["test.cfg"]) KEYID = CONFIG.get("pgpprocessor", "keyid") @@ -40,13 +42,20 @@ class ProcessorCase(unittest.TestCase): for i in range(ITERATIONS): MESSAGES.append(str(GPG.sign(MESSAGES[i], keyid = KEYID))) -class UnwrapperTest(ProcessorCase): + def setUp(self): + super(MessageWrapper, self).setUp() + + self.messages = list(MessageWrapper.MESSAGES) + self.keyid = MessageWrapper.KEYID + +class UnwrapperTest(MessageWrapper): """Verify that we can unwrap multiply-signed PGP messages correctly.""" def setUp(self): - self.messages = list(ProcessorCase.MESSAGES) + super(UnwrapperTest, self).setUp() + self.unwrapper = pgpprocessor.Unwrapper(self.messages[-1], - ProcessorCase.GPG) + MessageWrapper.GPG) def test_messages_wrapped(self): """Were the messages correctly wrapped in the first place?""" @@ -75,7 +84,8 @@ class UnwrapperTest(ProcessorCase): unwrapped_messages = self.messages[:-1] for message in reversed(unwrapped_messages): - self.assertEqual(message.strip(), self.unwrapper.next().strip()) + self.unwrapper.next() + self.assertEqual(message.strip(), self.unwrapper.message.strip()) def test_no_header_invalid(self): """Messages without heads are considered invalid."""