59d73c8320650a6bcb77eed759c694949d350cdb
Marco Ricci Change the author e-mail ad...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

57) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

72) 
Marco Ricci Add an actual derivepassphr...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

97) ]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 6 months ago

283) class TestCLI:
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

286)         with tests.isolated_config(
287)             monkeypatch=monkeypatch,
288)             runner=runner,
289)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

300) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

311)         with tests.isolated_config(
312)             monkeypatch=monkeypatch,
313)             runner=runner,
314)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

318)                 input=DUMMY_PASSPHRASE,
319)                 catch_exceptions=False,
320)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

327) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

328)     def test_202_disable_repetition(
329)         self, monkeypatch: pytest.MonkeyPatch
330)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

333)         with tests.isolated_config(
334)             monkeypatch=monkeypatch,
335)             runner=runner,
336)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

340)                 input=DUMMY_PASSPHRASE,
341)                 catch_exceptions=False,
342)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

343)             result = tests.ReadableResult.parse(_result)
344)         assert result.clean_exit(
345)             empty_stderr=True
346)         ), 'expected clean exit and empty stderr'
347)         passphrase = result.output.rstrip('\r\n')
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

353) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

354)     @pytest.mark.parametrize(
355)         'config',
356)         [
357)             pytest.param(
358)                 {
359)                     'global': {'key': DUMMY_KEY1_B64},
360)                     'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS},
361)                 },
362)                 id='global',
363)             ),
364)             pytest.param(
365)                 {
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

367)                     'services': {
368)                         DUMMY_SERVICE: {
369)                             'key': DUMMY_KEY1_B64,
370)                             **DUMMY_CONFIG_SETTINGS,
371)                         }
372)                     },
373)                 },
374)                 id='service',
375)             ),
376)         ],
377)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

378)     def test_204a_key_from_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

386)         ):
387)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

395)         result = tests.ReadableResult.parse(_result)
396)         assert result.clean_exit(
397)             empty_stderr=True
398)         ), 'expected clean exit and empty stderr'
399)         assert _result.stdout_bytes
400)         assert (
401)             _result.stdout_bytes.rstrip(b'\n') != DUMMY_RESULT_PASSPHRASE
402)         ), 'known false output: phrase-based instead of key-based'
403)         assert (
404)             _result.stdout_bytes.rstrip(b'\n') == DUMMY_RESULT_KEY1
405)         ), 'expected known output'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

406) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

407)     def test_204b_key_from_command_line(
408)         self, monkeypatch: pytest.MonkeyPatch
409)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

412)             monkeypatch=monkeypatch,
413)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

415)         ):
416)             monkeypatch.setattr(
417)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
418)             )
419)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

426)                 catch_exceptions=False,
427)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

428)         result = tests.ReadableResult.parse(_result)
429)         assert result.clean_exit(), 'expected clean exit'
430)         assert _result.stdout_bytes, 'expected program output'
431)         last_line = _result.stdout_bytes.splitlines(True)[-1]
432)         assert (
433)             last_line.rstrip(b'\n') != DUMMY_RESULT_PASSPHRASE
434)         ), 'known false output: phrase-based instead of key-based'
435)         assert (
436)             last_line.rstrip(b'\n') == DUMMY_RESULT_KEY1
437)         ), 'expected known output'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

438) 
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 5 months ago

439)     @pytest.mark.parametrize(
440)         'config',
441)         [
442)             pytest.param(
443)                 {
444)                     'global': {'key': DUMMY_KEY1_B64},
445)                     'services': {DUMMY_SERVICE: {}},
446)                 },
447)                 id='global_config',
448)             ),
449)             pytest.param(
450)                 {'services': {DUMMY_SERVICE: {'key': DUMMY_KEY2_B64}}},
451)                 id='service_config',
452)             ),
453)             pytest.param(
454)                 {
455)                     'global': {'key': DUMMY_KEY1_B64},
456)                     'services': {DUMMY_SERVICE: {'key': DUMMY_KEY2_B64}},
457)                 },
458)                 id='full_config',
459)             ),
460)         ],
461)     )
462)     @pytest.mark.parametrize('key_index', [1, 2, 3], ids=lambda i: f'index{i}')
463)     def test_204c_key_override_on_command_line(
464)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

467)         config: dict[str, Any],
468)         key_index: int,
469)     ) -> None:
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

479)             ):
480)                 _result = runner.invoke(
481)                     cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

485)         result = tests.ReadableResult.parse(_result)
486)         assert result.clean_exit(), 'expected clean exit'
487)         assert result.output, 'expected program output'
488)         assert result.stderr, 'expected stderr'
489)         assert (
490)             'Error:' not in result.stderr
491)         ), 'expected no error messages on stderr'
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

493)     def test_205_service_phrase_if_key_in_global_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

503)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', tests.sign)
504)             runner = click.testing.CliRunner(mix_stderr=False)
505)             with tests.isolated_vault_config(
506)                 monkeypatch=monkeypatch,
507)                 runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

509)                     'global': {'key': DUMMY_KEY1_B64},
510)                     'services': {
511)                         DUMMY_SERVICE: {
512)                             'phrase': DUMMY_PASSPHRASE.rstrip('\n'),
513)                             **DUMMY_CONFIG_SETTINGS,
514)                         }
515)                     },
516)                 },
517)             ):
518)                 _result = runner.invoke(
519)                     cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

521)                     catch_exceptions=False,
522)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

523)         result = tests.ReadableResult.parse(_result)
524)         assert result.clean_exit(), 'expected clean exit'
525)         assert _result.stdout_bytes, 'expected program output'
526)         last_line = _result.stdout_bytes.splitlines(True)[-1]
527)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

533) 
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 weeks ago

537)             pytest.param(
538)                 {
539)                     'global': {'key': DUMMY_KEY1_B64},
540)                     'services': {},
541)                 },
542)                 ['--config', '-p'],
543)                 id='global',
544)             ),
545)             pytest.param(
546)                 {
547)                     'services': {
548)                         DUMMY_SERVICE: {
549)                             'key': DUMMY_KEY1_B64,
550)                             **DUMMY_CONFIG_SETTINGS,
551)                         },
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

552)                     },
553)                 },
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 3 weeks ago

554)                 ['--config', '-p', '--', DUMMY_SERVICE],
555)                 id='service',
556)             ),
557)             pytest.param(
558)                 {
559)                     'global': {'key': DUMMY_KEY1_B64},
560)                     'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()},
561)                 },
562)                 ['--config', '-p', '--', DUMMY_SERVICE],
563)                 id='service-over-global',
564)             ),
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

565)         ],
566)     )
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

568)         self,
569)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

577)             monkeypatch.setattr(
578)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
579)             )
580)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', tests.sign)
581)             runner = click.testing.CliRunner(mix_stderr=False)
582)             with tests.isolated_vault_config(
583)                 monkeypatch=monkeypatch,
584)                 runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

586)             ):
587)                 _result = runner.invoke(
588)                     cli.derivepassphrase_vault,
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

590)                     input=DUMMY_PASSPHRASE,
591)                     catch_exceptions=False,
592)                 )
593)         result = tests.ReadableResult.parse(_result)
594)         assert result.clean_exit(), 'expected clean exit'
595)         assert not result.output.strip(), 'expected no program output'
596)         assert result.stderr, 'expected known error output'
597)         err_lines = result.stderr.splitlines(False)
598)         assert err_lines[0].startswith('Passphrase:')
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 weeks ago

602)         ) or tests.warning_emitted(
603)             'Setting a global passphrase is ineffective ',
604)             caplog.record_tuples,
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

606)         assert all(map(is_warning_line, result.stderr.splitlines(True)))
607)         assert all(
608)             map(is_harmless_config_import_warning, caplog.record_tuples)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

609)         ), 'unexpected error output'
610) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

611)     @pytest.mark.parametrize(
612)         'option',
613)         [
614)             '--lower',
615)             '--upper',
616)             '--number',
617)             '--space',
618)             '--dash',
619)             '--symbol',
620)             '--repeat',
621)             '--length',
622)         ],
623)     )
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

628)         with tests.isolated_config(
629)             monkeypatch=monkeypatch,
630)             runner=runner,
631)         ):
632)             for value in '-42', 'invalid':
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

636)                     input=DUMMY_PASSPHRASE,
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.error_exit(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

643) 
644)     @pytest.mark.parametrize(
645)         ['options', 'service', 'input', 'check_success'],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

646)         [
647)             (o.options, o.needs_service, o.input, o.check_success)
648)             for o in INTERESTING_OPTION_COMBINATIONS
649)             if not o.incompatible
650)         ],
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

651)     )
652)     def test_211_service_needed(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

663)             monkeypatch=monkeypatch,
664)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

670)                 input=input,
671)                 catch_exceptions=False,
672)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

680)                 assert result.error_exit(
681)                     error=err_msg
682)                 ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

684)                 assert result.clean_exit(
685)                     empty_stderr=True
686)                 ), 'expected clean exit'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

689)                 monkeypatch=monkeypatch,
690)                 runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

692)             ):
693)                 monkeypatch.setattr(
694)                     cli, '_prompt_for_passphrase', tests.auto_prompt
695)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

699)                     input=input,
700)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 months ago

705)     def test_211a_empty_service_name_causes_warning(
706)         self,
707)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

710)         def is_expected_warning(record: tuple[str, int, str]) -> bool:
711)             return is_harmless_config_import_warning(
712)                 record
713)             ) or tests.warning_emitted(
714)                 'An empty SERVICE is not supported by vault(1)', [record]
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

715)             )
716) 
717)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
718)         runner = click.testing.CliRunner(mix_stderr=False)
719)         with tests.isolated_vault_config(
720)             monkeypatch=monkeypatch,
721)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

723)         ):
724)             _result = runner.invoke(
725)                 cli.derivepassphrase_vault,
726)                 ['--config', '--length=30', '--', ''],
727)                 catch_exceptions=False,
728)             )
729)             result = tests.ReadableResult.parse(_result)
730)             assert result.clean_exit(empty_stderr=False), 'expected clean exit'
731)             assert result.stderr is not None, 'expected known error output'
732)             assert all(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

734)             ), 'expected known error output'
735)             assert cli._load_config() == {
736)                 'global': {'length': 30},
737)                 'services': {},
738)             }, 'requested configuration change was not applied'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

740)             _result = runner.invoke(
741)                 cli.derivepassphrase_vault,
742)                 ['--import', '-'],
743)                 input=json.dumps({'services': {'': {'length': 40}}}),
744)                 catch_exceptions=False,
745)             )
746)             result = tests.ReadableResult.parse(_result)
747)             assert result.clean_exit(empty_stderr=False), 'expected clean exit'
748)             assert result.stderr is not None, 'expected known error output'
749)             assert all(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

751)             ), 'expected known error output'
752)             assert cli._load_config() == {
753)                 'global': {'length': 30},
754)                 'services': {'': {'length': 40}},
755)             }, 'requested configuration change was not applied'
756) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

759)         [
760)             (o.options, o.needs_service)
761)             for o in INTERESTING_OPTION_COMBINATIONS
762)             if o.incompatible
763)         ],
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

765)     def test_212_incompatible_options(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

772)         with tests.isolated_config(
773)             monkeypatch=monkeypatch,
774)             runner=runner,
775)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

779)                 input=DUMMY_PASSPHRASE,
780)                 catch_exceptions=False,
781)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

782)         result = tests.ReadableResult.parse(_result)
783)         assert result.error_exit(
784)             error='mutually exclusive with '
785)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

787)     @pytest.mark.parametrize(
788)         'config',
789)         [
790)             conf.config
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

792)             if tests.is_valid_test_config(conf)
793)         ],
794)     )
795)     def test_213_import_config_success(
796)         self,
797)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

799)         config: Any,
800)     ) -> None:
801)         runner = click.testing.CliRunner(mix_stderr=False)
802)         with tests.isolated_vault_config(
803)             monkeypatch=monkeypatch,
804)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

806)         ):
807)             _result = runner.invoke(
808)                 cli.derivepassphrase_vault,
809)                 ['--import', '-'],
810)                 input=json.dumps(config),
811)                 catch_exceptions=False,
812)             )
813)             with open(
814)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
815)             ) as infile:
816)                 config2 = json.load(infile)
817)         result = tests.ReadableResult.parse(_result)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

825)     @hypothesis.given(
826)         conf=tests.smudged_vault_test_config(
827)             strategies.sampled_from(TEST_CONFIGS).filter(
828)                 tests.is_valid_test_config
829)             )
830)         )
831)     )
832)     def test_213a_import_config_success(
833)         self,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

835)         conf: tests.VaultTestConfig,
836)     ) -> None:
837)         config = conf.config
838)         config2 = copy.deepcopy(config)
839)         _types.clean_up_falsy_vault_config_values(config2)
840)         runner = click.testing.CliRunner(mix_stderr=False)
841)         with tests.isolated_vault_config(
842)             monkeypatch=pytest.MonkeyPatch(),
843)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

845)         ):
846)             _result = runner.invoke(
847)                 cli.derivepassphrase_vault,
848)                 ['--import', '-'],
849)                 input=json.dumps(config),
850)                 catch_exceptions=False,
851)             )
852)             with open(
853)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
854)             ) as infile:
855)                 config3 = json.load(infile)
856)         result = tests.ReadableResult.parse(_result)
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

862) 
863)     def test_213b_import_bad_config_not_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

875)         result = tests.ReadableResult.parse(_result)
876)         assert result.error_exit(
877)             error='Invalid vault config'
878)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

880)     def test_213c_import_bad_config_not_json_data(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

892)         result = tests.ReadableResult.parse(_result)
893)         assert result.error_exit(
894)             error='cannot decode JSON'
895)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

897)     def test_213d_import_bad_config_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

917)         result = tests.ReadableResult.parse(_result)
918)         assert result.error_exit(
919)             error=os.strerror(errno.EISDIR)
920)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 weeks ago

922)     @pytest.mark.parametrize(
923)         'export_options',
924)         [
925)             [],
926)             ['--export-as=sh'],
927)         ],
928)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

929)     def test_214_export_settings_no_stored_settings(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 weeks ago

939)                 # Test parent context navigation by not calling
940)                 # `cli.derivepassphrase_vault` directly.  Used e.g. in
941)                 # the `--export-as=sh` section to autoconstruct the
942)                 # program name correctly.
943)                 cli.derivepassphrase,
944)                 ['vault', '--export', '-', *export_options],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 weeks ago

950)     @pytest.mark.parametrize(
951)         'export_options',
952)         [
953)             [],
954)             ['--export-as=sh'],
955)         ],
956)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

957)     def test_214a_export_settings_bad_stored_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 weeks ago

977)     @pytest.mark.parametrize(
978)         'export_options',
979)         [
980)             [],
981)             ['--export-as=sh'],
982)         ],
983)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

984)     def test_214b_export_settings_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 weeks ago

1005)     @pytest.mark.parametrize(
1006)         'export_options',
1007)         [
1008)             [],
1009)             ['--export-as=sh'],
1010)         ],
1011)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1012)     def test_214c_export_settings_target_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 weeks ago

1015)         export_options: list[str],
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)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 weeks ago

1031)     @pytest.mark.parametrize(
1032)         'export_options',
1033)         [
1034)             [],
1035)             ['--export-as=sh'],
1036)         ],
1037)     )
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

1038)     def test_214d_export_settings_settings_directory_not_a_directory(
1039)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1053)                 catch_exceptions=False,
1054)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1061) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1062)     def test_220_edit_notes_successfully(
1063)         self, monkeypatch: pytest.MonkeyPatch
1064)     ) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1066) 
1067) # - - - - - >8 - - - - - >8 - - - - - >8 - - - - - >8 - - - - -
1068) contents go here
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1072)             monkeypatch=monkeypatch,
1073)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1088)             assert config == {
1089)                 'global': {'phrase': 'abc'},
1090)                 'services': {'sv': {'notes': 'contents go here'}},
1091)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1092) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1093)     def test_221_edit_notes_noop(
1094)         self, monkeypatch: pytest.MonkeyPatch
1095)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1098)             monkeypatch=monkeypatch,
1099)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

1116)     def test_222_edit_notes_marker_removed(
1117)         self, monkeypatch: pytest.MonkeyPatch
1118)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1121)             monkeypatch=monkeypatch,
1122)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1137)             assert config == {
1138)                 'global': {'phrase': 'abc'},
1139)                 'services': {'sv': {'notes': 'long\ntext'}},
1140)             }
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)     def test_223_edit_notes_abort(
1143)         self, monkeypatch: pytest.MonkeyPatch
1144)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1147)             monkeypatch=monkeypatch,
1148)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1167)     @pytest.mark.parametrize(
1168)         ['command_line', 'input', 'result_config'],
1169)         [
1170)             (
1171)                 ['--phrase'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1173)                 {'global': {'phrase': 'my passphrase'}, 'services': {}},
1174)             ),
1175)             (
1176)                 ['--key'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

1178)                 {
1179)                     'global': {'key': DUMMY_KEY1_B64, 'phrase': 'abc'},
1180)                     'services': {},
1181)                 },
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1182)             ),
1183)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1186)                 {
1187)                     'global': {'phrase': 'abc'},
1188)                     'services': {'sv': {'phrase': 'my passphrase'}},
1189)                 },
1190)             ),
1191)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1194)                 {
1195)                     'global': {'phrase': 'abc'},
1196)                     'services': {'sv': {'key': DUMMY_KEY1_B64}},
1197)                 },
1198)             ),
1199)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1202)                 {
1203)                     'global': {'phrase': 'abc'},
1204)                     'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1205)                 },
1206)             ),
1207)         ],
1208)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1209)     def test_224_store_config_good(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1214)         result_config: Any,
1215)     ) -> None:
1216)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1218)             monkeypatch=monkeypatch,
1219)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

1221)         ):
1222)             monkeypatch.setattr(
1223)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1224)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1227)                 ['--config', *command_line],
1228)                 catch_exceptions=False,
1229)                 input=input,
1230)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1237)             assert (
1238)                 config == result_config
1239)             ), 'stored config does not match expectation'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1240) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1241)     @pytest.mark.parametrize(
1242)         ['command_line', 'input', 'err_text'],
1243)         [
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1244)             (
1245)                 [],
1246)                 '',
1247)                 'Cannot update global settings without any given settings',
1248)             ),
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 5 months ago

1256)         ],
1257)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1258)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1262)         input: str,
1263)         err_text: str,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1267)             monkeypatch=monkeypatch,
1268)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

1270)         ):
1271)             monkeypatch.setattr(
1272)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1273)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1276)                 ['--config', *command_line],
1277)                 catch_exceptions=False,
1278)                 input=input,
1279)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1280)         result = tests.ReadableResult.parse(_result)
1281)         assert result.error_exit(
1282)             error=err_text
1283)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1284) 
1285)     def test_225a_store_config_fail_manual_no_ssh_key_selection(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1291)             monkeypatch=monkeypatch,
1292)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1296) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

1297)             def raiser() -> None:
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1303)                 ['--key', '--config'],
1304)                 catch_exceptions=False,
1305)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1306)         result = tests.ReadableResult.parse(_result)
1307)         assert result.error_exit(
1308)             error=custom_error
1309)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

1311)     def test_225b_store_config_fail_manual_no_ssh_agent(
1312)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1319)             monkeypatch=monkeypatch,
1320)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1326)                 ['--key', '--config'],
1327)                 catch_exceptions=False,
1328)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1333) 
1334)     def test_225c_store_config_fail_manual_bad_ssh_agent_connection(
1335)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1340)             monkeypatch=monkeypatch,
1341)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1347)                 ['--key', '--config'],
1348)                 catch_exceptions=False,
1349)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1354) 
1355)     @pytest.mark.parametrize('try_race_free_implementation', [True, False])
1356)     def test_225d_store_config_fail_manual_read_only_file(
1357)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1359)         try_race_free_implementation: bool,
1360)     ) -> None:
1361)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1363)             monkeypatch=monkeypatch,
1364)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1366)         ):
1367)             tests.make_file_readonly(
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1369)                 try_race_free_implementation=try_race_free_implementation,
1370)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1374)                 catch_exceptions=False,
1375)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1380) 
1381)     def test_225e_store_config_fail_manual_custom_error(
1382)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1387)             monkeypatch=monkeypatch,
1388)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1390)         ):
1391)             custom_error = 'custom error message'
1392) 
1393)             def raiser(config: Any) -> None:
1394)                 del config
1395)                 raise RuntimeError(custom_error)
1396) 
1397)             monkeypatch.setattr(cli, '_save_config', raiser)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1401)                 catch_exceptions=False,
1402)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1403)         result = tests.ReadableResult.parse(_result)
1404)         assert result.error_exit(
1405)             error=custom_error
1406)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1407) 
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

1408)     def test_225f_store_config_fail_unset_and_set_same_settings(
1409)         self,
1410)         monkeypatch: pytest.MonkeyPatch,
1411)     ) -> None:
1412)         runner = click.testing.CliRunner(mix_stderr=False)
1413)         with tests.isolated_vault_config(
1414)             monkeypatch=monkeypatch,
1415)             runner=runner,
1416)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
1417)         ):
1418)             _result = runner.invoke(
1419)                 cli.derivepassphrase_vault,
1420)                 [
1421)                     '--config',
1422)                     '--unset=length',
1423)                     '--length=15',
1424)                     '--',
1425)                     DUMMY_SERVICE,
1426)                 ],
1427)                 catch_exceptions=False,
1428)             )
1429)         result = tests.ReadableResult.parse(_result)
1430)         assert result.error_exit(
1431)             error='Attempted to unset and set --length at the same time.'
1432)         ), 'expected error exit and known error message'
1433) 
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

1434)     def test_225g_store_config_fail_manual_ssh_agent_no_keys_loaded(
1435)         self,
1436)         monkeypatch: pytest.MonkeyPatch,
1437)         running_ssh_agent: tests.RunningSSHAgentInfo,
1438)     ) -> None:
1439)         del running_ssh_agent
1440)         runner = click.testing.CliRunner(mix_stderr=False)
1441)         with tests.isolated_vault_config(
1442)             monkeypatch=monkeypatch,
1443)             runner=runner,
1444)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
1445)         ):
1446)             def func(
1447)                 *_args: Any,
1448)                 **_kwargs: Any,
1449)             ) -> list[_types.KeyCommentPair]:
1450)                 return []
1451) 
1452)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'list_keys', func)
1453)             _result = runner.invoke(
1454)                 cli.derivepassphrase_vault,
1455)                 ['--key', '--config'],
1456)                 catch_exceptions=False,
1457)             )
1458)         result = tests.ReadableResult.parse(_result)
1459)         assert result.error_exit(
1460)             error='no keys suitable'
1461)         ), 'expected error exit and known error message'
1462) 
1463)     def test_225h_store_config_fail_manual_ssh_agent_runtime_error(
1464)         self,
1465)         monkeypatch: pytest.MonkeyPatch,
1466)         running_ssh_agent: tests.RunningSSHAgentInfo,
1467)     ) -> None:
1468)         del running_ssh_agent
1469)         runner = click.testing.CliRunner(mix_stderr=False)
1470)         with tests.isolated_vault_config(
1471)             monkeypatch=monkeypatch,
1472)             runner=runner,
1473)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
1474)         ):
1475)             def raiser(*_args: Any, **_kwargs: Any) -> None:
1476)                 raise ssh_agent.TrailingDataError()
1477) 
1478)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'list_keys', raiser)
1479)             _result = runner.invoke(
1480)                 cli.derivepassphrase_vault,
1481)                 ['--key', '--config'],
1482)                 catch_exceptions=False,
1483)             )
1484)         result = tests.ReadableResult.parse(_result)
1485)         assert result.error_exit(
1486)             error='violates the communications protocol.'
1487)         ), 'expected error exit and known error message'
1488) 
1489)     def test_225i_store_config_fail_manual_ssh_agent_refuses(
1490)         self,
1491)         monkeypatch: pytest.MonkeyPatch,
1492)         running_ssh_agent: tests.RunningSSHAgentInfo,
1493)     ) -> None:
1494)         del running_ssh_agent
1495)         runner = click.testing.CliRunner(mix_stderr=False)
1496)         with tests.isolated_vault_config(
1497)             monkeypatch=monkeypatch,
1498)             runner=runner,
1499)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
1500)         ):
1501)             def func(*_args: Any, **_kwargs: Any) -> NoReturn:
1502)                 raise ssh_agent.SSHAgentFailedError(
1503)                     _types.SSH_AGENT.FAILURE, b''
1504)                 )
1505) 
1506)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'list_keys', func)
1507)             _result = runner.invoke(
1508)                 cli.derivepassphrase_vault,
1509)                 ['--key', '--config'],
1510)                 catch_exceptions=False,
1511)             )
1512)         result = tests.ReadableResult.parse(_result)
1513)         assert result.error_exit(
1514)             error='refused to'
1515)         ), 'expected error exit and known error message'
1516) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1519)         with tests.isolated_config(
1520)             monkeypatch=monkeypatch,
1521)             runner=runner,
1522)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1530) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1531)     def test_226a_no_passphrase_or_key(
1532)         self, monkeypatch: pytest.MonkeyPatch
1533)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1535)         with tests.isolated_config(
1536)             monkeypatch=monkeypatch,
1537)             runner=runner,
1538)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1548) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1549)     def test_230_config_directory_nonexistant(
1550)         self, monkeypatch: pytest.MonkeyPatch
1551)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1553)         runner = click.testing.CliRunner(mix_stderr=False)
1554)         with tests.isolated_config(
1555)             monkeypatch=monkeypatch,
1556)             runner=runner,
1557)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1559)             os_makedirs_called = False
1560)             real_os_makedirs = os.makedirs
1561) 
1562)             def makedirs(*args: Any, **kwargs: Any) -> Any:
1563)                 nonlocal os_makedirs_called
1564)                 os_makedirs_called = True
1565)                 return real_os_makedirs(*args, **kwargs)
1566) 
1567)             monkeypatch.setattr(os, 'makedirs', makedirs)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1570)                 ['--config', '-p'],
1571)                 catch_exceptions=False,
1572)                 input='abc\n',
1573)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1583)                 config_readback = json.load(infile)
1584)             assert config_readback == {
1585)                 'global': {'phrase': 'abc'},
1586)                 'services': {},
1587)             }, 'config mismatch'
1588) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1589)     def test_230a_config_directory_not_a_file(
1590)         self, monkeypatch: pytest.MonkeyPatch
1591)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1593)         runner = click.testing.CliRunner(mix_stderr=False)
1594)         with tests.isolated_config(
1595)             monkeypatch=monkeypatch,
1596)             runner=runner,
1597)         ):
1598)             _save_config = cli._save_config
1599) 
1600)             def obstruct_config_saving(*args: Any, **kwargs: Any) -> Any:
1601)                 with contextlib.suppress(FileNotFoundError):
1602)                     shutil.rmtree('.derivepassphrase')
1603)                 with open(
1604)                     '.derivepassphrase', 'w', encoding='UTF-8'
1605)                 ) as outfile:
1606)                     print('Obstruction!!', file=outfile)
1607)                 monkeypatch.setattr(cli, '_save_config', _save_config)
1608)                 return _save_config(*args, **kwargs)
1609) 
1610)             monkeypatch.setattr(cli, '_save_config', obstruct_config_saving)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1613)                 ['--config', '-p'],
1614)                 catch_exceptions=False,
1615)                 input='abc\n',
1616)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1621) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1622)     def test_230b_store_config_custom_error(
1623)         self, monkeypatch: pytest.MonkeyPatch
1624)     ) -> None:
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1625)         runner = click.testing.CliRunner(mix_stderr=False)
1626)         with tests.isolated_config(
1627)             monkeypatch=monkeypatch,
1628)             runner=runner,
1629)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1632)             def raiser(config: Any) -> None:
1633)                 del config
1634)                 raise RuntimeError(custom_error)
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1639)                 ['--config', '-p'],
1640)                 catch_exceptions=False,
1641)                 input='abc\n',
1642)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1650)         [
1651)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1653)                 ['--import', '-'],
1654)                 json.dumps({
1655)                     'global': {'phrase': 'Du\u0308sseldorf'},
1656)                     'services': {},
1657)                 }),
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

1659)                 id='global-NFC',
1660)             ),
1661)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1663)                 ['--import', '-'],
1664)                 json.dumps({
1665)                     'services': {
1666)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1667)                         'weird entry name': {'phrase': 'Du\u0308sseldorf'},
1668)                     }
1669)                 }),
1670)                 (
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

1672)                     'is not NFC-normalized'
1673)                 ),
1674)                 id='service-weird-name-NFC',
1675)             ),
1676)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

1682)                     f'is not NFC-normalized'
1683)                 ),
1684)                 id='config-NFC',
1685)             ),
1686)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

1691)                 id='direct-input-NFC',
1692)             ),
1693)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1694)                 textwrap.dedent(r"""
1695)                 [vault]
1696)                 default-unicode-normalization-form = 'NFD'
1697)                 """),
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1698)                 ['--import', '-'],
1699)                 json.dumps({
1700)                     'global': {
1701)                         'phrase': 'D\u00fcsseldorf',
1702)                     },
1703)                     'services': {},
1704)                 }),
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

1706)                 id='global-NFD',
1707)             ),
1708)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1709)                 textwrap.dedent(r"""
1710)                 [vault]
1711)                 default-unicode-normalization-form = 'NFD'
1712)                 """),
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1713)                 ['--import', '-'],
1714)                 json.dumps({
1715)                     'services': {
1716)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1717)                         'weird entry name': {'phrase': 'D\u00fcsseldorf'},
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1719)                 }),
1720)                 (
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

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

Marco Ricci authored 4 months ago

1722)                     'is not NFD-normalized'
1723)                 ),
1724)                 id='service-weird-name-NFD',
1725)             ),
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1726)             pytest.param(
1727)                 textwrap.dedent(r"""
1728)                 [vault.unicode-normalization-form]
1729)                 'weird entry name 2' = 'NFKD'
1730)                 """),
1731)                 ['--import', '-'],
1732)                 json.dumps({
1733)                     'services': {
1734)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1735)                         'weird entry name 1': {'phrase': 'D\u00fcsseldorf'},
1736)                         'weird entry name 2': {'phrase': 'D\u00fcsseldorf'},
1737)                     },
1738)                 }),
1739)                 (
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

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

Marco Ricci authored 3 weeks ago

1741)                     'is not NFKD-normalized'
1742)                 ),
1743)                 id='service-weird-name-2-NFKD',
1744)             ),
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1745)         ],
1746)     )
1747)     def test_300_unicode_normalization_form_warning(
1748)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1758)             monkeypatch=monkeypatch,
1759)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1760)             vault_config={
1761)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1762)             },
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1768)                 catch_exceptions=False,
1769)                 input=input,
1770)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1776) 
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1777)     @pytest.mark.parametrize(
1778)         ['main_config', 'command_line', 'input', 'error_message'],
1779)         [
1780)             pytest.param(
1781)                 textwrap.dedent(r"""
1782)                 [vault]
1783)                 default-unicode-normalization-form = 'XXX'
1784)                 """),
1785)                 ['--import', '-'],
1786)                 json.dumps({
1787)                     'services': {
1788)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1789)                         'with_normalization': {'phrase': 'D\u00fcsseldorf'},
1790)                     },
1791)                 }),
1792)                 (
1793)                     "Invalid value 'XXX' for config key "
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 3 weeks ago

1795)                 ),
1796)                 id='global',
1797)             ),
1798)             pytest.param(
1799)                 textwrap.dedent(r"""
1800)                 [vault.unicode-normalization-form]
1801)                 with_normalization = 'XXX'
1802)                 """),
1803)                 ['--import', '-'],
1804)                 json.dumps({
1805)                     'services': {
1806)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1807)                         'with_normalization': {'phrase': 'D\u00fcsseldorf'},
1808)                     },
1809)                 }),
1810)                 (
1811)                     "Invalid value 'XXX' for config key "
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 3 weeks ago

1813)                 ),
1814)                 id='service',
1815)             ),
1816)         ],
1817)     )
1818)     def test_301_unicode_normalization_form_error(
1819)         self,
1820)         monkeypatch: pytest.MonkeyPatch,
1821)         main_config: str,
1822)         command_line: list[str],
1823)         input: str | None,
1824)         error_message: str,
1825)     ) -> None:
1826)         runner = click.testing.CliRunner(mix_stderr=False)
1827)         with tests.isolated_vault_config(
1828)             monkeypatch=monkeypatch,
1829)             runner=runner,
1830)             vault_config={
1831)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1832)             },
1833)             main_config_str=main_config,
1834)         ):
1835)             _result = runner.invoke(
1836)                 cli.derivepassphrase_vault,
1837)                 command_line,
1838)                 catch_exceptions=False,
1839)                 input=input,
1840)             )
1841)         result = tests.ReadableResult.parse(_result)
1842)         assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

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

Marco Ricci authored 3 weeks ago

1844)         ), 'expected error exit and known error message'
1845)         assert result.error_exit(
1846)             error=error_message
1847)         ), 'expected error exit and known error message'
1848) 
1849)     @pytest.mark.parametrize(
1850)         'command_line',
1851)         [
1852)             pytest.param(
1853)                 ['--config', '--phrase'],
1854)                 id='configure global passphrase',
1855)             ),
1856)             pytest.param(
1857)                 ['--phrase', '--', DUMMY_SERVICE],
1858)                 id='interactive passphrase',
1859)             ),
1860)         ],
1861)     )
1862)     def test_301a_unicode_normalization_form_error_from_stored_config(
1863)         self,
1864)         monkeypatch: pytest.MonkeyPatch,
1865)         command_line: list[str],
1866)     ) -> None:
1867)         runner = click.testing.CliRunner(mix_stderr=False)
1868)         with tests.isolated_vault_config(
1869)             monkeypatch=monkeypatch,
1870)             runner=runner,
1871)             vault_config={
1872)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1873)             },
1874)             main_config_str=textwrap.dedent("""
1875)             [vault]
1876)             default-unicode-normalization-form = 'XXX'
1877)             """),
1878)         ):
1879)             _result = runner.invoke(
1880)                 cli.derivepassphrase_vault,
1881)                 command_line,
1882)                 input=DUMMY_PASSPHRASE,
1883)                 catch_exceptions=False,
1884)             )
1885)             result = tests.ReadableResult.parse(_result)
1886)             assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

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

Marco Ricci authored 3 weeks ago

1888)             ), 'expected error exit and known error message'
1889)             assert result.error_exit(
1890)                 error=(
1891)                     "Invalid value 'XXX' for config key "
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 3 weeks ago

1893)                 ),
1894)             ), 'expected error exit and known error message'
1895) 
1896)     def test_310_bad_user_config_file(
1897)         self,
1898)         monkeypatch: pytest.MonkeyPatch,
1899)     ) -> None:
1900)         runner = click.testing.CliRunner(mix_stderr=False)
1901)         with tests.isolated_vault_config(
1902)             monkeypatch=monkeypatch,
1903)             runner=runner,
1904)             vault_config={'services': {}},
1905)             main_config_str=textwrap.dedent("""
1906)             This file is not valid TOML.
1907)             """),
1908)         ):
1909)             _result = runner.invoke(
1910)                 cli.derivepassphrase_vault,
1911)                 ['--phrase', '--', DUMMY_SERVICE],
1912)                 input=DUMMY_PASSPHRASE,
1913)                 catch_exceptions=False,
1914)             )
1915)             result = tests.ReadableResult.parse(_result)
1916)             assert result.error_exit(
1917)                 error='Cannot load user config:'
1918)             ), 'expected error exit and known error message'
1919) 
Marco Ricci Fail gracefully if UNIX dom...

Marco Ricci authored 3 months ago

1920)     def test_400_missing_af_unix_support(
1921)         self,
1922)         monkeypatch: pytest.MonkeyPatch,
1923)     ) -> None:
1924)         runner = click.testing.CliRunner(mix_stderr=False)
1925)         with tests.isolated_vault_config(
1926)             monkeypatch=monkeypatch,
1927)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

1929)         ):
1930)             monkeypatch.setenv(
1931)                 'SSH_AUTH_SOCK', "the value doesn't even matter"
1932)             )
1933)             monkeypatch.delattr(socket, 'AF_UNIX', raising=False)
1934)             _result = runner.invoke(
1935)                 cli.derivepassphrase_vault,
1936)                 ['--key', '--config'],
1937)                 catch_exceptions=False,
1938)             )
1939)         result = tests.ReadableResult.parse(_result)
1940)         assert result.error_exit(
1941)             error='does not support UNIX domain sockets'
1942)         ), 'expected error exit and known error message'
1943) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

1946)     @pytest.mark.parametrize(
1947)         'config',
1948)         [
1949)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1950)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1951)             {
1952)                 'global': {'phrase': 'abc'},
1953)                 'services': {'sv': {'phrase': 'my passphrase'}},
1954)             },
1955)             {
1956)                 'global': {'phrase': 'abc'},
1957)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1958)             },
1959)             {
1960)                 'global': {'phrase': 'abc'},
1961)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1962)             },
1963)         ],
1964)     )
1965)     def test_100_load_config(
1966)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1967)     ) -> None:
1968)         runner = click.testing.CliRunner()
1969)         with tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

1971)         ):
1972)             config_filename = cli._config_filename(subsystem='vault')
1973)             with open(config_filename, encoding='UTF-8') as fileobj:
1974)                 assert json.load(fileobj) == config
1975)             assert cli._load_config() == config
1976) 
1977)     def test_110_save_bad_config(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

1981)         # Use parenthesized context manager expressions here once Python
1982)         # 3.9 becomes unsupported.
1983)         with contextlib.ExitStack() as stack:
1984)             stack.enter_context(
1985)                 tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

1987)                 )
1988)             )
1989)             stack.enter_context(
1990)                 pytest.raises(ValueError, match='Invalid vault config')
1991)             )
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1993) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1999)             # from https://montypython.fandom.com/wiki/Spam#The_menu
2000)             items = items or [
2001)                 'Egg and bacon',
2002)                 'Egg, sausage and bacon',
2003)                 'Egg and spam',
2004)                 'Egg, bacon and spam',
2005)                 'Egg, bacon, sausage and spam',
2006)                 'Spam, bacon, sausage and spam',
2007)                 'Spam, egg, spam, spam, bacon and spam',
2008)                 'Spam, spam, spam, egg and spam',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2009)                 (
2010)                     'Spam, spam, spam, spam, spam, spam, baked beans, '
2011)                     'spam, spam, spam and spam'
2012)                 ),
2013)                 (
2014)                     'Lobster thermidor aux crevettes with a mornay sauce '
2015)                     'garnished with truffle paté, brandy '
2016)                     'and a fried egg on top and spam'
2017)                 ),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2018)             ]
2019)             index = cli._prompt_for_selection(items, heading=heading)
2020)             click.echo('A fine choice: ', nl=False)
2021)             click.echo(items[index])
2022)             click.echo('(Note: Vikings strictly optional.)')
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

2025)         _result = runner.invoke(driver, [], input='9')
2026)         result = tests.ReadableResult.parse(_result)
2027)         assert result.clean_exit(
2028)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2029) Our menu:
2030) [1] Egg and bacon
2031) [2] Egg, sausage and bacon
2032) [3] Egg and spam
2033) [4] Egg, bacon and spam
2034) [5] Egg, bacon, sausage and spam
2035) [6] Spam, bacon, sausage and spam
2036) [7] Spam, egg, spam, spam, bacon and spam
2037) [8] Spam, spam, spam, egg and spam
2038) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
2039) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
2040) Your selection? (1-10, leave empty to abort): 9
2041) A fine choice: Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
2042) (Note: Vikings strictly optional.)
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

2048)         result = tests.ReadableResult.parse(_result)
2049)         assert result.error_exit(
2050)             error=IndexError
2051)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

2053)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

2055) [1] Egg and bacon
2056) [2] Egg, sausage and bacon
2057) [3] Egg and spam
2058) [4] Egg, bacon and spam
2059) [5] Egg, bacon, sausage and spam
2060) [6] Spam, bacon, sausage and spam
2061) [7] Spam, egg, spam, spam, bacon and spam
2062) [8] Spam, spam, spam, egg and spam
2063) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
2064) [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

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

2068) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

2074)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2075)                 cli._prompt_for_selection(
2076)                     [item], heading='', single_choice_prompt=prompt
2077)                 )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

2088)         result = tests.ReadableResult.parse(_result)
2089)         assert result.clean_exit(
2090)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

2099)             input='',
2100)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2101)         result = tests.ReadableResult.parse(_result)
2102)         assert result.error_exit(
2103)             error=IndexError
2104)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

2106)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

2110) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

2113) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

2117)         monkeypatch.setattr(
2118)             click,
2119)             'prompt',
2120)             lambda *a, **kw: json.dumps({'args': a, 'kwargs': kw}),
2121)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

2123)         err_msg = 'missing arguments to passphrase prompt'
2124)         assert 'args' in res, err_msg
2125)         assert 'kwargs' in res, err_msg
2126)         assert res['args'][:1] == ['Passphrase'], err_msg
2127)         assert res['kwargs'].get('default') == '', err_msg
2128)         assert not res['kwargs'].get('show_default', True), err_msg
2129)         assert res['kwargs'].get('err'), err_msg
2130)         assert res['kwargs'].get('hide_input'), err_msg
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

2132)     def test_120_standard_logging_context_manager(
2133)         self,
2134)         caplog: pytest.LogCaptureFixture,
2135)         capsys: pytest.CaptureFixture[str],
2136)     ) -> None:
2137)         prog_name = cli.StandardCLILogging.prog_name
2138)         package_name = cli.StandardCLILogging.package_name
2139)         logger = logging.getLogger(package_name)
2140)         deprecation_logger = logging.getLogger(f'{package_name}.deprecation')
2141)         logging_cm = cli.StandardCLILogging.ensure_standard_logging()
2142)         with logging_cm:
2143)             assert (
2144)                 sum(
2145)                     1
2146)                     for h in logger.handlers
2147)                     if h is cli.StandardCLILogging.cli_handler
2148)                 )
2149)                 == 1
2150)             )
2151)             logger.warning('message 1')
2152)             with logging_cm:
2153)                 deprecation_logger.warning('message 2')
2154)                 assert (
2155)                     sum(
2156)                         1
2157)                         for h in logger.handlers
2158)                         if h is cli.StandardCLILogging.cli_handler
2159)                     )
2160)                     == 1
2161)                 )
2162)                 assert capsys.readouterr() == (
2163)                     '',
2164)                     (
2165)                         f'{prog_name}: Warning: message 1\n'
2166)                         f'{prog_name}: Deprecation warning: message 2\n'
2167)                     ),
2168)                 )
2169)             logger.warning('message 3')
2170)             assert (
2171)                 sum(
2172)                     1
2173)                     for h in logger.handlers
2174)                     if h is cli.StandardCLILogging.cli_handler
2175)                 )
2176)                 == 1
2177)             )
2178)             assert capsys.readouterr() == (
2179)                 '',
2180)                 f'{prog_name}: Warning: message 3\n',
2181)             )
2182)             assert caplog.record_tuples == [
2183)                 (package_name, logging.WARNING, 'message 1'),
2184)                 (f'{package_name}.deprecation', logging.WARNING, 'message 2'),
2185)                 (package_name, logging.WARNING, 'message 3'),
2186)             ]
2187) 
2188)     def test_121_standard_logging_warnings_context_manager(
2189)         self,
2190)         caplog: pytest.LogCaptureFixture,
2191)         capsys: pytest.CaptureFixture[str],
2192)     ) -> None:
2193)         warnings_cm = cli.StandardCLILogging.ensure_standard_warnings_logging()
2194)         THE_FUTURE = 'the future will be here sooner than you think'  # noqa: N806
2195)         JUST_TESTING = 'just testing whether warnings work'  # noqa: N806
2196)         with warnings_cm:
2197)             assert (
2198)                 sum(
2199)                     1
2200)                     for h in logging.getLogger('py.warnings').handlers
2201)                     if h is cli.StandardCLILogging.warnings_handler
2202)                 )
2203)                 == 1
2204)             )
2205)             warnings.warn(UserWarning(JUST_TESTING), stacklevel=1)
2206)             with warnings_cm:
2207)                 warnings.warn(FutureWarning(THE_FUTURE), stacklevel=1)
2208)                 _out, err = capsys.readouterr()
2209)                 err_lines = err.splitlines(True)
2210)                 assert any(
2211)                     f'UserWarning: {JUST_TESTING}' in line
2212)                     for line in err_lines
2213)                 )
2214)                 assert any(
2215)                     f'FutureWarning: {THE_FUTURE}' in line
2216)                     for line in err_lines
2217)                 )
2218)             warnings.warn(UserWarning(JUST_TESTING), stacklevel=1)
2219)             _out, err = capsys.readouterr()
2220)             err_lines = err.splitlines(True)
2221)             assert any(
2222)                 f'UserWarning: {JUST_TESTING}' in line for line in err_lines
2223)             )
2224)             assert not any(
2225)                 f'FutureWarning: {THE_FUTURE}' in line for line in err_lines
2226)             )
2227)             record_tuples = caplog.record_tuples
2228)             assert [tup[:2] for tup in record_tuples] == [
2229)                 ('py.warnings', logging.WARNING),
2230)                 ('py.warnings', logging.WARNING),
2231)                 ('py.warnings', logging.WARNING),
2232)             ]
2233)             assert f'UserWarning: {JUST_TESTING}' in record_tuples[0][2]
2234)             assert f'FutureWarning: {THE_FUTURE}' in record_tuples[1][2]
2235)             assert f'UserWarning: {JUST_TESTING}' in record_tuples[2][2]
2236) 
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

2237)     def _export_as_sh_helper(
2238)         self,
2239)         config: Any,
2240)     ) -> None:
2241)         prog_name_list = ('derivepassphrase', 'vault')
2242)         with io.StringIO() as outfile:
2243)             cli._print_config_as_sh_script(
2244)                 config, outfile=outfile, prog_name_list=prog_name_list
2245)             )
2246)             script = outfile.getvalue()
2247)         runner = click.testing.CliRunner(mix_stderr=False)
2248)         monkeypatch = pytest.MonkeyPatch()
2249)         with tests.isolated_vault_config(
2250)             runner=runner,
2251)             monkeypatch=monkeypatch,
2252)             vault_config={'services': {}},
2253)         ):
2254)             for _result in vault_config_exporter_shell_interpreter(script):
2255)                 result = tests.ReadableResult.parse(_result)
2256)                 assert result.clean_exit()
2257)             assert cli._load_config() == config
2258) 
2259)     @hypothesis.given(
2260)         global_config_settable=tests.vault_full_service_config(),
2261)         global_config_importable=strategies.fixed_dictionaries(
2262)             {},
2263)             optional={
2264)                 'key': strategies.text(
2265)                     alphabet=strategies.characters(
2266)                         min_codepoint=32,
2267)                         max_codepoint=126,
2268)                     ),
2269)                     max_size=128,
2270)                 ),
2271)                 'phrase': strategies.text(
2272)                     alphabet=strategies.characters(
2273)                         min_codepoint=32,
2274)                         max_codepoint=126,
2275)                     ),
2276)                     max_size=64,
2277)                 ),
2278)             },
2279)         ),
2280)     )
2281)     def test_130a_export_as_sh_global(
2282)         self,
2283)         global_config_settable: _types.VaultConfigServicesSettings,
2284)         global_config_importable: _types.VaultConfigServicesSettings,
2285)     ) -> None:
2286)         config: _types.VaultConfig = {
2287)             'global': global_config_settable | global_config_importable,
2288)             'services': {},
2289)         }
2290)         assert _types.clean_up_falsy_vault_config_values(config) is not None
2291)         assert _types.is_vault_config(config)
2292)         return self._export_as_sh_helper(config)
2293) 
2294)     @hypothesis.given(
2295)         global_config_importable=strategies.fixed_dictionaries(
2296)             {},
2297)             optional={
2298)                 'key': strategies.text(
2299)                     alphabet=strategies.characters(
2300)                         min_codepoint=32,
2301)                         max_codepoint=126,
2302)                     ),
2303)                     max_size=128,
2304)                 ),
2305)                 'phrase': strategies.text(
2306)                     alphabet=strategies.characters(
2307)                         min_codepoint=32,
2308)                         max_codepoint=126,
2309)                     ),
2310)                     max_size=64,
2311)                 ),
2312)             },
2313)         ),
2314)     )
2315)     def test_130b_export_as_sh_global_only_imports(
2316)         self,
2317)         global_config_importable: _types.VaultConfigServicesSettings,
2318)     ) -> None:
2319)         config: _types.VaultConfig = {
2320)             'global': global_config_importable,
2321)             'services': {},
2322)         }
2323)         assert _types.clean_up_falsy_vault_config_values(config) is not None
2324)         assert _types.is_vault_config(config)
2325)         if not config['global']:
2326)             config.pop('global')
2327)         return self._export_as_sh_helper(config)
2328) 
2329)     @hypothesis.given(
2330)         service_name=strategies.text(
2331)             alphabet=strategies.characters(
2332)                 min_codepoint=32,
2333)                 max_codepoint=126,
2334)             ),
2335)             min_size=4,
2336)             max_size=64,
2337)         ),
2338)         service_config_settable=tests.vault_full_service_config(),
2339)         service_config_importable=strategies.fixed_dictionaries(
2340)             {},
2341)             optional={
2342)                 'key': strategies.text(
2343)                     alphabet=strategies.characters(
2344)                         min_codepoint=32,
2345)                         max_codepoint=126,
2346)                     ),
2347)                     max_size=128,
2348)                 ),
2349)                 'phrase': strategies.text(
2350)                     alphabet=strategies.characters(
2351)                         min_codepoint=32,
2352)                         max_codepoint=126,
2353)                     ),
2354)                     max_size=64,
2355)                 ),
2356)                 'notes': strategies.text(
2357)                     alphabet=strategies.characters(
2358)                         min_codepoint=32,
2359)                         max_codepoint=126,
2360)                         include_characters=('\n', '\f', '\t'),
2361)                     ),
2362)                     max_size=256,
2363)                 ),
2364)             },
2365)         ),
2366)     )
2367)     def test_130c_export_as_sh_service(
2368)         self,
2369)         service_name: str,
2370)         service_config_settable: _types.VaultConfigServicesSettings,
2371)         service_config_importable: _types.VaultConfigServicesSettings,
2372)     ) -> None:
2373)         config: _types.VaultConfig = {
2374)             'services': {
2375)                 service_name: (
2376)                     service_config_settable | service_config_importable
2377)                 ),
2378)             },
2379)         }
2380)         assert _types.clean_up_falsy_vault_config_values(config) is not None
2381)         assert _types.is_vault_config(config)
2382)         return self._export_as_sh_helper(config)
2383) 
2384)     @hypothesis.given(
2385)         service_name=strategies.text(
2386)             alphabet=strategies.characters(
2387)                 min_codepoint=32,
2388)                 max_codepoint=126,
2389)             ),
2390)             min_size=4,
2391)             max_size=64,
2392)         ),
2393)         service_config_importable=strategies.fixed_dictionaries(
2394)             {},
2395)             optional={
2396)                 'key': strategies.text(
2397)                     alphabet=strategies.characters(
2398)                         min_codepoint=32,
2399)                         max_codepoint=126,
2400)                     ),
2401)                     max_size=128,
2402)                 ),
2403)                 'phrase': strategies.text(
2404)                     alphabet=strategies.characters(
2405)                         min_codepoint=32,
2406)                         max_codepoint=126,
2407)                     ),
2408)                     max_size=64,
2409)                 ),
2410)                 'notes': strategies.text(
2411)                     alphabet=strategies.characters(
2412)                         min_codepoint=32,
2413)                         max_codepoint=126,
2414)                         include_characters=('\n', '\f', '\t'),
2415)                     ),
2416)                     max_size=256,
2417)                 ),
2418)             },
2419)         ),
2420)     )
2421)     def test_130d_export_as_sh_service_only_imports(
2422)         self,
2423)         service_name: str,
2424)         service_config_importable: _types.VaultConfigServicesSettings,
2425)     ) -> None:
2426)         config: _types.VaultConfig = {
2427)             'services': {
2428)                 service_name: service_config_importable,
2429)             },
2430)         }
2431)         assert _types.clean_up_falsy_vault_config_values(config) is not None
2432)         assert _types.is_vault_config(config)
2433)         return self._export_as_sh_helper(config)
2434) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2435)     @pytest.mark.parametrize(
2436)         ['command_line', 'config', 'result_config'],
2437)         [
2438)             (
2439)                 ['--delete-globals'],
2440)                 {'global': {'phrase': 'abc'}, 'services': {}},
2441)                 {'services': {}},
2442)             ),
2443)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

2444)                 ['--delete', '--', DUMMY_SERVICE],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2445)                 {
2446)                     'global': {'phrase': 'abc'},
2447)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
2448)                 },
2449)                 {'global': {'phrase': 'abc'}, 'services': {}},
2450)             ),
2451)             (
2452)                 ['--clear'],
2453)                 {
2454)                     'global': {'phrase': 'abc'},
2455)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
2456)                 },
2457)                 {'services': {}},
2458)             ),
2459)         ],
2460)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2461)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

2464)         command_line: list[str],
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

2465)         config: _types.VaultConfig,
2466)         result_config: _types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2467)     ) -> None:
2468)         runner = click.testing.CliRunner(mix_stderr=False)
2469)         for start_config in [config, result_config]:
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

2471)                 monkeypatch=monkeypatch,
2472)                 runner=runner,
2473)                 vault_config=start_config,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

2476)                     cli.derivepassphrase_vault,
2477)                     command_line,
2478)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

2487)                     config_readback = json.load(infile)
2488)                 assert config_readback == result_config
2489) 
2490)     def test_204_phrase_from_key_manually(self) -> None:
2491)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

2492)             vault.Vault(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2493)                 phrase=DUMMY_PHRASE_FROM_KEY1, **DUMMY_CONFIG_SETTINGS
2494)             ).generate(DUMMY_SERVICE)
2495)             == DUMMY_RESULT_KEY1
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2496)         )
2497) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2498)     @pytest.mark.parametrize(
2499)         ['vfunc', 'input'],
2500)         [
2501)             (cli._validate_occurrence_constraint, 20),
2502)             (cli._validate_length, 20),
2503)         ],
2504)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2505)     def test_210a_validate_constraints_manually(
2506)         self,
2507)         vfunc: Callable[[click.Context, click.Parameter, Any], int | None],
2508)         input: int,
2509)     ) -> None:
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2510)         ctx = cli.derivepassphrase_vault.make_context(cli.PROG_NAME, [])
2511)         param = cli.derivepassphrase_vault.params[0]
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2512)         assert vfunc(ctx, param, input) == input
2513) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

2514)     @pytest.mark.parametrize('conn_hint', ['none', 'socket', 'client'])
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 6 months ago

2515)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

2518)         running_ssh_agent: tests.RunningSSHAgentInfo,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2519)         conn_hint: str,
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 6 months ago

2520)     ) -> None:
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2523)             monkeypatch.setattr(
2524)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
2525)             )
2526)             hint: ssh_agent.SSHAgentClient | socket.socket | None
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

2527)             # Use match/case here once Python 3.9 becomes unsupported.
2528)             if conn_hint == 'client':
2529)                 hint = ssh_agent.SSHAgentClient()
2530)             elif conn_hint == 'socket':
2531)                 hint = socket.socket(family=socket.AF_UNIX)
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

2532)                 hint.connect(running_ssh_agent.socket)
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

2533)             else:
2534)                 assert conn_hint == 'none'
2535)                 hint = None
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

2536)             exception: Exception | None = None
2537)             try:
2538)                 list(cli._get_suitable_ssh_keys(hint))
2539)             except RuntimeError:  # pragma: no cover
2540)                 pass
2541)             except Exception as e:  # noqa: BLE001 # pragma: no cover
2542)                 exception = e
2543)             finally:
2544)                 assert (
2545)                     exception is None
2546)                 ), 'exception querying suitable SSH keys'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2547) 
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2548)     def test_400_key_to_phrase(
2549)         self,
2550)         monkeypatch: pytest.MonkeyPatch,
2551)         skip_if_no_af_unix_support: None,
2552)         ssh_agent_client_with_test_keys_loaded: ssh_agent.SSHAgentClient,
2553)     ) -> None:
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2554)         class ErrCallback(BaseException):
2555)             def __init__(self, *args: Any, **kwargs: Any) -> None:
2556)                 super().__init__(*args[:1])
2557)                 self.args = args
2558)                 self.kwargs = kwargs
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2559) 
2560)         def err(*args: Any, **_kwargs: Any) -> NoReturn:
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2561)             raise ErrCallback(*args, **_kwargs)
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2562) 
2563)         def fail(*_args: Any, **_kwargs: Any) -> Any:
2564)             raise ssh_agent.SSHAgentFailedError(
2565)                 _types.SSH_AGENT.FAILURE.value,
2566)                 b'',
2567)             )
2568) 
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2569)         def fail_runtime(*_args: Any, **_kwargs: Any) -> Any:
2570)             raise ssh_agent.TrailingDataError()
2571) 
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2572)         del skip_if_no_af_unix_support
2573)         monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', fail)
2574)         loaded_keys = list(ssh_agent_client_with_test_keys_loaded.list_keys())
2575)         loaded_key = base64.standard_b64encode(loaded_keys[0][0])
2576)         with monkeypatch.context() as mp:
2577)             mp.setattr(
2578)                 ssh_agent.SSHAgentClient,
2579)                 'list_keys',
2580)                 lambda *_a, **_kw: [],
2581)             )
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2582)             with pytest.raises(ErrCallback, match='not loaded into the agent'):
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2583)                 cli._key_to_phrase(loaded_key, error_callback=err)
2584)         with monkeypatch.context() as mp:
2585)             mp.setattr(ssh_agent.SSHAgentClient, 'list_keys', fail)
2586)             with pytest.raises(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2587)                 ErrCallback, match='SSH agent failed to or refused to'
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2588)             ):
2589)                 cli._key_to_phrase(loaded_key, error_callback=err)
2590)         with monkeypatch.context() as mp:
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2591)             mp.setattr(ssh_agent.SSHAgentClient, 'list_keys', fail_runtime)
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2592)             with pytest.raises(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2593)                 ErrCallback, match='SSH agent failed to or refused to'
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2594)             ) as excinfo:
2595)                 cli._key_to_phrase(loaded_key, error_callback=err)
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2596)             assert excinfo.value.kwargs
2597)             assert isinstance(
2598)                 excinfo.value.kwargs['exc_info'],
2599)                 ssh_agent.SSHAgentFailedError,
2600)             )
2601)             assert excinfo.value.kwargs['exc_info'].__context__ is not None
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2602)             assert isinstance(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2603)                 excinfo.value.kwargs['exc_info'].__context__,
2604)                 ssh_agent.TrailingDataError,
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2605)             )
2606)         with monkeypatch.context() as mp:
2607)             mp.delenv('SSH_AUTH_SOCK', raising=True)
2608)             with pytest.raises(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2609)                 ErrCallback, match='Cannot find any running SSH agent'
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2610)             ):
2611)                 cli._key_to_phrase(loaded_key, error_callback=err)
2612)         with monkeypatch.context() as mp:
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

2613)             mp.setenv('SSH_AUTH_SOCK', os.environ['SSH_AUTH_SOCK'] + '~')
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2614)             with pytest.raises(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2615)                 ErrCallback, match='Cannot connect to the SSH agent'
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2616)             ):
2617)                 cli._key_to_phrase(loaded_key, error_callback=err)
2618)         with monkeypatch.context() as mp:
2619)             mp.delattr(socket, 'AF_UNIX', raising=True)
2620)             with pytest.raises(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2621)                 ErrCallback, match='does not support UNIX domain sockets'
2622)             ):
2623)                 cli._key_to_phrase(loaded_key, error_callback=err)
2624)         with monkeypatch.context() as mp:
2625)             mp.setattr(ssh_agent.SSHAgentClient, 'sign', fail_runtime)
2626)             with pytest.raises(
2627)                 ErrCallback, match='violates the communications protocol'
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2628)             ):
2629)                 cli._key_to_phrase(loaded_key, error_callback=err)
2630) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2631) 
2632) class TestCLITransition:
2633)     def test_100_help_output(self, monkeypatch: pytest.MonkeyPatch) -> None:
2634)         runner = click.testing.CliRunner(mix_stderr=False)
2635)         with tests.isolated_config(
2636)             monkeypatch=monkeypatch,
2637)             runner=runner,
2638)         ):
2639)             _result = runner.invoke(
2640)                 cli.derivepassphrase, ['--help'], catch_exceptions=False
2641)             )
2642)             result = tests.ReadableResult.parse(_result)
2643)         assert result.clean_exit(
2644)             empty_stderr=True, output='currently implemented subcommands'
2645)         ), 'expected clean exit, and known help text'
2646) 
2647)     def test_101_help_output_export(
2648)         self, monkeypatch: pytest.MonkeyPatch
2649)     ) -> None:
2650)         runner = click.testing.CliRunner(mix_stderr=False)
2651)         with tests.isolated_config(
2652)             monkeypatch=monkeypatch,
2653)             runner=runner,
2654)         ):
2655)             _result = runner.invoke(
2656)                 cli.derivepassphrase,
2657)                 ['export', '--help'],
2658)                 catch_exceptions=False,
2659)             )
2660)             result = tests.ReadableResult.parse(_result)
2661)         assert result.clean_exit(
2662)             empty_stderr=True, output='only available subcommand'
2663)         ), 'expected clean exit, and known help text'
2664) 
2665)     def test_102_help_output_export_vault(
2666)         self, monkeypatch: pytest.MonkeyPatch
2667)     ) -> None:
2668)         runner = click.testing.CliRunner(mix_stderr=False)
2669)         with tests.isolated_config(
2670)             monkeypatch=monkeypatch,
2671)             runner=runner,
2672)         ):
2673)             _result = runner.invoke(
2674)                 cli.derivepassphrase,
2675)                 ['export', 'vault', '--help'],
2676)                 catch_exceptions=False,
2677)             )
2678)             result = tests.ReadableResult.parse(_result)
2679)         assert result.clean_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2680)             empty_stderr=True, output='Export a vault-native configuration'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2681)         ), 'expected clean exit, and known help text'
2682) 
2683)     def test_103_help_output_vault(
2684)         self, monkeypatch: pytest.MonkeyPatch
2685)     ) -> None:
2686)         runner = click.testing.CliRunner(mix_stderr=False)
2687)         with tests.isolated_config(
2688)             monkeypatch=monkeypatch,
2689)             runner=runner,
2690)         ):
2691)             _result = runner.invoke(
2692)                 cli.derivepassphrase,
2693)                 ['vault', '--help'],
2694)                 catch_exceptions=False,
2695)             )
2696)             result = tests.ReadableResult.parse(_result)
2697)         assert result.clean_exit(
Marco Ricci Add an actual derivepassphr...

Marco Ricci authored 2 weeks ago

2698)             empty_stderr=True, output='Passphrase generation:\n'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 week ago

2701)             empty_stderr=True, output='Use $VISUAL or $EDITOR to configure'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2702)         ), 'expected clean exit, and option group epilog in help text'
2703) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2704)     @pytest.mark.parametrize(
2705)         'config',
2706)         [
2707)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2708)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2709)             {
2710)                 'global': {'phrase': 'abc'},
2711)                 'services': {'sv': {'phrase': 'my passphrase'}},
2712)             },
2713)             {
2714)                 'global': {'phrase': 'abc'},
2715)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2716)             },
2717)             {
2718)                 'global': {'phrase': 'abc'},
2719)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2720)             },
2721)         ],
2722)     )
2723)     def test_110_load_config_backup(
2724)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2725)     ) -> None:
2726)         runner = click.testing.CliRunner()
2727)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2728)             config_filename = cli._config_filename(
2729)                 subsystem='old settings.json'
2730)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2731)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2732)                 print(json.dumps(config, indent=2), file=fileobj)
2733)             assert cli._migrate_and_load_old_config()[0] == config
2734) 
2735)     @pytest.mark.parametrize(
2736)         'config',
2737)         [
2738)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2739)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2740)             {
2741)                 'global': {'phrase': 'abc'},
2742)                 'services': {'sv': {'phrase': 'my passphrase'}},
2743)             },
2744)             {
2745)                 'global': {'phrase': 'abc'},
2746)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2747)             },
2748)             {
2749)                 'global': {'phrase': 'abc'},
2750)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2751)             },
2752)         ],
2753)     )
2754)     def test_111_migrate_config(
2755)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2756)     ) -> None:
2757)         runner = click.testing.CliRunner()
2758)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2759)             config_filename = cli._config_filename(
2760)                 subsystem='old settings.json'
2761)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2762)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2763)                 print(json.dumps(config, indent=2), file=fileobj)
2764)             assert cli._migrate_and_load_old_config() == (config, None)
2765) 
2766)     @pytest.mark.parametrize(
2767)         'config',
2768)         [
2769)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2770)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2771)             {
2772)                 'global': {'phrase': 'abc'},
2773)                 'services': {'sv': {'phrase': 'my passphrase'}},
2774)             },
2775)             {
2776)                 'global': {'phrase': 'abc'},
2777)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2778)             },
2779)             {
2780)                 'global': {'phrase': 'abc'},
2781)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2782)             },
2783)         ],
2784)     )
2785)     def test_112_migrate_config_error(
2786)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2787)     ) -> None:
2788)         runner = click.testing.CliRunner()
2789)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2790)             config_filename = cli._config_filename(
2791)                 subsystem='old settings.json'
2792)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2793)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2794)                 print(json.dumps(config, indent=2), file=fileobj)
2795)             os.mkdir(cli._config_filename(subsystem='vault'))
2796)             config2, err = cli._migrate_and_load_old_config()
2797)             assert config2 == config
2798)             assert isinstance(err, OSError)
2799)             assert err.errno == errno.EISDIR
2800) 
2801)     @pytest.mark.parametrize(
2802)         'config',
2803)         [
2804)             {'global': '', 'services': {}},
2805)             {'global': 0, 'services': {}},
2806)             {
2807)                 'global': {'phrase': 'abc'},
2808)                 'services': False,
2809)             },
2810)             {
2811)                 'global': {'phrase': 'abc'},
2812)                 'services': True,
2813)             },
2814)             {
2815)                 'global': {'phrase': 'abc'},
2816)                 'services': None,
2817)             },
2818)         ],
2819)     )
2820)     def test_113_migrate_config_error_bad_config_value(
2821)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2822)     ) -> None:
2823)         runner = click.testing.CliRunner()
2824)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2825)             config_filename = cli._config_filename(
2826)                 subsystem='old settings.json'
2827)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2828)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2829)                 print(json.dumps(config, indent=2), file=fileobj)
2830)             with pytest.raises(ValueError, match=cli._INVALID_VAULT_CONFIG):
2831)                 cli._migrate_and_load_old_config()
2832) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2833)     def test_200_forward_export_vault_path_parameter(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2834)         self,
2835)         monkeypatch: pytest.MonkeyPatch,
2836)         caplog: pytest.LogCaptureFixture,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2837)     ) -> None:
2838)         pytest.importorskip('cryptography', minversion='38.0')
2839)         runner = click.testing.CliRunner(mix_stderr=False)
2840)         with tests.isolated_vault_exporter_config(
2841)             monkeypatch=monkeypatch,
2842)             runner=runner,
2843)             vault_config=tests.VAULT_V03_CONFIG,
2844)             vault_key=tests.VAULT_MASTER_KEY,
2845)         ):
2846)             monkeypatch.setenv('VAULT_KEY', tests.VAULT_MASTER_KEY)
2847)             _result = runner.invoke(
2848)                 cli.derivepassphrase,
2849)                 ['export', 'VAULT_PATH'],
2850)             )
2851)         result = tests.ReadableResult.parse(_result)
2852)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2853)         assert tests.deprecation_warning_emitted(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2854)             '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

2855)         )
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2856)         assert tests.deprecation_warning_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2857)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

2858)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2859)         assert json.loads(result.output) == tests.VAULT_V03_CONFIG_DATA
2860) 
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2861)     def test_201_forward_export_vault_empty_commandline(
2862)         self,
2863)         monkeypatch: pytest.MonkeyPatch,
2864)         caplog: pytest.LogCaptureFixture,
2865)     ) -> None:
2866)         pytest.importorskip('cryptography', minversion='38.0')
2867)         runner = click.testing.CliRunner(mix_stderr=False)
2868)         with tests.isolated_config(
2869)             monkeypatch=monkeypatch,
2870)             runner=runner,
2871)         ):
2872)             _result = runner.invoke(
2873)                 cli.derivepassphrase,
2874)                 ['export'],
2875)             )
2876)         result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2877)         assert tests.deprecation_warning_emitted(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2878)             '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

2879)         )
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2880)         assert tests.deprecation_warning_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2881)             'Defaulting to subcommand "vault"', caplog.record_tuples
2882)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2883)         assert result.error_exit(
2884)             error="Missing argument 'PATH'"
2885)         ), 'expected error exit and known error type'
2886) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2887)     @pytest.mark.parametrize(
2888)         'charset_name', ['lower', 'upper', 'number', 'space', 'dash', 'symbol']
2889)     )
2890)     def test_210_forward_vault_disable_character_set(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2891)         self,
2892)         monkeypatch: pytest.MonkeyPatch,
2893)         caplog: pytest.LogCaptureFixture,
2894)         charset_name: str,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

2898)         charset = vault.Vault._CHARSETS[charset_name].decode('ascii')
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2899)         runner = click.testing.CliRunner(mix_stderr=False)
2900)         with tests.isolated_config(
2901)             monkeypatch=monkeypatch,
2902)             runner=runner,
2903)         ):
2904)             _result = runner.invoke(
2905)                 cli.derivepassphrase,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

2906)                 [option, '0', '-p', '--', DUMMY_SERVICE],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2907)                 input=DUMMY_PASSPHRASE,
2908)                 catch_exceptions=False,
2909)             )
2910)             result = tests.ReadableResult.parse(_result)
2911)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2912)         assert tests.deprecation_warning_emitted(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2913)             '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

2914)         )
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2915)         assert tests.deprecation_warning_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2916)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

2917)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2918)         for c in charset:
2919)             assert (
2920)                 c not in result.output
2921)             ), f'derived password contains forbidden character {c!r}'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2922) 
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2923)     def test_211_forward_vault_empty_command_line(
2924)         self,
2925)         monkeypatch: pytest.MonkeyPatch,
2926)         caplog: pytest.LogCaptureFixture,
2927)     ) -> None:
2928)         runner = click.testing.CliRunner(mix_stderr=False)
2929)         with tests.isolated_config(
2930)             monkeypatch=monkeypatch,
2931)             runner=runner,
2932)         ):
2933)             _result = runner.invoke(
2934)                 cli.derivepassphrase,
2935)                 [],
2936)                 input=DUMMY_PASSPHRASE,
2937)                 catch_exceptions=False,
2938)             )
2939)             result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2940)         assert tests.deprecation_warning_emitted(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2941)             '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

2942)         )
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2943)         assert tests.deprecation_warning_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2944)             'Defaulting to subcommand "vault"', caplog.record_tuples
2945)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2946)         assert result.error_exit(
Marco Ricci Update the CLI to use the t...

Marco Ricci authored 1 week ago

2947)             error='Deriving a passphrase requires a SERVICE.'
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2948)         ), 'expected error exit and known error type'
2949) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2950)     def test_300_export_using_old_config_file(
2951)         self,
2952)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2953)         caplog: pytest.LogCaptureFixture,
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

2955)         caplog.set_level(logging.INFO)
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2956)         runner = click.testing.CliRunner(mix_stderr=False)
2957)         with tests.isolated_config(
2958)             monkeypatch=monkeypatch,
2959)             runner=runner,
2960)         ):
2961)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2962)                 cli._config_filename(subsystem='old settings.json'),
2963)                 'w',
2964)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2965)             ) as fileobj:
2966)                 print(
2967)                     json.dumps(
2968)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
2969)                         indent=2,
2970)                     ),
2971)                     file=fileobj,
2972)                 )
2973)             _result = runner.invoke(
2974)                 cli.derivepassphrase_vault,
2975)                 ['--export', '-'],
2976)                 catch_exceptions=False,
2977)             )
2978)         result = tests.ReadableResult.parse(_result)
2979)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2980)         assert tests.deprecation_warning_emitted(
2981)             'v0.1-style config file', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2982)         ), 'expected known warning message in stderr'
Marco Ricci Fix usage of `--debug`, `--...

Marco Ricci authored 3 weeks ago

2983)         assert tests.deprecation_info_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2984)             'Successfully migrated to ', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2985)         ), 'expected known warning message in stderr'
2986) 
2987)     def test_300a_export_using_old_config_file_migration_error(
2988)         self,
2989)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2990)         caplog: pytest.LogCaptureFixture,
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2991)     ) -> None:
2992)         runner = click.testing.CliRunner(mix_stderr=False)
2993)         with tests.isolated_config(
2994)             monkeypatch=monkeypatch,
2995)             runner=runner,
2996)         ):
2997)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2998)                 cli._config_filename(subsystem='old settings.json'),
2999)                 'w',
3000)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3001)             ) as fileobj:
3002)                 print(
3003)                     json.dumps(
3004)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
3005)                         indent=2,
3006)                     ),
3007)                     file=fileobj,
3008)                 )
3009) 
3010)             def raiser(*_args: Any, **_kwargs: Any) -> None:
3011)                 raise OSError(
3012)                     errno.EACCES,
3013)                     os.strerror(errno.EACCES),
3014)                     cli._config_filename(subsystem='vault'),
3015)                 )
3016) 
3017)             monkeypatch.setattr(os, 'replace', raiser)
3018)             _result = runner.invoke(
3019)                 cli.derivepassphrase_vault,
3020)                 ['--export', '-'],
3021)                 catch_exceptions=False,
3022)             )
3023)         result = tests.ReadableResult.parse(_result)
3024)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

3025)         assert tests.deprecation_warning_emitted(
3026)             'v0.1-style config file', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

3028)         assert tests.warning_emitted(
3029)             'Failed to migrate to ', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

3030)         ), 'expected known warning message in stderr'
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3031) 
3032) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3033) _known_services = (DUMMY_SERVICE, 'email', 'bank', 'work')
3034) _valid_properties = (
3035)     'length',
3036)     'repeat',
3037)     'upper',
3038)     'lower',
3039)     'number',
3040)     'space',
3041)     'dash',
3042)     'symbol',
3043) )
3044) 
3045) 
3046) def _build_reduced_vault_config_settings(
3047)     config: _types.VaultConfigServicesSettings,
3048)     keys_to_purge: frozenset[str],
3049) ) -> _types.VaultConfigServicesSettings:
3050)     config2 = copy.deepcopy(config)
3051)     for key in keys_to_purge:
3052)         config2.pop(key, None)  # type: ignore[misc]
3053)     return config2
3054) 
3055) 
3056) _services_strategy = strategies.builds(
3057)     _build_reduced_vault_config_settings,
3058)     tests.vault_full_service_config(),
3059)     strategies.sets(
3060)         strategies.sampled_from(_valid_properties),
3061)         max_size=7,
3062)     ),
3063) )
3064) 
3065) 
3066) def _assemble_config(
3067)     global_data: _types.VaultConfigGlobalSettings,
3068)     service_data: list[tuple[str, _types.VaultConfigServicesSettings]],
3069) ) -> _types.VaultConfig:
3070)     services_dict = dict(service_data)
3071)     return (
3072)         {'global': global_data, 'services': services_dict}
3073)         if global_data
3074)         else {'services': services_dict}
3075)     )
3076) 
3077) 
3078) @strategies.composite
3079) def _draw_service_name_and_data(
3080)     draw: hypothesis.strategies.DrawFn,
3081)     num_entries: int,
3082) ) -> tuple[tuple[str, _types.VaultConfigServicesSettings], ...]:
3083)     possible_services = list(_known_services)
3084)     selected_services: list[str] = []
3085)     for _ in range(num_entries):
3086)         selected_services.append(
3087)             draw(strategies.sampled_from(possible_services))
3088)         )
3089)         possible_services.remove(selected_services[-1])
3090)     return tuple(
3091)         (service, draw(_services_strategy)) for service in selected_services
3092)     )
3093) 
3094) 
3095) _vault_full_config = strategies.builds(
3096)     _assemble_config,
3097)     _services_strategy,
3098)     strategies.integers(
3099)         min_value=2,
3100)         max_value=4,
3101)     ).flatmap(_draw_service_name_and_data),
3102) )
3103) 
3104) 
Marco Ricci Actually correctly implemen...

Marco Ricci authored 4 weeks ago

3105) @tests.hypothesis_settings_coverage_compatible
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3106) class ConfigManagementStateMachine(stateful.RuleBasedStateMachine):
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3107)     def __init__(self) -> None:
3108)         super().__init__()
3109)         self.runner = click.testing.CliRunner(mix_stderr=False)
3110)         self.exit_stack = contextlib.ExitStack().__enter__()
3111)         self.monkeypatch = self.exit_stack.enter_context(
3112)             pytest.MonkeyPatch().context()
3113)         )
3114)         self.isolated_config = self.exit_stack.enter_context(
3115)             tests.isolated_vault_config(
3116)                 monkeypatch=self.monkeypatch,
3117)                 runner=self.runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

3118)                 vault_config={'services': {}},
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3119)             )
3120)         )
3121) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3122)     setting = stateful.Bundle('setting')
3123)     configuration = stateful.Bundle('configuration')
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3124) 
3125)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3126)         target=configuration,
3127)         configs=strategies.lists(
3128)             _vault_full_config,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3129)             min_size=8,
3130)             max_size=8,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3131)         ),
3132)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3133)     def declare_initial_configs(
3134)         self,
3135)         configs: Iterable[_types.VaultConfig],
3136)     ) -> Iterable[_types.VaultConfig]:
3137)         return stateful.multiple(*configs)
Marco Ricci Test config merging with pa...

Marco Ricci authored 4 weeks ago

3138) 
3139)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3140)         target=setting,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3141)         configs=strategies.lists(
3142)             _vault_full_config,
3143)             min_size=4,
3144)             max_size=4,
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

3145)         ),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3146)     )
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3147)     def extract_initial_settings(
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3148)         self,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3149)         configs: list[_types.VaultConfig],
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3150)     ) -> Iterable[_types.VaultConfigServicesSettings]:
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3151)         settings: list[_types.VaultConfigServicesSettings] = []
3152)         for c in configs:
3153)             settings.extend(c['services'].values())
3154)         return stateful.multiple(*map(copy.deepcopy, settings))
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3155) 
3156)     @staticmethod
3157)     def fold_configs(
3158)         c1: _types.VaultConfig, c2: _types.VaultConfig
3159)     ) -> _types.VaultConfig:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3160)         """Fold `c1` into `c2`, overriding the latter."""
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3161)         new_global_dict = c1.get('global', c2.get('global'))
3162)         if new_global_dict is not None:
3163)             return {
3164)                 'global': new_global_dict,
3165)                 'services': {**c2['services'], **c1['services']},
3166)             }
3167)         return {
3168)             'services': {**c2['services'], **c1['services']},
3169)         }
3170) 
3171)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3172)         target=configuration,
3173)         config=configuration,
3174)         setting=setting.filter(bool),
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3175)         maybe_unset=strategies.sets(
3176)             strategies.sampled_from(_valid_properties),
3177)             max_size=3,
3178)         ),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3179)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3180)     )
3181)     def set_globals(
3182)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3183)         config: _types.VaultConfig,
3184)         setting: _types.VaultConfigGlobalSettings,
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3185)         maybe_unset: set[str],
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3186)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3187)     ) -> _types.VaultConfig:
3188)         cli._save_config(config)
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3189)         config_global = config.get('global', {})
3190)         maybe_unset = set(maybe_unset) - setting.keys()
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3191)         if overwrite:
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3192)             config['global'] = config_global = {}
3193)         elif maybe_unset:
3194)             for key in maybe_unset:
3195)                 config_global.pop(key, None)  # type: ignore[misc]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3196)         config.setdefault('global', {}).update(setting)
3197)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3198)         # NOTE: This relies on settings_obj containing only the keys
3199)         # "length", "repeat", "upper", "lower", "number", "space",
3200)         # "dash" and "symbol".
3201)         _result = self.runner.invoke(
3202)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3203)             [
3204)                 '--config',
3205)                 '--overwrite-existing' if overwrite else '--merge-existing',
3206)             ]
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3207)             + [f'--unset={key}' for key in maybe_unset]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3208)             + [
3209)                 f'--{key}={value}'
3210)                 for key, value in setting.items()
3211)                 if key in _valid_properties
3212)             ],
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3213)             catch_exceptions=False,
3214)         )
3215)         result = tests.ReadableResult.parse(_result)
3216)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3217)         assert cli._load_config() == config
3218)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3219) 
3220)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3221)         target=configuration,
3222)         config=configuration,
3223)         service=strategies.sampled_from(_known_services),
3224)         setting=setting.filter(bool),
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3225)         maybe_unset=strategies.sets(
3226)             strategies.sampled_from(_valid_properties),
3227)             max_size=3,
3228)         ),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3229)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3230)     )
3231)     def set_service(
3232)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3233)         config: _types.VaultConfig,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3234)         service: str,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3235)         setting: _types.VaultConfigServicesSettings,
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3236)         maybe_unset: set[str],
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3237)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3238)     ) -> _types.VaultConfig:
3239)         cli._save_config(config)
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3240)         config_service = config['services'].get(service, {})
3241)         maybe_unset = set(maybe_unset) - setting.keys()
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3242)         if overwrite:
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3243)             config['services'][service] = config_service = {}
3244)         elif maybe_unset:
3245)             for key in maybe_unset:
3246)                 config_service.pop(key, None)  # type: ignore[misc]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3247)         config['services'].setdefault(service, {}).update(setting)
3248)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3249)         # NOTE: This relies on settings_obj containing only the keys
3250)         # "length", "repeat", "upper", "lower", "number", "space",
3251)         # "dash" and "symbol".
3252)         _result = self.runner.invoke(
3253)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3254)             [
3255)                 '--config',
3256)                 '--overwrite-existing' if overwrite else '--merge-existing',
3257)             ]
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3258)             + [f'--unset={key}' for key in maybe_unset]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3259)             + [
3260)                 f'--{key}={value}'
3261)                 for key, value in setting.items()
3262)                 if key in _valid_properties
3263)             ]
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3264)             + ['--', service],
3265)             catch_exceptions=False,
3266)         )
3267)         result = tests.ReadableResult.parse(_result)
3268)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3269)         assert cli._load_config() == config
3270)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3271) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3272)     @stateful.rule(
3273)         target=configuration,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3274)         config=configuration,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3275)     )
3276)     def purge_global(
3277)         self,
3278)         config: _types.VaultConfig,
3279)     ) -> _types.VaultConfig:
3280)         cli._save_config(config)
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3281)         config.pop('global', None)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3282)         _result = self.runner.invoke(
3283)             cli.derivepassphrase_vault,
3284)             ['--delete-globals'],
3285)             input='y',
3286)             catch_exceptions=False,
3287)         )
3288)         result = tests.ReadableResult.parse(_result)
3289)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3290)         assert cli._load_config() == config
3291)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3292) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3293)     @stateful.rule(
3294)         target=configuration,
3295)         config_and_service=configuration.filter(
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3296)             lambda c: bool(c['services'])
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3297)         ).flatmap(
3298)             lambda c: strategies.tuples(
3299)                 strategies.just(c),
3300)                 strategies.sampled_from(tuple(c['services'].keys())),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3301)             )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3302)         ),
3303)     )
3304)     def purge_service(
3305)         self,
3306)         config_and_service: tuple[_types.VaultConfig, str],
3307)     ) -> _types.VaultConfig:
3308)         config, service = config_and_service
3309)         cli._save_config(config)
3310)         config['services'].pop(service, None)
3311)         _result = self.runner.invoke(
3312)             cli.derivepassphrase_vault,
3313)             ['--delete', '--', service],
3314)             input='y',
3315)             catch_exceptions=False,
3316)         )
3317)         result = tests.ReadableResult.parse(_result)
3318)         assert result.clean_exit(empty_stderr=False)
3319)         assert cli._load_config() == config
3320)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3321) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3322)     @stateful.rule(
3323)         target=configuration,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3324)         config=configuration,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3325)     )
3326)     def purge_all(
3327)         self,
3328)         config: _types.VaultConfig,
3329)     ) -> _types.VaultConfig:
3330)         cli._save_config(config)
3331)         config = {'services': {}}
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3332)         _result = self.runner.invoke(
3333)             cli.derivepassphrase_vault,
3334)             ['--clear'],
3335)             input='y',
3336)             catch_exceptions=False,
3337)         )
3338)         result = tests.ReadableResult.parse(_result)
3339)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3340)         assert cli._load_config() == config
3341)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3342) 
3343)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3344)         target=configuration,
3345)         base_config=configuration,
3346)         config_to_import=configuration,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3347)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3348)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3349)     def import_configuration(
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3350)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3351)         base_config: _types.VaultConfig,
3352)         config_to_import: _types.VaultConfig,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3353)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3354)     ) -> _types.VaultConfig:
3355)         cli._save_config(base_config)
3356)         config = (
3357)             self.fold_configs(config_to_import, base_config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3358)             if not overwrite
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3359)             else config_to_import
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3360)         )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3361)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3362)         _result = self.runner.invoke(
3363)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3364)             ['--import', '-']
3365)             + (['--overwrite-existing'] if overwrite else []),
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3366)             input=json.dumps(config_to_import),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3367)             catch_exceptions=False,
3368)         )
3369)         assert tests.ReadableResult.parse(_result).clean_exit(
3370)             empty_stderr=False
3371)         )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3372)         assert cli._load_config() == config
3373)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3374) 
3375)     def teardown(self) -> None:
3376)         self.exit_stack.close()
3377) 
3378)