Пример #1
0
def _cmd_keys(*args):  # pragma: no cover
    check = check_repo_ex()

    ns = args[0]
    # We try to prevent developers from creating root keys on the dev
    # machines.
    if ns.create_keys is True and ns.import_keys is True:
        log.error("Only one options is allowed at a time")
        return

    # Okay the actual check is pretty weak but we are all grown ups here :)
    if ns.create_keys is True and check is True:
        log.error("You can not create off-line keys on your dev machine")
        return

    # Can't import if we don't have a config to place it in.
    if ns.import_keys is True and check is False:
        return

    # We are supposed to be on another secure computer.
    # Security is in the eye of the beholder.
    # That was deep.
    if ns.create_keys is True and check is False:
        if hasattr(ns, "test"):
            log.debug("We are testing!")
            app_name = "test"
            # Starting up with some testing in mind.
            k = Keys(test=True)
        else:
            k = Keys()
            # Get the app name for the soon to be generated keypack.pyu
            app_name = get_correct_answer("Please enter app name",
                                          required=True)

        # Create the keypack for this particular application.
        # make_keypack will return True if successful.
        if k.make_keypack(app_name):
            log.info("Keypack placed in cwd")
        else:
            log.error("Failed to create keypack")
            return

    # Save the keypack.pyu that's in the current directory to the
    # .pyupdater/config.pyu file.
    if ns.import_keys is True and check is True:
        cm = ConfigManager()
        config = cm.load_config()
        ki = KeyImporter()
        if ki.start():
            log.info("Keypack import successfully")
            cm.save_config(config)
        else:
            log.error("Keypack import failed")
Пример #2
0
 def test_key_importer_fail(self):
     ki = KeyImporter()
     assert ki.start() is False
Пример #3
0
    def test_key_importer(self):
        k = Keys(test=True)
        k.make_keypack('one')

        ki = KeyImporter()
        assert ki.start() is True