コード例 #1
0
 def test_credentials_for_archive_empty(self):
     # If there are no ArchiveAuthTokens for an archive just
     # the buildd secret is returned.
     self.ppa.buildd_secret = "sekr1t"
     self.assertEquals(
         [("buildd", "sekr1t", "bu")],
         list(htpasswd_credentials_for_archive(self.ppa)))
コード例 #2
0
    def test_credentials_for_archive(self):
        # ArchiveAuthTokens for an archive are returned by
        # credentials_for_archive.
        self.ppa.buildd_secret = "geheim"
        name12 = getUtility(IPersonSet).getByName("name12")
        name16 = getUtility(IPersonSet).getByName("name16")
        hyphenated = self.factory.makePerson(name="a-b-c")
        self.ppa.newSubscription(name12, self.ppa.owner)
        self.ppa.newSubscription(name16, self.ppa.owner)
        self.ppa.newSubscription(hyphenated, self.ppa.owner)
        first_created_token = self.ppa.newAuthToken(name16)
        second_created_token = self.ppa.newAuthToken(name12)
        third_created_token = self.ppa.newAuthToken(hyphenated)
        named_token_20 = self.ppa.newNamedAuthToken("name20", as_dict=False)
        named_token_14 = self.ppa.newNamedAuthToken("name14", as_dict=False)
        named_token_99 = self.ppa.newNamedAuthToken("name99", as_dict=False)
        named_token_99.deactivate()

        expected_credentials = [
            ("buildd", "geheim", "bu"),
            ("+name14", named_token_14.token, "bm"),
            ("+name20", named_token_20.token, "bm"),
            ("a-b-c", third_created_token.token, "YS"),
            ("name12", second_created_token.token, "bm"),
            ("name16", first_created_token.token, "bm"),
        ]
        credentials = list(htpasswd_credentials_for_archive(self.ppa))

        # Use assertEqual instead of assertContentEqual to verify order.
        self.assertEqual(expected_credentials, credentials)
コード例 #3
0
    def generateHtpasswd(self, ppa):
        """Generate a htpasswd file for `ppa`s `tokens`.

        :param ppa: The context PPA (an `IArchive`).
        :return: The filename of the htpasswd file that was generated.
        """
        # Create a temporary file that will be a new .htpasswd.
        pub_config = getPubConfig(ppa)
        if not os.path.exists(pub_config.temproot):
            os.makedirs(pub_config.temproot)
        fd, temp_filename = tempfile.mkstemp(dir=pub_config.temproot)
        os.close(fd)

        write_htpasswd(temp_filename, htpasswd_credentials_for_archive(ppa))

        return temp_filename
コード例 #4
0
    def generateHtpasswd(self, ppa):
        """Generate a htpasswd file for `ppa`s `tokens`.

        :param ppa: The context PPA (an `IArchive`).
        :return: The filename of the htpasswd file that was generated.
        """
        # Create a temporary file that will be a new .htpasswd.
        pub_config = getPubConfig(ppa)
        if not os.path.exists(pub_config.htaccessroot):
            os.makedirs(pub_config.htaccessroot)
        fd, temp_filename = tempfile.mkstemp(dir=pub_config.htaccessroot)
        os.close(fd)

        write_htpasswd(
            temp_filename, htpasswd_credentials_for_archive(ppa))

        return temp_filename
コード例 #5
0
def _setupHtaccess(archive, pubconf, log):
    """Setup .htaccess/.htpasswd files for an archive.
    """
    if not archive.private:
        # FIXME: JRV 20101108 leftover .htaccess and .htpasswd files
        # should be removed when support for making existing 3PA's public
        # is added; bug=376072
        return

    htaccess_path = os.path.join(pubconf.htaccessroot, ".htaccess")
    htpasswd_path = os.path.join(pubconf.htaccessroot, ".htpasswd")
    # After the initial htaccess/htpasswd files
    # are created generate_ppa_htaccess is responsible for
    # updating the tokens.
    if not os.path.exists(htaccess_path):
        log.debug("Writing htaccess file.")
        write_htaccess(htaccess_path, pubconf.htaccessroot)
        passwords = htpasswd_credentials_for_archive(archive)
        write_htpasswd(htpasswd_path, passwords)
コード例 #6
0
    def test_credentials_for_archive(self):
        # ArchiveAuthTokens for an archive are returned by
        # credentials_for_archive.
        self.ppa.buildd_secret = "geheim"
        name12 = getUtility(IPersonSet).getByName("name12")
        name16 = getUtility(IPersonSet).getByName("name16")
        self.ppa.newSubscription(name12, self.ppa.owner)
        self.ppa.newSubscription(name16, self.ppa.owner)
        first_created_token = self.ppa.newAuthToken(name16)
        tokens = [
            (token.person_id, token.token)
            for token in [self.ppa.newAuthToken(name12), first_created_token]]

        credentials = list(htpasswd_credentials_for_archive(self.ppa, tokens))

        self.assertContentEqual(
            credentials, [
                ("buildd", "geheim", "bu"),
                ("name12", tokens[0][1], "na"),
                ("name16", tokens[1][1], "na")
                ])