Exemplo n.º 1
0
def test_get_workdir_gives_homedir_if_HOME_is_in_env(makedirs, caplog):
    homedir = TemporaryDirectory(suffix='-home')
    EnvironmentVarGuard().set('HOME', homedir.name)
    workdir = os.path.join(homedir.name, '.config', 'requests_gpgauthlib')
    caplog.set_level(logging.WARNING)

    assert get_workdir() == workdir
    makedirs.assert_called_with(workdir, exist_ok=True)
    assert not caplog.records
Exemplo n.º 2
0
def test_get_workdir_gives_cwd_if_HOME_is_not_in_env_and_tmp_unwriteable(
        makedirs, getcwd, caplog):
    EnvironmentVarGuard().unset('HOME')
    workdir = os.path.join('/cwd', '.config', 'requests_gpgauthlib')
    caplog.set_level(logging.WARNING)

    assert get_workdir() == workdir
    makedirs.assert_has_calls([
        call('/tmp/requests_gpgauthlib', exist_ok=True),
        call(workdir, exist_ok=True),
    ])
    assert caplog.record_tuples == [
        ('requests_gpgauthlib.utils', logging.WARNING,
         'get_workdir: HOME undefined and /tmp unwriteable, using /cwd')
    ]
Exemplo n.º 3
0
def cli(ctx: Any, verbose: bool) -> None:
    """
    Passbolt CLI.
    """
    if verbose:
        levels = {1: logging.WARNING, 2: logging.INFO, 3: logging.DEBUG}
        logging.basicConfig(level=levels.get(verbose, logging.ERROR))

    if 'config' not in ctx.obj:
        config_path = get_config_path()
        try:
            ctx.obj['config'] = parse_config(config_path)
        except FileNotFoundError:
            ctx.obj['config'] = create_config_file(config_path, config_values_wizard())

    if 'gpg' not in ctx.obj:
        ctx.obj['gpg'] = create_gpg(get_workdir())
Exemplo n.º 4
0
    def __init__(self, gpg, server_url, user_fingerprint, verify, **kwargs):
        # Skip GPGAuthSession.__init__
        super(GPGAuthSession, self).__init__(**kwargs)

        self.server_url = server_url.rstrip('/')
        self.auth_uri = '/auth'

        self.gpg = gpg
        self.user_specified_fingerprint = user_fingerprint
        self.verify = verify

        self._cookie_filename = os.path.join(get_workdir(),
                                             'gpgauth_session_cookies')
        self.cookies = MozillaCookieJar(self._cookie_filename)
        try:
            self.cookies.load(ignore_discard=True)
        except FileNotFoundError:
            pass