コード例 #1
0
    def test_write_htpasswd(self):
        """Test that writing the .htpasswd file works properly."""
        fd, filename = tempfile.mkstemp()
        os.close(fd)

        TEST_PASSWORD = "******"
        TEST_PASSWORD2 = "passwor2"

        # We provide a constant salt to the crypt function so that we
        # can test the encrypted result.
        SALT = "XX"

        user1 = ("user", TEST_PASSWORD, SALT)
        user2 = ("user2", TEST_PASSWORD2, SALT)
        list_of_users = [user1]
        list_of_users.append(user2)

        write_htpasswd(filename, list_of_users)

        expected_contents = [
            "user:XXq2wKiyI43A2",
            "user2:XXaQB8b5Gtwi.",
            ]

        file = open(filename, "r")
        file_contents = file.read().splitlines()
        file.close()
        os.remove(filename)

        self.assertEqual(expected_contents, file_contents)
コード例 #2
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
コード例 #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.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
コード例 #4
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)