~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/archiveuploader/tests/test_changesfile.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-05-25 10:56:35 UTC
  • mfrom: (13067.2.38 bug-783855)
  • Revision ID: launchpad@pqm.canonical.com-20110525105635-flk6c823bai3a22o
[r=julian-edwards][bug=783855] Replace signature verification and tag
 file parsing in archiveuploader.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
import os
9
9
 
10
10
from debian.deb822 import Changes
 
11
from zope.component import getUtility
11
12
 
12
 
from canonical.testing.layers import LaunchpadZopelessLayer
 
13
from canonical.launchpad.ftests import import_public_test_keys
 
14
from canonical.testing.layers import (
 
15
    LaunchpadZopelessLayer,
 
16
    ZopelessDatabaseLayer,
 
17
    )
13
18
from lp.archiveuploader.changesfile import (
14
19
    CannotDetermineFileTypeError,
15
20
    ChangesFile,
23
28
    UdebBinaryUploadFile,
24
29
    UploadError,
25
30
    )
26
 
from lp.archiveuploader.tests import AbsolutelyAnythingGoesUploadPolicy
 
31
from lp.archiveuploader.tests import (
 
32
    AbsolutelyAnythingGoesUploadPolicy,
 
33
    datadir,
 
34
    )
 
35
from lp.archiveuploader.uploadpolicy import InsecureUploadPolicy
 
36
from lp.registry.interfaces.person import IPersonSet
27
37
from lp.services.log.logger import BufferLogger
28
38
from lp.testing import TestCase
 
39
from lp.testing.keyserver import KeyServerTac
29
40
 
30
41
 
31
42
class TestDetermineFileClassAndName(TestCase):
188
199
        self.assertRaises(
189
200
            UploadError,
190
201
            self.createChangesFile, "mypkg_0.1_i386.changes", contents)
 
202
 
 
203
 
 
204
class TestSignatureVerification(TestCase):
 
205
 
 
206
    layer = ZopelessDatabaseLayer
 
207
 
 
208
    def setUp(self):
 
209
        super(TestSignatureVerification, self).setUp()
 
210
        self.useFixture(KeyServerTac())
 
211
        import_public_test_keys()
 
212
 
 
213
    def test_valid_signature_accepted(self):
 
214
        # A correctly signed changes file is excepted, and all its
 
215
        # content is parsed.
 
216
        path = datadir('signatures/signed.changes')
 
217
        parsed = ChangesFile(path, InsecureUploadPolicy(), BufferLogger())
 
218
        self.assertEqual(
 
219
            getUtility(IPersonSet).getByEmail('foo.bar@canonical.com'),
 
220
            parsed.signer)
 
221
        expected = "\AFormat: 1.7\n.*foo_1.0-1.diff.gz\Z"
 
222
        self.assertTextMatchesExpressionIgnoreWhitespace(
 
223
            expected,
 
224
            parsed.parsed_content)
 
225
 
 
226
    def test_no_signature_rejected(self):
 
227
        # An unsigned changes file is rejected.
 
228
        path = datadir('signatures/unsigned.changes')
 
229
        self.assertRaises(
 
230
            UploadError,
 
231
            ChangesFile, path, InsecureUploadPolicy(), BufferLogger())
 
232
 
 
233
    def test_prefix_ignored(self):
 
234
        # A signed changes file with an unsigned prefix has only the
 
235
        # signed part parsed.
 
236
        path = datadir('signatures/prefixed.changes')
 
237
        parsed = ChangesFile(path, InsecureUploadPolicy(), BufferLogger())
 
238
        self.assertEqual(
 
239
            getUtility(IPersonSet).getByEmail('foo.bar@canonical.com'),
 
240
            parsed.signer)
 
241
        expected = "\AFormat: 1.7\n.*foo_1.0-1.diff.gz\Z"
 
242
        self.assertTextMatchesExpressionIgnoreWhitespace(
 
243
            expected,
 
244
            parsed.parsed_content)
 
245
        self.assertEqual("breezy", parsed.suite_name)
 
246
        self.assertNotIn("evil", parsed.changes_comment)