~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/poppy/tests/test_poppy.py

[r=adeuring][bug=374019] Add support to the new twisted-based poppy
        ftp server to reject invalidly gpg-signed uploaded .changes
        files directly in the FTP session.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
__metaclass__ = type
7
7
 
 
8
import ftplib
8
9
import os
9
10
import shutil
10
11
import stat
37
38
    )
38
39
from lp.poppy.hooks import Hooks
39
40
from lp.testing import TestCaseWithFactory
 
41
from lp.testing.keyserver import KeyServerTac
40
42
 
41
43
 
42
44
class FTPServer(Fixture):
371
373
                self.root_dir, upload_dirs[index], "test")).read()
372
374
            self.assertEqual(content, expected_contents[index])
373
375
 
 
376
    def test_bad_gpg_on_changesfile(self):
 
377
        """Check that we get a rejection error when uploading .changes files
 
378
        with invalid GPG signatures.
 
379
        """
 
380
        # Start up the poppy server.
 
381
        self.server.waitForStartUp()
 
382
 
 
383
        transport = self.server.getTransport()
 
384
        if transport.external_url().startswith("sftp"):
 
385
            # We're not GPG-checking sftp uploads right now.
 
386
            return
 
387
 
 
388
        # Start up the test keyserver.
 
389
        tac = KeyServerTac()
 
390
        tac.setUp()
 
391
        self.addCleanup(tac.tearDown)
 
392
 
 
393
        fake_file = StringIO.StringIO("fake contents")
 
394
 
 
395
        # We can't use bzrlib's transport here because it uploads a
 
396
        # renamed file before renaming it on the server.
 
397
        f = ftplib.FTP()
 
398
        f.connect(host="localhost", port=config.poppy.ftp_port)
 
399
        f.login()
 
400
        self.assertRaises(
 
401
            ftplib.error_perm,
 
402
            f.storbinary,
 
403
            'STOR '+'foo_source.changes',
 
404
            fake_file)
 
405
 
374
406
 
375
407
def test_suite():
376
408
    tests = unittest.TestLoader().loadTestsFromName(__name__)