bba4bd075ab5e1d6a6a76d90b129ad0d58425b96
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 Consolidate shell completio...

Marco Ricci authored 2 days ago

32)     from collections.abc import Callable, Iterable, Iterator, Sequence
33)     from collections.abc import Set as AbstractSet
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

34)     from typing import NoReturn
Marco Ricci Add prototype command-line...

Marco Ricci authored 6 months ago

35) 
Marco Ricci Consolidate shell completio...

Marco Ricci authored 2 days ago

36)     from typing_extensions import Literal
37) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

49) DUMMY_KEY2_B64 = tests.DUMMY_KEY2_B64
50) DUMMY_KEY3 = tests.DUMMY_KEY3
51) DUMMY_KEY3_B64 = tests.DUMMY_KEY3_B64
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

53) TEST_CONFIGS = tests.TEST_CONFIGS
54) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

60) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

65)     check_success: bool
66) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

73)     check_success: bool
74) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

75) 
Marco Ricci Add an actual derivepassphr...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

89)     ('--notes',),
90)     ('--config',),
91)     ('--delete',),
92)     ('--delete-globals',),
93)     ('--clear',),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

96)     ('--notes',),
97)     ('--delete',),
98)     ('--delete-globals',),
99)     ('--clear',),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

100) ]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

105)         True,
106)         DUMMY_PASSPHRASE,
107)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

108)     ('--key',): 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)     ('--length', '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)     ('--repeat', '20'): 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)     ('--lower', '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)     ('--upper', '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)     ('--number', '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)     ('--space', '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)     ('--dash', '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)     ('--symbol', '1'): IncompatibleConfiguration(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

159)         [('--import', '-')], False, None
160)     ),
161)     ('--import', '-'): IncompatibleConfiguration([], False, None),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

184) for opt, config in INCOMPATIBLE.items():
185)     for opt2 in config.other_options:
186)         INTERESTING_OPTION_COMBINATIONS.extend([
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

201)         ])
202) for opt, config in SINGLES.items():
203)     INTERESTING_OPTION_COMBINATIONS.append(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

212) 
213) 
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 2 months ago

231)         ),
232)     ]
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

234) 
235) 
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 week ago

373)     def test_200_help_output(
374)         self,
375)         monkeypatch: pytest.MonkeyPatch,
376)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

378)         with tests.isolated_config(
379)             monkeypatch=monkeypatch,
380)             runner=runner,
381)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

383)                 cli.derivepassphrase_vault,
384)                 ['--help'],
385)                 catch_exceptions=False,
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

427)         with tests.isolated_config(
428)             monkeypatch=monkeypatch,
429)             runner=runner,
430)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

434)                 input=DUMMY_PASSPHRASE,
435)                 catch_exceptions=False,
436)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

443) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

444)     def test_202_disable_repetition(
445)         self, monkeypatch: pytest.MonkeyPatch
446)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

449)         with tests.isolated_config(
450)             monkeypatch=monkeypatch,
451)             runner=runner,
452)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

456)                 input=DUMMY_PASSPHRASE,
457)                 catch_exceptions=False,
458)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

469) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

494)     def test_204a_key_from_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

502)         ):
503)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

522) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

523)     def test_204b_key_from_command_line(
524)         self, monkeypatch: pytest.MonkeyPatch
525)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

528)             monkeypatch=monkeypatch,
529)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

531)         ):
532)             monkeypatch.setattr(
533)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
534)             )
535)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

542)                 catch_exceptions=False,
543)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

554) 
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

583)         config: dict[str, Any],
584)         key_index: int,
585)     ) -> None:
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

595)             ):
596)                 _result = runner.invoke(
597)                     cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

609)     def test_205_service_phrase_if_key_in_global_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

637)                     catch_exceptions=False,
638)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

649) 
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 2 months ago

668)                     },
669)                 },
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 2 months ago

681)         ],
682)     )
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 2 months ago

684)         self,
685)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

702)             ):
703)                 _result = runner.invoke(
704)                     cli.derivepassphrase_vault,
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 weeks ago

718)         ) or tests.warning_emitted(
719)             'Setting a global passphrase is ineffective ',
720)             caplog.record_tuples,
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

722)         assert all(map(is_warning_line, result.stderr.splitlines(True)))
723)         assert all(
724)             map(is_harmless_config_import_warning, caplog.record_tuples)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

725)         ), 'unexpected error output'
726) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

752)                     input=DUMMY_PASSPHRASE,
753)                     catch_exceptions=False,
754)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

759) 
760)     @pytest.mark.parametrize(
761)         ['options', 'service', 'input', 'check_success'],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

767)     )
768)     def test_211_service_needed(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

779)             monkeypatch=monkeypatch,
780)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

786)                 input=input,
787)                 catch_exceptions=False,
788)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

796)                 assert result.error_exit(
797)                     error=err_msg
798)                 ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

800)                 assert result.clean_exit(
801)                     empty_stderr=True
802)                 ), 'expected clean exit'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

805)                 monkeypatch=monkeypatch,
806)                 runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

808)             ):
809)                 monkeypatch.setattr(
810)                     cli, '_prompt_for_passphrase', tests.auto_prompt
811)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

815)                     input=input,
816)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 months ago

821)     def test_211a_empty_service_name_causes_warning(
822)         self,
823)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

881)     def test_212_incompatible_options(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

888)         with tests.isolated_config(
889)             monkeypatch=monkeypatch,
890)             runner=runner,
891)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

895)                 input=DUMMY_PASSPHRASE,
896)                 catch_exceptions=False,
897)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

903)     @pytest.mark.parametrize(
904)         'config',
905)         [
906)             conf.config
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

978) 
979)     def test_213b_import_bad_config_not_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

996)     def test_213c_import_bad_config_not_json_data(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

1013)     def test_213d_import_bad_config_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 6 months ago

1045)     def test_214_export_settings_no_stored_settings(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 6 months ago

1073)     def test_214a_export_settings_bad_stored_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 6 months ago

1100)     def test_214b_export_settings_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 6 months ago

1128)     def test_214c_export_settings_target_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 5 months ago

1154)     def test_214d_export_settings_settings_directory_not_a_directory(
1155)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1169)                 catch_exceptions=False,
1170)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1177) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1178)     def test_220_edit_notes_successfully(
1179)         self, monkeypatch: pytest.MonkeyPatch
1180)     ) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1182) 
1183) # - - - - - >8 - - - - - >8 - - - - - >8 - - - - - >8 - - - - -
1184) contents go here
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1188)             monkeypatch=monkeypatch,
1189)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1208) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1209)     def test_221_edit_notes_noop(
1210)         self, monkeypatch: pytest.MonkeyPatch
1211)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1214)             monkeypatch=monkeypatch,
1215)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

1232)     def test_222_edit_notes_marker_removed(
1233)         self, monkeypatch: pytest.MonkeyPatch
1234)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1237)             monkeypatch=monkeypatch,
1238)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1257) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1258)     def test_223_edit_notes_abort(
1259)         self, monkeypatch: pytest.MonkeyPatch
1260)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1263)             monkeypatch=monkeypatch,
1264)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

1294)                 {
1295)                     'global': {'key': DUMMY_KEY1_B64, 'phrase': 'abc'},
1296)                     'services': {},
1297)                 },
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1298)             ),
1299)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1325)     def test_224_store_config_good(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1330)         result_config: Any,
1331)     ) -> None:
1332)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1334)             monkeypatch=monkeypatch,
1335)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

1337)         ):
1338)             monkeypatch.setattr(
1339)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1340)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1343)                 ['--config', *command_line],
1344)                 catch_exceptions=False,
1345)                 input=input,
1346)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1353)             assert (
1354)                 config == result_config
1355)             ), 'stored config does not match expectation'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1356) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1357)     @pytest.mark.parametrize(
1358)         ['command_line', 'input', 'err_text'],
1359)         [
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1360)             (
1361)                 [],
1362)                 '',
1363)                 'Cannot update global settings without any given settings',
1364)             ),
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 5 months ago

1372)         ],
1373)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1374)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1378)         input: str,
1379)         err_text: str,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1383)             monkeypatch=monkeypatch,
1384)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

1386)         ):
1387)             monkeypatch.setattr(
1388)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1389)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1392)                 ['--config', *command_line],
1393)                 catch_exceptions=False,
1394)                 input=input,
1395)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1400) 
1401)     def test_225a_store_config_fail_manual_no_ssh_key_selection(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1407)             monkeypatch=monkeypatch,
1408)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1412) 
Marco Ricci Support suppressing or forc...

Marco Ricci authored 1 week ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1419)                 ['--key', '--config'],
1420)                 catch_exceptions=False,
1421)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

1427)     def test_225b_store_config_fail_manual_no_ssh_agent(
1428)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1435)             monkeypatch=monkeypatch,
1436)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1442)                 ['--key', '--config'],
1443)                 catch_exceptions=False,
1444)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1449) 
1450)     def test_225c_store_config_fail_manual_bad_ssh_agent_connection(
1451)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1456)             monkeypatch=monkeypatch,
1457)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1463)                 ['--key', '--config'],
1464)                 catch_exceptions=False,
1465)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1475)         try_race_free_implementation: bool,
1476)     ) -> None:
1477)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1479)             monkeypatch=monkeypatch,
1480)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1482)         ):
1483)             tests.make_file_readonly(
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1485)                 try_race_free_implementation=try_race_free_implementation,
1486)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1490)                 catch_exceptions=False,
1491)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1496) 
1497)     def test_225e_store_config_fail_manual_custom_error(
1498)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1503)             monkeypatch=monkeypatch,
1504)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1517)                 catch_exceptions=False,
1518)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1523) 
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1635)         with tests.isolated_config(
1636)             monkeypatch=monkeypatch,
1637)             runner=runner,
1638)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1646) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1647)     def test_226a_no_passphrase_or_key(
1648)         self, monkeypatch: pytest.MonkeyPatch
1649)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1651)         with tests.isolated_config(
1652)             monkeypatch=monkeypatch,
1653)             runner=runner,
1654)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1664) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1665)     def test_230_config_directory_nonexistant(
1666)         self, monkeypatch: pytest.MonkeyPatch
1667)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1686)                 ['--config', '-p'],
1687)                 catch_exceptions=False,
1688)                 input='abc\n',
1689)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1705)     def test_230a_config_directory_not_a_file(
1706)         self, monkeypatch: pytest.MonkeyPatch
1707)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1729)                 ['--config', '-p'],
1730)                 catch_exceptions=False,
1731)                 input='abc\n',
1732)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1737) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1738)     def test_230b_store_config_custom_error(
1739)         self, monkeypatch: pytest.MonkeyPatch
1740)     ) -> None:
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1748)             def raiser(config: Any) -> None:
1749)                 del config
1750)                 raise RuntimeError(custom_error)
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1755)                 ['--config', '-p'],
1756)                 catch_exceptions=False,
1757)                 input='abc\n',
1758)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1766)         [
1767)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

1775)                 id='global-NFC',
1776)             ),
1777)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

1798)                     f'is not NFC-normalized'
1799)                 ),
1800)                 id='config-NFC',
1801)             ),
1802)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

1807)                 id='direct-input-NFC',
1808)             ),
1809)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

1822)                 id='global-NFD',
1823)             ),
1824)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1835)                 }),
1836)                 (
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

1838)                     'is not NFD-normalized'
1839)                 ),
1840)                 id='service-weird-name-NFD',
1841)             ),
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 3 weeks ago

1857)                     'is not NFKD-normalized'
1858)                 ),
1859)                 id='service-weird-name-2-NFKD',
1860)             ),
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1861)         ],
1862)     )
1863)     def test_300_unicode_normalization_form_warning(
1864)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1874)             monkeypatch=monkeypatch,
1875)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1876)             vault_config={
1877)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1878)             },
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1884)                 catch_exceptions=False,
1885)                 input=input,
1886)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1892) 
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

2109) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

2164)         result = tests.ReadableResult.parse(_result)
2165)         assert result.error_exit(
2166)             error=IndexError
2167)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

2169)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2170)             == """\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2171) [1] Egg and bacon
2172) [2] Egg, sausage and bacon
2173) [3] Egg and spam
2174) [4] Egg, bacon and spam
2175) [5] Egg, bacon, sausage and spam
2176) [6] Spam, bacon, sausage and spam
2177) [7] Spam, egg, spam, spam, bacon and spam
2178) [8] Spam, spam, spam, egg and spam
2179) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
2180) [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

2181) Your selection? (1-10, leave empty to abort):\x20
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

2183)         ), 'expected known output'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2184) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

2186)         @click.command()
2187)         @click.option('--item', default='baked beans')
2188)         @click.argument('prompt')
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

2189)         def driver(item: str, prompt: str) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2190)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2191)                 cli._prompt_for_selection(
2192)                     [item], heading='', single_choice_prompt=prompt
2193)                 )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

2194)             except IndexError:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2195)                 click.echo('Boo.')
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

2196)                 raise
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2197)             else:
2198)                 click.echo('Great!')
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

2201)         _result = runner.invoke(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2202)             driver, ['Will replace with spam. Confirm, y/n?'], input='y'
2203)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2204)         result = tests.ReadableResult.parse(_result)
2205)         assert result.clean_exit(
2206)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2207) [1] baked beans
2208) Will replace with spam. Confirm, y/n? y
2209) Great!
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

2213)             driver,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

2214)             ['Will replace with spam, okay? (Please say "y" or "n".)'],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2215)             input='',
2216)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2217)         result = tests.ReadableResult.parse(_result)
2218)         assert result.error_exit(
2219)             error=IndexError
2220)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

2222)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2223)             == """\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2224) [1] baked beans
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

2225) Will replace with spam, okay? (Please say "y" or "n".):\x20
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2226) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

2228)         ), 'expected known output'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2229) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2230)     def test_113_prompt_for_passphrase(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2231)         self, monkeypatch: pytest.MonkeyPatch
2232)     ) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2233)         monkeypatch.setattr(
2234)             click,
2235)             'prompt',
2236)             lambda *a, **kw: json.dumps({'args': a, 'kwargs': kw}),
2237)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2238)         res = json.loads(cli._prompt_for_passphrase())
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

2239)         err_msg = 'missing arguments to passphrase prompt'
2240)         assert 'args' in res, err_msg
2241)         assert 'kwargs' in res, err_msg
2242)         assert res['args'][:1] == ['Passphrase'], err_msg
2243)         assert res['kwargs'].get('default') == '', err_msg
2244)         assert not res['kwargs'].get('show_default', True), err_msg
2245)         assert res['kwargs'].get('err'), err_msg
2246)         assert res['kwargs'].get('hide_input'), err_msg
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

2248)     def test_120_standard_logging_context_manager(
2249)         self,
2250)         caplog: pytest.LogCaptureFixture,
2251)         capsys: pytest.CaptureFixture[str],
2252)     ) -> None:
2253)         prog_name = cli.StandardCLILogging.prog_name
2254)         package_name = cli.StandardCLILogging.package_name
2255)         logger = logging.getLogger(package_name)
2256)         deprecation_logger = logging.getLogger(f'{package_name}.deprecation')
2257)         logging_cm = cli.StandardCLILogging.ensure_standard_logging()
2258)         with logging_cm:
2259)             assert (
2260)                 sum(
2261)                     1
2262)                     for h in logger.handlers
2263)                     if h is cli.StandardCLILogging.cli_handler
2264)                 )
2265)                 == 1
2266)             )
2267)             logger.warning('message 1')
2268)             with logging_cm:
2269)                 deprecation_logger.warning('message 2')
2270)                 assert (
2271)                     sum(
2272)                         1
2273)                         for h in logger.handlers
2274)                         if h is cli.StandardCLILogging.cli_handler
2275)                     )
2276)                     == 1
2277)                 )
2278)                 assert capsys.readouterr() == (
2279)                     '',
2280)                     (
2281)                         f'{prog_name}: Warning: message 1\n'
2282)                         f'{prog_name}: Deprecation warning: message 2\n'
2283)                     ),
2284)                 )
2285)             logger.warning('message 3')
2286)             assert (
2287)                 sum(
2288)                     1
2289)                     for h in logger.handlers
2290)                     if h is cli.StandardCLILogging.cli_handler
2291)                 )
2292)                 == 1
2293)             )
2294)             assert capsys.readouterr() == (
2295)                 '',
2296)                 f'{prog_name}: Warning: message 3\n',
2297)             )
2298)             assert caplog.record_tuples == [
2299)                 (package_name, logging.WARNING, 'message 1'),
2300)                 (f'{package_name}.deprecation', logging.WARNING, 'message 2'),
2301)                 (package_name, logging.WARNING, 'message 3'),
2302)             ]
2303) 
2304)     def test_121_standard_logging_warnings_context_manager(
2305)         self,
2306)         caplog: pytest.LogCaptureFixture,
2307)         capsys: pytest.CaptureFixture[str],
2308)     ) -> None:
2309)         warnings_cm = cli.StandardCLILogging.ensure_standard_warnings_logging()
2310)         THE_FUTURE = 'the future will be here sooner than you think'  # noqa: N806
2311)         JUST_TESTING = 'just testing whether warnings work'  # noqa: N806
2312)         with warnings_cm:
2313)             assert (
2314)                 sum(
2315)                     1
2316)                     for h in logging.getLogger('py.warnings').handlers
2317)                     if h is cli.StandardCLILogging.warnings_handler
2318)                 )
2319)                 == 1
2320)             )
2321)             warnings.warn(UserWarning(JUST_TESTING), stacklevel=1)
2322)             with warnings_cm:
2323)                 warnings.warn(FutureWarning(THE_FUTURE), stacklevel=1)
2324)                 _out, err = capsys.readouterr()
2325)                 err_lines = err.splitlines(True)
2326)                 assert any(
2327)                     f'UserWarning: {JUST_TESTING}' in line
2328)                     for line in err_lines
2329)                 )
2330)                 assert any(
2331)                     f'FutureWarning: {THE_FUTURE}' in line
2332)                     for line in err_lines
2333)                 )
2334)             warnings.warn(UserWarning(JUST_TESTING), stacklevel=1)
2335)             _out, err = capsys.readouterr()
2336)             err_lines = err.splitlines(True)
2337)             assert any(
2338)                 f'UserWarning: {JUST_TESTING}' in line for line in err_lines
2339)             )
2340)             assert not any(
2341)                 f'FutureWarning: {THE_FUTURE}' in line for line in err_lines
2342)             )
2343)             record_tuples = caplog.record_tuples
2344)             assert [tup[:2] for tup in record_tuples] == [
2345)                 ('py.warnings', logging.WARNING),
2346)                 ('py.warnings', logging.WARNING),
2347)                 ('py.warnings', logging.WARNING),
2348)             ]
2349)             assert f'UserWarning: {JUST_TESTING}' in record_tuples[0][2]
2350)             assert f'FutureWarning: {THE_FUTURE}' in record_tuples[1][2]
2351)             assert f'UserWarning: {JUST_TESTING}' in record_tuples[2][2]
2352) 
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

2353)     def _export_as_sh_helper(
2354)         self,
2355)         config: Any,
2356)     ) -> None:
2357)         prog_name_list = ('derivepassphrase', 'vault')
2358)         with io.StringIO() as outfile:
2359)             cli._print_config_as_sh_script(
2360)                 config, outfile=outfile, prog_name_list=prog_name_list
2361)             )
2362)             script = outfile.getvalue()
2363)         runner = click.testing.CliRunner(mix_stderr=False)
2364)         monkeypatch = pytest.MonkeyPatch()
2365)         with tests.isolated_vault_config(
2366)             runner=runner,
2367)             monkeypatch=monkeypatch,
2368)             vault_config={'services': {}},
2369)         ):
2370)             for _result in vault_config_exporter_shell_interpreter(script):
2371)                 result = tests.ReadableResult.parse(_result)
2372)                 assert result.clean_exit()
2373)             assert cli._load_config() == config
2374) 
2375)     @hypothesis.given(
2376)         global_config_settable=tests.vault_full_service_config(),
2377)         global_config_importable=strategies.fixed_dictionaries(
2378)             {},
2379)             optional={
2380)                 'key': strategies.text(
2381)                     alphabet=strategies.characters(
2382)                         min_codepoint=32,
2383)                         max_codepoint=126,
2384)                     ),
2385)                     max_size=128,
2386)                 ),
2387)                 'phrase': strategies.text(
2388)                     alphabet=strategies.characters(
2389)                         min_codepoint=32,
2390)                         max_codepoint=126,
2391)                     ),
2392)                     max_size=64,
2393)                 ),
2394)             },
2395)         ),
2396)     )
2397)     def test_130a_export_as_sh_global(
2398)         self,
2399)         global_config_settable: _types.VaultConfigServicesSettings,
2400)         global_config_importable: _types.VaultConfigServicesSettings,
2401)     ) -> None:
2402)         config: _types.VaultConfig = {
2403)             'global': global_config_settable | global_config_importable,
2404)             'services': {},
2405)         }
2406)         assert _types.clean_up_falsy_vault_config_values(config) is not None
2407)         assert _types.is_vault_config(config)
2408)         return self._export_as_sh_helper(config)
2409) 
2410)     @hypothesis.given(
2411)         global_config_importable=strategies.fixed_dictionaries(
2412)             {},
2413)             optional={
2414)                 'key': strategies.text(
2415)                     alphabet=strategies.characters(
2416)                         min_codepoint=32,
2417)                         max_codepoint=126,
2418)                     ),
2419)                     max_size=128,
2420)                 ),
2421)                 'phrase': strategies.text(
2422)                     alphabet=strategies.characters(
2423)                         min_codepoint=32,
2424)                         max_codepoint=126,
2425)                     ),
2426)                     max_size=64,
2427)                 ),
2428)             },
2429)         ),
2430)     )
2431)     def test_130b_export_as_sh_global_only_imports(
2432)         self,
2433)         global_config_importable: _types.VaultConfigServicesSettings,
2434)     ) -> None:
2435)         config: _types.VaultConfig = {
2436)             'global': global_config_importable,
2437)             'services': {},
2438)         }
2439)         assert _types.clean_up_falsy_vault_config_values(config) is not None
2440)         assert _types.is_vault_config(config)
2441)         if not config['global']:
2442)             config.pop('global')
2443)         return self._export_as_sh_helper(config)
2444) 
2445)     @hypothesis.given(
2446)         service_name=strategies.text(
2447)             alphabet=strategies.characters(
2448)                 min_codepoint=32,
2449)                 max_codepoint=126,
2450)             ),
2451)             min_size=4,
2452)             max_size=64,
2453)         ),
2454)         service_config_settable=tests.vault_full_service_config(),
2455)         service_config_importable=strategies.fixed_dictionaries(
2456)             {},
2457)             optional={
2458)                 'key': strategies.text(
2459)                     alphabet=strategies.characters(
2460)                         min_codepoint=32,
2461)                         max_codepoint=126,
2462)                     ),
2463)                     max_size=128,
2464)                 ),
2465)                 'phrase': strategies.text(
2466)                     alphabet=strategies.characters(
2467)                         min_codepoint=32,
2468)                         max_codepoint=126,
2469)                     ),
2470)                     max_size=64,
2471)                 ),
2472)                 'notes': strategies.text(
2473)                     alphabet=strategies.characters(
2474)                         min_codepoint=32,
2475)                         max_codepoint=126,
2476)                         include_characters=('\n', '\f', '\t'),
2477)                     ),
2478)                     max_size=256,
2479)                 ),
2480)             },
2481)         ),
2482)     )
2483)     def test_130c_export_as_sh_service(
2484)         self,
2485)         service_name: str,
2486)         service_config_settable: _types.VaultConfigServicesSettings,
2487)         service_config_importable: _types.VaultConfigServicesSettings,
2488)     ) -> None:
2489)         config: _types.VaultConfig = {
2490)             'services': {
2491)                 service_name: (
2492)                     service_config_settable | service_config_importable
2493)                 ),
2494)             },
2495)         }
2496)         assert _types.clean_up_falsy_vault_config_values(config) is not None
2497)         assert _types.is_vault_config(config)
2498)         return self._export_as_sh_helper(config)
2499) 
2500)     @hypothesis.given(
2501)         service_name=strategies.text(
2502)             alphabet=strategies.characters(
2503)                 min_codepoint=32,
2504)                 max_codepoint=126,
2505)             ),
2506)             min_size=4,
2507)             max_size=64,
2508)         ),
2509)         service_config_importable=strategies.fixed_dictionaries(
2510)             {},
2511)             optional={
2512)                 'key': strategies.text(
2513)                     alphabet=strategies.characters(
2514)                         min_codepoint=32,
2515)                         max_codepoint=126,
2516)                     ),
2517)                     max_size=128,
2518)                 ),
2519)                 'phrase': strategies.text(
2520)                     alphabet=strategies.characters(
2521)                         min_codepoint=32,
2522)                         max_codepoint=126,
2523)                     ),
2524)                     max_size=64,
2525)                 ),
2526)                 'notes': strategies.text(
2527)                     alphabet=strategies.characters(
2528)                         min_codepoint=32,
2529)                         max_codepoint=126,
2530)                         include_characters=('\n', '\f', '\t'),
2531)                     ),
2532)                     max_size=256,
2533)                 ),
2534)             },
2535)         ),
2536)     )
2537)     def test_130d_export_as_sh_service_only_imports(
2538)         self,
2539)         service_name: str,
2540)         service_config_importable: _types.VaultConfigServicesSettings,
2541)     ) -> None:
2542)         config: _types.VaultConfig = {
2543)             'services': {
2544)                 service_name: service_config_importable,
2545)             },
2546)         }
2547)         assert _types.clean_up_falsy_vault_config_values(config) is not None
2548)         assert _types.is_vault_config(config)
2549)         return self._export_as_sh_helper(config)
2550) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2551)     @pytest.mark.parametrize(
2552)         ['command_line', 'config', 'result_config'],
2553)         [
2554)             (
2555)                 ['--delete-globals'],
2556)                 {'global': {'phrase': 'abc'}, 'services': {}},
2557)                 {'services': {}},
2558)             ),
2559)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

2560)                 ['--delete', '--', DUMMY_SERVICE],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2561)                 {
2562)                     'global': {'phrase': 'abc'},
2563)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
2564)                 },
2565)                 {'global': {'phrase': 'abc'}, 'services': {}},
2566)             ),
2567)             (
2568)                 ['--clear'],
2569)                 {
2570)                     'global': {'phrase': 'abc'},
2571)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
2572)                 },
2573)                 {'services': {}},
2574)             ),
2575)         ],
2576)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2577)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

2580)         command_line: list[str],
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

2581)         config: _types.VaultConfig,
2582)         result_config: _types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2583)     ) -> None:
2584)         runner = click.testing.CliRunner(mix_stderr=False)
2585)         for start_config in [config, result_config]:
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

2587)                 monkeypatch=monkeypatch,
2588)                 runner=runner,
2589)                 vault_config=start_config,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

2592)                     cli.derivepassphrase_vault,
2593)                     command_line,
2594)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

2603)                     config_readback = json.load(infile)
2604)                 assert config_readback == result_config
2605) 
2606)     def test_204_phrase_from_key_manually(self) -> None:
2607)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

2608)             vault.Vault(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2609)                 phrase=DUMMY_PHRASE_FROM_KEY1, **DUMMY_CONFIG_SETTINGS
2610)             ).generate(DUMMY_SERVICE)
2611)             == DUMMY_RESULT_KEY1
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2612)         )
2613) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2614)     @pytest.mark.parametrize(
2615)         ['vfunc', 'input'],
2616)         [
2617)             (cli._validate_occurrence_constraint, 20),
2618)             (cli._validate_length, 20),
2619)         ],
2620)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2621)     def test_210a_validate_constraints_manually(
2622)         self,
2623)         vfunc: Callable[[click.Context, click.Parameter, Any], int | None],
2624)         input: int,
2625)     ) -> None:
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2626)         ctx = cli.derivepassphrase_vault.make_context(cli.PROG_NAME, [])
2627)         param = cli.derivepassphrase_vault.params[0]
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2628)         assert vfunc(ctx, param, input) == input
2629) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

2630)     @pytest.mark.parametrize('conn_hint', ['none', 'socket', 'client'])
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 6 months ago

2631)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

2634)         running_ssh_agent: tests.RunningSSHAgentInfo,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2635)         conn_hint: str,
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 6 months ago

2636)     ) -> None:
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2639)             monkeypatch.setattr(
2640)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
2641)             )
2642)             hint: ssh_agent.SSHAgentClient | socket.socket | None
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

2643)             # Use match/case here once Python 3.9 becomes unsupported.
2644)             if conn_hint == 'client':
2645)                 hint = ssh_agent.SSHAgentClient()
2646)             elif conn_hint == 'socket':
2647)                 hint = socket.socket(family=socket.AF_UNIX)
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

2648)                 hint.connect(running_ssh_agent.socket)
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

2649)             else:
2650)                 assert conn_hint == 'none'
2651)                 hint = None
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

2652)             exception: Exception | None = None
2653)             try:
2654)                 list(cli._get_suitable_ssh_keys(hint))
2655)             except RuntimeError:  # pragma: no cover
2656)                 pass
2657)             except Exception as e:  # noqa: BLE001 # pragma: no cover
2658)                 exception = e
2659)             finally:
2660)                 assert (
2661)                     exception is None
2662)                 ), 'exception querying suitable SSH keys'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2663) 
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2664)     def test_400_key_to_phrase(
2665)         self,
2666)         monkeypatch: pytest.MonkeyPatch,
2667)         skip_if_no_af_unix_support: None,
2668)         ssh_agent_client_with_test_keys_loaded: ssh_agent.SSHAgentClient,
2669)     ) -> None:
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2670)         class ErrCallback(BaseException):
2671)             def __init__(self, *args: Any, **kwargs: Any) -> None:
2672)                 super().__init__(*args[:1])
2673)                 self.args = args
2674)                 self.kwargs = kwargs
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2675) 
2676)         def err(*args: Any, **_kwargs: Any) -> NoReturn:
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2677)             raise ErrCallback(*args, **_kwargs)
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2678) 
2679)         def fail(*_args: Any, **_kwargs: Any) -> Any:
2680)             raise ssh_agent.SSHAgentFailedError(
2681)                 _types.SSH_AGENT.FAILURE.value,
2682)                 b'',
2683)             )
2684) 
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2685)         def fail_runtime(*_args: Any, **_kwargs: Any) -> Any:
2686)             raise ssh_agent.TrailingDataError()
2687) 
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2688)         del skip_if_no_af_unix_support
2689)         monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', fail)
2690)         loaded_keys = list(ssh_agent_client_with_test_keys_loaded.list_keys())
2691)         loaded_key = base64.standard_b64encode(loaded_keys[0][0])
2692)         with monkeypatch.context() as mp:
2693)             mp.setattr(
2694)                 ssh_agent.SSHAgentClient,
2695)                 'list_keys',
2696)                 lambda *_a, **_kw: [],
2697)             )
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2698)             with pytest.raises(ErrCallback, match='not loaded into the agent'):
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2699)                 cli._key_to_phrase(loaded_key, error_callback=err)
2700)         with monkeypatch.context() as mp:
2701)             mp.setattr(ssh_agent.SSHAgentClient, 'list_keys', fail)
2702)             with pytest.raises(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2703)                 ErrCallback, match='SSH agent failed to or refused to'
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2704)             ):
2705)                 cli._key_to_phrase(loaded_key, error_callback=err)
2706)         with monkeypatch.context() as mp:
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2707)             mp.setattr(ssh_agent.SSHAgentClient, 'list_keys', fail_runtime)
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2708)             with pytest.raises(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2709)                 ErrCallback, match='SSH agent failed to or refused to'
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2710)             ) as excinfo:
2711)                 cli._key_to_phrase(loaded_key, error_callback=err)
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2712)             assert excinfo.value.kwargs
2713)             assert isinstance(
2714)                 excinfo.value.kwargs['exc_info'],
2715)                 ssh_agent.SSHAgentFailedError,
2716)             )
2717)             assert excinfo.value.kwargs['exc_info'].__context__ is not None
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2718)             assert isinstance(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2719)                 excinfo.value.kwargs['exc_info'].__context__,
2720)                 ssh_agent.TrailingDataError,
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2721)             )
2722)         with monkeypatch.context() as mp:
2723)             mp.delenv('SSH_AUTH_SOCK', raising=True)
2724)             with pytest.raises(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2725)                 ErrCallback, match='Cannot find any running SSH agent'
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2726)             ):
2727)                 cli._key_to_phrase(loaded_key, error_callback=err)
2728)         with monkeypatch.context() as mp:
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

2729)             mp.setenv('SSH_AUTH_SOCK', os.environ['SSH_AUTH_SOCK'] + '~')
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2730)             with pytest.raises(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2731)                 ErrCallback, match='Cannot connect to the SSH agent'
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2732)             ):
2733)                 cli._key_to_phrase(loaded_key, error_callback=err)
2734)         with monkeypatch.context() as mp:
2735)             mp.delattr(socket, 'AF_UNIX', raising=True)
2736)             with pytest.raises(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2737)                 ErrCallback, match='does not support UNIX domain sockets'
2738)             ):
2739)                 cli._key_to_phrase(loaded_key, error_callback=err)
2740)         with monkeypatch.context() as mp:
2741)             mp.setattr(ssh_agent.SSHAgentClient, 'sign', fail_runtime)
2742)             with pytest.raises(
2743)                 ErrCallback, match='violates the communications protocol'
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2744)             ):
2745)                 cli._key_to_phrase(loaded_key, error_callback=err)
2746) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2747) 
2748) class TestCLITransition:
2749)     def test_100_help_output(self, monkeypatch: pytest.MonkeyPatch) -> None:
2750)         runner = click.testing.CliRunner(mix_stderr=False)
2751)         with tests.isolated_config(
2752)             monkeypatch=monkeypatch,
2753)             runner=runner,
2754)         ):
2755)             _result = runner.invoke(
2756)                 cli.derivepassphrase, ['--help'], catch_exceptions=False
2757)             )
2758)             result = tests.ReadableResult.parse(_result)
2759)         assert result.clean_exit(
2760)             empty_stderr=True, output='currently implemented subcommands'
2761)         ), 'expected clean exit, and known help text'
2762) 
2763)     def test_101_help_output_export(
2764)         self, monkeypatch: pytest.MonkeyPatch
2765)     ) -> None:
2766)         runner = click.testing.CliRunner(mix_stderr=False)
2767)         with tests.isolated_config(
2768)             monkeypatch=monkeypatch,
2769)             runner=runner,
2770)         ):
2771)             _result = runner.invoke(
2772)                 cli.derivepassphrase,
2773)                 ['export', '--help'],
2774)                 catch_exceptions=False,
2775)             )
2776)             result = tests.ReadableResult.parse(_result)
2777)         assert result.clean_exit(
2778)             empty_stderr=True, output='only available subcommand'
2779)         ), 'expected clean exit, and known help text'
2780) 
2781)     def test_102_help_output_export_vault(
2782)         self, monkeypatch: pytest.MonkeyPatch
2783)     ) -> None:
2784)         runner = click.testing.CliRunner(mix_stderr=False)
2785)         with tests.isolated_config(
2786)             monkeypatch=monkeypatch,
2787)             runner=runner,
2788)         ):
2789)             _result = runner.invoke(
2790)                 cli.derivepassphrase,
2791)                 ['export', 'vault', '--help'],
2792)                 catch_exceptions=False,
2793)             )
2794)             result = tests.ReadableResult.parse(_result)
2795)         assert result.clean_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2796)             empty_stderr=True, output='Export a vault-native configuration'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2797)         ), 'expected clean exit, and known help text'
2798) 
2799)     def test_103_help_output_vault(
2800)         self, monkeypatch: pytest.MonkeyPatch
2801)     ) -> None:
2802)         runner = click.testing.CliRunner(mix_stderr=False)
2803)         with tests.isolated_config(
2804)             monkeypatch=monkeypatch,
2805)             runner=runner,
2806)         ):
2807)             _result = runner.invoke(
2808)                 cli.derivepassphrase,
2809)                 ['vault', '--help'],
2810)                 catch_exceptions=False,
2811)             )
2812)             result = tests.ReadableResult.parse(_result)
2813)         assert result.clean_exit(
Marco Ricci Add an actual derivepassphr...

Marco Ricci authored 2 weeks ago

2814)             empty_stderr=True, output='Passphrase generation:\n'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 week ago

2817)             empty_stderr=True, output='Use $VISUAL or $EDITOR to configure'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2818)         ), 'expected clean exit, and option group epilog in help text'
2819) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2820)     @pytest.mark.parametrize(
2821)         'config',
2822)         [
2823)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2824)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2825)             {
2826)                 'global': {'phrase': 'abc'},
2827)                 'services': {'sv': {'phrase': 'my passphrase'}},
2828)             },
2829)             {
2830)                 'global': {'phrase': 'abc'},
2831)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2832)             },
2833)             {
2834)                 'global': {'phrase': 'abc'},
2835)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2836)             },
2837)         ],
2838)     )
2839)     def test_110_load_config_backup(
2840)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2841)     ) -> None:
2842)         runner = click.testing.CliRunner()
2843)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2844)             config_filename = cli._config_filename(
2845)                 subsystem='old settings.json'
2846)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2847)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2848)                 print(json.dumps(config, indent=2), file=fileobj)
2849)             assert cli._migrate_and_load_old_config()[0] == config
2850) 
2851)     @pytest.mark.parametrize(
2852)         'config',
2853)         [
2854)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2855)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2856)             {
2857)                 'global': {'phrase': 'abc'},
2858)                 'services': {'sv': {'phrase': 'my passphrase'}},
2859)             },
2860)             {
2861)                 'global': {'phrase': 'abc'},
2862)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2863)             },
2864)             {
2865)                 'global': {'phrase': 'abc'},
2866)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2867)             },
2868)         ],
2869)     )
2870)     def test_111_migrate_config(
2871)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2872)     ) -> None:
2873)         runner = click.testing.CliRunner()
2874)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2875)             config_filename = cli._config_filename(
2876)                 subsystem='old settings.json'
2877)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2878)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2879)                 print(json.dumps(config, indent=2), file=fileobj)
2880)             assert cli._migrate_and_load_old_config() == (config, None)
2881) 
2882)     @pytest.mark.parametrize(
2883)         'config',
2884)         [
2885)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2886)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2887)             {
2888)                 'global': {'phrase': 'abc'},
2889)                 'services': {'sv': {'phrase': 'my passphrase'}},
2890)             },
2891)             {
2892)                 'global': {'phrase': 'abc'},
2893)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2894)             },
2895)             {
2896)                 'global': {'phrase': 'abc'},
2897)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2898)             },
2899)         ],
2900)     )
2901)     def test_112_migrate_config_error(
2902)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2903)     ) -> None:
2904)         runner = click.testing.CliRunner()
2905)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2906)             config_filename = cli._config_filename(
2907)                 subsystem='old settings.json'
2908)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2909)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2910)                 print(json.dumps(config, indent=2), file=fileobj)
2911)             os.mkdir(cli._config_filename(subsystem='vault'))
2912)             config2, err = cli._migrate_and_load_old_config()
2913)             assert config2 == config
2914)             assert isinstance(err, OSError)
2915)             assert err.errno == errno.EISDIR
2916) 
2917)     @pytest.mark.parametrize(
2918)         'config',
2919)         [
2920)             {'global': '', 'services': {}},
2921)             {'global': 0, 'services': {}},
2922)             {
2923)                 'global': {'phrase': 'abc'},
2924)                 'services': False,
2925)             },
2926)             {
2927)                 'global': {'phrase': 'abc'},
2928)                 'services': True,
2929)             },
2930)             {
2931)                 'global': {'phrase': 'abc'},
2932)                 'services': None,
2933)             },
2934)         ],
2935)     )
2936)     def test_113_migrate_config_error_bad_config_value(
2937)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2938)     ) -> None:
2939)         runner = click.testing.CliRunner()
2940)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2941)             config_filename = cli._config_filename(
2942)                 subsystem='old settings.json'
2943)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2944)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2945)                 print(json.dumps(config, indent=2), file=fileobj)
2946)             with pytest.raises(ValueError, match=cli._INVALID_VAULT_CONFIG):
2947)                 cli._migrate_and_load_old_config()
2948) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2949)     def test_200_forward_export_vault_path_parameter(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2950)         self,
2951)         monkeypatch: pytest.MonkeyPatch,
2952)         caplog: pytest.LogCaptureFixture,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2953)     ) -> None:
2954)         pytest.importorskip('cryptography', minversion='38.0')
2955)         runner = click.testing.CliRunner(mix_stderr=False)
2956)         with tests.isolated_vault_exporter_config(
2957)             monkeypatch=monkeypatch,
2958)             runner=runner,
2959)             vault_config=tests.VAULT_V03_CONFIG,
2960)             vault_key=tests.VAULT_MASTER_KEY,
2961)         ):
2962)             monkeypatch.setenv('VAULT_KEY', tests.VAULT_MASTER_KEY)
2963)             _result = runner.invoke(
2964)                 cli.derivepassphrase,
2965)                 ['export', 'VAULT_PATH'],
2966)             )
2967)         result = tests.ReadableResult.parse(_result)
2968)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2969)         assert tests.deprecation_warning_emitted(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2970)             '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

2971)         )
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2972)         assert tests.deprecation_warning_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2973)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

2974)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2975)         assert json.loads(result.output) == tests.VAULT_V03_CONFIG_DATA
2976) 
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2977)     def test_201_forward_export_vault_empty_commandline(
2978)         self,
2979)         monkeypatch: pytest.MonkeyPatch,
2980)         caplog: pytest.LogCaptureFixture,
2981)     ) -> None:
2982)         pytest.importorskip('cryptography', minversion='38.0')
2983)         runner = click.testing.CliRunner(mix_stderr=False)
2984)         with tests.isolated_config(
2985)             monkeypatch=monkeypatch,
2986)             runner=runner,
2987)         ):
2988)             _result = runner.invoke(
2989)                 cli.derivepassphrase,
2990)                 ['export'],
2991)             )
2992)         result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2993)         assert tests.deprecation_warning_emitted(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2994)             '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

2995)         )
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2996)         assert tests.deprecation_warning_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2997)             'Defaulting to subcommand "vault"', caplog.record_tuples
2998)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2999)         assert result.error_exit(
3000)             error="Missing argument 'PATH'"
3001)         ), 'expected error exit and known error type'
3002) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

3003)     @pytest.mark.parametrize(
3004)         'charset_name', ['lower', 'upper', 'number', 'space', 'dash', 'symbol']
3005)     )
3006)     def test_210_forward_vault_disable_character_set(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3007)         self,
3008)         monkeypatch: pytest.MonkeyPatch,
3009)         caplog: pytest.LogCaptureFixture,
3010)         charset_name: str,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

3014)         charset = vault.Vault._CHARSETS[charset_name].decode('ascii')
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

3015)         runner = click.testing.CliRunner(mix_stderr=False)
3016)         with tests.isolated_config(
3017)             monkeypatch=monkeypatch,
3018)             runner=runner,
3019)         ):
3020)             _result = runner.invoke(
3021)                 cli.derivepassphrase,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

3022)                 [option, '0', '-p', '--', DUMMY_SERVICE],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

3023)                 input=DUMMY_PASSPHRASE,
3024)                 catch_exceptions=False,
3025)             )
3026)             result = tests.ReadableResult.parse(_result)
3027)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3028)         assert tests.deprecation_warning_emitted(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

3029)             '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

3030)         )
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

3031)         assert tests.deprecation_warning_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3032)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

3033)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

3034)         for c in charset:
3035)             assert (
3036)                 c not in result.output
3037)             ), f'derived password contains forbidden character {c!r}'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3038) 
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

3039)     def test_211_forward_vault_empty_command_line(
3040)         self,
3041)         monkeypatch: pytest.MonkeyPatch,
3042)         caplog: pytest.LogCaptureFixture,
3043)     ) -> None:
3044)         runner = click.testing.CliRunner(mix_stderr=False)
3045)         with tests.isolated_config(
3046)             monkeypatch=monkeypatch,
3047)             runner=runner,
3048)         ):
3049)             _result = runner.invoke(
3050)                 cli.derivepassphrase,
3051)                 [],
3052)                 input=DUMMY_PASSPHRASE,
3053)                 catch_exceptions=False,
3054)             )
3055)             result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3056)         assert tests.deprecation_warning_emitted(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

3057)             '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

3058)         )
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

3059)         assert tests.deprecation_warning_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3060)             'Defaulting to subcommand "vault"', caplog.record_tuples
3061)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

3062)         assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

3063)             error='Deriving a passphrase requires a SERVICE.'
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

3064)         ), 'expected error exit and known error type'
3065) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3066)     def test_300_export_using_old_config_file(
3067)         self,
3068)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3069)         caplog: pytest.LogCaptureFixture,
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

3071)         caplog.set_level(logging.INFO)
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3072)         runner = click.testing.CliRunner(mix_stderr=False)
3073)         with tests.isolated_config(
3074)             monkeypatch=monkeypatch,
3075)             runner=runner,
3076)         ):
3077)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

3078)                 cli._config_filename(subsystem='old settings.json'),
3079)                 'w',
3080)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3081)             ) as fileobj:
3082)                 print(
3083)                     json.dumps(
3084)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
3085)                         indent=2,
3086)                     ),
3087)                     file=fileobj,
3088)                 )
3089)             _result = runner.invoke(
3090)                 cli.derivepassphrase_vault,
3091)                 ['--export', '-'],
3092)                 catch_exceptions=False,
3093)             )
3094)         result = tests.ReadableResult.parse(_result)
3095)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3096)         assert tests.deprecation_warning_emitted(
3097)             'v0.1-style config file', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3098)         ), 'expected known warning message in stderr'
Marco Ricci Fix usage of `--debug`, `--...

Marco Ricci authored 3 weeks ago

3099)         assert tests.deprecation_info_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3100)             'Successfully migrated to ', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3101)         ), 'expected known warning message in stderr'
3102) 
3103)     def test_300a_export_using_old_config_file_migration_error(
3104)         self,
3105)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3106)         caplog: pytest.LogCaptureFixture,
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3107)     ) -> None:
3108)         runner = click.testing.CliRunner(mix_stderr=False)
3109)         with tests.isolated_config(
3110)             monkeypatch=monkeypatch,
3111)             runner=runner,
3112)         ):
3113)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

3114)                 cli._config_filename(subsystem='old settings.json'),
3115)                 'w',
3116)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3117)             ) as fileobj:
3118)                 print(
3119)                     json.dumps(
3120)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
3121)                         indent=2,
3122)                     ),
3123)                     file=fileobj,
3124)                 )
3125) 
3126)             def raiser(*_args: Any, **_kwargs: Any) -> None:
3127)                 raise OSError(
3128)                     errno.EACCES,
3129)                     os.strerror(errno.EACCES),
3130)                     cli._config_filename(subsystem='vault'),
3131)                 )
3132) 
3133)             monkeypatch.setattr(os, 'replace', raiser)
3134)             _result = runner.invoke(
3135)                 cli.derivepassphrase_vault,
3136)                 ['--export', '-'],
3137)                 catch_exceptions=False,
3138)             )
3139)         result = tests.ReadableResult.parse(_result)
3140)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3141)         assert tests.deprecation_warning_emitted(
3142)             'v0.1-style config file', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

3144)         assert tests.warning_emitted(
3145)             'Failed to migrate to ', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3146)         ), 'expected known warning message in stderr'
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3147) 
Marco Ricci Consolidate shell completio...

Marco Ricci authored 2 days ago

3148)     def test_400_completion_service_name_old_config_file(
3149)         self,
3150)         monkeypatch: pytest.MonkeyPatch,
3151)     ) -> None:
3152)         runner = click.testing.CliRunner(mix_stderr=False)
3153)         config = {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}}
3154)         with tests.isolated_vault_config(
3155)             monkeypatch=monkeypatch,
3156)             runner=runner,
3157)             vault_config=config,
3158)         ):
3159)             old_name = cli._config_filename(subsystem='old settings.json')
3160)             new_name = cli._config_filename(subsystem='vault')
3161)             with contextlib.suppress(FileNotFoundError):
3162)                 os.remove(old_name)
3163)             os.rename(new_name, old_name)
3164)             assert cli._shell_complete_service(
3165)                 click.Context(cli.derivepassphrase),
3166)                 click.Argument(['some_parameter']),
3167)                 '',
3168)             ) == [DUMMY_SERVICE]
3169) 
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3170) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3171) _known_services = (DUMMY_SERVICE, 'email', 'bank', 'work')
3172) _valid_properties = (
3173)     'length',
3174)     'repeat',
3175)     'upper',
3176)     'lower',
3177)     'number',
3178)     'space',
3179)     'dash',
3180)     'symbol',
3181) )
3182) 
3183) 
3184) def _build_reduced_vault_config_settings(
3185)     config: _types.VaultConfigServicesSettings,
3186)     keys_to_purge: frozenset[str],
3187) ) -> _types.VaultConfigServicesSettings:
3188)     config2 = copy.deepcopy(config)
3189)     for key in keys_to_purge:
3190)         config2.pop(key, None)  # type: ignore[misc]
3191)     return config2
3192) 
3193) 
3194) _services_strategy = strategies.builds(
3195)     _build_reduced_vault_config_settings,
3196)     tests.vault_full_service_config(),
3197)     strategies.sets(
3198)         strategies.sampled_from(_valid_properties),
3199)         max_size=7,
3200)     ),
3201) )
3202) 
3203) 
3204) def _assemble_config(
3205)     global_data: _types.VaultConfigGlobalSettings,
3206)     service_data: list[tuple[str, _types.VaultConfigServicesSettings]],
3207) ) -> _types.VaultConfig:
3208)     services_dict = dict(service_data)
3209)     return (
3210)         {'global': global_data, 'services': services_dict}
3211)         if global_data
3212)         else {'services': services_dict}
3213)     )
3214) 
3215) 
3216) @strategies.composite
3217) def _draw_service_name_and_data(
3218)     draw: hypothesis.strategies.DrawFn,
3219)     num_entries: int,
3220) ) -> tuple[tuple[str, _types.VaultConfigServicesSettings], ...]:
3221)     possible_services = list(_known_services)
3222)     selected_services: list[str] = []
3223)     for _ in range(num_entries):
3224)         selected_services.append(
3225)             draw(strategies.sampled_from(possible_services))
3226)         )
3227)         possible_services.remove(selected_services[-1])
3228)     return tuple(
3229)         (service, draw(_services_strategy)) for service in selected_services
3230)     )
3231) 
3232) 
3233) _vault_full_config = strategies.builds(
3234)     _assemble_config,
3235)     _services_strategy,
3236)     strategies.integers(
3237)         min_value=2,
3238)         max_value=4,
3239)     ).flatmap(_draw_service_name_and_data),
3240) )
3241) 
3242) 
Marco Ricci Actually correctly implemen...

Marco Ricci authored 4 weeks ago

3243) @tests.hypothesis_settings_coverage_compatible
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3244) class ConfigManagementStateMachine(stateful.RuleBasedStateMachine):
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3245)     def __init__(self) -> None:
3246)         super().__init__()
3247)         self.runner = click.testing.CliRunner(mix_stderr=False)
3248)         self.exit_stack = contextlib.ExitStack().__enter__()
3249)         self.monkeypatch = self.exit_stack.enter_context(
3250)             pytest.MonkeyPatch().context()
3251)         )
3252)         self.isolated_config = self.exit_stack.enter_context(
3253)             tests.isolated_vault_config(
3254)                 monkeypatch=self.monkeypatch,
3255)                 runner=self.runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

3256)                 vault_config={'services': {}},
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3257)             )
3258)         )
3259) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3260)     setting = stateful.Bundle('setting')
3261)     configuration = stateful.Bundle('configuration')
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3262) 
3263)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3264)         target=configuration,
3265)         configs=strategies.lists(
3266)             _vault_full_config,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3267)             min_size=8,
3268)             max_size=8,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3269)         ),
3270)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3271)     def declare_initial_configs(
3272)         self,
3273)         configs: Iterable[_types.VaultConfig],
3274)     ) -> Iterable[_types.VaultConfig]:
3275)         return stateful.multiple(*configs)
Marco Ricci Test config merging with pa...

Marco Ricci authored 4 weeks ago

3276) 
3277)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3278)         target=setting,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3279)         configs=strategies.lists(
3280)             _vault_full_config,
3281)             min_size=4,
3282)             max_size=4,
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

3283)         ),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3284)     )
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3285)     def extract_initial_settings(
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3286)         self,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3287)         configs: list[_types.VaultConfig],
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3288)     ) -> Iterable[_types.VaultConfigServicesSettings]:
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3289)         settings: list[_types.VaultConfigServicesSettings] = []
3290)         for c in configs:
3291)             settings.extend(c['services'].values())
3292)         return stateful.multiple(*map(copy.deepcopy, settings))
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3293) 
3294)     @staticmethod
3295)     def fold_configs(
3296)         c1: _types.VaultConfig, c2: _types.VaultConfig
3297)     ) -> _types.VaultConfig:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3298)         """Fold `c1` into `c2`, overriding the latter."""
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3299)         new_global_dict = c1.get('global', c2.get('global'))
3300)         if new_global_dict is not None:
3301)             return {
3302)                 'global': new_global_dict,
3303)                 'services': {**c2['services'], **c1['services']},
3304)             }
3305)         return {
3306)             'services': {**c2['services'], **c1['services']},
3307)         }
3308) 
3309)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3310)         target=configuration,
3311)         config=configuration,
3312)         setting=setting.filter(bool),
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3313)         maybe_unset=strategies.sets(
3314)             strategies.sampled_from(_valid_properties),
3315)             max_size=3,
3316)         ),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3317)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3318)     )
3319)     def set_globals(
3320)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3321)         config: _types.VaultConfig,
3322)         setting: _types.VaultConfigGlobalSettings,
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3323)         maybe_unset: set[str],
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3324)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3325)     ) -> _types.VaultConfig:
3326)         cli._save_config(config)
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3327)         config_global = config.get('global', {})
3328)         maybe_unset = set(maybe_unset) - setting.keys()
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3329)         if overwrite:
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3330)             config['global'] = config_global = {}
3331)         elif maybe_unset:
3332)             for key in maybe_unset:
3333)                 config_global.pop(key, None)  # type: ignore[misc]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3334)         config.setdefault('global', {}).update(setting)
3335)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3336)         # NOTE: This relies on settings_obj containing only the keys
3337)         # "length", "repeat", "upper", "lower", "number", "space",
3338)         # "dash" and "symbol".
3339)         _result = self.runner.invoke(
3340)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3341)             [
3342)                 '--config',
3343)                 '--overwrite-existing' if overwrite else '--merge-existing',
3344)             ]
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3345)             + [f'--unset={key}' for key in maybe_unset]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3346)             + [
3347)                 f'--{key}={value}'
3348)                 for key, value in setting.items()
3349)                 if key in _valid_properties
3350)             ],
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3351)             catch_exceptions=False,
3352)         )
3353)         result = tests.ReadableResult.parse(_result)
3354)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3355)         assert cli._load_config() == config
3356)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3357) 
3358)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3359)         target=configuration,
3360)         config=configuration,
3361)         service=strategies.sampled_from(_known_services),
3362)         setting=setting.filter(bool),
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3363)         maybe_unset=strategies.sets(
3364)             strategies.sampled_from(_valid_properties),
3365)             max_size=3,
3366)         ),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3367)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3368)     )
3369)     def set_service(
3370)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3371)         config: _types.VaultConfig,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3372)         service: str,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3373)         setting: _types.VaultConfigServicesSettings,
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3374)         maybe_unset: set[str],
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3375)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3376)     ) -> _types.VaultConfig:
3377)         cli._save_config(config)
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3378)         config_service = config['services'].get(service, {})
3379)         maybe_unset = set(maybe_unset) - setting.keys()
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3380)         if overwrite:
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3381)             config['services'][service] = config_service = {}
3382)         elif maybe_unset:
3383)             for key in maybe_unset:
3384)                 config_service.pop(key, None)  # type: ignore[misc]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3385)         config['services'].setdefault(service, {}).update(setting)
3386)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3387)         # NOTE: This relies on settings_obj containing only the keys
3388)         # "length", "repeat", "upper", "lower", "number", "space",
3389)         # "dash" and "symbol".
3390)         _result = self.runner.invoke(
3391)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3392)             [
3393)                 '--config',
3394)                 '--overwrite-existing' if overwrite else '--merge-existing',
3395)             ]
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3396)             + [f'--unset={key}' for key in maybe_unset]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3397)             + [
3398)                 f'--{key}={value}'
3399)                 for key, value in setting.items()
3400)                 if key in _valid_properties
3401)             ]
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3402)             + ['--', service],
3403)             catch_exceptions=False,
3404)         )
3405)         result = tests.ReadableResult.parse(_result)
3406)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3407)         assert cli._load_config() == config
3408)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3409) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3410)     @stateful.rule(
3411)         target=configuration,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3412)         config=configuration,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3413)     )
3414)     def purge_global(
3415)         self,
3416)         config: _types.VaultConfig,
3417)     ) -> _types.VaultConfig:
3418)         cli._save_config(config)
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3419)         config.pop('global', None)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3420)         _result = self.runner.invoke(
3421)             cli.derivepassphrase_vault,
3422)             ['--delete-globals'],
3423)             input='y',
3424)             catch_exceptions=False,
3425)         )
3426)         result = tests.ReadableResult.parse(_result)
3427)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3428)         assert cli._load_config() == config
3429)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3430) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3431)     @stateful.rule(
3432)         target=configuration,
3433)         config_and_service=configuration.filter(
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3434)             lambda c: bool(c['services'])
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3435)         ).flatmap(
3436)             lambda c: strategies.tuples(
3437)                 strategies.just(c),
3438)                 strategies.sampled_from(tuple(c['services'].keys())),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3439)             )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3440)         ),
3441)     )
3442)     def purge_service(
3443)         self,
3444)         config_and_service: tuple[_types.VaultConfig, str],
3445)     ) -> _types.VaultConfig:
3446)         config, service = config_and_service
3447)         cli._save_config(config)
3448)         config['services'].pop(service, None)
3449)         _result = self.runner.invoke(
3450)             cli.derivepassphrase_vault,
3451)             ['--delete', '--', service],
3452)             input='y',
3453)             catch_exceptions=False,
3454)         )
3455)         result = tests.ReadableResult.parse(_result)
3456)         assert result.clean_exit(empty_stderr=False)
3457)         assert cli._load_config() == config
3458)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3459) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3460)     @stateful.rule(
3461)         target=configuration,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3462)         config=configuration,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3463)     )
3464)     def purge_all(
3465)         self,
3466)         config: _types.VaultConfig,
3467)     ) -> _types.VaultConfig:
3468)         cli._save_config(config)
3469)         config = {'services': {}}
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3470)         _result = self.runner.invoke(
3471)             cli.derivepassphrase_vault,
3472)             ['--clear'],
3473)             input='y',
3474)             catch_exceptions=False,
3475)         )
3476)         result = tests.ReadableResult.parse(_result)
3477)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3478)         assert cli._load_config() == config
3479)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3480) 
3481)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3482)         target=configuration,
3483)         base_config=configuration,
3484)         config_to_import=configuration,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3485)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3486)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3487)     def import_configuration(
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3488)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3489)         base_config: _types.VaultConfig,
3490)         config_to_import: _types.VaultConfig,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3491)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3492)     ) -> _types.VaultConfig:
3493)         cli._save_config(base_config)
3494)         config = (
3495)             self.fold_configs(config_to_import, base_config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3496)             if not overwrite
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3497)             else config_to_import
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3498)         )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3499)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3500)         _result = self.runner.invoke(
3501)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3502)             ['--import', '-']
3503)             + (['--overwrite-existing'] if overwrite else []),
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3504)             input=json.dumps(config_to_import),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3505)             catch_exceptions=False,
3506)         )
3507)         assert tests.ReadableResult.parse(_result).clean_exit(
3508)             empty_stderr=False
3509)         )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3510)         assert cli._load_config() == config
3511)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3512) 
3513)     def teardown(self) -> None:
3514)         self.exit_stack.close()
3515) 
3516) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3517) TestConfigManagement = ConfigManagementStateMachine.TestCase