ca43b9971f58117d4c5b3126eb159a39cb36bf59
Marco Ricci Change the author e-mail ad...

Marco Ricci authored 4 months ago

1) # SPDX-FileCopyrightText: 2024 Marco Ricci <software@the13thletter.info>
Marco Ricci Add prototype command-line...

Marco Ricci authored 6 months ago

2) #
3) # SPDX-License-Identifier: MIT
4) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

5) from __future__ import annotations
6) 
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

7) import base64
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

8) import contextlib
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

9) import copy
Marco Ricci Remove `click` handling of...

Marco Ricci authored 4 months ago

10) import errno
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

11) import io
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

12) import json
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

13) import logging
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

14) import os
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

15) import shlex
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

16) import shutil
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

17) import socket
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

18) import textwrap
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

19) import warnings
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

20) from typing import TYPE_CHECKING
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

21) 
Marco Ricci Add prototype command-line...

Marco Ricci authored 6 months ago

22) import click.testing
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

23) import hypothesis
Marco Ricci Add prototype command-line...

Marco Ricci authored 6 months ago

24) import pytest
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

25) from hypothesis import stateful, strategies
26) from typing_extensions import Any, NamedTuple
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

27) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

28) import tests
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

29) from derivepassphrase import _types, cli, ssh_agent, vault
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

30) 
31) if TYPE_CHECKING:
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

32)     from collections.abc import Callable, Iterable, Iterator
33)     from typing import NoReturn
Marco Ricci Add prototype command-line...

Marco Ricci authored 6 months ago

34) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

35) DUMMY_SERVICE = tests.DUMMY_SERVICE
36) DUMMY_PASSPHRASE = tests.DUMMY_PASSPHRASE
37) DUMMY_CONFIG_SETTINGS = tests.DUMMY_CONFIG_SETTINGS
38) DUMMY_RESULT_PASSPHRASE = tests.DUMMY_RESULT_PASSPHRASE
39) DUMMY_RESULT_KEY1 = tests.DUMMY_RESULT_KEY1
40) DUMMY_PHRASE_FROM_KEY1_RAW = tests.DUMMY_PHRASE_FROM_KEY1_RAW
41) DUMMY_PHRASE_FROM_KEY1 = tests.DUMMY_PHRASE_FROM_KEY1
42) 
43) DUMMY_KEY1 = tests.DUMMY_KEY1
44) DUMMY_KEY1_B64 = tests.DUMMY_KEY1_B64
45) DUMMY_KEY2 = tests.DUMMY_KEY2
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 5 months ago

46) DUMMY_KEY2_B64 = tests.DUMMY_KEY2_B64
47) DUMMY_KEY3 = tests.DUMMY_KEY3
48) DUMMY_KEY3_B64 = tests.DUMMY_KEY3_B64
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

49) 
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

50) TEST_CONFIGS = tests.TEST_CONFIGS
51) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

52) 
53) class IncompatibleConfiguration(NamedTuple):
54)     other_options: list[tuple[str, ...]]
55)     needs_service: bool | None
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

56)     input: str | None
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

57) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

58) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

59) class SingleConfiguration(NamedTuple):
60)     needs_service: bool | None
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

61)     input: str | None
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

62)     check_success: bool
63) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

64) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

65) class OptionCombination(NamedTuple):
66)     options: list[str]
67)     incompatible: bool
68)     needs_service: bool | None
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

69)     input: str | None
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

70)     check_success: bool
71) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

72) 
Marco Ricci Add an actual derivepassphr...

Marco Ricci authored 2 weeks ago

73) PASSPHRASE_GENERATION_OPTIONS: list[tuple[str, ...]] = [
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

74)     ('--phrase',),
75)     ('--key',),
76)     ('--length', '20'),
77)     ('--repeat', '20'),
78)     ('--lower', '1'),
79)     ('--upper', '1'),
80)     ('--number', '1'),
81)     ('--space', '1'),
82)     ('--dash', '1'),
83)     ('--symbol', '1'),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

84) ]
85) CONFIGURATION_OPTIONS: list[tuple[str, ...]] = [
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

86)     ('--notes',),
87)     ('--config',),
88)     ('--delete',),
89)     ('--delete-globals',),
90)     ('--clear',),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

91) ]
92) CONFIGURATION_COMMANDS: list[tuple[str, ...]] = [
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

93)     ('--notes',),
94)     ('--delete',),
95)     ('--delete-globals',),
96)     ('--clear',),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

97) ]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

98) STORAGE_OPTIONS: list[tuple[str, ...]] = [('--export', '-'), ('--import', '-')]
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

99) INCOMPATIBLE: dict[tuple[str, ...], IncompatibleConfiguration] = {
100)     ('--phrase',): IncompatibleConfiguration(
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

101)         [('--key',), *CONFIGURATION_COMMANDS, *STORAGE_OPTIONS],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

102)         True,
103)         DUMMY_PASSPHRASE,
104)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

105)     ('--key',): IncompatibleConfiguration(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

106)         CONFIGURATION_COMMANDS + STORAGE_OPTIONS, True, DUMMY_PASSPHRASE
107)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

108)     ('--length', '20'): IncompatibleConfiguration(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

109)         CONFIGURATION_COMMANDS + STORAGE_OPTIONS, True, DUMMY_PASSPHRASE
110)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

111)     ('--repeat', '20'): IncompatibleConfiguration(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

112)         CONFIGURATION_COMMANDS + STORAGE_OPTIONS, True, DUMMY_PASSPHRASE
113)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

114)     ('--lower', '1'): IncompatibleConfiguration(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

115)         CONFIGURATION_COMMANDS + STORAGE_OPTIONS, True, DUMMY_PASSPHRASE
116)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

117)     ('--upper', '1'): IncompatibleConfiguration(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

118)         CONFIGURATION_COMMANDS + STORAGE_OPTIONS, True, DUMMY_PASSPHRASE
119)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

120)     ('--number', '1'): IncompatibleConfiguration(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

121)         CONFIGURATION_COMMANDS + STORAGE_OPTIONS, True, DUMMY_PASSPHRASE
122)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

123)     ('--space', '1'): IncompatibleConfiguration(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

124)         CONFIGURATION_COMMANDS + STORAGE_OPTIONS, True, DUMMY_PASSPHRASE
125)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

126)     ('--dash', '1'): IncompatibleConfiguration(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

127)         CONFIGURATION_COMMANDS + STORAGE_OPTIONS, True, DUMMY_PASSPHRASE
128)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

129)     ('--symbol', '1'): IncompatibleConfiguration(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

130)         CONFIGURATION_COMMANDS + STORAGE_OPTIONS, True, DUMMY_PASSPHRASE
131)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

132)     ('--notes',): IncompatibleConfiguration(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

133)         [
134)             ('--config',),
135)             ('--delete',),
136)             ('--delete-globals',),
137)             ('--clear',),
138)             *STORAGE_OPTIONS,
139)         ],
140)         True,
141)         None,
142)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

143)     ('--config', '-p'): IncompatibleConfiguration(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

144)         [('--delete',), ('--delete-globals',), ('--clear',), *STORAGE_OPTIONS],
145)         None,
146)         DUMMY_PASSPHRASE,
147)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

148)     ('--delete',): IncompatibleConfiguration(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

149)         [('--delete-globals',), ('--clear',), *STORAGE_OPTIONS], True, None
150)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

151)     ('--delete-globals',): IncompatibleConfiguration(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

152)         [('--clear',), *STORAGE_OPTIONS], False, None
153)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

154)     ('--clear',): IncompatibleConfiguration(STORAGE_OPTIONS, False, None),
155)     ('--export', '-'): IncompatibleConfiguration(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

156)         [('--import', '-')], False, None
157)     ),
158)     ('--import', '-'): IncompatibleConfiguration([], False, None),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

159) }
160) SINGLES: dict[tuple[str, ...], SingleConfiguration] = {
161)     ('--phrase',): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
162)     ('--key',): SingleConfiguration(True, None, False),
163)     ('--length', '20'): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
164)     ('--repeat', '20'): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
165)     ('--lower', '1'): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
166)     ('--upper', '1'): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
167)     ('--number', '1'): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
168)     ('--space', '1'): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
169)     ('--dash', '1'): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
170)     ('--symbol', '1'): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
171)     ('--notes',): SingleConfiguration(True, None, False),
172)     ('--config', '-p'): SingleConfiguration(None, DUMMY_PASSPHRASE, False),
173)     ('--delete',): SingleConfiguration(True, None, False),
174)     ('--delete-globals',): SingleConfiguration(False, None, True),
175)     ('--clear',): SingleConfiguration(False, None, True),
176)     ('--export', '-'): SingleConfiguration(False, None, True),
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

177)     ('--import', '-'): SingleConfiguration(False, '{"services": {}}', True),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

178) }
179) INTERESTING_OPTION_COMBINATIONS: list[OptionCombination] = []
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 6 months ago

180) config: IncompatibleConfiguration | SingleConfiguration
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

181) for opt, config in INCOMPATIBLE.items():
182)     for opt2 in config.other_options:
183)         INTERESTING_OPTION_COMBINATIONS.extend([
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

184)             OptionCombination(
185)                 options=list(opt + opt2),
186)                 incompatible=True,
187)                 needs_service=config.needs_service,
188)                 input=config.input,
189)                 check_success=False,
190)             ),
191)             OptionCombination(
192)                 options=list(opt2 + opt),
193)                 incompatible=True,
194)                 needs_service=config.needs_service,
195)                 input=config.input,
196)                 check_success=False,
197)             ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

198)         ])
199) for opt, config in SINGLES.items():
200)     INTERESTING_OPTION_COMBINATIONS.append(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

201)         OptionCombination(
202)             options=list(opt),
203)             incompatible=False,
204)             needs_service=config.needs_service,
205)             input=config.input,
206)             check_success=config.check_success,
207)         )
208)     )
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

209) 
210) 
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

211) def is_warning_line(line: str) -> bool:
212)     """Return true if the line is a warning line."""
213)     return ' Warning: ' in line or ' Deprecation warning: ' in line
214) 
215) 
216) def is_harmless_config_import_warning(record: tuple[str, int, str]) -> bool:
217)     """Return true if the warning is harmless, during config import."""
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

218)     possible_warnings = [
219)         'Replacing invalid value ',
220)         'Removing ineffective setting ',
221)         (
222)             'Setting a global passphrase is ineffective '
223)             'because a key is also set.'
224)         ),
225)         (
226)             'Setting a service passphrase is ineffective '
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 2 weeks ago

227)             'because a key is also set:'
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

228)         ),
229)     ]
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

230)     return any(tests.warning_emitted(w, [record]) for w in possible_warnings)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

231) 
232) 
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

233) def vault_config_exporter_shell_interpreter(  # noqa: C901
234)     script: str | Iterable[str],
235)     /,
236)     *,
237)     prog_name_list: list[str] | None = None,
238)     command: click.BaseCommand | None = None,
239)     runner: click.testing.CliRunner | None = None,
240) ) -> Iterator[click.testing.Result]:
241)     if isinstance(script, str):  # pragma: no cover
242)         script = script.splitlines(False)
243)     if prog_name_list is None:  # pragma: no cover
244)         prog_name_list = ['derivepassphrase', 'vault']
245)     if command is None:  # pragma: no cover
246)         command = cli.derivepassphrase_vault
247)     if runner is None:  # pragma: no cover
248)         runner = click.testing.CliRunner(mix_stderr=False)
249)     n = len(prog_name_list)
250)     it = iter(script)
251)     while True:
252)         try:
253)             raw_line = next(it)
254)         except StopIteration:
255)             break
256)         else:
257)             line = shlex.split(raw_line)
258)         input_buffer: list[str] = []
259)         if line[:n] != prog_name_list:
260)             continue
261)         line[:n] = []
262)         if line and line[-1] == '<<HERE':
263)             # naive HERE document support
264)             while True:
265)                 try:
266)                     raw_line = next(it)
267)                 except StopIteration as exc:  # pragma: no cover
268)                     msg = 'incomplete here document'
269)                     raise EOFError(msg) from exc
270)                 else:
271)                     if raw_line == 'HERE':
272)                         break
273)                     input_buffer.append(raw_line)
274)             line.pop()
275)         yield runner.invoke(
276)             command,
277)             line,
278)             catch_exceptions=False,
279)             input=(''.join(x + '\n' for x in input_buffer) or None),
280)         )
281) 
282) 
Marco Ricci Add tests for help and vers...

Marco Ricci authored 1 week ago

283) class TestAllCLI:
284)     @pytest.mark.parametrize(
285)         ['command', 'non_eager_arguments'],
286)         [
287)             ([], []),
288)             ([], ['export']),
289)             (['export'], []),
290)             (['export'], ['vault']),
291)             (['export', 'vault'], []),
292)             (['export', 'vault'], ['--format', 'this-format-doesnt-exist']),
293)             (['vault'], []),
294)             (['vault'], ['--export', './']),
295)         ]
296)     )
297)     @pytest.mark.parametrize('arguments', [['--help'], ['--version']])
298)     def test_200_eager_options(
299)         self,
300)         monkeypatch: pytest.MonkeyPatch,
301)         command: list[str],
302)         arguments: list[str],
303)         non_eager_arguments: list[str],
304)     ) -> None:
305)         runner = click.testing.CliRunner(mix_stderr=False)
306)         with tests.isolated_config(
307)             monkeypatch=monkeypatch,
308)             runner=runner,
309)         ):
310)             _result = runner.invoke(
311)                 cli.derivepassphrase,
312)                 [*command, *arguments, *non_eager_arguments],
313)                 catch_exceptions=False,
314)             )
315)             result = tests.ReadableResult.parse(_result)
316)         assert result.clean_exit(empty_stderr=True), 'expected clean exit'
317) 
318)     @pytest.mark.parametrize('no_color', [False, True])
319)     @pytest.mark.parametrize('force_color', [False, True])
320)     @pytest.mark.parametrize('isatty', [False, True])
321)     @pytest.mark.parametrize(
322)         ['command_line', 'input'],
323)         [
324)             (
325)                 ['vault', '--import', '-'],
326)                 '{"services": {"": {"length": 20}}}',
327)             ),
328)         ]
329)     )
330)     def test_201_no_color_force_color(
331)         self,
332)         monkeypatch: pytest.MonkeyPatch,
333)         no_color: bool,
334)         force_color: bool,
335)         isatty: bool,
336)         command_line: list[str],
337)         input: str | None,
338)     ) -> None:
339)         # Force color on if force_color.  Otherwise force color off if
340)         # no_color.  Otherwise set color if and only if we have a TTY.
341)         color = force_color or not no_color if isatty else force_color
342)         runner = click.testing.CliRunner(mix_stderr=False)
343)         with tests.isolated_config(
344)             monkeypatch=monkeypatch,
345)             runner=runner,
346)         ):
347)             if no_color:
348)                 monkeypatch.setenv('NO_COLOR', 'yes')
349)             if force_color:
350)                 monkeypatch.setenv('FORCE_COLOR', 'yes')
351)             _result = runner.invoke(
352)                 cli.derivepassphrase,
353)                 command_line,
354)                 input=input,
355)                 catch_exceptions=False,
356)                 color=isatty,
357)             )
358)             result = tests.ReadableResult.parse(_result)
359)         assert (
360)             not color
361)             or '\x1b[0m' in result.stderr
362)             or '\x1b[m' in result.stderr
363)         ), 'Expected color, but found no ANSI reset sequence'
364)         assert (
365)             color or '\x1b[' not in result.stderr
366)         ), 'Expected no color, but found an ANSI control sequence'
367) 
368) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

369) class TestCLI:
Marco Ricci Add tests for help and vers...

Marco Ricci authored 1 week ago

370)     def test_200_help_output(
371)         self,
372)         monkeypatch: pytest.MonkeyPatch,
373)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

374)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

375)         with tests.isolated_config(
376)             monkeypatch=monkeypatch,
377)             runner=runner,
378)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

379)             _result = runner.invoke(
Marco Ricci Add tests for help and vers...

Marco Ricci authored 1 week ago

380)                 cli.derivepassphrase_vault,
381)                 ['--help'],
382)                 catch_exceptions=False,
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

383)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

384)             result = tests.ReadableResult.parse(_result)
385)         assert result.clean_exit(
Marco Ricci Add an actual derivepassphr...

Marco Ricci authored 2 weeks ago

386)             empty_stderr=True, output='Passphrase generation:\n'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

387)         ), 'expected clean exit, and option groups in help text'
388)         assert result.clean_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

389)             empty_stderr=True, output='Use $VISUAL or $EDITOR to configure'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

390)         ), 'expected clean exit, and option group epilog in help text'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

391) 
Marco Ricci Add tests for help and vers...

Marco Ricci authored 1 week ago

392)     def test_200a_version_output(
393)         self,
394)         monkeypatch: pytest.MonkeyPatch,
395)     ) -> None:
396)         runner = click.testing.CliRunner(mix_stderr=False)
397)         with tests.isolated_config(
398)             monkeypatch=monkeypatch,
399)             runner=runner,
400)         ):
401)             _result = runner.invoke(
402)                 cli.derivepassphrase_vault,
403)                 ['--version'],
404)                 catch_exceptions=False,
405)             )
406)             result = tests.ReadableResult.parse(_result)
407)         assert result.clean_exit(
408)             empty_stderr=True, output=cli.PROG_NAME
409)         ), 'expected clean exit, and program name in version text'
410)         assert result.clean_exit(
411)             empty_stderr=True, output=cli.__version__
412)         ), 'expected clean exit, and version in help text'
413) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

414)     @pytest.mark.parametrize(
415)         'charset_name', ['lower', 'upper', 'number', 'space', 'dash', 'symbol']
416)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

417)     def test_201_disable_character_set(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

418)         self, monkeypatch: pytest.MonkeyPatch, charset_name: str
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

419)     ) -> None:
420)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
421)         option = f'--{charset_name}'
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

422)         charset = vault.Vault._CHARSETS[charset_name].decode('ascii')
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

423)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

424)         with tests.isolated_config(
425)             monkeypatch=monkeypatch,
426)             runner=runner,
427)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

428)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

429)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

430)                 [option, '0', '-p', '--', DUMMY_SERVICE],
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

431)                 input=DUMMY_PASSPHRASE,
432)                 catch_exceptions=False,
433)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

434)             result = tests.ReadableResult.parse(_result)
435)         assert result.clean_exit(empty_stderr=True), 'expected clean exit:'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

436)         for c in charset:
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

437)             assert (
438)                 c not in result.output
439)             ), f'derived password contains forbidden character {c!r}'
Marco Ricci Add prototype command-line...

Marco Ricci authored 6 months ago

440) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

441)     def test_202_disable_repetition(
442)         self, monkeypatch: pytest.MonkeyPatch
443)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

444)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
445)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

446)         with tests.isolated_config(
447)             monkeypatch=monkeypatch,
448)             runner=runner,
449)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

450)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

451)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

452)                 ['--repeat', '0', '-p', '--', DUMMY_SERVICE],
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

453)                 input=DUMMY_PASSPHRASE,
454)                 catch_exceptions=False,
455)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

456)             result = tests.ReadableResult.parse(_result)
457)         assert result.clean_exit(
458)             empty_stderr=True
459)         ), 'expected clean exit and empty stderr'
460)         passphrase = result.output.rstrip('\r\n')
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

461)         for i in range(len(passphrase) - 1):
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

462)             assert passphrase[i : i + 1] != passphrase[i + 1 : i + 2], (
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

463)                 f'derived password contains repeated character '
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

464)                 f'at position {i}: {result.output!r}'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

465)             )
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

466) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

467)     @pytest.mark.parametrize(
468)         'config',
469)         [
470)             pytest.param(
471)                 {
472)                     'global': {'key': DUMMY_KEY1_B64},
473)                     'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS},
474)                 },
475)                 id='global',
476)             ),
477)             pytest.param(
478)                 {
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

479)                     'global': {'phrase': DUMMY_PASSPHRASE.rstrip('\n')},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

480)                     'services': {
481)                         DUMMY_SERVICE: {
482)                             'key': DUMMY_KEY1_B64,
483)                             **DUMMY_CONFIG_SETTINGS,
484)                         }
485)                     },
486)                 },
487)                 id='service',
488)             ),
489)         ],
490)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

491)     def test_204a_key_from_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

492)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

493)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

494)         config: _types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

495)     ) -> None:
496)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

497)         with tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

498)             monkeypatch=monkeypatch, runner=runner, vault_config=config
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

499)         ):
500)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

501)                 vault.Vault, 'phrase_from_key', tests.phrase_from_key
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

502)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

503)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

504)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

505)                 ['--', DUMMY_SERVICE],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

506)                 catch_exceptions=False,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

507)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

508)         result = tests.ReadableResult.parse(_result)
509)         assert result.clean_exit(
510)             empty_stderr=True
511)         ), 'expected clean exit and empty stderr'
512)         assert _result.stdout_bytes
513)         assert (
514)             _result.stdout_bytes.rstrip(b'\n') != DUMMY_RESULT_PASSPHRASE
515)         ), 'known false output: phrase-based instead of key-based'
516)         assert (
517)             _result.stdout_bytes.rstrip(b'\n') == DUMMY_RESULT_KEY1
518)         ), 'expected known output'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

519) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

520)     def test_204b_key_from_command_line(
521)         self, monkeypatch: pytest.MonkeyPatch
522)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

523)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

524)         with tests.isolated_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

525)             monkeypatch=monkeypatch,
526)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

527)             vault_config={'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

528)         ):
529)             monkeypatch.setattr(
530)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
531)             )
532)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

533)                 vault.Vault, 'phrase_from_key', tests.phrase_from_key
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

534)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

535)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

536)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

537)                 ['-k', '--', DUMMY_SERVICE],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

538)                 input='1\n',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

539)                 catch_exceptions=False,
540)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

541)         result = tests.ReadableResult.parse(_result)
542)         assert result.clean_exit(), 'expected clean exit'
543)         assert _result.stdout_bytes, 'expected program output'
544)         last_line = _result.stdout_bytes.splitlines(True)[-1]
545)         assert (
546)             last_line.rstrip(b'\n') != DUMMY_RESULT_PASSPHRASE
547)         ), 'known false output: phrase-based instead of key-based'
548)         assert (
549)             last_line.rstrip(b'\n') == DUMMY_RESULT_KEY1
550)         ), 'expected known output'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

551) 
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 5 months ago

552)     @pytest.mark.parametrize(
553)         'config',
554)         [
555)             pytest.param(
556)                 {
557)                     'global': {'key': DUMMY_KEY1_B64},
558)                     'services': {DUMMY_SERVICE: {}},
559)                 },
560)                 id='global_config',
561)             ),
562)             pytest.param(
563)                 {'services': {DUMMY_SERVICE: {'key': DUMMY_KEY2_B64}}},
564)                 id='service_config',
565)             ),
566)             pytest.param(
567)                 {
568)                     'global': {'key': DUMMY_KEY1_B64},
569)                     'services': {DUMMY_SERVICE: {'key': DUMMY_KEY2_B64}},
570)                 },
571)                 id='full_config',
572)             ),
573)         ],
574)     )
575)     @pytest.mark.parametrize('key_index', [1, 2, 3], ids=lambda i: f'index{i}')
576)     def test_204c_key_override_on_command_line(
577)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

578)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

579)         running_ssh_agent: tests.RunningSSHAgentInfo,
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 5 months ago

580)         config: dict[str, Any],
581)         key_index: int,
582)     ) -> None:
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

583)         with monkeypatch.context():
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

584)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent.socket)
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

585)             monkeypatch.setattr(
586)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 5 months ago

587)             )
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

588)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', tests.sign)
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

589)             runner = click.testing.CliRunner(mix_stderr=False)
590)             with tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

591)                 monkeypatch=monkeypatch, runner=runner, vault_config=config
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

592)             ):
593)                 _result = runner.invoke(
594)                     cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

595)                     ['-k', '--', DUMMY_SERVICE],
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

596)                     input=f'{key_index}\n',
597)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

598)         result = tests.ReadableResult.parse(_result)
599)         assert result.clean_exit(), 'expected clean exit'
600)         assert result.output, 'expected program output'
601)         assert result.stderr, 'expected stderr'
602)         assert (
603)             'Error:' not in result.stderr
604)         ), 'expected no error messages on stderr'
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 5 months ago

605) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

606)     def test_205_service_phrase_if_key_in_global_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

607)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

608)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

609)         running_ssh_agent: tests.RunningSSHAgentInfo,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

610)     ) -> None:
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

611)         with monkeypatch.context():
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

612)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent.socket)
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

613)             monkeypatch.setattr(
614)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

615)             )
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

616)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', tests.sign)
617)             runner = click.testing.CliRunner(mix_stderr=False)
618)             with tests.isolated_vault_config(
619)                 monkeypatch=monkeypatch,
620)                 runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

621)                 vault_config={
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

622)                     'global': {'key': DUMMY_KEY1_B64},
623)                     'services': {
624)                         DUMMY_SERVICE: {
625)                             'phrase': DUMMY_PASSPHRASE.rstrip('\n'),
626)                             **DUMMY_CONFIG_SETTINGS,
627)                         }
628)                     },
629)                 },
630)             ):
631)                 _result = runner.invoke(
632)                     cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

633)                     ['--', DUMMY_SERVICE],
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

634)                     catch_exceptions=False,
635)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

636)         result = tests.ReadableResult.parse(_result)
637)         assert result.clean_exit(), 'expected clean exit'
638)         assert _result.stdout_bytes, 'expected program output'
639)         last_line = _result.stdout_bytes.splitlines(True)[-1]
640)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

641)             last_line.rstrip(b'\n') != DUMMY_RESULT_PASSPHRASE
642)         ), 'known false output: phrase-based instead of key-based'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

643)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

644)             last_line.rstrip(b'\n') == DUMMY_RESULT_KEY1
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

645)         ), 'expected known output'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

646) 
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

647)     @pytest.mark.parametrize(
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 2 weeks ago

648)         ['config', 'command_line'],
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

649)         [
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 2 weeks ago

650)             pytest.param(
651)                 {
652)                     'global': {'key': DUMMY_KEY1_B64},
653)                     'services': {},
654)                 },
655)                 ['--config', '-p'],
656)                 id='global',
657)             ),
658)             pytest.param(
659)                 {
660)                     'services': {
661)                         DUMMY_SERVICE: {
662)                             'key': DUMMY_KEY1_B64,
663)                             **DUMMY_CONFIG_SETTINGS,
664)                         },
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

665)                     },
666)                 },
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 2 weeks ago

667)                 ['--config', '-p', '--', DUMMY_SERVICE],
668)                 id='service',
669)             ),
670)             pytest.param(
671)                 {
672)                     'global': {'key': DUMMY_KEY1_B64},
673)                     'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()},
674)                 },
675)                 ['--config', '-p', '--', DUMMY_SERVICE],
676)                 id='service-over-global',
677)             ),
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

678)         ],
679)     )
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 2 weeks ago

680)     def test_206_setting_phrase_thus_overriding_key_in_config(
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

681)         self,
682)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

683)         running_ssh_agent: tests.RunningSSHAgentInfo,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

684)         caplog: pytest.LogCaptureFixture,
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

685)         config: _types.VaultConfig,
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 2 weeks ago

686)         command_line: list[str],
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

687)     ) -> None:
688)         with monkeypatch.context():
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

689)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent.socket)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

690)             monkeypatch.setattr(
691)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
692)             )
693)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', tests.sign)
694)             runner = click.testing.CliRunner(mix_stderr=False)
695)             with tests.isolated_vault_config(
696)                 monkeypatch=monkeypatch,
697)                 runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

698)                 vault_config=config,
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

699)             ):
700)                 _result = runner.invoke(
701)                     cli.derivepassphrase_vault,
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 2 weeks ago

702)                     command_line,
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

703)                     input=DUMMY_PASSPHRASE,
704)                     catch_exceptions=False,
705)                 )
706)         result = tests.ReadableResult.parse(_result)
707)         assert result.clean_exit(), 'expected clean exit'
708)         assert not result.output.strip(), 'expected no program output'
709)         assert result.stderr, 'expected known error output'
710)         err_lines = result.stderr.splitlines(False)
711)         assert err_lines[0].startswith('Passphrase:')
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

712)         assert tests.warning_emitted(
713)             'Setting a service passphrase is ineffective ',
714)             caplog.record_tuples,
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 2 weeks ago

715)         ) or tests.warning_emitted(
716)             'Setting a global passphrase is ineffective ',
717)             caplog.record_tuples,
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

718)         ), 'expected known warning message'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

719)         assert all(map(is_warning_line, result.stderr.splitlines(True)))
720)         assert all(
721)             map(is_harmless_config_import_warning, caplog.record_tuples)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

722)         ), 'unexpected error output'
723) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

724)     @pytest.mark.parametrize(
725)         'option',
726)         [
727)             '--lower',
728)             '--upper',
729)             '--number',
730)             '--space',
731)             '--dash',
732)             '--symbol',
733)             '--repeat',
734)             '--length',
735)         ],
736)     )
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

737)     def test_210_invalid_argument_range(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

738)         self, monkeypatch: pytest.MonkeyPatch, option: str
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

739)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

740)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

741)         with tests.isolated_config(
742)             monkeypatch=monkeypatch,
743)             runner=runner,
744)         ):
745)             for value in '-42', 'invalid':
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

746)                 _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

747)                     cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

748)                     [option, value, '-p', '--', DUMMY_SERVICE],
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

749)                     input=DUMMY_PASSPHRASE,
750)                     catch_exceptions=False,
751)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

752)                 result = tests.ReadableResult.parse(_result)
753)                 assert result.error_exit(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

754)                     error='Invalid value'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

755)                 ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

756) 
757)     @pytest.mark.parametrize(
758)         ['options', 'service', 'input', 'check_success'],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

759)         [
760)             (o.options, o.needs_service, o.input, o.check_success)
761)             for o in INTERESTING_OPTION_COMBINATIONS
762)             if not o.incompatible
763)         ],
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

764)     )
765)     def test_211_service_needed(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

766)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

767)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

768)         options: list[str],
769)         service: bool | None,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

770)         input: str | None,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

771)         check_success: bool,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

772)     ) -> None:
773)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
774)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

775)         with tests.isolated_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

776)             monkeypatch=monkeypatch,
777)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

778)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

779)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

780)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

781)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

782)                 options if service else [*options, '--', DUMMY_SERVICE],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

783)                 input=input,
784)                 catch_exceptions=False,
785)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

786)             result = tests.ReadableResult.parse(_result)
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

787)             if service is not None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

788)                 err_msg = (
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

789)                     ' requires a SERVICE'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

790)                     if service
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

791)                     else ' does not take a SERVICE argument'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

792)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

793)                 assert result.error_exit(
794)                     error=err_msg
795)                 ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

796)             else:
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

797)                 assert result.clean_exit(
798)                     empty_stderr=True
799)                 ), 'expected clean exit'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

800)         if check_success:
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

801)             with tests.isolated_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

802)                 monkeypatch=monkeypatch,
803)                 runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

804)                 vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

805)             ):
806)                 monkeypatch.setattr(
807)                     cli, '_prompt_for_passphrase', tests.auto_prompt
808)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

809)                 _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

810)                     cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

811)                     [*options, '--', DUMMY_SERVICE] if service else options,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

812)                     input=input,
813)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

814)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

815)                 result = tests.ReadableResult.parse(_result)
816)             assert result.clean_exit(empty_stderr=True), 'expected clean exit'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

817) 
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

818)     def test_211a_empty_service_name_causes_warning(
819)         self,
820)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

821)         caplog: pytest.LogCaptureFixture,
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

822)     ) -> None:
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

823)         def is_expected_warning(record: tuple[str, int, str]) -> bool:
824)             return is_harmless_config_import_warning(
825)                 record
826)             ) or tests.warning_emitted(
827)                 'An empty SERVICE is not supported by vault(1)', [record]
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

828)             )
829) 
830)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
831)         runner = click.testing.CliRunner(mix_stderr=False)
832)         with tests.isolated_vault_config(
833)             monkeypatch=monkeypatch,
834)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

835)             vault_config={'services': {}},
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

836)         ):
837)             _result = runner.invoke(
838)                 cli.derivepassphrase_vault,
839)                 ['--config', '--length=30', '--', ''],
840)                 catch_exceptions=False,
841)             )
842)             result = tests.ReadableResult.parse(_result)
843)             assert result.clean_exit(empty_stderr=False), 'expected clean exit'
844)             assert result.stderr is not None, 'expected known error output'
845)             assert all(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

846)                 map(is_expected_warning, caplog.record_tuples)
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

847)             ), 'expected known error output'
848)             assert cli._load_config() == {
849)                 'global': {'length': 30},
850)                 'services': {},
851)             }, 'requested configuration change was not applied'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

852)             caplog.clear()
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

853)             _result = runner.invoke(
854)                 cli.derivepassphrase_vault,
855)                 ['--import', '-'],
856)                 input=json.dumps({'services': {'': {'length': 40}}}),
857)                 catch_exceptions=False,
858)             )
859)             result = tests.ReadableResult.parse(_result)
860)             assert result.clean_exit(empty_stderr=False), 'expected clean exit'
861)             assert result.stderr is not None, 'expected known error output'
862)             assert all(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

863)                 map(is_expected_warning, caplog.record_tuples)
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

864)             ), 'expected known error output'
865)             assert cli._load_config() == {
866)                 'global': {'length': 30},
867)                 'services': {'': {'length': 40}},
868)             }, 'requested configuration change was not applied'
869) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

870)     @pytest.mark.parametrize(
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

871)         ['options', 'service'],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

872)         [
873)             (o.options, o.needs_service)
874)             for o in INTERESTING_OPTION_COMBINATIONS
875)             if o.incompatible
876)         ],
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

877)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

878)     def test_212_incompatible_options(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

879)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

880)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

881)         options: list[str],
882)         service: bool | None,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

883)     ) -> None:
884)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

885)         with tests.isolated_config(
886)             monkeypatch=monkeypatch,
887)             runner=runner,
888)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

889)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

890)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

891)                 [*options, '--', DUMMY_SERVICE] if service else options,
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

892)                 input=DUMMY_PASSPHRASE,
893)                 catch_exceptions=False,
894)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

895)         result = tests.ReadableResult.parse(_result)
896)         assert result.error_exit(
897)             error='mutually exclusive with '
898)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

899) 
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

900)     @pytest.mark.parametrize(
901)         'config',
902)         [
903)             conf.config
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

904)             for conf in TEST_CONFIGS
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

905)             if tests.is_valid_test_config(conf)
906)         ],
907)     )
908)     def test_213_import_config_success(
909)         self,
910)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

911)         caplog: pytest.LogCaptureFixture,
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

912)         config: Any,
913)     ) -> None:
914)         runner = click.testing.CliRunner(mix_stderr=False)
915)         with tests.isolated_vault_config(
916)             monkeypatch=monkeypatch,
917)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

918)             vault_config={'services': {}},
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

919)         ):
920)             _result = runner.invoke(
921)                 cli.derivepassphrase_vault,
922)                 ['--import', '-'],
923)                 input=json.dumps(config),
924)                 catch_exceptions=False,
925)             )
926)             with open(
927)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
928)             ) as infile:
929)                 config2 = json.load(infile)
930)         result = tests.ReadableResult.parse(_result)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

931)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

932)         assert config2 == config, 'config not imported correctly'
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

933)         assert not result.stderr or all(  # pragma: no branch
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

934)             map(is_harmless_config_import_warning, caplog.record_tuples)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

935)         ), 'unexpected error output'
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

936) 
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

937)     @tests.hypothesis_settings_coverage_compatible_with_caplog
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

938)     @hypothesis.given(
939)         conf=tests.smudged_vault_test_config(
940)             strategies.sampled_from(TEST_CONFIGS).filter(
941)                 tests.is_valid_test_config
942)             )
943)         )
944)     )
945)     def test_213a_import_config_success(
946)         self,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

947)         caplog: pytest.LogCaptureFixture,
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

948)         conf: tests.VaultTestConfig,
949)     ) -> None:
950)         config = conf.config
951)         config2 = copy.deepcopy(config)
952)         _types.clean_up_falsy_vault_config_values(config2)
953)         runner = click.testing.CliRunner(mix_stderr=False)
954)         with tests.isolated_vault_config(
955)             monkeypatch=pytest.MonkeyPatch(),
956)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

957)             vault_config={'services': {}},
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

958)         ):
959)             _result = runner.invoke(
960)                 cli.derivepassphrase_vault,
961)                 ['--import', '-'],
962)                 input=json.dumps(config),
963)                 catch_exceptions=False,
964)             )
965)             with open(
966)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
967)             ) as infile:
968)                 config3 = json.load(infile)
969)         result = tests.ReadableResult.parse(_result)
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

970)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

971)         assert config3 == config2, 'config not imported correctly'
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

972)         assert not result.stderr or all(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

973)             map(is_harmless_config_import_warning, caplog.record_tuples)
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

974)         ), 'unexpected error output'
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

975) 
976)     def test_213b_import_bad_config_not_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

977)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

978)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

979)     ) -> None:
980)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

981)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

982)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

983)                 cli.derivepassphrase_vault,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

984)                 ['--import', '-'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

985)                 input='null',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

986)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

987)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

988)         result = tests.ReadableResult.parse(_result)
989)         assert result.error_exit(
990)             error='Invalid vault config'
991)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

992) 
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

993)     def test_213c_import_bad_config_not_json_data(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

994)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

995)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

996)     ) -> None:
997)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

998)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

999)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1000)                 cli.derivepassphrase_vault,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1001)                 ['--import', '-'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1002)                 input='This string is not valid JSON.',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1003)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1004)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1005)         result = tests.ReadableResult.parse(_result)
1006)         assert result.error_exit(
1007)             error='cannot decode JSON'
1008)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

1009) 
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

1010)     def test_213d_import_bad_config_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1011)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1012)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1013)     ) -> None:
1014)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1015)         # `isolated_vault_config` validates the configuration.  So, to
1016)         # pass an actual broken configuration, we must open the
1017)         # configuration file ourselves afterwards, inside the context.
1018)         # We also might as well use `isolated_config` instead.
1019)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1020)             with open(
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

1021)                 cli._config_filename(subsystem='vault'), 'w', encoding='UTF-8'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1022)             ) as outfile:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1023)                 print('This string is not valid JSON.', file=outfile)
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

1024)             dname = cli._config_filename(subsystem=None)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1025)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1026)                 cli.derivepassphrase_vault,
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 6 months ago

1027)                 ['--import', os.fsdecode(dname)],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1028)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1029)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1030)         result = tests.ReadableResult.parse(_result)
1031)         assert result.error_exit(
1032)             error=os.strerror(errno.EISDIR)
1033)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1034) 
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

1035)     @pytest.mark.parametrize(
1036)         'export_options',
1037)         [
1038)             [],
1039)             ['--export-as=sh'],
1040)         ],
1041)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1042)     def test_214_export_settings_no_stored_settings(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1043)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1044)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

1045)         export_options: list[str],
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1046)     ) -> None:
1047)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1048)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

1049)             with contextlib.suppress(FileNotFoundError):
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

1050)                 os.remove(cli._config_filename(subsystem='vault'))
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1051)             _result = runner.invoke(
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

1052)                 # Test parent context navigation by not calling
1053)                 # `cli.derivepassphrase_vault` directly.  Used e.g. in
1054)                 # the `--export-as=sh` section to autoconstruct the
1055)                 # program name correctly.
1056)                 cli.derivepassphrase,
1057)                 ['vault', '--export', '-', *export_options],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1058)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1059)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1060)         result = tests.ReadableResult.parse(_result)
1061)         assert result.clean_exit(empty_stderr=True), 'expected clean exit'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

1062) 
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

1063)     @pytest.mark.parametrize(
1064)         'export_options',
1065)         [
1066)             [],
1067)             ['--export-as=sh'],
1068)         ],
1069)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1070)     def test_214a_export_settings_bad_stored_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1071)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1072)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

1073)         export_options: list[str],
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1074)     ) -> None:
1075)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1076)         with tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1077)             monkeypatch=monkeypatch, runner=runner, vault_config={}
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1078)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1079)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1080)                 cli.derivepassphrase_vault,
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

1081)                 ['--export', '-', *export_options],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1082)                 input='null',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1083)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1084)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1085)         result = tests.ReadableResult.parse(_result)
1086)         assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1087)             error='Cannot load vault settings:'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1088)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

1089) 
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

1090)     @pytest.mark.parametrize(
1091)         'export_options',
1092)         [
1093)             [],
1094)             ['--export-as=sh'],
1095)         ],
1096)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1097)     def test_214b_export_settings_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1098)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1099)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

1100)         export_options: list[str],
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1101)     ) -> None:
1102)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1103)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

1104)             with contextlib.suppress(FileNotFoundError):
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

1105)                 os.remove(cli._config_filename(subsystem='vault'))
1106)             os.makedirs(cli._config_filename(subsystem='vault'))
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1107)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1108)                 cli.derivepassphrase_vault,
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

1109)                 ['--export', '-', *export_options],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1110)                 input='null',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1111)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1112)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1113)         result = tests.ReadableResult.parse(_result)
1114)         assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1115)             error='Cannot load vault settings:'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1116)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

1117) 
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

1118)     @pytest.mark.parametrize(
1119)         'export_options',
1120)         [
1121)             [],
1122)             ['--export-as=sh'],
1123)         ],
1124)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1125)     def test_214c_export_settings_target_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1126)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1127)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

1128)         export_options: list[str],
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1129)     ) -> None:
1130)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1131)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

1132)             dname = cli._config_filename(subsystem=None)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1133)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1134)                 cli.derivepassphrase_vault,
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

1135)                 ['--export', os.fsdecode(dname), *export_options],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1136)                 input='null',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1137)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1138)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1139)         result = tests.ReadableResult.parse(_result)
1140)         assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1141)             error='Cannot export vault settings:'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1142)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

1143) 
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

1144)     @pytest.mark.parametrize(
1145)         'export_options',
1146)         [
1147)             [],
1148)             ['--export-as=sh'],
1149)         ],
1150)     )
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

1151)     def test_214d_export_settings_settings_directory_not_a_directory(
1152)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1153)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

1154)         export_options: list[str],
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

1155)     ) -> None:
1156)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1157)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

1158)             with contextlib.suppress(FileNotFoundError):
1159)                 shutil.rmtree('.derivepassphrase')
1160)             with open('.derivepassphrase', 'w', encoding='UTF-8') as outfile:
1161)                 print('Obstruction!!', file=outfile)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1162)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1163)                 cli.derivepassphrase_vault,
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

1164)                 ['--export', '-', *export_options],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1165)                 input='null',
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

1166)                 catch_exceptions=False,
1167)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1168)         result = tests.ReadableResult.parse(_result)
1169)         assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1170)             error='Cannot load vault settings:'
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1171)         ) or result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1172)             error='Cannot load user config:'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1173)         ), 'expected error exit and known error message'
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

1174) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1175)     def test_220_edit_notes_successfully(
1176)         self, monkeypatch: pytest.MonkeyPatch
1177)     ) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1178)         edit_result = """
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

1179) 
1180) # - - - - - >8 - - - - - >8 - - - - - >8 - - - - - >8 - - - - -
1181) contents go here
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1182) """
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1183)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1184)         with tests.isolated_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1185)             monkeypatch=monkeypatch,
1186)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1187)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1188)         ):
1189)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: edit_result)  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1190)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1191)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1192)                 ['--notes', '--', 'sv'],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1193)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1194)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1195)             result = tests.ReadableResult.parse(_result)
1196)             assert result.clean_exit(empty_stderr=True), 'expected clean exit'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

1197)             with open(
1198)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
1199)             ) as infile:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1200)                 config = json.load(infile)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1201)             assert config == {
1202)                 'global': {'phrase': 'abc'},
1203)                 'services': {'sv': {'notes': 'contents go here'}},
1204)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1205) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1206)     def test_221_edit_notes_noop(
1207)         self, monkeypatch: pytest.MonkeyPatch
1208)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1209)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1210)         with tests.isolated_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1211)             monkeypatch=monkeypatch,
1212)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1213)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1214)         ):
1215)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: None)  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1216)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1217)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1218)                 ['--notes', '--', 'sv'],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1219)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1220)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1221)             result = tests.ReadableResult.parse(_result)
1222)             assert result.clean_exit(empty_stderr=True), 'expected clean exit'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

1223)             with open(
1224)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
1225)             ) as infile:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1226)                 config = json.load(infile)
1227)             assert config == {'global': {'phrase': 'abc'}, 'services': {}}
1228) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1229)     def test_222_edit_notes_marker_removed(
1230)         self, monkeypatch: pytest.MonkeyPatch
1231)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1232)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1233)         with tests.isolated_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1234)             monkeypatch=monkeypatch,
1235)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1236)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1237)         ):
1238)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: 'long\ntext')  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1239)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1240)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1241)                 ['--notes', '--', 'sv'],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1242)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1243)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1244)             result = tests.ReadableResult.parse(_result)
1245)             assert result.clean_exit(empty_stderr=True), 'expected clean exit'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

1246)             with open(
1247)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
1248)             ) as infile:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1249)                 config = json.load(infile)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1250)             assert config == {
1251)                 'global': {'phrase': 'abc'},
1252)                 'services': {'sv': {'notes': 'long\ntext'}},
1253)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1254) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1255)     def test_223_edit_notes_abort(
1256)         self, monkeypatch: pytest.MonkeyPatch
1257)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1258)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1259)         with tests.isolated_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1260)             monkeypatch=monkeypatch,
1261)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1262)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1263)         ):
1264)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: '\n\n')  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1265)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1266)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1267)                 ['--notes', '--', 'sv'],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1268)                 catch_exceptions=False,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1269)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1270)             result = tests.ReadableResult.parse(_result)
1271)             assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1272)                 error='the user aborted the request'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1273)             ), 'expected known error message'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

1274)             with open(
1275)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
1276)             ) as infile:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1277)                 config = json.load(infile)
1278)             assert config == {'global': {'phrase': 'abc'}, 'services': {}}
1279) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1280)     @pytest.mark.parametrize(
1281)         ['command_line', 'input', 'result_config'],
1282)         [
1283)             (
1284)                 ['--phrase'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1285)                 'my passphrase\n',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1286)                 {'global': {'phrase': 'my passphrase'}, 'services': {}},
1287)             ),
1288)             (
1289)                 ['--key'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1290)                 '1\n',
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

1291)                 {
1292)                     'global': {'key': DUMMY_KEY1_B64, 'phrase': 'abc'},
1293)                     'services': {},
1294)                 },
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1295)             ),
1296)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1297)                 ['--phrase', '--', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1298)                 'my passphrase\n',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1299)                 {
1300)                     'global': {'phrase': 'abc'},
1301)                     'services': {'sv': {'phrase': 'my passphrase'}},
1302)                 },
1303)             ),
1304)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1305)                 ['--key', '--', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1306)                 '1\n',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1307)                 {
1308)                     'global': {'phrase': 'abc'},
1309)                     'services': {'sv': {'key': DUMMY_KEY1_B64}},
1310)                 },
1311)             ),
1312)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1313)                 ['--key', '--length', '15', '--', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1314)                 '1\n',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1315)                 {
1316)                     'global': {'phrase': 'abc'},
1317)                     'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1318)                 },
1319)             ),
1320)         ],
1321)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1322)     def test_224_store_config_good(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1323)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1324)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1325)         command_line: list[str],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1326)         input: str,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1327)         result_config: Any,
1328)     ) -> None:
1329)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1330)         with tests.isolated_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1331)             monkeypatch=monkeypatch,
1332)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1333)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1334)         ):
1335)             monkeypatch.setattr(
1336)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1337)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1338)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1339)                 cli.derivepassphrase_vault,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1340)                 ['--config', *command_line],
1341)                 catch_exceptions=False,
1342)                 input=input,
1343)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1344)             result = tests.ReadableResult.parse(_result)
1345)             assert result.clean_exit(), 'expected clean exit'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

1346)             with open(
1347)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
1348)             ) as infile:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1349)                 config = json.load(infile)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1350)             assert (
1351)                 config == result_config
1352)             ), 'stored config does not match expectation'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1353) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1354)     @pytest.mark.parametrize(
1355)         ['command_line', 'input', 'err_text'],
1356)         [
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1357)             (
1358)                 [],
1359)                 '',
1360)                 'Cannot update global settings without any given settings',
1361)             ),
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1362)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1363)                 ['--', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1364)                 '',
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1365)                 'Cannot update service settings without any given settings',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1366)             ),
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1367)             (['--phrase', '--', 'sv'], '', 'No passphrase was given'),
1368)             (['--key'], '', 'No SSH key was selected'),
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1369)         ],
1370)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1371)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1372)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1373)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1374)         command_line: list[str],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1375)         input: str,
1376)         err_text: str,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1377)     ) -> None:
1378)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1379)         with tests.isolated_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1380)             monkeypatch=monkeypatch,
1381)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1382)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1383)         ):
1384)             monkeypatch.setattr(
1385)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1386)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1387)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1388)                 cli.derivepassphrase_vault,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1389)                 ['--config', *command_line],
1390)                 catch_exceptions=False,
1391)                 input=input,
1392)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1393)         result = tests.ReadableResult.parse(_result)
1394)         assert result.error_exit(
1395)             error=err_text
1396)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1397) 
1398)     def test_225a_store_config_fail_manual_no_ssh_key_selection(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1399)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1400)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1401)     ) -> None:
1402)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1403)         with tests.isolated_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1404)             monkeypatch=monkeypatch,
1405)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1406)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1407)         ):
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

1408)             custom_error = 'custom error message'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1409) 
Marco Ricci Support suppressing or forc...

Marco Ricci authored 1 week ago

1410)             def raiser(*_args: Any, **_kwargs: Any) -> None:
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

1411)                 raise RuntimeError(custom_error)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1412) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1413)             monkeypatch.setattr(cli, '_select_ssh_key', raiser)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1414)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1415)                 cli.derivepassphrase_vault,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1416)                 ['--key', '--config'],
1417)                 catch_exceptions=False,
1418)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1419)         result = tests.ReadableResult.parse(_result)
1420)         assert result.error_exit(
1421)             error=custom_error
1422)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1423) 
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1424)     def test_225b_store_config_fail_manual_no_ssh_agent(
1425)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1426)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Fail gracefully if UNIX dom...

Marco Ricci authored 3 months ago

1427)         skip_if_no_af_unix_support: None,
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1428)     ) -> None:
Marco Ricci Fail gracefully if UNIX dom...

Marco Ricci authored 3 months ago

1429)         del skip_if_no_af_unix_support
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1430)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1431)         with tests.isolated_vault_config(
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1432)             monkeypatch=monkeypatch,
1433)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1434)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1435)         ):
1436)             monkeypatch.delenv('SSH_AUTH_SOCK', raising=False)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1437)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1438)                 cli.derivepassphrase_vault,
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1439)                 ['--key', '--config'],
1440)                 catch_exceptions=False,
1441)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1442)         result = tests.ReadableResult.parse(_result)
1443)         assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1444)             error='Cannot find any running SSH agent'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1445)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1446) 
1447)     def test_225c_store_config_fail_manual_bad_ssh_agent_connection(
1448)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1449)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1450)     ) -> None:
1451)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1452)         with tests.isolated_vault_config(
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1453)             monkeypatch=monkeypatch,
1454)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1455)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1456)         ):
1457)             monkeypatch.setenv('SSH_AUTH_SOCK', os.getcwd())
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1458)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1459)                 cli.derivepassphrase_vault,
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1460)                 ['--key', '--config'],
1461)                 catch_exceptions=False,
1462)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1463)         result = tests.ReadableResult.parse(_result)
1464)         assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1465)             error='Cannot connect to the SSH agent'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1466)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1467) 
1468)     @pytest.mark.parametrize('try_race_free_implementation', [True, False])
1469)     def test_225d_store_config_fail_manual_read_only_file(
1470)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1471)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1472)         try_race_free_implementation: bool,
1473)     ) -> None:
1474)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1475)         with tests.isolated_vault_config(
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1476)             monkeypatch=monkeypatch,
1477)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1478)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1479)         ):
1480)             tests.make_file_readonly(
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

1481)                 cli._config_filename(subsystem='vault'),
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1482)                 try_race_free_implementation=try_race_free_implementation,
1483)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1484)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1485)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1486)                 ['--config', '--length=15', '--', DUMMY_SERVICE],
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1487)                 catch_exceptions=False,
1488)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1489)         result = tests.ReadableResult.parse(_result)
1490)         assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1491)             error='Cannot store vault settings:'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1492)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1493) 
1494)     def test_225e_store_config_fail_manual_custom_error(
1495)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1496)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1497)     ) -> None:
1498)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1499)         with tests.isolated_vault_config(
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1500)             monkeypatch=monkeypatch,
1501)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1502)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1503)         ):
1504)             custom_error = 'custom error message'
1505) 
1506)             def raiser(config: Any) -> None:
1507)                 del config
1508)                 raise RuntimeError(custom_error)
1509) 
1510)             monkeypatch.setattr(cli, '_save_config', raiser)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1511)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1512)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1513)                 ['--config', '--length=15', '--', DUMMY_SERVICE],
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1514)                 catch_exceptions=False,
1515)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1516)         result = tests.ReadableResult.parse(_result)
1517)         assert result.error_exit(
1518)             error=custom_error
1519)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1520) 
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

1521)     def test_225f_store_config_fail_unset_and_set_same_settings(
1522)         self,
1523)         monkeypatch: pytest.MonkeyPatch,
1524)     ) -> None:
1525)         runner = click.testing.CliRunner(mix_stderr=False)
1526)         with tests.isolated_vault_config(
1527)             monkeypatch=monkeypatch,
1528)             runner=runner,
1529)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
1530)         ):
1531)             _result = runner.invoke(
1532)                 cli.derivepassphrase_vault,
1533)                 [
1534)                     '--config',
1535)                     '--unset=length',
1536)                     '--length=15',
1537)                     '--',
1538)                     DUMMY_SERVICE,
1539)                 ],
1540)                 catch_exceptions=False,
1541)             )
1542)         result = tests.ReadableResult.parse(_result)
1543)         assert result.error_exit(
1544)             error='Attempted to unset and set --length at the same time.'
1545)         ), 'expected error exit and known error message'
1546) 
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1547)     def test_225g_store_config_fail_manual_ssh_agent_no_keys_loaded(
1548)         self,
1549)         monkeypatch: pytest.MonkeyPatch,
1550)         running_ssh_agent: tests.RunningSSHAgentInfo,
1551)     ) -> None:
1552)         del running_ssh_agent
1553)         runner = click.testing.CliRunner(mix_stderr=False)
1554)         with tests.isolated_vault_config(
1555)             monkeypatch=monkeypatch,
1556)             runner=runner,
1557)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
1558)         ):
1559)             def func(
1560)                 *_args: Any,
1561)                 **_kwargs: Any,
1562)             ) -> list[_types.KeyCommentPair]:
1563)                 return []
1564) 
1565)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'list_keys', func)
1566)             _result = runner.invoke(
1567)                 cli.derivepassphrase_vault,
1568)                 ['--key', '--config'],
1569)                 catch_exceptions=False,
1570)             )
1571)         result = tests.ReadableResult.parse(_result)
1572)         assert result.error_exit(
1573)             error='no keys suitable'
1574)         ), 'expected error exit and known error message'
1575) 
1576)     def test_225h_store_config_fail_manual_ssh_agent_runtime_error(
1577)         self,
1578)         monkeypatch: pytest.MonkeyPatch,
1579)         running_ssh_agent: tests.RunningSSHAgentInfo,
1580)     ) -> None:
1581)         del running_ssh_agent
1582)         runner = click.testing.CliRunner(mix_stderr=False)
1583)         with tests.isolated_vault_config(
1584)             monkeypatch=monkeypatch,
1585)             runner=runner,
1586)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
1587)         ):
1588)             def raiser(*_args: Any, **_kwargs: Any) -> None:
1589)                 raise ssh_agent.TrailingDataError()
1590) 
1591)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'list_keys', raiser)
1592)             _result = runner.invoke(
1593)                 cli.derivepassphrase_vault,
1594)                 ['--key', '--config'],
1595)                 catch_exceptions=False,
1596)             )
1597)         result = tests.ReadableResult.parse(_result)
1598)         assert result.error_exit(
1599)             error='violates the communications protocol.'
1600)         ), 'expected error exit and known error message'
1601) 
1602)     def test_225i_store_config_fail_manual_ssh_agent_refuses(
1603)         self,
1604)         monkeypatch: pytest.MonkeyPatch,
1605)         running_ssh_agent: tests.RunningSSHAgentInfo,
1606)     ) -> None:
1607)         del running_ssh_agent
1608)         runner = click.testing.CliRunner(mix_stderr=False)
1609)         with tests.isolated_vault_config(
1610)             monkeypatch=monkeypatch,
1611)             runner=runner,
1612)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
1613)         ):
1614)             def func(*_args: Any, **_kwargs: Any) -> NoReturn:
1615)                 raise ssh_agent.SSHAgentFailedError(
1616)                     _types.SSH_AGENT.FAILURE, b''
1617)                 )
1618) 
1619)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'list_keys', func)
1620)             _result = runner.invoke(
1621)                 cli.derivepassphrase_vault,
1622)                 ['--key', '--config'],
1623)                 catch_exceptions=False,
1624)             )
1625)         result = tests.ReadableResult.parse(_result)
1626)         assert result.error_exit(
1627)             error='refused to'
1628)         ), 'expected error exit and known error message'
1629) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1630)     def test_226_no_arguments(self, monkeypatch: pytest.MonkeyPatch) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1631)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

1632)         with tests.isolated_config(
1633)             monkeypatch=monkeypatch,
1634)             runner=runner,
1635)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1636)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1637)                 cli.derivepassphrase_vault, [], catch_exceptions=False
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

1638)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1639)         result = tests.ReadableResult.parse(_result)
1640)         assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1641)             error='Deriving a passphrase requires a SERVICE'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1642)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

1643) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1644)     def test_226a_no_passphrase_or_key(
1645)         self, monkeypatch: pytest.MonkeyPatch
1646)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1647)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

1648)         with tests.isolated_config(
1649)             monkeypatch=monkeypatch,
1650)             runner=runner,
1651)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1652)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1653)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1654)                 ['--', DUMMY_SERVICE],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1655)                 catch_exceptions=False,
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

1656)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1657)         result = tests.ReadableResult.parse(_result)
1658)         assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1659)             error='No passphrase or key was given'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1660)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

1661) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1662)     def test_230_config_directory_nonexistant(
1663)         self, monkeypatch: pytest.MonkeyPatch
1664)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

1665)         """https://github.com/the-13th-letter/derivepassphrase/issues/6"""
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

1666)         runner = click.testing.CliRunner(mix_stderr=False)
1667)         with tests.isolated_config(
1668)             monkeypatch=monkeypatch,
1669)             runner=runner,
1670)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

1671)             shutil.rmtree('.derivepassphrase')
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

1672)             os_makedirs_called = False
1673)             real_os_makedirs = os.makedirs
1674) 
1675)             def makedirs(*args: Any, **kwargs: Any) -> Any:
1676)                 nonlocal os_makedirs_called
1677)                 os_makedirs_called = True
1678)                 return real_os_makedirs(*args, **kwargs)
1679) 
1680)             monkeypatch.setattr(os, 'makedirs', makedirs)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1681)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1682)                 cli.derivepassphrase_vault,
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

1683)                 ['--config', '-p'],
1684)                 catch_exceptions=False,
1685)                 input='abc\n',
1686)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1687)             result = tests.ReadableResult.parse(_result)
1688)             assert result.clean_exit(), 'expected clean exit'
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

1689)             assert (
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1690)                 result.stderr == 'Passphrase:'
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

1691)             ), 'program unexpectedly failed?!'
1692)             assert os_makedirs_called, 'os.makedirs has not been called?!'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

1693)             with open(
1694)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
1695)             ) as infile:
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

1696)                 config_readback = json.load(infile)
1697)             assert config_readback == {
1698)                 'global': {'phrase': 'abc'},
1699)                 'services': {},
1700)             }, 'config mismatch'
1701) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1702)     def test_230a_config_directory_not_a_file(
1703)         self, monkeypatch: pytest.MonkeyPatch
1704)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

1705)         """https://github.com/the-13th-letter/derivepassphrase/issues/6"""
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

1706)         runner = click.testing.CliRunner(mix_stderr=False)
1707)         with tests.isolated_config(
1708)             monkeypatch=monkeypatch,
1709)             runner=runner,
1710)         ):
1711)             _save_config = cli._save_config
1712) 
1713)             def obstruct_config_saving(*args: Any, **kwargs: Any) -> Any:
1714)                 with contextlib.suppress(FileNotFoundError):
1715)                     shutil.rmtree('.derivepassphrase')
1716)                 with open(
1717)                     '.derivepassphrase', 'w', encoding='UTF-8'
1718)                 ) as outfile:
1719)                     print('Obstruction!!', file=outfile)
1720)                 monkeypatch.setattr(cli, '_save_config', _save_config)
1721)                 return _save_config(*args, **kwargs)
1722) 
1723)             monkeypatch.setattr(cli, '_save_config', obstruct_config_saving)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1724)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1725)                 cli.derivepassphrase_vault,
Marco Ricci Fix error bubbling in outda...

Marco Ricci authored 4 months ago

1726)                 ['--config', '-p'],
1727)                 catch_exceptions=False,
1728)                 input='abc\n',
1729)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1730)             result = tests.ReadableResult.parse(_result)
1731)             assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1732)                 error='Cannot store vault settings:'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1733)             ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1734) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1735)     def test_230b_store_config_custom_error(
1736)         self, monkeypatch: pytest.MonkeyPatch
1737)     ) -> None:
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1738)         runner = click.testing.CliRunner(mix_stderr=False)
1739)         with tests.isolated_config(
1740)             monkeypatch=monkeypatch,
1741)             runner=runner,
1742)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

1743)             custom_error = 'custom error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1744) 
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

1745)             def raiser(config: Any) -> None:
1746)                 del config
1747)                 raise RuntimeError(custom_error)
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1748) 
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

1749)             monkeypatch.setattr(cli, '_save_config', raiser)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1750)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1751)                 cli.derivepassphrase_vault,
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1752)                 ['--config', '-p'],
1753)                 catch_exceptions=False,
1754)                 input='abc\n',
1755)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1756)             result = tests.ReadableResult.parse(_result)
1757)             assert result.error_exit(
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

1758)                 error=custom_error
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1759)             ), 'expected error exit and known error message'
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

1760) 
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1761)     @pytest.mark.parametrize(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1762)         ['main_config', 'command_line', 'input', 'warning_message'],
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1763)         [
1764)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1765)                 '',
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1766)                 ['--import', '-'],
1767)                 json.dumps({
1768)                     'global': {'phrase': 'Du\u0308sseldorf'},
1769)                     'services': {},
1770)                 }),
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1771)                 'The $.global passphrase is not NFC-normalized',
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1772)                 id='global-NFC',
1773)             ),
1774)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1775)                 '',
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1776)                 ['--import', '-'],
1777)                 json.dumps({
1778)                     'services': {
1779)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1780)                         'weird entry name': {'phrase': 'Du\u0308sseldorf'},
1781)                     }
1782)                 }),
1783)                 (
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1784)                     'The $.services["weird entry name"] passphrase '
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1785)                     'is not NFC-normalized'
1786)                 ),
1787)                 id='service-weird-name-NFC',
1788)             ),
1789)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1790)                 '',
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1791)                 ['--config', '-p', '--', DUMMY_SERVICE],
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1792)                 'Du\u0308sseldorf',
1793)                 (
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1794)                     f'The $.services.{DUMMY_SERVICE} passphrase '
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1795)                     f'is not NFC-normalized'
1796)                 ),
1797)                 id='config-NFC',
1798)             ),
1799)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1800)                 '',
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1801)                 ['-p', '--', DUMMY_SERVICE],
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1802)                 'Du\u0308sseldorf',
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1803)                 'The interactive input passphrase is not NFC-normalized',
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1804)                 id='direct-input-NFC',
1805)             ),
1806)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1807)                 textwrap.dedent(r"""
1808)                 [vault]
1809)                 default-unicode-normalization-form = 'NFD'
1810)                 """),
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1811)                 ['--import', '-'],
1812)                 json.dumps({
1813)                     'global': {
1814)                         'phrase': 'D\u00fcsseldorf',
1815)                     },
1816)                     'services': {},
1817)                 }),
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1818)                 'The $.global passphrase is not NFD-normalized',
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1819)                 id='global-NFD',
1820)             ),
1821)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1822)                 textwrap.dedent(r"""
1823)                 [vault]
1824)                 default-unicode-normalization-form = 'NFD'
1825)                 """),
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1826)                 ['--import', '-'],
1827)                 json.dumps({
1828)                     'services': {
1829)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1830)                         'weird entry name': {'phrase': 'D\u00fcsseldorf'},
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 4 months ago

1831)                     },
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1832)                 }),
1833)                 (
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1834)                     'The $.services["weird entry name"] passphrase '
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1835)                     'is not NFD-normalized'
1836)                 ),
1837)                 id='service-weird-name-NFD',
1838)             ),
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1839)             pytest.param(
1840)                 textwrap.dedent(r"""
1841)                 [vault.unicode-normalization-form]
1842)                 'weird entry name 2' = 'NFKD'
1843)                 """),
1844)                 ['--import', '-'],
1845)                 json.dumps({
1846)                     'services': {
1847)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1848)                         'weird entry name 1': {'phrase': 'D\u00fcsseldorf'},
1849)                         'weird entry name 2': {'phrase': 'D\u00fcsseldorf'},
1850)                     },
1851)                 }),
1852)                 (
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1853)                     'The $.services["weird entry name 2"] passphrase '
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1854)                     'is not NFKD-normalized'
1855)                 ),
1856)                 id='service-weird-name-2-NFKD',
1857)             ),
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1858)         ],
1859)     )
1860)     def test_300_unicode_normalization_form_warning(
1861)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1862)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

1863)         caplog: pytest.LogCaptureFixture,
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1864)         main_config: str,
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1865)         command_line: list[str],
1866)         input: str | None,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1867)         warning_message: str,
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1868)     ) -> None:
1869)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

1870)         with tests.isolated_vault_config(
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1871)             monkeypatch=monkeypatch,
1872)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1873)             vault_config={
1874)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1875)             },
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1876)             main_config_str=main_config,
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1877)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1878)             _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1879)                 cli.derivepassphrase_vault,
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1880)                 ['--debug', *command_line],
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1881)                 catch_exceptions=False,
1882)                 input=input,
1883)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1884)         result = tests.ReadableResult.parse(_result)
1885)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

1886)         assert tests.warning_emitted(
1887)             warning_message, caplog.record_tuples
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1888)         ), 'expected known warning message in stderr'
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1889) 
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1890)     @pytest.mark.parametrize(
1891)         ['main_config', 'command_line', 'input', 'error_message'],
1892)         [
1893)             pytest.param(
1894)                 textwrap.dedent(r"""
1895)                 [vault]
1896)                 default-unicode-normalization-form = 'XXX'
1897)                 """),
1898)                 ['--import', '-'],
1899)                 json.dumps({
1900)                     'services': {
1901)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1902)                         'with_normalization': {'phrase': 'D\u00fcsseldorf'},
1903)                     },
1904)                 }),
1905)                 (
1906)                     "Invalid value 'XXX' for config key "
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

1907)                     'vault.default-unicode-normalization-form'
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1908)                 ),
1909)                 id='global',
1910)             ),
1911)             pytest.param(
1912)                 textwrap.dedent(r"""
1913)                 [vault.unicode-normalization-form]
1914)                 with_normalization = 'XXX'
1915)                 """),
1916)                 ['--import', '-'],
1917)                 json.dumps({
1918)                     'services': {
1919)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1920)                         'with_normalization': {'phrase': 'D\u00fcsseldorf'},
1921)                     },
1922)                 }),
1923)                 (
1924)                     "Invalid value 'XXX' for config key "
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

1925)                     'vault.with_normalization.unicode-normalization-form'
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1926)                 ),
1927)                 id='service',
1928)             ),
1929)         ],
1930)     )
1931)     def test_301_unicode_normalization_form_error(
1932)         self,
1933)         monkeypatch: pytest.MonkeyPatch,
1934)         main_config: str,
1935)         command_line: list[str],
1936)         input: str | None,
1937)         error_message: str,
1938)     ) -> None:
1939)         runner = click.testing.CliRunner(mix_stderr=False)
1940)         with tests.isolated_vault_config(
1941)             monkeypatch=monkeypatch,
1942)             runner=runner,
1943)             vault_config={
1944)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1945)             },
1946)             main_config_str=main_config,
1947)         ):
1948)             _result = runner.invoke(
1949)                 cli.derivepassphrase_vault,
1950)                 command_line,
1951)                 catch_exceptions=False,
1952)                 input=input,
1953)             )
1954)         result = tests.ReadableResult.parse(_result)
1955)         assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1956)             error='The user configuration file is invalid.'
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1957)         ), 'expected error exit and known error message'
1958)         assert result.error_exit(
1959)             error=error_message
1960)         ), 'expected error exit and known error message'
1961) 
1962)     @pytest.mark.parametrize(
1963)         'command_line',
1964)         [
1965)             pytest.param(
1966)                 ['--config', '--phrase'],
1967)                 id='configure global passphrase',
1968)             ),
1969)             pytest.param(
1970)                 ['--phrase', '--', DUMMY_SERVICE],
1971)                 id='interactive passphrase',
1972)             ),
1973)         ],
1974)     )
1975)     def test_301a_unicode_normalization_form_error_from_stored_config(
1976)         self,
1977)         monkeypatch: pytest.MonkeyPatch,
1978)         command_line: list[str],
1979)     ) -> None:
1980)         runner = click.testing.CliRunner(mix_stderr=False)
1981)         with tests.isolated_vault_config(
1982)             monkeypatch=monkeypatch,
1983)             runner=runner,
1984)             vault_config={
1985)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1986)             },
1987)             main_config_str=textwrap.dedent("""
1988)             [vault]
1989)             default-unicode-normalization-form = 'XXX'
1990)             """),
1991)         ):
1992)             _result = runner.invoke(
1993)                 cli.derivepassphrase_vault,
1994)                 command_line,
1995)                 input=DUMMY_PASSPHRASE,
1996)                 catch_exceptions=False,
1997)             )
1998)             result = tests.ReadableResult.parse(_result)
1999)             assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2000)                 error='The user configuration file is invalid.'
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

2001)             ), 'expected error exit and known error message'
2002)             assert result.error_exit(
2003)                 error=(
2004)                     "Invalid value 'XXX' for config key "
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

2005)                     'vault.default-unicode-normalization-form'
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

2006)                 ),
2007)             ), 'expected error exit and known error message'
2008) 
2009)     def test_310_bad_user_config_file(
2010)         self,
2011)         monkeypatch: pytest.MonkeyPatch,
2012)     ) -> None:
2013)         runner = click.testing.CliRunner(mix_stderr=False)
2014)         with tests.isolated_vault_config(
2015)             monkeypatch=monkeypatch,
2016)             runner=runner,
2017)             vault_config={'services': {}},
2018)             main_config_str=textwrap.dedent("""
2019)             This file is not valid TOML.
2020)             """),
2021)         ):
2022)             _result = runner.invoke(
2023)                 cli.derivepassphrase_vault,
2024)                 ['--phrase', '--', DUMMY_SERVICE],
2025)                 input=DUMMY_PASSPHRASE,
2026)                 catch_exceptions=False,
2027)             )
2028)             result = tests.ReadableResult.parse(_result)
2029)             assert result.error_exit(
2030)                 error='Cannot load user config:'
2031)             ), 'expected error exit and known error message'
2032) 
Marco Ricci Fail gracefully if UNIX dom...

Marco Ricci authored 3 months ago

2033)     def test_400_missing_af_unix_support(
2034)         self,
2035)         monkeypatch: pytest.MonkeyPatch,
2036)     ) -> None:
2037)         runner = click.testing.CliRunner(mix_stderr=False)
2038)         with tests.isolated_vault_config(
2039)             monkeypatch=monkeypatch,
2040)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

2041)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Fail gracefully if UNIX dom...

Marco Ricci authored 3 months ago

2042)         ):
2043)             monkeypatch.setenv(
2044)                 'SSH_AUTH_SOCK', "the value doesn't even matter"
2045)             )
2046)             monkeypatch.delattr(socket, 'AF_UNIX', raising=False)
2047)             _result = runner.invoke(
2048)                 cli.derivepassphrase_vault,
2049)                 ['--key', '--config'],
2050)                 catch_exceptions=False,
2051)             )
2052)         result = tests.ReadableResult.parse(_result)
2053)         assert result.error_exit(
2054)             error='does not support UNIX domain sockets'
2055)         ), 'expected error exit and known error message'
2056) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

2057) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2058) class TestCLIUtils:
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2059)     @pytest.mark.parametrize(
2060)         'config',
2061)         [
2062)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2063)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2064)             {
2065)                 'global': {'phrase': 'abc'},
2066)                 'services': {'sv': {'phrase': 'my passphrase'}},
2067)             },
2068)             {
2069)                 'global': {'phrase': 'abc'},
2070)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2071)             },
2072)             {
2073)                 'global': {'phrase': 'abc'},
2074)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2075)             },
2076)         ],
2077)     )
2078)     def test_100_load_config(
2079)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2080)     ) -> None:
2081)         runner = click.testing.CliRunner()
2082)         with tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

2083)             monkeypatch=monkeypatch, runner=runner, vault_config=config
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2084)         ):
2085)             config_filename = cli._config_filename(subsystem='vault')
2086)             with open(config_filename, encoding='UTF-8') as fileobj:
2087)                 assert json.load(fileobj) == config
2088)             assert cli._load_config() == config
2089) 
2090)     def test_110_save_bad_config(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2091)         self, monkeypatch: pytest.MonkeyPatch
2092)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2093)         runner = click.testing.CliRunner()
Marco Ricci Refactor code to run under...

Marco Ricci authored 1 month ago

2094)         # Use parenthesized context manager expressions here once Python
2095)         # 3.9 becomes unsupported.
2096)         with contextlib.ExitStack() as stack:
2097)             stack.enter_context(
2098)                 tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

2099)                     monkeypatch=monkeypatch, runner=runner, vault_config={}
Marco Ricci Refactor code to run under...

Marco Ricci authored 1 month ago

2100)                 )
2101)             )
2102)             stack.enter_context(
2103)                 pytest.raises(ValueError, match='Invalid vault config')
2104)             )
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 4 months ago

2105)             cli._save_config(None)  # type: ignore[arg-type]
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2106) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2107)     def test_111_prompt_for_selection_multiple(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2108)         @click.command()
2109)         @click.option('--heading', default='Our menu:')
2110)         @click.argument('items', nargs=-1)
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

2111)         def driver(heading: str, items: list[str]) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2112)             # from https://montypython.fandom.com/wiki/Spam#The_menu
2113)             items = items or [
2114)                 'Egg and bacon',
2115)                 'Egg, sausage and bacon',
2116)                 'Egg and spam',
2117)                 'Egg, bacon and spam',
2118)                 'Egg, bacon, sausage and spam',
2119)                 'Spam, bacon, sausage and spam',
2120)                 'Spam, egg, spam, spam, bacon and spam',
2121)                 'Spam, spam, spam, egg and spam',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2122)                 (
2123)                     'Spam, spam, spam, spam, spam, spam, baked beans, '
2124)                     'spam, spam, spam and spam'
2125)                 ),
2126)                 (
2127)                     'Lobster thermidor aux crevettes with a mornay sauce '
2128)                     'garnished with truffle paté, brandy '
2129)                     'and a fried egg on top and spam'
2130)                 ),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2131)             ]
2132)             index = cli._prompt_for_selection(items, heading=heading)
2133)             click.echo('A fine choice: ', nl=False)
2134)             click.echo(items[index])
2135)             click.echo('(Note: Vikings strictly optional.)')
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2136) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2137)         runner = click.testing.CliRunner(mix_stderr=True)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2138)         _result = runner.invoke(driver, [], input='9')
2139)         result = tests.ReadableResult.parse(_result)
2140)         assert result.clean_exit(
2141)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2142) Our menu:
2143) [1] Egg and bacon
2144) [2] Egg, sausage and bacon
2145) [3] Egg and spam
2146) [4] Egg, bacon and spam
2147) [5] Egg, bacon, sausage and spam
2148) [6] Spam, bacon, sausage and spam
2149) [7] Spam, egg, spam, spam, bacon and spam
2150) [8] Spam, spam, spam, egg and spam
2151) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
2152) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
2153) Your selection? (1-10, leave empty to abort): 9
2154) A fine choice: Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
2155) (Note: Vikings strictly optional.)
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

2156) """
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2157)         ), 'expected clean exit'
2158)         _result = runner.invoke(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2159)             driver, ['--heading='], input='', catch_exceptions=True
2160)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2161)         result = tests.ReadableResult.parse(_result)
2162)         assert result.error_exit(
2163)             error=IndexError
2164)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2165)         assert (
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2166)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2167)             == """\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2168) [1] Egg and bacon
2169) [2] Egg, sausage and bacon
2170) [3] Egg and spam
2171) [4] Egg, bacon and spam
2172) [5] Egg, bacon, sausage and spam
2173) [6] Spam, bacon, sausage and spam
2174) [7] Spam, egg, spam, spam, bacon and spam
2175) [8] Spam, spam, spam, egg and spam
2176) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
2177) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2178) Your selection? (1-10, leave empty to abort):\x20
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

2179) """
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2180)         ), 'expected known output'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2181) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2182)     def test_112_prompt_for_selection_single(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2183)         @click.command()
2184)         @click.option('--item', default='baked beans')
2185)         @click.argument('prompt')
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

2186)         def driver(item: str, prompt: str) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2187)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2188)                 cli._prompt_for_selection(
2189)                     [item], heading='', single_choice_prompt=prompt
2190)                 )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

2191)             except IndexError:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2192)                 click.echo('Boo.')
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

2193)                 raise
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2194)             else:
2195)                 click.echo('Great!')
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2196) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2197)         runner = click.testing.CliRunner(mix_stderr=True)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2198)         _result = runner.invoke(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2199)             driver, ['Will replace with spam. Confirm, y/n?'], input='y'
2200)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2201)         result = tests.ReadableResult.parse(_result)
2202)         assert result.clean_exit(
2203)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2204) [1] baked beans
2205) Will replace with spam. Confirm, y/n? y
2206) Great!
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2207) """
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2208)         ), 'expected clean exit'
2209)         _result = runner.invoke(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2210)             driver,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

2211)             ['Will replace with spam, okay? (Please say "y" or "n".)'],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2212)             input='',
2213)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2214)         result = tests.ReadableResult.parse(_result)
2215)         assert result.error_exit(
2216)             error=IndexError
2217)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2218)         assert (
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2219)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2220)             == """\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2221) [1] baked beans
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

2222) Will replace with spam, okay? (Please say "y" or "n".):\x20
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2223) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2224) """
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2225)         ), 'expected known output'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2226) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2227)     def test_113_prompt_for_passphrase(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2228)         self, monkeypatch: pytest.MonkeyPatch
2229)     ) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2230)         monkeypatch.setattr(
2231)             click,
2232)             'prompt',
2233)             lambda *a, **kw: json.dumps({'args': a, 'kwargs': kw}),
2234)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2235)         res = json.loads(cli._prompt_for_passphrase())
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

2236)         err_msg = 'missing arguments to passphrase prompt'
2237)         assert 'args' in res, err_msg
2238)         assert 'kwargs' in res, err_msg
2239)         assert res['args'][:1] == ['Passphrase'], err_msg
2240)         assert res['kwargs'].get('default') == '', err_msg
2241)         assert not res['kwargs'].get('show_default', True), err_msg
2242)         assert res['kwargs'].get('err'), err_msg
2243)         assert res['kwargs'].get('hide_input'), err_msg
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2244) 
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2245)     def test_120_standard_logging_context_manager(
2246)         self,
2247)         caplog: pytest.LogCaptureFixture,
2248)         capsys: pytest.CaptureFixture[str],
2249)     ) -> None:
2250)         prog_name = cli.StandardCLILogging.prog_name
2251)         package_name = cli.StandardCLILogging.package_name
2252)         logger = logging.getLogger(package_name)
2253)         deprecation_logger = logging.getLogger(f'{package_name}.deprecation')
2254)         logging_cm = cli.StandardCLILogging.ensure_standard_logging()
2255)         with logging_cm:
2256)             assert (
2257)                 sum(
2258)                     1
2259)                     for h in logger.handlers
2260)                     if h is cli.StandardCLILogging.cli_handler
2261)                 )
2262)                 == 1
2263)             )
2264)             logger.warning('message 1')
2265)             with logging_cm:
2266)                 deprecation_logger.warning('message 2')
2267)                 assert (
2268)                     sum(
2269)                         1
2270)                         for h in logger.handlers
2271)                         if h is cli.StandardCLILogging.cli_handler
2272)                     )
2273)                     == 1
2274)                 )
2275)                 assert capsys.readouterr() == (
2276)                     '',
2277)                     (
2278)                         f'{prog_name}: Warning: message 1\n'
2279)                         f'{prog_name}: Deprecation warning: message 2\n'
2280)                     ),
2281)                 )
2282)             logger.warning('message 3')
2283)             assert (
2284)                 sum(
2285)                     1
2286)                     for h in logger.handlers
2287)                     if h is cli.StandardCLILogging.cli_handler
2288)                 )
2289)                 == 1
2290)             )
2291)             assert capsys.readouterr() == (
2292)                 '',
2293)                 f'{prog_name}: Warning: message 3\n',
2294)             )
2295)             assert caplog.record_tuples == [
2296)                 (package_name, logging.WARNING, 'message 1'),
2297)                 (f'{package_name}.deprecation', logging.WARNING, 'message 2'),
2298)                 (package_name, logging.WARNING, 'message 3'),
2299)             ]
2300) 
2301)     def test_121_standard_logging_warnings_context_manager(
2302)         self,
2303)         caplog: pytest.LogCaptureFixture,
2304)         capsys: pytest.CaptureFixture[str],
2305)     ) -> None:
2306)         warnings_cm = cli.StandardCLILogging.ensure_standard_warnings_logging()
2307)         THE_FUTURE = 'the future will be here sooner than you think'  # noqa: N806
2308)         JUST_TESTING = 'just testing whether warnings work'  # noqa: N806
2309)         with warnings_cm:
2310)             assert (
2311)                 sum(
2312)                     1
2313)                     for h in logging.getLogger('py.warnings').handlers
2314)                     if h is cli.StandardCLILogging.warnings_handler
2315)                 )
2316)                 == 1
2317)             )
2318)             warnings.warn(UserWarning(JUST_TESTING), stacklevel=1)
2319)             with warnings_cm:
2320)                 warnings.warn(FutureWarning(THE_FUTURE), stacklevel=1)
2321)                 _out, err = capsys.readouterr()
2322)                 err_lines = err.splitlines(True)
2323)                 assert any(
2324)                     f'UserWarning: {JUST_TESTING}' in line
2325)                     for line in err_lines
2326)                 )
2327)                 assert any(
2328)                     f'FutureWarning: {THE_FUTURE}' in line
2329)                     for line in err_lines
2330)                 )
2331)             warnings.warn(UserWarning(JUST_TESTING), stacklevel=1)
2332)             _out, err = capsys.readouterr()
2333)             err_lines = err.splitlines(True)
2334)             assert any(
2335)                 f'UserWarning: {JUST_TESTING}' in line for line in err_lines
2336)             )
2337)             assert not any(
2338)                 f'FutureWarning: {THE_FUTURE}' in line for line in err_lines
2339)             )
2340)             record_tuples = caplog.record_tuples
2341)             assert [tup[:2] for tup in record_tuples] == [
2342)                 ('py.warnings', logging.WARNING),
2343)                 ('py.warnings', logging.WARNING),
2344)                 ('py.warnings', logging.WARNING),
2345)             ]
2346)             assert f'UserWarning: {JUST_TESTING}' in record_tuples[0][2]
2347)             assert f'FutureWarning: {THE_FUTURE}' in record_tuples[1][2]
2348)             assert f'UserWarning: {JUST_TESTING}' in record_tuples[2][2]
2349) 
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

2350)     def _export_as_sh_helper(
2351)         self,
2352)         config: Any,
2353)     ) -> None:
2354)         prog_name_list = ('derivepassphrase', 'vault')
2355)         with io.StringIO() as outfile:
2356)             cli._print_config_as_sh_script(
2357)                 config, outfile=outfile, prog_name_list=prog_name_list
2358)             )
2359)             script = outfile.getvalue()
2360)         runner = click.testing.CliRunner(mix_stderr=False)
2361)         monkeypatch = pytest.MonkeyPatch()
2362)         with tests.isolated_vault_config(
2363)             runner=runner,
2364)             monkeypatch=monkeypatch,
2365)             vault_config={'services': {}},
2366)         ):
2367)             for _result in vault_config_exporter_shell_interpreter(script):
2368)                 result = tests.ReadableResult.parse(_result)
2369)                 assert result.clean_exit()
2370)             assert cli._load_config() == config
2371) 
2372)     @hypothesis.given(
2373)         global_config_settable=tests.vault_full_service_config(),
2374)         global_config_importable=strategies.fixed_dictionaries(
2375)             {},
2376)             optional={
2377)                 'key': strategies.text(
2378)                     alphabet=strategies.characters(
2379)                         min_codepoint=32,
2380)                         max_codepoint=126,
2381)                     ),
2382)                     max_size=128,
2383)                 ),
2384)                 'phrase': strategies.text(
2385)                     alphabet=strategies.characters(
2386)                         min_codepoint=32,
2387)                         max_codepoint=126,
2388)                     ),
2389)                     max_size=64,
2390)                 ),
2391)             },
2392)         ),
2393)     )
2394)     def test_130a_export_as_sh_global(
2395)         self,
2396)         global_config_settable: _types.VaultConfigServicesSettings,
2397)         global_config_importable: _types.VaultConfigServicesSettings,
2398)     ) -> None:
2399)         config: _types.VaultConfig = {
2400)             'global': global_config_settable | global_config_importable,
2401)             'services': {},
2402)         }
2403)         assert _types.clean_up_falsy_vault_config_values(config) is not None
2404)         assert _types.is_vault_config(config)
2405)         return self._export_as_sh_helper(config)
2406) 
2407)     @hypothesis.given(
2408)         global_config_importable=strategies.fixed_dictionaries(
2409)             {},
2410)             optional={
2411)                 'key': strategies.text(
2412)                     alphabet=strategies.characters(
2413)                         min_codepoint=32,
2414)                         max_codepoint=126,
2415)                     ),
2416)                     max_size=128,
2417)                 ),
2418)                 'phrase': strategies.text(
2419)                     alphabet=strategies.characters(
2420)                         min_codepoint=32,
2421)                         max_codepoint=126,
2422)                     ),
2423)                     max_size=64,
2424)                 ),
2425)             },
2426)         ),
2427)     )
2428)     def test_130b_export_as_sh_global_only_imports(
2429)         self,
2430)         global_config_importable: _types.VaultConfigServicesSettings,
2431)     ) -> None:
2432)         config: _types.VaultConfig = {
2433)             'global': global_config_importable,
2434)             'services': {},
2435)         }
2436)         assert _types.clean_up_falsy_vault_config_values(config) is not None
2437)         assert _types.is_vault_config(config)
2438)         if not config['global']:
2439)             config.pop('global')
2440)         return self._export_as_sh_helper(config)
2441) 
2442)     @hypothesis.given(
2443)         service_name=strategies.text(
2444)             alphabet=strategies.characters(
2445)                 min_codepoint=32,
2446)                 max_codepoint=126,
2447)             ),
2448)             min_size=4,
2449)             max_size=64,
2450)         ),
2451)         service_config_settable=tests.vault_full_service_config(),
2452)         service_config_importable=strategies.fixed_dictionaries(
2453)             {},
2454)             optional={
2455)                 'key': strategies.text(
2456)                     alphabet=strategies.characters(
2457)                         min_codepoint=32,
2458)                         max_codepoint=126,
2459)                     ),
2460)                     max_size=128,
2461)                 ),
2462)                 'phrase': strategies.text(
2463)                     alphabet=strategies.characters(
2464)                         min_codepoint=32,
2465)                         max_codepoint=126,
2466)                     ),
2467)                     max_size=64,
2468)                 ),
2469)                 'notes': strategies.text(
2470)                     alphabet=strategies.characters(
2471)                         min_codepoint=32,
2472)                         max_codepoint=126,
2473)                         include_characters=('\n', '\f', '\t'),
2474)                     ),
2475)                     max_size=256,
2476)                 ),
2477)             },
2478)         ),
2479)     )
2480)     def test_130c_export_as_sh_service(
2481)         self,
2482)         service_name: str,
2483)         service_config_settable: _types.VaultConfigServicesSettings,
2484)         service_config_importable: _types.VaultConfigServicesSettings,
2485)     ) -> None:
2486)         config: _types.VaultConfig = {
2487)             'services': {
2488)                 service_name: (
2489)                     service_config_settable | service_config_importable
2490)                 ),
2491)             },
2492)         }
2493)         assert _types.clean_up_falsy_vault_config_values(config) is not None
2494)         assert _types.is_vault_config(config)
2495)         return self._export_as_sh_helper(config)
2496) 
2497)     @hypothesis.given(
2498)         service_name=strategies.text(
2499)             alphabet=strategies.characters(
2500)                 min_codepoint=32,
2501)                 max_codepoint=126,
2502)             ),
2503)             min_size=4,
2504)             max_size=64,
2505)         ),
2506)         service_config_importable=strategies.fixed_dictionaries(
2507)             {},
2508)             optional={
2509)                 'key': strategies.text(
2510)                     alphabet=strategies.characters(
2511)                         min_codepoint=32,
2512)                         max_codepoint=126,
2513)                     ),
2514)                     max_size=128,
2515)                 ),
2516)                 'phrase': strategies.text(
2517)                     alphabet=strategies.characters(
2518)                         min_codepoint=32,
2519)                         max_codepoint=126,
2520)                     ),
2521)                     max_size=64,
2522)                 ),
2523)                 'notes': strategies.text(
2524)                     alphabet=strategies.characters(
2525)                         min_codepoint=32,
2526)                         max_codepoint=126,
2527)                         include_characters=('\n', '\f', '\t'),
2528)                     ),
2529)                     max_size=256,
2530)                 ),
2531)             },
2532)         ),
2533)     )
2534)     def test_130d_export_as_sh_service_only_imports(
2535)         self,
2536)         service_name: str,
2537)         service_config_importable: _types.VaultConfigServicesSettings,
2538)     ) -> None:
2539)         config: _types.VaultConfig = {
2540)             'services': {
2541)                 service_name: service_config_importable,
2542)             },
2543)         }
2544)         assert _types.clean_up_falsy_vault_config_values(config) is not None
2545)         assert _types.is_vault_config(config)
2546)         return self._export_as_sh_helper(config)
2547) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2548)     @pytest.mark.parametrize(
2549)         ['command_line', 'config', 'result_config'],
2550)         [
2551)             (
2552)                 ['--delete-globals'],
2553)                 {'global': {'phrase': 'abc'}, 'services': {}},
2554)                 {'services': {}},
2555)             ),
2556)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

2557)                 ['--delete', '--', DUMMY_SERVICE],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2558)                 {
2559)                     'global': {'phrase': 'abc'},
2560)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
2561)                 },
2562)                 {'global': {'phrase': 'abc'}, 'services': {}},
2563)             ),
2564)             (
2565)                 ['--clear'],
2566)                 {
2567)                     'global': {'phrase': 'abc'},
2568)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
2569)                 },
2570)                 {'services': {}},
2571)             ),
2572)         ],
2573)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2574)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2575)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2576)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2577)         command_line: list[str],
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

2578)         config: _types.VaultConfig,
2579)         result_config: _types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2580)     ) -> None:
2581)         runner = click.testing.CliRunner(mix_stderr=False)
2582)         for start_config in [config, result_config]:
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

2583)             with tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

2584)                 monkeypatch=monkeypatch,
2585)                 runner=runner,
2586)                 vault_config=start_config,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2587)             ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2588)                 _result = runner.invoke(
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2589)                     cli.derivepassphrase_vault,
2590)                     command_line,
2591)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2592)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2593)                 result = tests.ReadableResult.parse(_result)
2594)                 assert result.clean_exit(
2595)                     empty_stderr=True
2596)                 ), 'expected clean exit'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2597)                 with open(
2598)                     cli._config_filename(subsystem='vault'), encoding='UTF-8'
2599)                 ) as infile:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2600)                     config_readback = json.load(infile)
2601)                 assert config_readback == result_config
2602) 
2603)     def test_204_phrase_from_key_manually(self) -> None:
2604)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

2605)             vault.Vault(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2606)                 phrase=DUMMY_PHRASE_FROM_KEY1, **DUMMY_CONFIG_SETTINGS
2607)             ).generate(DUMMY_SERVICE)
2608)             == DUMMY_RESULT_KEY1
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2609)         )
2610) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2611)     @pytest.mark.parametrize(
2612)         ['vfunc', 'input'],
2613)         [
2614)             (cli._validate_occurrence_constraint, 20),
2615)             (cli._validate_length, 20),
2616)         ],
2617)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2618)     def test_210a_validate_constraints_manually(
2619)         self,
2620)         vfunc: Callable[[click.Context, click.Parameter, Any], int | None],
2621)         input: int,
2622)     ) -> None:
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2623)         ctx = cli.derivepassphrase_vault.make_context(cli.PROG_NAME, [])
2624)         param = cli.derivepassphrase_vault.params[0]
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2625)         assert vfunc(ctx, param, input) == input
2626) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

2627)     @pytest.mark.parametrize('conn_hint', ['none', 'socket', 'client'])
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 6 months ago

2628)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2629)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2630)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

2631)         running_ssh_agent: tests.RunningSSHAgentInfo,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2632)         conn_hint: str,
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 6 months ago

2633)     ) -> None:
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

2634)         with monkeypatch.context():
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

2635)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent.socket)
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

2636)             monkeypatch.setattr(
2637)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
2638)             )
2639)             hint: ssh_agent.SSHAgentClient | socket.socket | None
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

2640)             # Use match/case here once Python 3.9 becomes unsupported.
2641)             if conn_hint == 'client':
2642)                 hint = ssh_agent.SSHAgentClient()
2643)             elif conn_hint == 'socket':
2644)                 hint = socket.socket(family=socket.AF_UNIX)
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

2645)                 hint.connect(running_ssh_agent.socket)
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

2646)             else:
2647)                 assert conn_hint == 'none'
2648)                 hint = None
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

2649)             exception: Exception | None = None
2650)             try:
2651)                 list(cli._get_suitable_ssh_keys(hint))
2652)             except RuntimeError:  # pragma: no cover
2653)                 pass
2654)             except Exception as e:  # noqa: BLE001 # pragma: no cover
2655)                 exception = e
2656)             finally:
2657)                 assert (
2658)                     exception is None
2659)                 ), 'exception querying suitable SSH keys'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2660) 
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2661)     def test_400_key_to_phrase(
2662)         self,
2663)         monkeypatch: pytest.MonkeyPatch,
2664)         skip_if_no_af_unix_support: None,
2665)         ssh_agent_client_with_test_keys_loaded: ssh_agent.SSHAgentClient,
2666)     ) -> None:
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2667)         class ErrCallback(BaseException):
2668)             def __init__(self, *args: Any, **kwargs: Any) -> None:
2669)                 super().__init__(*args[:1])
2670)                 self.args = args
2671)                 self.kwargs = kwargs
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2672) 
2673)         def err(*args: Any, **_kwargs: Any) -> NoReturn:
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2674)             raise ErrCallback(*args, **_kwargs)
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2675) 
2676)         def fail(*_args: Any, **_kwargs: Any) -> Any:
2677)             raise ssh_agent.SSHAgentFailedError(
2678)                 _types.SSH_AGENT.FAILURE.value,
2679)                 b'',
2680)             )
2681) 
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2682)         def fail_runtime(*_args: Any, **_kwargs: Any) -> Any:
2683)             raise ssh_agent.TrailingDataError()
2684) 
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2685)         del skip_if_no_af_unix_support
2686)         monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', fail)
2687)         loaded_keys = list(ssh_agent_client_with_test_keys_loaded.list_keys())
2688)         loaded_key = base64.standard_b64encode(loaded_keys[0][0])
2689)         with monkeypatch.context() as mp:
2690)             mp.setattr(
2691)                 ssh_agent.SSHAgentClient,
2692)                 'list_keys',
2693)                 lambda *_a, **_kw: [],
2694)             )
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2695)             with pytest.raises(ErrCallback, match='not loaded into the agent'):
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2696)                 cli._key_to_phrase(loaded_key, error_callback=err)
2697)         with monkeypatch.context() as mp:
2698)             mp.setattr(ssh_agent.SSHAgentClient, 'list_keys', fail)
2699)             with pytest.raises(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2700)                 ErrCallback, match='SSH agent failed to or refused to'
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2701)             ):
2702)                 cli._key_to_phrase(loaded_key, error_callback=err)
2703)         with monkeypatch.context() as mp:
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2704)             mp.setattr(ssh_agent.SSHAgentClient, 'list_keys', fail_runtime)
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2705)             with pytest.raises(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2706)                 ErrCallback, match='SSH agent failed to or refused to'
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2707)             ) as excinfo:
2708)                 cli._key_to_phrase(loaded_key, error_callback=err)
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2709)             assert excinfo.value.kwargs
2710)             assert isinstance(
2711)                 excinfo.value.kwargs['exc_info'],
2712)                 ssh_agent.SSHAgentFailedError,
2713)             )
2714)             assert excinfo.value.kwargs['exc_info'].__context__ is not None
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2715)             assert isinstance(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2716)                 excinfo.value.kwargs['exc_info'].__context__,
2717)                 ssh_agent.TrailingDataError,
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2718)             )
2719)         with monkeypatch.context() as mp:
2720)             mp.delenv('SSH_AUTH_SOCK', raising=True)
2721)             with pytest.raises(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2722)                 ErrCallback, match='Cannot find any running SSH agent'
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2723)             ):
2724)                 cli._key_to_phrase(loaded_key, error_callback=err)
2725)         with monkeypatch.context() as mp:
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

2726)             mp.setenv('SSH_AUTH_SOCK', os.environ['SSH_AUTH_SOCK'] + '~')
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2727)             with pytest.raises(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2728)                 ErrCallback, match='Cannot connect to the SSH agent'
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2729)             ):
2730)                 cli._key_to_phrase(loaded_key, error_callback=err)
2731)         with monkeypatch.context() as mp:
2732)             mp.delattr(socket, 'AF_UNIX', raising=True)
2733)             with pytest.raises(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2734)                 ErrCallback, match='does not support UNIX domain sockets'
2735)             ):
2736)                 cli._key_to_phrase(loaded_key, error_callback=err)
2737)         with monkeypatch.context() as mp:
2738)             mp.setattr(ssh_agent.SSHAgentClient, 'sign', fail_runtime)
2739)             with pytest.raises(
2740)                 ErrCallback, match='violates the communications protocol'
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2741)             ):
2742)                 cli._key_to_phrase(loaded_key, error_callback=err)
2743) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2744) 
2745) class TestCLITransition:
2746)     def test_100_help_output(self, monkeypatch: pytest.MonkeyPatch) -> None:
2747)         runner = click.testing.CliRunner(mix_stderr=False)
2748)         with tests.isolated_config(
2749)             monkeypatch=monkeypatch,
2750)             runner=runner,
2751)         ):
2752)             _result = runner.invoke(
2753)                 cli.derivepassphrase, ['--help'], catch_exceptions=False
2754)             )
2755)             result = tests.ReadableResult.parse(_result)
2756)         assert result.clean_exit(
2757)             empty_stderr=True, output='currently implemented subcommands'
2758)         ), 'expected clean exit, and known help text'
2759) 
2760)     def test_101_help_output_export(
2761)         self, monkeypatch: pytest.MonkeyPatch
2762)     ) -> None:
2763)         runner = click.testing.CliRunner(mix_stderr=False)
2764)         with tests.isolated_config(
2765)             monkeypatch=monkeypatch,
2766)             runner=runner,
2767)         ):
2768)             _result = runner.invoke(
2769)                 cli.derivepassphrase,
2770)                 ['export', '--help'],
2771)                 catch_exceptions=False,
2772)             )
2773)             result = tests.ReadableResult.parse(_result)
2774)         assert result.clean_exit(
2775)             empty_stderr=True, output='only available subcommand'
2776)         ), 'expected clean exit, and known help text'
2777) 
2778)     def test_102_help_output_export_vault(
2779)         self, monkeypatch: pytest.MonkeyPatch
2780)     ) -> None:
2781)         runner = click.testing.CliRunner(mix_stderr=False)
2782)         with tests.isolated_config(
2783)             monkeypatch=monkeypatch,
2784)             runner=runner,
2785)         ):
2786)             _result = runner.invoke(
2787)                 cli.derivepassphrase,
2788)                 ['export', 'vault', '--help'],
2789)                 catch_exceptions=False,
2790)             )
2791)             result = tests.ReadableResult.parse(_result)
2792)         assert result.clean_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2793)             empty_stderr=True, output='Export a vault-native configuration'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2794)         ), 'expected clean exit, and known help text'
2795) 
2796)     def test_103_help_output_vault(
2797)         self, monkeypatch: pytest.MonkeyPatch
2798)     ) -> None:
2799)         runner = click.testing.CliRunner(mix_stderr=False)
2800)         with tests.isolated_config(
2801)             monkeypatch=monkeypatch,
2802)             runner=runner,
2803)         ):
2804)             _result = runner.invoke(
2805)                 cli.derivepassphrase,
2806)                 ['vault', '--help'],
2807)                 catch_exceptions=False,
2808)             )
2809)             result = tests.ReadableResult.parse(_result)
2810)         assert result.clean_exit(
Marco Ricci Add an actual derivepassphr...

Marco Ricci authored 2 weeks ago

2811)             empty_stderr=True, output='Passphrase generation:\n'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2812)         ), 'expected clean exit, and option groups in help text'
2813)         assert result.clean_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2814)             empty_stderr=True, output='Use $VISUAL or $EDITOR to configure'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2815)         ), 'expected clean exit, and option group epilog in help text'
2816) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2817)     @pytest.mark.parametrize(
2818)         'config',
2819)         [
2820)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2821)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2822)             {
2823)                 'global': {'phrase': 'abc'},
2824)                 'services': {'sv': {'phrase': 'my passphrase'}},
2825)             },
2826)             {
2827)                 'global': {'phrase': 'abc'},
2828)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2829)             },
2830)             {
2831)                 'global': {'phrase': 'abc'},
2832)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2833)             },
2834)         ],
2835)     )
2836)     def test_110_load_config_backup(
2837)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2838)     ) -> None:
2839)         runner = click.testing.CliRunner()
2840)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2841)             config_filename = cli._config_filename(
2842)                 subsystem='old settings.json'
2843)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2844)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2845)                 print(json.dumps(config, indent=2), file=fileobj)
2846)             assert cli._migrate_and_load_old_config()[0] == config
2847) 
2848)     @pytest.mark.parametrize(
2849)         'config',
2850)         [
2851)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2852)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2853)             {
2854)                 'global': {'phrase': 'abc'},
2855)                 'services': {'sv': {'phrase': 'my passphrase'}},
2856)             },
2857)             {
2858)                 'global': {'phrase': 'abc'},
2859)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2860)             },
2861)             {
2862)                 'global': {'phrase': 'abc'},
2863)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2864)             },
2865)         ],
2866)     )
2867)     def test_111_migrate_config(
2868)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2869)     ) -> None:
2870)         runner = click.testing.CliRunner()
2871)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2872)             config_filename = cli._config_filename(
2873)                 subsystem='old settings.json'
2874)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2875)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2876)                 print(json.dumps(config, indent=2), file=fileobj)
2877)             assert cli._migrate_and_load_old_config() == (config, None)
2878) 
2879)     @pytest.mark.parametrize(
2880)         'config',
2881)         [
2882)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2883)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2884)             {
2885)                 'global': {'phrase': 'abc'},
2886)                 'services': {'sv': {'phrase': 'my passphrase'}},
2887)             },
2888)             {
2889)                 'global': {'phrase': 'abc'},
2890)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2891)             },
2892)             {
2893)                 'global': {'phrase': 'abc'},
2894)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2895)             },
2896)         ],
2897)     )
2898)     def test_112_migrate_config_error(
2899)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2900)     ) -> None:
2901)         runner = click.testing.CliRunner()
2902)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2903)             config_filename = cli._config_filename(
2904)                 subsystem='old settings.json'
2905)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2906)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2907)                 print(json.dumps(config, indent=2), file=fileobj)
2908)             os.mkdir(cli._config_filename(subsystem='vault'))
2909)             config2, err = cli._migrate_and_load_old_config()
2910)             assert config2 == config
2911)             assert isinstance(err, OSError)
2912)             assert err.errno == errno.EISDIR
2913) 
2914)     @pytest.mark.parametrize(
2915)         'config',
2916)         [
2917)             {'global': '', 'services': {}},
2918)             {'global': 0, 'services': {}},
2919)             {
2920)                 'global': {'phrase': 'abc'},
2921)                 'services': False,
2922)             },
2923)             {
2924)                 'global': {'phrase': 'abc'},
2925)                 'services': True,
2926)             },
2927)             {
2928)                 'global': {'phrase': 'abc'},
2929)                 'services': None,
2930)             },
2931)         ],
2932)     )
2933)     def test_113_migrate_config_error_bad_config_value(
2934)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2935)     ) -> None:
2936)         runner = click.testing.CliRunner()
2937)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2938)             config_filename = cli._config_filename(
2939)                 subsystem='old settings.json'
2940)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2941)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2942)                 print(json.dumps(config, indent=2), file=fileobj)
2943)             with pytest.raises(ValueError, match=cli._INVALID_VAULT_CONFIG):
2944)                 cli._migrate_and_load_old_config()
2945) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2946)     def test_200_forward_export_vault_path_parameter(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2947)         self,
2948)         monkeypatch: pytest.MonkeyPatch,
2949)         caplog: pytest.LogCaptureFixture,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2950)     ) -> None:
2951)         pytest.importorskip('cryptography', minversion='38.0')
2952)         runner = click.testing.CliRunner(mix_stderr=False)
2953)         with tests.isolated_vault_exporter_config(
2954)             monkeypatch=monkeypatch,
2955)             runner=runner,
2956)             vault_config=tests.VAULT_V03_CONFIG,
2957)             vault_key=tests.VAULT_MASTER_KEY,
2958)         ):
2959)             monkeypatch.setenv('VAULT_KEY', tests.VAULT_MASTER_KEY)
2960)             _result = runner.invoke(
2961)                 cli.derivepassphrase,
2962)                 ['export', 'VAULT_PATH'],
2963)             )
2964)         result = tests.ReadableResult.parse(_result)
2965)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2966)         assert tests.deprecation_warning_emitted(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2967)             'A subcommand will be required here in v1.0', caplog.record_tuples
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2968)         )
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2969)         assert tests.deprecation_warning_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2970)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

2971)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2972)         assert json.loads(result.output) == tests.VAULT_V03_CONFIG_DATA
2973) 
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2974)     def test_201_forward_export_vault_empty_commandline(
2975)         self,
2976)         monkeypatch: pytest.MonkeyPatch,
2977)         caplog: pytest.LogCaptureFixture,
2978)     ) -> None:
2979)         pytest.importorskip('cryptography', minversion='38.0')
2980)         runner = click.testing.CliRunner(mix_stderr=False)
2981)         with tests.isolated_config(
2982)             monkeypatch=monkeypatch,
2983)             runner=runner,
2984)         ):
2985)             _result = runner.invoke(
2986)                 cli.derivepassphrase,
2987)                 ['export'],
2988)             )
2989)         result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2990)         assert tests.deprecation_warning_emitted(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2991)             'A subcommand will be required here in v1.0', caplog.record_tuples
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2992)         )
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2993)         assert tests.deprecation_warning_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2994)             'Defaulting to subcommand "vault"', caplog.record_tuples
2995)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2996)         assert result.error_exit(
2997)             error="Missing argument 'PATH'"
2998)         ), 'expected error exit and known error type'
2999) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

3000)     @pytest.mark.parametrize(
3001)         'charset_name', ['lower', 'upper', 'number', 'space', 'dash', 'symbol']
3002)     )
3003)     def test_210_forward_vault_disable_character_set(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3004)         self,
3005)         monkeypatch: pytest.MonkeyPatch,
3006)         caplog: pytest.LogCaptureFixture,
3007)         charset_name: str,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

3008)     ) -> None:
3009)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
3010)         option = f'--{charset_name}'
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

3011)         charset = vault.Vault._CHARSETS[charset_name].decode('ascii')
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

3012)         runner = click.testing.CliRunner(mix_stderr=False)
3013)         with tests.isolated_config(
3014)             monkeypatch=monkeypatch,
3015)             runner=runner,
3016)         ):
3017)             _result = runner.invoke(
3018)                 cli.derivepassphrase,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

3019)                 [option, '0', '-p', '--', DUMMY_SERVICE],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

3020)                 input=DUMMY_PASSPHRASE,
3021)                 catch_exceptions=False,
3022)             )
3023)             result = tests.ReadableResult.parse(_result)
3024)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3025)         assert tests.deprecation_warning_emitted(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

3026)             'A subcommand will be required here in v1.0', caplog.record_tuples
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3027)         )
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

3028)         assert tests.deprecation_warning_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3029)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

3030)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

3031)         for c in charset:
3032)             assert (
3033)                 c not in result.output
3034)             ), f'derived password contains forbidden character {c!r}'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3035) 
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

3036)     def test_211_forward_vault_empty_command_line(
3037)         self,
3038)         monkeypatch: pytest.MonkeyPatch,
3039)         caplog: pytest.LogCaptureFixture,
3040)     ) -> None:
3041)         runner = click.testing.CliRunner(mix_stderr=False)
3042)         with tests.isolated_config(
3043)             monkeypatch=monkeypatch,
3044)             runner=runner,
3045)         ):
3046)             _result = runner.invoke(
3047)                 cli.derivepassphrase,
3048)                 [],
3049)                 input=DUMMY_PASSPHRASE,
3050)                 catch_exceptions=False,
3051)             )
3052)             result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3053)         assert tests.deprecation_warning_emitted(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

3054)             'A subcommand will be required here in v1.0', caplog.record_tuples
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3055)         )
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

3056)         assert tests.deprecation_warning_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3057)             'Defaulting to subcommand "vault"', caplog.record_tuples
3058)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

3059)         assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

3060)             error='Deriving a passphrase requires a SERVICE.'
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

3061)         ), 'expected error exit and known error type'
3062) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3063)     def test_300_export_using_old_config_file(
3064)         self,
3065)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3066)         caplog: pytest.LogCaptureFixture,
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3067)     ) -> None:
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3068)         caplog.set_level(logging.INFO)
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3069)         runner = click.testing.CliRunner(mix_stderr=False)
3070)         with tests.isolated_config(
3071)             monkeypatch=monkeypatch,
3072)             runner=runner,
3073)         ):
3074)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

3075)                 cli._config_filename(subsystem='old settings.json'),
3076)                 'w',
3077)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3078)             ) as fileobj:
3079)                 print(
3080)                     json.dumps(
3081)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
3082)                         indent=2,
3083)                     ),
3084)                     file=fileobj,
3085)                 )
3086)             _result = runner.invoke(
3087)                 cli.derivepassphrase_vault,
3088)                 ['--export', '-'],
3089)                 catch_exceptions=False,
3090)             )
3091)         result = tests.ReadableResult.parse(_result)
3092)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3093)         assert tests.deprecation_warning_emitted(
3094)             'v0.1-style config file', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3095)         ), 'expected known warning message in stderr'
Marco Ricci Fix usage of `--debug`, `--...

Marco Ricci authored 3 weeks ago

3096)         assert tests.deprecation_info_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3097)             'Successfully migrated to ', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3098)         ), 'expected known warning message in stderr'
3099) 
3100)     def test_300a_export_using_old_config_file_migration_error(
3101)         self,
3102)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3103)         caplog: pytest.LogCaptureFixture,
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3104)     ) -> None:
3105)         runner = click.testing.CliRunner(mix_stderr=False)
3106)         with tests.isolated_config(
3107)             monkeypatch=monkeypatch,
3108)             runner=runner,
3109)         ):
3110)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

3111)                 cli._config_filename(subsystem='old settings.json'),
3112)                 'w',
3113)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3114)             ) as fileobj:
3115)                 print(
3116)                     json.dumps(
3117)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
3118)                         indent=2,
3119)                     ),
3120)                     file=fileobj,
3121)                 )
3122) 
3123)             def raiser(*_args: Any, **_kwargs: Any) -> None:
3124)                 raise OSError(
3125)                     errno.EACCES,
3126)                     os.strerror(errno.EACCES),
3127)                     cli._config_filename(subsystem='vault'),
3128)                 )
3129) 
3130)             monkeypatch.setattr(os, 'replace', raiser)
3131)             _result = runner.invoke(
3132)                 cli.derivepassphrase_vault,
3133)                 ['--export', '-'],
3134)                 catch_exceptions=False,
3135)             )
3136)         result = tests.ReadableResult.parse(_result)
3137)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3138)         assert tests.deprecation_warning_emitted(
3139)             'v0.1-style config file', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3140)         ), 'expected known warning message in stderr'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3141)         assert tests.warning_emitted(
3142)             'Failed to migrate to ', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3143)         ), 'expected known warning message in stderr'
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3144) 
3145) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3146) _known_services = (DUMMY_SERVICE, 'email', 'bank', 'work')
3147) _valid_properties = (
3148)     'length',
3149)     'repeat',
3150)     'upper',
3151)     'lower',
3152)     'number',
3153)     'space',
3154)     'dash',
3155)     'symbol',
3156) )
3157) 
3158) 
3159) def _build_reduced_vault_config_settings(
3160)     config: _types.VaultConfigServicesSettings,
3161)     keys_to_purge: frozenset[str],
3162) ) -> _types.VaultConfigServicesSettings:
3163)     config2 = copy.deepcopy(config)
3164)     for key in keys_to_purge:
3165)         config2.pop(key, None)  # type: ignore[misc]
3166)     return config2
3167) 
3168) 
3169) _services_strategy = strategies.builds(
3170)     _build_reduced_vault_config_settings,
3171)     tests.vault_full_service_config(),
3172)     strategies.sets(
3173)         strategies.sampled_from(_valid_properties),
3174)         max_size=7,
3175)     ),
3176) )
3177) 
3178) 
3179) def _assemble_config(
3180)     global_data: _types.VaultConfigGlobalSettings,
3181)     service_data: list[tuple[str, _types.VaultConfigServicesSettings]],
3182) ) -> _types.VaultConfig:
3183)     services_dict = dict(service_data)
3184)     return (
3185)         {'global': global_data, 'services': services_dict}
3186)         if global_data
3187)         else {'services': services_dict}
3188)     )
3189) 
3190) 
3191) @strategies.composite
3192) def _draw_service_name_and_data(
3193)     draw: hypothesis.strategies.DrawFn,
3194)     num_entries: int,
3195) ) -> tuple[tuple[str, _types.VaultConfigServicesSettings], ...]:
3196)     possible_services = list(_known_services)
3197)     selected_services: list[str] = []
3198)     for _ in range(num_entries):
3199)         selected_services.append(
3200)             draw(strategies.sampled_from(possible_services))
3201)         )
3202)         possible_services.remove(selected_services[-1])
3203)     return tuple(
3204)         (service, draw(_services_strategy)) for service in selected_services
3205)     )
3206) 
3207) 
3208) _vault_full_config = strategies.builds(
3209)     _assemble_config,
3210)     _services_strategy,
3211)     strategies.integers(
3212)         min_value=2,
3213)         max_value=4,
3214)     ).flatmap(_draw_service_name_and_data),
3215) )
3216) 
3217) 
Marco Ricci Actually correctly implemen...

Marco Ricci authored 4 weeks ago

3218) @tests.hypothesis_settings_coverage_compatible
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3219) class ConfigManagementStateMachine(stateful.RuleBasedStateMachine):
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3220)     def __init__(self) -> None:
3221)         super().__init__()
3222)         self.runner = click.testing.CliRunner(mix_stderr=False)
3223)         self.exit_stack = contextlib.ExitStack().__enter__()
3224)         self.monkeypatch = self.exit_stack.enter_context(
3225)             pytest.MonkeyPatch().context()
3226)         )
3227)         self.isolated_config = self.exit_stack.enter_context(
3228)             tests.isolated_vault_config(
3229)                 monkeypatch=self.monkeypatch,
3230)                 runner=self.runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

3231)                 vault_config={'services': {}},
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3232)             )
3233)         )
3234) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3235)     setting = stateful.Bundle('setting')
3236)     configuration = stateful.Bundle('configuration')
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3237) 
3238)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3239)         target=configuration,
3240)         configs=strategies.lists(
3241)             _vault_full_config,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3242)             min_size=8,
3243)             max_size=8,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3244)         ),
3245)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3246)     def declare_initial_configs(
3247)         self,
3248)         configs: Iterable[_types.VaultConfig],
3249)     ) -> Iterable[_types.VaultConfig]:
3250)         return stateful.multiple(*configs)
Marco Ricci Test config merging with pa...

Marco Ricci authored 4 weeks ago

3251) 
3252)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3253)         target=setting,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3254)         configs=strategies.lists(
3255)             _vault_full_config,
3256)             min_size=4,
3257)             max_size=4,
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

3258)         ),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3259)     )
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3260)     def extract_initial_settings(
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3261)         self,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3262)         configs: list[_types.VaultConfig],
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3263)     ) -> Iterable[_types.VaultConfigServicesSettings]:
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3264)         settings: list[_types.VaultConfigServicesSettings] = []
3265)         for c in configs:
3266)             settings.extend(c['services'].values())
3267)         return stateful.multiple(*map(copy.deepcopy, settings))
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3268) 
3269)     @staticmethod
3270)     def fold_configs(
3271)         c1: _types.VaultConfig, c2: _types.VaultConfig
3272)     ) -> _types.VaultConfig:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3273)         """Fold `c1` into `c2`, overriding the latter."""
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3274)         new_global_dict = c1.get('global', c2.get('global'))
3275)         if new_global_dict is not None:
3276)             return {
3277)                 'global': new_global_dict,
3278)                 'services': {**c2['services'], **c1['services']},
3279)             }
3280)         return {
3281)             'services': {**c2['services'], **c1['services']},
3282)         }
3283) 
3284)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3285)         target=configuration,
3286)         config=configuration,
3287)         setting=setting.filter(bool),
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3288)         maybe_unset=strategies.sets(
3289)             strategies.sampled_from(_valid_properties),
3290)             max_size=3,
3291)         ),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3292)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3293)     )
3294)     def set_globals(
3295)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3296)         config: _types.VaultConfig,
3297)         setting: _types.VaultConfigGlobalSettings,
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3298)         maybe_unset: set[str],
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3299)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3300)     ) -> _types.VaultConfig:
3301)         cli._save_config(config)
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3302)         config_global = config.get('global', {})
3303)         maybe_unset = set(maybe_unset) - setting.keys()
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3304)         if overwrite:
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3305)             config['global'] = config_global = {}
3306)         elif maybe_unset:
3307)             for key in maybe_unset:
3308)                 config_global.pop(key, None)  # type: ignore[misc]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3309)         config.setdefault('global', {}).update(setting)
3310)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3311)         # NOTE: This relies on settings_obj containing only the keys
3312)         # "length", "repeat", "upper", "lower", "number", "space",
3313)         # "dash" and "symbol".
3314)         _result = self.runner.invoke(
3315)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3316)             [
3317)                 '--config',
3318)                 '--overwrite-existing' if overwrite else '--merge-existing',
3319)             ]
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3320)             + [f'--unset={key}' for key in maybe_unset]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3321)             + [
3322)                 f'--{key}={value}'
3323)                 for key, value in setting.items()
3324)                 if key in _valid_properties
3325)             ],
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3326)             catch_exceptions=False,
3327)         )
3328)         result = tests.ReadableResult.parse(_result)
3329)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3330)         assert cli._load_config() == config
3331)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3332) 
3333)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3334)         target=configuration,
3335)         config=configuration,
3336)         service=strategies.sampled_from(_known_services),
3337)         setting=setting.filter(bool),
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3338)         maybe_unset=strategies.sets(
3339)             strategies.sampled_from(_valid_properties),
3340)             max_size=3,
3341)         ),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3342)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3343)     )
3344)     def set_service(
3345)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3346)         config: _types.VaultConfig,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3347)         service: str,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3348)         setting: _types.VaultConfigServicesSettings,
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3349)         maybe_unset: set[str],
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3350)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3351)     ) -> _types.VaultConfig:
3352)         cli._save_config(config)
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3353)         config_service = config['services'].get(service, {})
3354)         maybe_unset = set(maybe_unset) - setting.keys()
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3355)         if overwrite:
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3356)             config['services'][service] = config_service = {}
3357)         elif maybe_unset:
3358)             for key in maybe_unset:
3359)                 config_service.pop(key, None)  # type: ignore[misc]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3360)         config['services'].setdefault(service, {}).update(setting)
3361)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3362)         # NOTE: This relies on settings_obj containing only the keys
3363)         # "length", "repeat", "upper", "lower", "number", "space",
3364)         # "dash" and "symbol".
3365)         _result = self.runner.invoke(
3366)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3367)             [
3368)                 '--config',
3369)                 '--overwrite-existing' if overwrite else '--merge-existing',
3370)             ]
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3371)             + [f'--unset={key}' for key in maybe_unset]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3372)             + [
3373)                 f'--{key}={value}'
3374)                 for key, value in setting.items()
3375)                 if key in _valid_properties
3376)             ]
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3377)             + ['--', service],
3378)             catch_exceptions=False,
3379)         )
3380)         result = tests.ReadableResult.parse(_result)
3381)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3382)         assert cli._load_config() == config
3383)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3384) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3385)     @stateful.rule(
3386)         target=configuration,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3387)         config=configuration,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3388)     )
3389)     def purge_global(
3390)         self,
3391)         config: _types.VaultConfig,
3392)     ) -> _types.VaultConfig:
3393)         cli._save_config(config)
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3394)         config.pop('global', None)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3395)         _result = self.runner.invoke(
3396)             cli.derivepassphrase_vault,
3397)             ['--delete-globals'],
3398)             input='y',
3399)             catch_exceptions=False,
3400)         )
3401)         result = tests.ReadableResult.parse(_result)
3402)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3403)         assert cli._load_config() == config
3404)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3405) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3406)     @stateful.rule(
3407)         target=configuration,
3408)         config_and_service=configuration.filter(
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3409)             lambda c: bool(c['services'])
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3410)         ).flatmap(
3411)             lambda c: strategies.tuples(
3412)                 strategies.just(c),
3413)                 strategies.sampled_from(tuple(c['services'].keys())),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3414)             )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3415)         ),
3416)     )
3417)     def purge_service(
3418)         self,
3419)         config_and_service: tuple[_types.VaultConfig, str],
3420)     ) -> _types.VaultConfig:
3421)         config, service = config_and_service
3422)         cli._save_config(config)
3423)         config['services'].pop(service, None)
3424)         _result = self.runner.invoke(
3425)             cli.derivepassphrase_vault,
3426)             ['--delete', '--', service],
3427)             input='y',
3428)             catch_exceptions=False,
3429)         )
3430)         result = tests.ReadableResult.parse(_result)
3431)         assert result.clean_exit(empty_stderr=False)
3432)         assert cli._load_config() == config
3433)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3434) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3435)     @stateful.rule(
3436)         target=configuration,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3437)         config=configuration,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3438)     )
3439)     def purge_all(
3440)         self,
3441)         config: _types.VaultConfig,
3442)     ) -> _types.VaultConfig:
3443)         cli._save_config(config)
3444)         config = {'services': {}}
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3445)         _result = self.runner.invoke(
3446)             cli.derivepassphrase_vault,
3447)             ['--clear'],
3448)             input='y',
3449)             catch_exceptions=False,
3450)         )
3451)         result = tests.ReadableResult.parse(_result)
3452)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3453)         assert cli._load_config() == config
3454)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3455) 
3456)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3457)         target=configuration,
3458)         base_config=configuration,
3459)         config_to_import=configuration,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3460)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3461)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3462)     def import_configuration(
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3463)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3464)         base_config: _types.VaultConfig,
3465)         config_to_import: _types.VaultConfig,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3466)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3467)     ) -> _types.VaultConfig:
3468)         cli._save_config(base_config)
3469)         config = (
3470)             self.fold_configs(config_to_import, base_config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3471)             if not overwrite
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3472)             else config_to_import
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3473)         )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3474)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3475)         _result = self.runner.invoke(
3476)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3477)             ['--import', '-']
3478)             + (['--overwrite-existing'] if overwrite else []),
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3479)             input=json.dumps(config_to_import),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3480)             catch_exceptions=False,
3481)         )
3482)         assert tests.ReadableResult.parse(_result).clean_exit(
3483)             empty_stderr=False
3484)         )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3485)         assert cli._load_config() == config
3486)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3487) 
3488)     def teardown(self) -> None:
3489)         self.exit_stack.close()
3490) 
3491)