コード例 #1
0
ファイル: test_repo.py プロジェクト: ktosiek/vorta
def test_repo_add_success(qapp, qtbot, mocker, borg_json_output):
    LONG_PASSWORD = '******'

    # Add new repo window
    main = qapp.main_window
    main.repoTab.repo_added.disconnect()
    add_repo_window = AddRepoWindow(main)
    test_repo_url = f'vorta-test-repo.{uuid.uuid4()}.com:repo'  # Random repo URL to avoid macOS keychain

    qtbot.keyClicks(add_repo_window.repoURL, test_repo_url)
    qtbot.keyClicks(add_repo_window.passwordLineEdit, LONG_PASSWORD)

    stdout, stderr = borg_json_output('info')
    popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
    mocker.patch.object(vorta.borg.borg_thread,
                        'Popen',
                        return_value=popen_result)

    qtbot.mouseClick(add_repo_window.saveButton, QtCore.Qt.LeftButton)

    with qtbot.waitSignal(add_repo_window.thread.result,
                          timeout=3000) as blocker:
        pass

    main.repoTab.process_new_repo(blocker.args[0])

    assert EventLogModel.select().count() == 1
    assert RepoModel.get(id=2).url == test_repo_url

    from vorta.utils import keyring
    assert keyring.get_password("vorta-repo",
                                RepoModel.get(id=2).url) == LONG_PASSWORD
コード例 #2
0
ファイル: borg_thread.py プロジェクト: rossomah/vorta
    def prepare(cls, profile):
        """
        Prepare for running Borg. This function in the base class should be called from all
        subclasses and calls that define their own `cmd`.

        The `prepare()` step does these things:
        - validate if all conditions to run command are met
        - build borg command

        `prepare()` is run 2x. First at the global level and then for each subcommand.

        :return: dict(ok: book, message: str)
        """
        ret = {'ok': False}

        # Do checks to see if running Borg is possible.
        if cls.is_running():
            ret['message'] = trans_late('messages',
                                        'Backup is already in progress.')
            return ret

        if cls.prepare_bin() is None:
            ret['message'] = trans_late('messages',
                                        'Borg binary was not found.')
            return ret

        if profile.repo is None:
            ret['message'] = trans_late('messages',
                                        'Add a backup repository first.')
            return ret

        # Try to get password from chosen keyring backend.
        logger.debug("Using %s keyring to store passwords.",
                     keyring.__class__.__name__)
        ret['password'] = keyring.get_password('vorta-repo', profile.repo.url)

        # Try to fall back to DB Keyring, if we use the system keychain.
        if ret['password'] is None and keyring.is_primary:
            logger.debug(
                'Password not found in primary keyring. Falling back to VortaDBKeyring.'
            )
            ret['password'] = VortaDBKeyring().get_password(
                'vorta-repo', profile.repo.url)

            # Give warning and continue if password is found there.
            if ret['password'] is not None:
                logger.warning(
                    'Found password in database, but secure storage was available. '
                    'Consider re-adding the repo to use it.')

        ret['ssh_key'] = profile.ssh_key
        ret['repo_id'] = profile.repo.id
        ret['repo_url'] = profile.repo.url
        ret['extra_borg_arguments'] = profile.repo.extra_borg_arguments
        ret['profile_name'] = profile.name

        ret['ok'] = True

        return ret
コード例 #3
0
ファイル: borg_thread.py プロジェクト: ejmvar/vorta
    def prepare(cls, profile):
        """
        Prepare for running Borg. This function in the base class should be called from all
        subclasses and calls that define their own `cmd`.

        The `prepare()` step does these things:
        - validate if all conditions to run command are met
        - build borg command

        `prepare()` is run 2x. First at the global level and then for each subcommand.

        :return: dict(ok: book, message: str)
        """
        ret = {'ok': False}

        # Do checks to see if running Borg is possible.
        if cls.is_running():
            ret['message'] = trans_late('messages',
                                        'Backup is already in progress.')
            return ret

        if cls.prepare_bin() is None:
            ret['message'] = trans_late('messages',
                                        'Borg binary was not found.')
            return ret

        if profile.repo is None:
            ret['message'] = trans_late('messages',
                                        'Add a backup repository first.')
            return ret

        # Try to get password from chosen keyring backend.
        try:
            ret['password'] = keyring.get_password("vorta-repo",
                                                   profile.repo.url)
        except Exception:
            ret['message'] = trans_late(
                'messages',
                'Please make sure you grant Vorta permission to use the Keychain.'
            )
            return ret

        ret['ssh_key'] = profile.ssh_key
        ret['repo_id'] = profile.repo.id
        ret['repo_url'] = profile.repo.url
        ret['profile_name'] = profile.name

        ret['ok'] = True

        return ret
コード例 #4
0
ファイル: test_utils.py プロジェクト: wjt/vorta
def test_keyring(qapp):
    UNICODE_PW = 'kjalsdfüadsfäadsfß'
    REPO = f'vorta-test-repo.{uuid.uuid4()}.com:repo'  # Random repo URL

    keyring.set_password('vorta-repo', REPO, UNICODE_PW)
    assert keyring.get_password("vorta-repo", REPO) == UNICODE_PW