Exemplo n.º 1
0
 def setUp(self):
     TestCase.setUp(self)
     self.tarfile_path = "/tmp/_verify_extract"
     self.tarfile_name = os.path.join(self.tarfile_path, "test_tarfile.tar")
     self.custom_processor = CustomUpload()
     self.custom_processor.tmpdir = self.makeTemporaryDirectory()
     self.custom_processor.tarfile_path = self.tarfile_name
Exemplo n.º 2
0
 def test_sign_with_signing_key(self):
     filename = os.path.join(getPubConfig(self.archive).archiveroot, "file")
     write_file(filename, "contents")
     self.assertIsNone(self.archive.signing_key)
     self.useFixture(InProcessKeyServerFixture()).start()
     key_path = os.path.join(gpgkeysdir, '*****@*****.**')
     yield IArchiveSigningKey(self.archive).setSigningKey(
         key_path, async_keyserver=True)
     self.assertIsNotNone(self.archive.signing_key)
     custom_processor = CustomUpload()
     custom_processor.sign(self.archive, "suite", filename)
     with open(filename) as cleartext_file:
         cleartext = cleartext_file.read()
         with open("%s.gpg" % filename) as signature_file:
             signature = getUtility(IGPGHandler).getVerifiedSignature(
                 cleartext, signature_file.read())
     self.assertEqual(self.archive.signing_key.fingerprint,
                      signature.fingerprint)
Exemplo n.º 3
0
    def testFixCurrentSymlink(self):
        """Test `CustomUpload.fixCurrentSymlink` behaviour.

        Ensure only 3 entries named as valid versions are kept around and
        the 'current' symbolic link is created (or updated) to point to the
        latests entry.

        Also check if it copes with entries not named as valid versions and
        leave them alone.
        """
        # Setup a bogus `CustomUpload` object with the 'targetdir' pointing
        # to the directory created for the test.
        custom_processor = CustomUpload()
        custom_processor.targetdir = self.test_dir

        # Let's create 4 entries named as valid versions.
        os.mkdir(os.path.join(self.test_dir, '1.0'))
        os.mkdir(os.path.join(self.test_dir, '1.1'))
        os.mkdir(os.path.join(self.test_dir, '1.2'))
        os.mkdir(os.path.join(self.test_dir, '1.3'))
        self.assertEntries(['1.0', '1.1', '1.2', '1.3'])

        # `fixCurrentSymlink` will keep only the latest 3 and create a
        # 'current' symbolic link the highest one.
        custom_processor.fixCurrentSymlink()
        self.assertEntries(['1.1', '1.2', '1.3', 'current'])
        self.assertEqual('1.3',
                         os.readlink(os.path.join(self.test_dir, 'current')))

        # When there is a invalid version present in the directory it is
        # ignored, since it was probably put there manually. The symbolic
        # link still pointing to the latest version.
        os.mkdir(os.path.join(self.test_dir, '1.4'))
        os.mkdir(os.path.join(self.test_dir, 'alpha-5'))
        custom_processor.fixCurrentSymlink()
        self.assertEntries(['1.2', '1.3', '1.4', 'alpha-5', 'current'])
        self.assertEqual('1.4',
                         os.readlink(os.path.join(self.test_dir, 'current')))
Exemplo n.º 4
0
 def test_sign_with_external_run_parts(self):
     self.enableRunParts(distribution_name=self.distro.name)
     archiveroot = getPubConfig(self.archive).archiveroot
     filename = os.path.join(archiveroot, "file")
     write_file(filename, "contents")
     self.assertIsNone(self.archive.signing_key)
     run_parts_fixture = self.useFixture(
         MonkeyPatch("lp.archivepublisher.archivesigningkey.run_parts",
                     FakeMethod()))
     custom_processor = CustomUpload()
     custom_processor.sign(self.archive, "suite", filename)
     args, kwargs = run_parts_fixture.new_value.calls[0]
     self.assertEqual((self.distro.name, "sign.d"), args)
     self.assertThat(
         kwargs["env"],
         MatchesDict({
             "ARCHIVEROOT": Equals(archiveroot),
             "INPUT_PATH": Equals(filename),
             "OUTPUT_PATH": Equals("%s.gpg" % filename),
             "MODE": Equals("detached"),
             "DISTRIBUTION": Equals(self.distro.name),
             "SUITE": Equals("suite"),
         }))
Exemplo n.º 5
0
 def test_sign_without_signing_key(self):
     filename = os.path.join(getPubConfig(self.archive).archiveroot, "file")
     self.assertIsNone(self.archive.signing_key)
     custom_processor = CustomUpload()
     custom_processor.sign(self.archive, "suite", filename)
     self.assertThat("%s.gpg" % filename, Not(PathExists()))