Esempio n. 1
0
 def process_result(self, result):
     if result['returncode'] == 0:
         new_repo, created = RepoModel.get_or_create(
             url=result['params']['repo_url'],
             defaults={
                 'encryption': result['params']['encryption'],
                 'extra_borg_arguments': result['params']['extra_borg_arguments'],
             }
         )
         if new_repo.encryption != 'none':
             get_keyring().set_password("vorta-repo", new_repo.url, result['params']['password'])
         new_repo.save()
Esempio n. 2
0
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.keyring.abc import get_keyring
    keyring = get_keyring()
    assert keyring.get_password("vorta-repo",
                                RepoModel.get(id=2).url) == LONG_PASSWORD
Esempio n. 3
0
def test_keyring(qapp):
    UNICODE_PW = 'kjalsdfüadsfäadsfß'
    REPO = f'vorta-test-repo.{uuid.uuid4()}.com:repo'  # Random repo URL

    keyring = get_keyring()
    keyring.set_password('vorta-repo', REPO, UNICODE_PW)
    assert keyring.get_password("vorta-repo", REPO) == UNICODE_PW
Esempio n. 4
0
    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

        if not borg_compat.check('JSON_LOG'):
            ret['message'] = trans_late('messages', 'Your Borg version is too old. >=1.1.0 is required.')
            return ret

        # Try to get password from chosen keyring backend.
        keyring = get_keyring()
        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
Esempio n. 5
0
    def process_result(self, result):
        if result['returncode'] == 0:
            new_repo, _ = RepoModel.get_or_create(url=result['cmd'][-1])
            if 'cache' in result['data']:
                stats = result['data']['cache']['stats']
                new_repo.total_size = stats['total_size']
                new_repo.unique_csize = stats['unique_csize']
                new_repo.unique_size = stats['unique_size']
                new_repo.total_unique_chunks = stats['total_unique_chunks']
            if 'encryption' in result['data']:
                new_repo.encryption = result['data']['encryption']['mode']
            if new_repo.encryption != 'none':
                get_keyring().set_password("vorta-repo", new_repo.url,
                                           result['params']['password'])

            new_repo.extra_borg_arguments = result['params'][
                'extra_borg_arguments']

            new_repo.save()