f36630533e3f8d9932e4b1b2975ec3d8bde7b45a
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 finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

97) ]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 weeks ago

233) def vault_config_exporter_shell_interpreter(  # noqa: C901
234)     script: str | Iterable[str],
235)     /,
236)     *,
237)     prog_name_list: list[str] | None = None,
238)     command: click.BaseCommand | None = None,
239)     runner: click.testing.CliRunner | None = None,
240) ) -> Iterator[click.testing.Result]:
241)     if isinstance(script, str):  # pragma: no cover
242)         script = script.splitlines(False)
243)     if prog_name_list is None:  # pragma: no cover
244)         prog_name_list = ['derivepassphrase', 'vault']
245)     if command is None:  # pragma: no cover
246)         command = cli.derivepassphrase_vault
247)     if runner is None:  # pragma: no cover
248)         runner = click.testing.CliRunner(mix_stderr=False)
249)     n = len(prog_name_list)
250)     it = iter(script)
251)     while True:
252)         try:
253)             raw_line = next(it)
254)         except StopIteration:
255)             break
256)         else:
257)             line = shlex.split(raw_line)
258)         input_buffer: list[str] = []
259)         if line[:n] != prog_name_list:
260)             continue
261)         line[:n] = []
262)         if line and line[-1] == '<<HERE':
263)             # naive HERE document support
264)             while True:
265)                 try:
266)                     raw_line = next(it)
267)                 except StopIteration as exc:  # pragma: no cover
268)                     msg = 'incomplete here document'
269)                     raise EOFError(msg) from exc
270)                 else:
271)                     if raw_line == 'HERE':
272)                         break
273)                     input_buffer.append(raw_line)
274)             line.pop()
275)         yield runner.invoke(
276)             command,
277)             line,
278)             catch_exceptions=False,
279)             input=(''.join(x + '\n' for x in input_buffer) or None),
280)         )
281) 
282) 
Marco Ricci 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(
295)             empty_stderr=True, output='Password generation:\n'
296)         ), 'expected clean exit, and option groups in help text'
297)         assert result.clean_exit(
298)             empty_stderr=True, output='Use NUMBER=0, e.g. "--symbol 0"'
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 2 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 2 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 2 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 2 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 2 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 2 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 2 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(
974)             error='Cannot load config'
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(
1002)             error='Cannot load config'
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(
1028)             error='Cannot store config'
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(
1057)             error='Cannot load config'
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1058)         ) or result.error_exit(
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(
1159)                 error='user aborted request'
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 Clean up testing machinery...

Marco Ricci authored 4 months ago

1244)             ([], '', 'Cannot update global settings without actual settings'),
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1247)                 '',
1248)                 'Cannot update service settings without actual settings',
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)             (['--phrase', '--', 'sv'], '', 'No passphrase given'),
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1251)             (['--key'], '', 'No valid SSH key selected'),
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1252)         ],
1253)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1254)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1258)         input: str,
1259)         err_text: str,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

1266)         ):
1267)             monkeypatch.setattr(
1268)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1269)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1272)                 ['--config', *command_line],
1273)                 catch_exceptions=False,
1274)                 input=input,
1275)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1276)         result = tests.ReadableResult.parse(_result)
1277)         assert result.error_exit(
1278)             error=err_text
1279)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1280) 
1281)     def test_225a_store_config_fail_manual_no_ssh_key_selection(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1287)             monkeypatch=monkeypatch,
1288)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1299)                 ['--key', '--config'],
1300)                 catch_exceptions=False,
1301)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1302)         result = tests.ReadableResult.parse(_result)
1303)         assert result.error_exit(
1304)             error=custom_error
1305)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

1307)     def test_225b_store_config_fail_manual_no_ssh_agent(
1308)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1315)             monkeypatch=monkeypatch,
1316)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1322)                 ['--key', '--config'],
1323)                 catch_exceptions=False,
1324)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1325)         result = tests.ReadableResult.parse(_result)
1326)         assert result.error_exit(
1327)             error='Cannot find running SSH agent'
1328)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1329) 
1330)     def test_225c_store_config_fail_manual_bad_ssh_agent_connection(
1331)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1336)             monkeypatch=monkeypatch,
1337)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1346)         result = tests.ReadableResult.parse(_result)
1347)         assert result.error_exit(
1348)             error='Cannot connect to SSH agent'
1349)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1350) 
1351)     @pytest.mark.parametrize('try_race_free_implementation', [True, False])
1352)     def test_225d_store_config_fail_manual_read_only_file(
1353)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1355)         try_race_free_implementation: bool,
1356)     ) -> None:
1357)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1359)             monkeypatch=monkeypatch,
1360)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1362)         ):
1363)             tests.make_file_readonly(
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1365)                 try_race_free_implementation=try_race_free_implementation,
1366)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1370)                 catch_exceptions=False,
1371)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1372)         result = tests.ReadableResult.parse(_result)
1373)         assert result.error_exit(
1374)             error='Cannot store config'
1375)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1376) 
1377)     def test_225e_store_config_fail_manual_custom_error(
1378)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1397)                 catch_exceptions=False,
1398)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1399)         result = tests.ReadableResult.parse(_result)
1400)         assert result.error_exit(
1401)             error=custom_error
1402)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1403) 
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1432)         with tests.isolated_config(
1433)             monkeypatch=monkeypatch,
1434)             runner=runner,
1435)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1439)         result = tests.ReadableResult.parse(_result)
1440)         assert result.error_exit(
1441)             error='SERVICE is required'
1442)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

1443) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1444)     def test_226a_no_passphrase_or_key(
1445)         self, monkeypatch: pytest.MonkeyPatch
1446)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1448)         with tests.isolated_config(
1449)             monkeypatch=monkeypatch,
1450)             runner=runner,
1451)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1457)         result = tests.ReadableResult.parse(_result)
1458)         assert result.error_exit(
1459)             error='No passphrase or key given'
1460)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

1461) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1462)     def test_230_config_directory_nonexistant(
1463)         self, monkeypatch: pytest.MonkeyPatch
1464)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1466)         runner = click.testing.CliRunner(mix_stderr=False)
1467)         with tests.isolated_config(
1468)             monkeypatch=monkeypatch,
1469)             runner=runner,
1470)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1472)             os_makedirs_called = False
1473)             real_os_makedirs = os.makedirs
1474) 
1475)             def makedirs(*args: Any, **kwargs: Any) -> Any:
1476)                 nonlocal os_makedirs_called
1477)                 os_makedirs_called = True
1478)                 return real_os_makedirs(*args, **kwargs)
1479) 
1480)             monkeypatch.setattr(os, 'makedirs', makedirs)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1483)                 ['--config', '-p'],
1484)                 catch_exceptions=False,
1485)                 input='abc\n',
1486)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1496)                 config_readback = json.load(infile)
1497)             assert config_readback == {
1498)                 'global': {'phrase': 'abc'},
1499)                 'services': {},
1500)             }, 'config mismatch'
1501) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1502)     def test_230a_config_directory_not_a_file(
1503)         self, monkeypatch: pytest.MonkeyPatch
1504)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1506)         runner = click.testing.CliRunner(mix_stderr=False)
1507)         with tests.isolated_config(
1508)             monkeypatch=monkeypatch,
1509)             runner=runner,
1510)         ):
1511)             _save_config = cli._save_config
1512) 
1513)             def obstruct_config_saving(*args: Any, **kwargs: Any) -> Any:
1514)                 with contextlib.suppress(FileNotFoundError):
1515)                     shutil.rmtree('.derivepassphrase')
1516)                 with open(
1517)                     '.derivepassphrase', 'w', encoding='UTF-8'
1518)                 ) as outfile:
1519)                     print('Obstruction!!', file=outfile)
1520)                 monkeypatch.setattr(cli, '_save_config', _save_config)
1521)                 return _save_config(*args, **kwargs)
1522) 
1523)             monkeypatch.setattr(cli, '_save_config', obstruct_config_saving)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1526)                 ['--config', '-p'],
1527)                 catch_exceptions=False,
1528)                 input='abc\n',
1529)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1530)             result = tests.ReadableResult.parse(_result)
1531)             assert result.error_exit(
1532)                 error='Cannot store config'
1533)             ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1534) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1535)     def test_230b_store_config_custom_error(
1536)         self, monkeypatch: pytest.MonkeyPatch
1537)     ) -> None:
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1538)         runner = click.testing.CliRunner(mix_stderr=False)
1539)         with tests.isolated_config(
1540)             monkeypatch=monkeypatch,
1541)             runner=runner,
1542)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1545)             def raiser(config: Any) -> None:
1546)                 del config
1547)                 raise RuntimeError(custom_error)
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1552)                 ['--config', '-p'],
1553)                 catch_exceptions=False,
1554)                 input='abc\n',
1555)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1563)         [
1564)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1566)                 ['--import', '-'],
1567)                 json.dumps({
1568)                     'global': {'phrase': 'Du\u0308sseldorf'},
1569)                     'services': {},
1570)                 }),
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1572)                 id='global-NFC',
1573)             ),
1574)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1576)                 ['--import', '-'],
1577)                 json.dumps({
1578)                     'services': {
1579)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1580)                         'weird entry name': {'phrase': 'Du\u0308sseldorf'},
1581)                     }
1582)                 }),
1583)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1585)                     'is not NFC-normalized'
1586)                 ),
1587)                 id='service-weird-name-NFC',
1588)             ),
1589)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1592)                 'Du\u0308sseldorf',
1593)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1595)                     f'is not NFC-normalized'
1596)                 ),
1597)                 id='config-NFC',
1598)             ),
1599)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1602)                 'Du\u0308sseldorf',
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1604)                 id='direct-input-NFC',
1605)             ),
1606)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1607)                 textwrap.dedent(r"""
1608)                 [vault]
1609)                 default-unicode-normalization-form = 'NFD'
1610)                 """),
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1611)                 ['--import', '-'],
1612)                 json.dumps({
1613)                     'global': {
1614)                         'phrase': 'D\u00fcsseldorf',
1615)                     },
1616)                     'services': {},
1617)                 }),
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1619)                 id='global-NFD',
1620)             ),
1621)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1622)                 textwrap.dedent(r"""
1623)                 [vault]
1624)                 default-unicode-normalization-form = 'NFD'
1625)                 """),
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1626)                 ['--import', '-'],
1627)                 json.dumps({
1628)                     'services': {
1629)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1630)                         'weird entry name': {'phrase': 'D\u00fcsseldorf'},
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1632)                 }),
1633)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1635)                     'is not NFD-normalized'
1636)                 ),
1637)                 id='service-weird-name-NFD',
1638)             ),
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1639)             pytest.param(
1640)                 textwrap.dedent(r"""
1641)                 [vault.unicode-normalization-form]
1642)                 'weird entry name 2' = 'NFKD'
1643)                 """),
1644)                 ['--import', '-'],
1645)                 json.dumps({
1646)                     'services': {
1647)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1648)                         'weird entry name 1': {'phrase': 'D\u00fcsseldorf'},
1649)                         'weird entry name 2': {'phrase': 'D\u00fcsseldorf'},
1650)                     },
1651)                 }),
1652)                 (
1653)                     'the $.services["weird entry name 2"] passphrase '
1654)                     'is not NFKD-normalized'
1655)                 ),
1656)                 id='service-weird-name-2-NFKD',
1657)             ),
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1658)         ],
1659)     )
1660)     def test_300_unicode_normalization_form_warning(
1661)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1671)             monkeypatch=monkeypatch,
1672)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1673)             vault_config={
1674)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1675)             },
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1681)                 catch_exceptions=False,
1682)                 input=input,
1683)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1689) 
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1690)     @pytest.mark.parametrize(
1691)         ['main_config', 'command_line', 'input', 'error_message'],
1692)         [
1693)             pytest.param(
1694)                 textwrap.dedent(r"""
1695)                 [vault]
1696)                 default-unicode-normalization-form = 'XXX'
1697)                 """),
1698)                 ['--import', '-'],
1699)                 json.dumps({
1700)                     'services': {
1701)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1702)                         'with_normalization': {'phrase': 'D\u00fcsseldorf'},
1703)                     },
1704)                 }),
1705)                 (
1706)                     "Invalid value 'XXX' for config key "
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 3 weeks ago

1708)                 ),
1709)                 id='global',
1710)             ),
1711)             pytest.param(
1712)                 textwrap.dedent(r"""
1713)                 [vault.unicode-normalization-form]
1714)                 with_normalization = 'XXX'
1715)                 """),
1716)                 ['--import', '-'],
1717)                 json.dumps({
1718)                     'services': {
1719)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1720)                         'with_normalization': {'phrase': 'D\u00fcsseldorf'},
1721)                     },
1722)                 }),
1723)                 (
1724)                     "Invalid value 'XXX' for config key "
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 3 weeks ago

1726)                 ),
1727)                 id='service',
1728)             ),
1729)         ],
1730)     )
1731)     def test_301_unicode_normalization_form_error(
1732)         self,
1733)         monkeypatch: pytest.MonkeyPatch,
1734)         main_config: str,
1735)         command_line: list[str],
1736)         input: str | None,
1737)         error_message: str,
1738)     ) -> None:
1739)         runner = click.testing.CliRunner(mix_stderr=False)
1740)         with tests.isolated_vault_config(
1741)             monkeypatch=monkeypatch,
1742)             runner=runner,
1743)             vault_config={
1744)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1745)             },
1746)             main_config_str=main_config,
1747)         ):
1748)             _result = runner.invoke(
1749)                 cli.derivepassphrase_vault,
1750)                 command_line,
1751)                 catch_exceptions=False,
1752)                 input=input,
1753)             )
1754)         result = tests.ReadableResult.parse(_result)
1755)         assert result.error_exit(
1756)             error='The configuration file is invalid.'
1757)         ), 'expected error exit and known error message'
1758)         assert result.error_exit(
1759)             error=error_message
1760)         ), 'expected error exit and known error message'
1761) 
1762)     @pytest.mark.parametrize(
1763)         'command_line',
1764)         [
1765)             pytest.param(
1766)                 ['--config', '--phrase'],
1767)                 id='configure global passphrase',
1768)             ),
1769)             pytest.param(
1770)                 ['--phrase', '--', DUMMY_SERVICE],
1771)                 id='interactive passphrase',
1772)             ),
1773)         ],
1774)     )
1775)     def test_301a_unicode_normalization_form_error_from_stored_config(
1776)         self,
1777)         monkeypatch: pytest.MonkeyPatch,
1778)         command_line: list[str],
1779)     ) -> None:
1780)         runner = click.testing.CliRunner(mix_stderr=False)
1781)         with tests.isolated_vault_config(
1782)             monkeypatch=monkeypatch,
1783)             runner=runner,
1784)             vault_config={
1785)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1786)             },
1787)             main_config_str=textwrap.dedent("""
1788)             [vault]
1789)             default-unicode-normalization-form = 'XXX'
1790)             """),
1791)         ):
1792)             _result = runner.invoke(
1793)                 cli.derivepassphrase_vault,
1794)                 command_line,
1795)                 input=DUMMY_PASSPHRASE,
1796)                 catch_exceptions=False,
1797)             )
1798)             result = tests.ReadableResult.parse(_result)
1799)             assert result.error_exit(
1800)                 error='The configuration file is invalid.'
1801)             ), 'expected error exit and known error message'
1802)             assert result.error_exit(
1803)                 error=(
1804)                     "Invalid value 'XXX' for config key "
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 3 weeks ago

1806)                 ),
1807)             ), 'expected error exit and known error message'
1808) 
1809)     def test_310_bad_user_config_file(
1810)         self,
1811)         monkeypatch: pytest.MonkeyPatch,
1812)     ) -> None:
1813)         runner = click.testing.CliRunner(mix_stderr=False)
1814)         with tests.isolated_vault_config(
1815)             monkeypatch=monkeypatch,
1816)             runner=runner,
1817)             vault_config={'services': {}},
1818)             main_config_str=textwrap.dedent("""
1819)             This file is not valid TOML.
1820)             """),
1821)         ):
1822)             _result = runner.invoke(
1823)                 cli.derivepassphrase_vault,
1824)                 ['--phrase', '--', DUMMY_SERVICE],
1825)                 input=DUMMY_PASSPHRASE,
1826)                 catch_exceptions=False,
1827)             )
1828)             result = tests.ReadableResult.parse(_result)
1829)             assert result.error_exit(
1830)                 error='Cannot load user config:'
1831)             ), 'expected error exit and known error message'
1832) 
Marco Ricci Fail gracefully if UNIX dom...

Marco Ricci authored 3 months ago

1833)     def test_400_missing_af_unix_support(
1834)         self,
1835)         monkeypatch: pytest.MonkeyPatch,
1836)     ) -> None:
1837)         runner = click.testing.CliRunner(mix_stderr=False)
1838)         with tests.isolated_vault_config(
1839)             monkeypatch=monkeypatch,
1840)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

1842)         ):
1843)             monkeypatch.setenv(
1844)                 'SSH_AUTH_SOCK', "the value doesn't even matter"
1845)             )
1846)             monkeypatch.delattr(socket, 'AF_UNIX', raising=False)
1847)             _result = runner.invoke(
1848)                 cli.derivepassphrase_vault,
1849)                 ['--key', '--config'],
1850)                 catch_exceptions=False,
1851)             )
1852)         result = tests.ReadableResult.parse(_result)
1853)         assert result.error_exit(
1854)             error='does not support UNIX domain sockets'
1855)         ), 'expected error exit and known error message'
1856) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

1859)     @pytest.mark.parametrize(
1860)         'config',
1861)         [
1862)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1863)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1864)             {
1865)                 'global': {'phrase': 'abc'},
1866)                 'services': {'sv': {'phrase': 'my passphrase'}},
1867)             },
1868)             {
1869)                 'global': {'phrase': 'abc'},
1870)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1871)             },
1872)             {
1873)                 'global': {'phrase': 'abc'},
1874)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1875)             },
1876)         ],
1877)     )
1878)     def test_100_load_config(
1879)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1880)     ) -> None:
1881)         runner = click.testing.CliRunner()
1882)         with tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

1884)         ):
1885)             config_filename = cli._config_filename(subsystem='vault')
1886)             with open(config_filename, encoding='UTF-8') as fileobj:
1887)                 assert json.load(fileobj) == config
1888)             assert cli._load_config() == config
1889) 
1890)     def test_110_save_bad_config(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

1894)         # Use parenthesized context manager expressions here once Python
1895)         # 3.9 becomes unsupported.
1896)         with contextlib.ExitStack() as stack:
1897)             stack.enter_context(
1898)                 tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

1900)                 )
1901)             )
1902)             stack.enter_context(
1903)                 pytest.raises(ValueError, match='Invalid vault config')
1904)             )
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1906) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1912)             # from https://montypython.fandom.com/wiki/Spam#The_menu
1913)             items = items or [
1914)                 'Egg and bacon',
1915)                 'Egg, sausage and bacon',
1916)                 'Egg and spam',
1917)                 'Egg, bacon and spam',
1918)                 'Egg, bacon, sausage and spam',
1919)                 'Spam, bacon, sausage and spam',
1920)                 'Spam, egg, spam, spam, bacon and spam',
1921)                 'Spam, spam, spam, egg and spam',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1922)                 (
1923)                     'Spam, spam, spam, spam, spam, spam, baked beans, '
1924)                     'spam, spam, spam and spam'
1925)                 ),
1926)                 (
1927)                     'Lobster thermidor aux crevettes with a mornay sauce '
1928)                     'garnished with truffle paté, brandy '
1929)                     'and a fried egg on top and spam'
1930)                 ),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1931)             ]
1932)             index = cli._prompt_for_selection(items, heading=heading)
1933)             click.echo('A fine choice: ', nl=False)
1934)             click.echo(items[index])
1935)             click.echo('(Note: Vikings strictly optional.)')
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

1938)         _result = runner.invoke(driver, [], input='9')
1939)         result = tests.ReadableResult.parse(_result)
1940)         assert result.clean_exit(
1941)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1942) Our menu:
1943) [1] Egg and bacon
1944) [2] Egg, sausage and bacon
1945) [3] Egg and spam
1946) [4] Egg, bacon and spam
1947) [5] Egg, bacon, sausage and spam
1948) [6] Spam, bacon, sausage and spam
1949) [7] Spam, egg, spam, spam, bacon and spam
1950) [8] Spam, spam, spam, egg and spam
1951) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1952) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
1953) Your selection? (1-10, leave empty to abort): 9
1954) A fine choice: Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1955) (Note: Vikings strictly optional.)
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1961)         result = tests.ReadableResult.parse(_result)
1962)         assert result.error_exit(
1963)             error=IndexError
1964)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1966)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1968) [1] Egg and bacon
1969) [2] Egg, sausage and bacon
1970) [3] Egg and spam
1971) [4] Egg, bacon and spam
1972) [5] Egg, bacon, sausage and spam
1973) [6] Spam, bacon, sausage and spam
1974) [7] Spam, egg, spam, spam, bacon and spam
1975) [8] Spam, spam, spam, egg and spam
1976) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1977) [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

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1981) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1987)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1988)                 cli._prompt_for_selection(
1989)                     [item], heading='', single_choice_prompt=prompt
1990)                 )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

2001)         result = tests.ReadableResult.parse(_result)
2002)         assert result.clean_exit(
2003)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

2012)             input='',
2013)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

2014)         result = tests.ReadableResult.parse(_result)
2015)         assert result.error_exit(
2016)             error=IndexError
2017)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

2019)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

2023) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

2026) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

2030)         monkeypatch.setattr(
2031)             click,
2032)             'prompt',
2033)             lambda *a, **kw: json.dumps({'args': a, 'kwargs': kw}),
2034)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

2036)         err_msg = 'missing arguments to passphrase prompt'
2037)         assert 'args' in res, err_msg
2038)         assert 'kwargs' in res, err_msg
2039)         assert res['args'][:1] == ['Passphrase'], err_msg
2040)         assert res['kwargs'].get('default') == '', err_msg
2041)         assert not res['kwargs'].get('show_default', True), err_msg
2042)         assert res['kwargs'].get('err'), err_msg
2043)         assert res['kwargs'].get('hide_input'), err_msg
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

2045)     def test_120_standard_logging_context_manager(
2046)         self,
2047)         caplog: pytest.LogCaptureFixture,
2048)         capsys: pytest.CaptureFixture[str],
2049)     ) -> None:
2050)         prog_name = cli.StandardCLILogging.prog_name
2051)         package_name = cli.StandardCLILogging.package_name
2052)         logger = logging.getLogger(package_name)
2053)         deprecation_logger = logging.getLogger(f'{package_name}.deprecation')
2054)         logging_cm = cli.StandardCLILogging.ensure_standard_logging()
2055)         with logging_cm:
2056)             assert (
2057)                 sum(
2058)                     1
2059)                     for h in logger.handlers
2060)                     if h is cli.StandardCLILogging.cli_handler
2061)                 )
2062)                 == 1
2063)             )
2064)             logger.warning('message 1')
2065)             with logging_cm:
2066)                 deprecation_logger.warning('message 2')
2067)                 assert (
2068)                     sum(
2069)                         1
2070)                         for h in logger.handlers
2071)                         if h is cli.StandardCLILogging.cli_handler
2072)                     )
2073)                     == 1
2074)                 )
2075)                 assert capsys.readouterr() == (
2076)                     '',
2077)                     (
2078)                         f'{prog_name}: Warning: message 1\n'
2079)                         f'{prog_name}: Deprecation warning: message 2\n'
2080)                     ),
2081)                 )
2082)             logger.warning('message 3')
2083)             assert (
2084)                 sum(
2085)                     1
2086)                     for h in logger.handlers
2087)                     if h is cli.StandardCLILogging.cli_handler
2088)                 )
2089)                 == 1
2090)             )
2091)             assert capsys.readouterr() == (
2092)                 '',
2093)                 f'{prog_name}: Warning: message 3\n',
2094)             )
2095)             assert caplog.record_tuples == [
2096)                 (package_name, logging.WARNING, 'message 1'),
2097)                 (f'{package_name}.deprecation', logging.WARNING, 'message 2'),
2098)                 (package_name, logging.WARNING, 'message 3'),
2099)             ]
2100) 
2101)     def test_121_standard_logging_warnings_context_manager(
2102)         self,
2103)         caplog: pytest.LogCaptureFixture,
2104)         capsys: pytest.CaptureFixture[str],
2105)     ) -> None:
2106)         warnings_cm = cli.StandardCLILogging.ensure_standard_warnings_logging()
2107)         THE_FUTURE = 'the future will be here sooner than you think'  # noqa: N806
2108)         JUST_TESTING = 'just testing whether warnings work'  # noqa: N806
2109)         with warnings_cm:
2110)             assert (
2111)                 sum(
2112)                     1
2113)                     for h in logging.getLogger('py.warnings').handlers
2114)                     if h is cli.StandardCLILogging.warnings_handler
2115)                 )
2116)                 == 1
2117)             )
2118)             warnings.warn(UserWarning(JUST_TESTING), stacklevel=1)
2119)             with warnings_cm:
2120)                 warnings.warn(FutureWarning(THE_FUTURE), stacklevel=1)
2121)                 _out, err = capsys.readouterr()
2122)                 err_lines = err.splitlines(True)
2123)                 assert any(
2124)                     f'UserWarning: {JUST_TESTING}' in line
2125)                     for line in err_lines
2126)                 )
2127)                 assert any(
2128)                     f'FutureWarning: {THE_FUTURE}' in line
2129)                     for line in err_lines
2130)                 )
2131)             warnings.warn(UserWarning(JUST_TESTING), stacklevel=1)
2132)             _out, err = capsys.readouterr()
2133)             err_lines = err.splitlines(True)
2134)             assert any(
2135)                 f'UserWarning: {JUST_TESTING}' in line for line in err_lines
2136)             )
2137)             assert not any(
2138)                 f'FutureWarning: {THE_FUTURE}' in line for line in err_lines
2139)             )
2140)             record_tuples = caplog.record_tuples
2141)             assert [tup[:2] for tup in record_tuples] == [
2142)                 ('py.warnings', logging.WARNING),
2143)                 ('py.warnings', logging.WARNING),
2144)                 ('py.warnings', logging.WARNING),
2145)             ]
2146)             assert f'UserWarning: {JUST_TESTING}' in record_tuples[0][2]
2147)             assert f'FutureWarning: {THE_FUTURE}' in record_tuples[1][2]
2148)             assert f'UserWarning: {JUST_TESTING}' in record_tuples[2][2]
2149) 
Marco Ricci Support exporting the `vaul...

Marco Ricci authored 2 weeks ago

2150)     def _export_as_sh_helper(
2151)         self,
2152)         config: Any,
2153)     ) -> None:
2154)         prog_name_list = ('derivepassphrase', 'vault')
2155)         with io.StringIO() as outfile:
2156)             cli._print_config_as_sh_script(
2157)                 config, outfile=outfile, prog_name_list=prog_name_list
2158)             )
2159)             script = outfile.getvalue()
2160)         runner = click.testing.CliRunner(mix_stderr=False)
2161)         monkeypatch = pytest.MonkeyPatch()
2162)         with tests.isolated_vault_config(
2163)             runner=runner,
2164)             monkeypatch=monkeypatch,
2165)             vault_config={'services': {}},
2166)         ):
2167)             for _result in vault_config_exporter_shell_interpreter(script):
2168)                 result = tests.ReadableResult.parse(_result)
2169)                 assert result.clean_exit()
2170)             assert cli._load_config() == config
2171) 
2172)     @hypothesis.given(
2173)         global_config_settable=tests.vault_full_service_config(),
2174)         global_config_importable=strategies.fixed_dictionaries(
2175)             {},
2176)             optional={
2177)                 'key': strategies.text(
2178)                     alphabet=strategies.characters(
2179)                         min_codepoint=32,
2180)                         max_codepoint=126,
2181)                     ),
2182)                     max_size=128,
2183)                 ),
2184)                 'phrase': strategies.text(
2185)                     alphabet=strategies.characters(
2186)                         min_codepoint=32,
2187)                         max_codepoint=126,
2188)                     ),
2189)                     max_size=64,
2190)                 ),
2191)             },
2192)         ),
2193)     )
2194)     def test_130a_export_as_sh_global(
2195)         self,
2196)         global_config_settable: _types.VaultConfigServicesSettings,
2197)         global_config_importable: _types.VaultConfigServicesSettings,
2198)     ) -> None:
2199)         config: _types.VaultConfig = {
2200)             'global': global_config_settable | global_config_importable,
2201)             'services': {},
2202)         }
2203)         assert _types.clean_up_falsy_vault_config_values(config) is not None
2204)         assert _types.is_vault_config(config)
2205)         return self._export_as_sh_helper(config)
2206) 
2207)     @hypothesis.given(
2208)         global_config_importable=strategies.fixed_dictionaries(
2209)             {},
2210)             optional={
2211)                 'key': strategies.text(
2212)                     alphabet=strategies.characters(
2213)                         min_codepoint=32,
2214)                         max_codepoint=126,
2215)                     ),
2216)                     max_size=128,
2217)                 ),
2218)                 'phrase': strategies.text(
2219)                     alphabet=strategies.characters(
2220)                         min_codepoint=32,
2221)                         max_codepoint=126,
2222)                     ),
2223)                     max_size=64,
2224)                 ),
2225)             },
2226)         ),
2227)     )
2228)     def test_130b_export_as_sh_global_only_imports(
2229)         self,
2230)         global_config_importable: _types.VaultConfigServicesSettings,
2231)     ) -> None:
2232)         config: _types.VaultConfig = {
2233)             'global': global_config_importable,
2234)             'services': {},
2235)         }
2236)         assert _types.clean_up_falsy_vault_config_values(config) is not None
2237)         assert _types.is_vault_config(config)
2238)         if not config['global']:
2239)             config.pop('global')
2240)         return self._export_as_sh_helper(config)
2241) 
2242)     @hypothesis.given(
2243)         service_name=strategies.text(
2244)             alphabet=strategies.characters(
2245)                 min_codepoint=32,
2246)                 max_codepoint=126,
2247)             ),
2248)             min_size=4,
2249)             max_size=64,
2250)         ),
2251)         service_config_settable=tests.vault_full_service_config(),
2252)         service_config_importable=strategies.fixed_dictionaries(
2253)             {},
2254)             optional={
2255)                 'key': strategies.text(
2256)                     alphabet=strategies.characters(
2257)                         min_codepoint=32,
2258)                         max_codepoint=126,
2259)                     ),
2260)                     max_size=128,
2261)                 ),
2262)                 'phrase': strategies.text(
2263)                     alphabet=strategies.characters(
2264)                         min_codepoint=32,
2265)                         max_codepoint=126,
2266)                     ),
2267)                     max_size=64,
2268)                 ),
2269)                 'notes': strategies.text(
2270)                     alphabet=strategies.characters(
2271)                         min_codepoint=32,
2272)                         max_codepoint=126,
2273)                         include_characters=('\n', '\f', '\t'),
2274)                     ),
2275)                     max_size=256,
2276)                 ),
2277)             },
2278)         ),
2279)     )
2280)     def test_130c_export_as_sh_service(
2281)         self,
2282)         service_name: str,
2283)         service_config_settable: _types.VaultConfigServicesSettings,
2284)         service_config_importable: _types.VaultConfigServicesSettings,
2285)     ) -> None:
2286)         config: _types.VaultConfig = {
2287)             'services': {
2288)                 service_name: (
2289)                     service_config_settable | service_config_importable
2290)                 ),
2291)             },
2292)         }
2293)         assert _types.clean_up_falsy_vault_config_values(config) is not None
2294)         assert _types.is_vault_config(config)
2295)         return self._export_as_sh_helper(config)
2296) 
2297)     @hypothesis.given(
2298)         service_name=strategies.text(
2299)             alphabet=strategies.characters(
2300)                 min_codepoint=32,
2301)                 max_codepoint=126,
2302)             ),
2303)             min_size=4,
2304)             max_size=64,
2305)         ),
2306)         service_config_importable=strategies.fixed_dictionaries(
2307)             {},
2308)             optional={
2309)                 'key': strategies.text(
2310)                     alphabet=strategies.characters(
2311)                         min_codepoint=32,
2312)                         max_codepoint=126,
2313)                     ),
2314)                     max_size=128,
2315)                 ),
2316)                 'phrase': strategies.text(
2317)                     alphabet=strategies.characters(
2318)                         min_codepoint=32,
2319)                         max_codepoint=126,
2320)                     ),
2321)                     max_size=64,
2322)                 ),
2323)                 'notes': strategies.text(
2324)                     alphabet=strategies.characters(
2325)                         min_codepoint=32,
2326)                         max_codepoint=126,
2327)                         include_characters=('\n', '\f', '\t'),
2328)                     ),
2329)                     max_size=256,
2330)                 ),
2331)             },
2332)         ),
2333)     )
2334)     def test_130d_export_as_sh_service_only_imports(
2335)         self,
2336)         service_name: str,
2337)         service_config_importable: _types.VaultConfigServicesSettings,
2338)     ) -> None:
2339)         config: _types.VaultConfig = {
2340)             'services': {
2341)                 service_name: service_config_importable,
2342)             },
2343)         }
2344)         assert _types.clean_up_falsy_vault_config_values(config) is not None
2345)         assert _types.is_vault_config(config)
2346)         return self._export_as_sh_helper(config)
2347) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2348)     @pytest.mark.parametrize(
2349)         ['command_line', 'config', 'result_config'],
2350)         [
2351)             (
2352)                 ['--delete-globals'],
2353)                 {'global': {'phrase': 'abc'}, 'services': {}},
2354)                 {'services': {}},
2355)             ),
2356)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

2357)                 ['--delete', '--', DUMMY_SERVICE],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2358)                 {
2359)                     'global': {'phrase': 'abc'},
2360)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
2361)                 },
2362)                 {'global': {'phrase': 'abc'}, 'services': {}},
2363)             ),
2364)             (
2365)                 ['--clear'],
2366)                 {
2367)                     'global': {'phrase': 'abc'},
2368)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
2369)                 },
2370)                 {'services': {}},
2371)             ),
2372)         ],
2373)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2374)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

2377)         command_line: list[str],
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 5 months ago

2378)         config: _types.VaultConfig,
2379)         result_config: _types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2380)     ) -> None:
2381)         runner = click.testing.CliRunner(mix_stderr=False)
2382)         for start_config in [config, result_config]:
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

2384)                 monkeypatch=monkeypatch,
2385)                 runner=runner,
2386)                 vault_config=start_config,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

2389)                     cli.derivepassphrase_vault,
2390)                     command_line,
2391)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

2400)                     config_readback = json.load(infile)
2401)                 assert config_readback == result_config
2402) 
2403)     def test_204_phrase_from_key_manually(self) -> None:
2404)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

2405)             vault.Vault(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2406)                 phrase=DUMMY_PHRASE_FROM_KEY1, **DUMMY_CONFIG_SETTINGS
2407)             ).generate(DUMMY_SERVICE)
2408)             == DUMMY_RESULT_KEY1
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2409)         )
2410) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2411)     @pytest.mark.parametrize(
2412)         ['vfunc', 'input'],
2413)         [
2414)             (cli._validate_occurrence_constraint, 20),
2415)             (cli._validate_length, 20),
2416)         ],
2417)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2418)     def test_210a_validate_constraints_manually(
2419)         self,
2420)         vfunc: Callable[[click.Context, click.Parameter, Any], int | None],
2421)         input: int,
2422)     ) -> None:
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2423)         ctx = cli.derivepassphrase_vault.make_context(cli.PROG_NAME, [])
2424)         param = cli.derivepassphrase_vault.params[0]
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2425)         assert vfunc(ctx, param, input) == input
2426) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

2427)     @pytest.mark.parametrize('conn_hint', ['none', 'socket', 'client'])
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 6 months ago

2428)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

2431)         running_ssh_agent: tests.RunningSSHAgentInfo,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2432)         conn_hint: str,
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 6 months ago

2433)     ) -> None:
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2436)             monkeypatch.setattr(
2437)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
2438)             )
2439)             hint: ssh_agent.SSHAgentClient | socket.socket | None
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

2440)             # Use match/case here once Python 3.9 becomes unsupported.
2441)             if conn_hint == 'client':
2442)                 hint = ssh_agent.SSHAgentClient()
2443)             elif conn_hint == 'socket':
2444)                 hint = socket.socket(family=socket.AF_UNIX)
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

2445)                 hint.connect(running_ssh_agent.socket)
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

2446)             else:
2447)                 assert conn_hint == 'none'
2448)                 hint = None
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

2449)             exception: Exception | None = None
2450)             try:
2451)                 list(cli._get_suitable_ssh_keys(hint))
2452)             except RuntimeError:  # pragma: no cover
2453)                 pass
2454)             except Exception as e:  # noqa: BLE001 # pragma: no cover
2455)                 exception = e
2456)             finally:
2457)                 assert (
2458)                     exception is None
2459)                 ), 'exception querying suitable SSH keys'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2460) 
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2461)     def test_400_key_to_phrase(
2462)         self,
2463)         monkeypatch: pytest.MonkeyPatch,
2464)         skip_if_no_af_unix_support: None,
2465)         ssh_agent_client_with_test_keys_loaded: ssh_agent.SSHAgentClient,
2466)     ) -> None:
2467)         class CustomError(RuntimeError):
2468)             pass
2469) 
2470)         def err(*args: Any, **_kwargs: Any) -> NoReturn:
2471)             args = args or ('custom error message',)
2472)             raise CustomError(*args)
2473) 
2474)         def fail(*_args: Any, **_kwargs: Any) -> Any:
2475)             raise ssh_agent.SSHAgentFailedError(
2476)                 _types.SSH_AGENT.FAILURE.value,
2477)                 b'',
2478)             )
2479) 
2480)         del skip_if_no_af_unix_support
2481)         monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', fail)
2482)         loaded_keys = list(ssh_agent_client_with_test_keys_loaded.list_keys())
2483)         loaded_key = base64.standard_b64encode(loaded_keys[0][0])
2484)         with monkeypatch.context() as mp:
2485)             mp.setattr(
2486)                 ssh_agent.SSHAgentClient,
2487)                 'list_keys',
2488)                 lambda *_a, **_kw: [],
2489)             )
2490)             with pytest.raises(CustomError, match='not loaded into the agent'):
2491)                 cli._key_to_phrase(loaded_key, error_callback=err)
2492)         with monkeypatch.context() as mp:
2493)             mp.setattr(ssh_agent.SSHAgentClient, 'list_keys', fail)
2494)             with pytest.raises(
2495)                 CustomError, match='SSH agent failed to complete'
2496)             ):
2497)                 cli._key_to_phrase(loaded_key, error_callback=err)
2498)         with monkeypatch.context() as mp:
2499)             mp.setattr(ssh_agent.SSHAgentClient, 'list_keys', err)
2500)             with pytest.raises(
2501)                 CustomError, match='SSH agent failed to complete'
2502)             ) as excinfo:
2503)                 cli._key_to_phrase(loaded_key, error_callback=err)
2504)             assert excinfo.value.args
2505)             assert isinstance(
2506)                 excinfo.value.args[0], ssh_agent.SSHAgentFailedError
2507)             )
2508)             assert excinfo.value.args[0].__context__ is not None
2509)             assert isinstance(excinfo.value.args[0].__context__, CustomError)
2510)         with monkeypatch.context() as mp:
2511)             mp.delenv('SSH_AUTH_SOCK', raising=True)
2512)             with pytest.raises(
2513)                 CustomError, match='Cannot find running SSH agent'
2514)             ):
2515)                 cli._key_to_phrase(loaded_key, error_callback=err)
2516)         with monkeypatch.context() as mp:
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

2517)             mp.setenv('SSH_AUTH_SOCK', os.environ['SSH_AUTH_SOCK'] + '~')
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2518)             with pytest.raises(
2519)                 CustomError, match='Cannot connect to SSH agent'
2520)             ):
2521)                 cli._key_to_phrase(loaded_key, error_callback=err)
2522)         with monkeypatch.context() as mp:
2523)             mp.delattr(socket, 'AF_UNIX', raising=True)
2524)             with pytest.raises(
2525)                 CustomError, match='does not support UNIX domain sockets'
2526)             ):
2527)                 cli._key_to_phrase(loaded_key, error_callback=err)
2528) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2529) 
2530) class TestCLITransition:
2531)     def test_100_help_output(self, monkeypatch: pytest.MonkeyPatch) -> None:
2532)         runner = click.testing.CliRunner(mix_stderr=False)
2533)         with tests.isolated_config(
2534)             monkeypatch=monkeypatch,
2535)             runner=runner,
2536)         ):
2537)             _result = runner.invoke(
2538)                 cli.derivepassphrase, ['--help'], catch_exceptions=False
2539)             )
2540)             result = tests.ReadableResult.parse(_result)
2541)         assert result.clean_exit(
2542)             empty_stderr=True, output='currently implemented subcommands'
2543)         ), 'expected clean exit, and known help text'
2544) 
2545)     def test_101_help_output_export(
2546)         self, monkeypatch: pytest.MonkeyPatch
2547)     ) -> None:
2548)         runner = click.testing.CliRunner(mix_stderr=False)
2549)         with tests.isolated_config(
2550)             monkeypatch=monkeypatch,
2551)             runner=runner,
2552)         ):
2553)             _result = runner.invoke(
2554)                 cli.derivepassphrase,
2555)                 ['export', '--help'],
2556)                 catch_exceptions=False,
2557)             )
2558)             result = tests.ReadableResult.parse(_result)
2559)         assert result.clean_exit(
2560)             empty_stderr=True, output='only available subcommand'
2561)         ), 'expected clean exit, and known help text'
2562) 
2563)     def test_102_help_output_export_vault(
2564)         self, monkeypatch: pytest.MonkeyPatch
2565)     ) -> None:
2566)         runner = click.testing.CliRunner(mix_stderr=False)
2567)         with tests.isolated_config(
2568)             monkeypatch=monkeypatch,
2569)             runner=runner,
2570)         ):
2571)             _result = runner.invoke(
2572)                 cli.derivepassphrase,
2573)                 ['export', 'vault', '--help'],
2574)                 catch_exceptions=False,
2575)             )
2576)             result = tests.ReadableResult.parse(_result)
2577)         assert result.clean_exit(
2578)             empty_stderr=True, output='Read the vault-native configuration'
2579)         ), 'expected clean exit, and known help text'
2580) 
2581)     def test_103_help_output_vault(
2582)         self, monkeypatch: pytest.MonkeyPatch
2583)     ) -> None:
2584)         runner = click.testing.CliRunner(mix_stderr=False)
2585)         with tests.isolated_config(
2586)             monkeypatch=monkeypatch,
2587)             runner=runner,
2588)         ):
2589)             _result = runner.invoke(
2590)                 cli.derivepassphrase,
2591)                 ['vault', '--help'],
2592)                 catch_exceptions=False,
2593)             )
2594)             result = tests.ReadableResult.parse(_result)
2595)         assert result.clean_exit(
2596)             empty_stderr=True, output='Password generation:\n'
2597)         ), 'expected clean exit, and option groups in help text'
2598)         assert result.clean_exit(
2599)             empty_stderr=True, output='Use NUMBER=0, e.g. "--symbol 0"'
2600)         ), 'expected clean exit, and option group epilog in help text'
2601) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2602)     @pytest.mark.parametrize(
2603)         'config',
2604)         [
2605)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2606)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2607)             {
2608)                 'global': {'phrase': 'abc'},
2609)                 'services': {'sv': {'phrase': 'my passphrase'}},
2610)             },
2611)             {
2612)                 'global': {'phrase': 'abc'},
2613)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2614)             },
2615)             {
2616)                 'global': {'phrase': 'abc'},
2617)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2618)             },
2619)         ],
2620)     )
2621)     def test_110_load_config_backup(
2622)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2623)     ) -> None:
2624)         runner = click.testing.CliRunner()
2625)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2626)             config_filename = cli._config_filename(
2627)                 subsystem='old settings.json'
2628)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2629)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2630)                 print(json.dumps(config, indent=2), file=fileobj)
2631)             assert cli._migrate_and_load_old_config()[0] == config
2632) 
2633)     @pytest.mark.parametrize(
2634)         'config',
2635)         [
2636)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2637)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2638)             {
2639)                 'global': {'phrase': 'abc'},
2640)                 'services': {'sv': {'phrase': 'my passphrase'}},
2641)             },
2642)             {
2643)                 'global': {'phrase': 'abc'},
2644)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2645)             },
2646)             {
2647)                 'global': {'phrase': 'abc'},
2648)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2649)             },
2650)         ],
2651)     )
2652)     def test_111_migrate_config(
2653)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2654)     ) -> None:
2655)         runner = click.testing.CliRunner()
2656)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2657)             config_filename = cli._config_filename(
2658)                 subsystem='old settings.json'
2659)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2660)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2661)                 print(json.dumps(config, indent=2), file=fileobj)
2662)             assert cli._migrate_and_load_old_config() == (config, None)
2663) 
2664)     @pytest.mark.parametrize(
2665)         'config',
2666)         [
2667)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2668)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2669)             {
2670)                 'global': {'phrase': 'abc'},
2671)                 'services': {'sv': {'phrase': 'my passphrase'}},
2672)             },
2673)             {
2674)                 'global': {'phrase': 'abc'},
2675)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2676)             },
2677)             {
2678)                 'global': {'phrase': 'abc'},
2679)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2680)             },
2681)         ],
2682)     )
2683)     def test_112_migrate_config_error(
2684)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2685)     ) -> None:
2686)         runner = click.testing.CliRunner()
2687)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2688)             config_filename = cli._config_filename(
2689)                 subsystem='old settings.json'
2690)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2691)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2692)                 print(json.dumps(config, indent=2), file=fileobj)
2693)             os.mkdir(cli._config_filename(subsystem='vault'))
2694)             config2, err = cli._migrate_and_load_old_config()
2695)             assert config2 == config
2696)             assert isinstance(err, OSError)
2697)             assert err.errno == errno.EISDIR
2698) 
2699)     @pytest.mark.parametrize(
2700)         'config',
2701)         [
2702)             {'global': '', 'services': {}},
2703)             {'global': 0, 'services': {}},
2704)             {
2705)                 'global': {'phrase': 'abc'},
2706)                 'services': False,
2707)             },
2708)             {
2709)                 'global': {'phrase': 'abc'},
2710)                 'services': True,
2711)             },
2712)             {
2713)                 'global': {'phrase': 'abc'},
2714)                 'services': None,
2715)             },
2716)         ],
2717)     )
2718)     def test_113_migrate_config_error_bad_config_value(
2719)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2720)     ) -> None:
2721)         runner = click.testing.CliRunner()
2722)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2723)             config_filename = cli._config_filename(
2724)                 subsystem='old settings.json'
2725)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2726)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2727)                 print(json.dumps(config, indent=2), file=fileobj)
2728)             with pytest.raises(ValueError, match=cli._INVALID_VAULT_CONFIG):
2729)                 cli._migrate_and_load_old_config()
2730) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2731)     def test_200_forward_export_vault_path_parameter(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2732)         self,
2733)         monkeypatch: pytest.MonkeyPatch,
2734)         caplog: pytest.LogCaptureFixture,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2735)     ) -> None:
2736)         pytest.importorskip('cryptography', minversion='38.0')
2737)         runner = click.testing.CliRunner(mix_stderr=False)
2738)         with tests.isolated_vault_exporter_config(
2739)             monkeypatch=monkeypatch,
2740)             runner=runner,
2741)             vault_config=tests.VAULT_V03_CONFIG,
2742)             vault_key=tests.VAULT_MASTER_KEY,
2743)         ):
2744)             monkeypatch.setenv('VAULT_KEY', tests.VAULT_MASTER_KEY)
2745)             _result = runner.invoke(
2746)                 cli.derivepassphrase,
2747)                 ['export', 'VAULT_PATH'],
2748)             )
2749)         result = tests.ReadableResult.parse(_result)
2750)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2751)         assert tests.deprecation_warning_emitted(
2752)             'A subcommand will be required in v1.0', caplog.record_tuples
2753)         )
2754)         assert tests.warning_emitted(
2755)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

2756)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2757)         assert json.loads(result.output) == tests.VAULT_V03_CONFIG_DATA
2758) 
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2759)     def test_201_forward_export_vault_empty_commandline(
2760)         self,
2761)         monkeypatch: pytest.MonkeyPatch,
2762)         caplog: pytest.LogCaptureFixture,
2763)     ) -> None:
2764)         pytest.importorskip('cryptography', minversion='38.0')
2765)         runner = click.testing.CliRunner(mix_stderr=False)
2766)         with tests.isolated_config(
2767)             monkeypatch=monkeypatch,
2768)             runner=runner,
2769)         ):
2770)             _result = runner.invoke(
2771)                 cli.derivepassphrase,
2772)                 ['export'],
2773)             )
2774)         result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2775)         assert tests.deprecation_warning_emitted(
2776)             'A subcommand will be required in v1.0', caplog.record_tuples
2777)         )
2778)         assert tests.warning_emitted(
2779)             'Defaulting to subcommand "vault"', caplog.record_tuples
2780)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2781)         assert result.error_exit(
2782)             error="Missing argument 'PATH'"
2783)         ), 'expected error exit and known error type'
2784) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2785)     @pytest.mark.parametrize(
2786)         'charset_name', ['lower', 'upper', 'number', 'space', 'dash', 'symbol']
2787)     )
2788)     def test_210_forward_vault_disable_character_set(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2789)         self,
2790)         monkeypatch: pytest.MonkeyPatch,
2791)         caplog: pytest.LogCaptureFixture,
2792)         charset_name: str,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

2796)         charset = vault.Vault._CHARSETS[charset_name].decode('ascii')
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2797)         runner = click.testing.CliRunner(mix_stderr=False)
2798)         with tests.isolated_config(
2799)             monkeypatch=monkeypatch,
2800)             runner=runner,
2801)         ):
2802)             _result = runner.invoke(
2803)                 cli.derivepassphrase,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

2804)                 [option, '0', '-p', '--', DUMMY_SERVICE],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2805)                 input=DUMMY_PASSPHRASE,
2806)                 catch_exceptions=False,
2807)             )
2808)             result = tests.ReadableResult.parse(_result)
2809)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2810)         assert tests.deprecation_warning_emitted(
2811)             'A subcommand will be required in v1.0', caplog.record_tuples
2812)         )
2813)         assert tests.warning_emitted(
2814)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

2815)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2816)         for c in charset:
2817)             assert (
2818)                 c not in result.output
2819)             ), f'derived password contains forbidden character {c!r}'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2820) 
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2821)     def test_211_forward_vault_empty_command_line(
2822)         self,
2823)         monkeypatch: pytest.MonkeyPatch,
2824)         caplog: pytest.LogCaptureFixture,
2825)     ) -> None:
2826)         runner = click.testing.CliRunner(mix_stderr=False)
2827)         with tests.isolated_config(
2828)             monkeypatch=monkeypatch,
2829)             runner=runner,
2830)         ):
2831)             _result = runner.invoke(
2832)                 cli.derivepassphrase,
2833)                 [],
2834)                 input=DUMMY_PASSPHRASE,
2835)                 catch_exceptions=False,
2836)             )
2837)             result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2838)         assert tests.deprecation_warning_emitted(
2839)             'A subcommand will be required in v1.0', caplog.record_tuples
2840)         )
2841)         assert tests.warning_emitted(
2842)             'Defaulting to subcommand "vault"', caplog.record_tuples
2843)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2844)         assert result.error_exit(
2845)             error='SERVICE is required'
2846)         ), 'expected error exit and known error type'
2847) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2848)     def test_300_export_using_old_config_file(
2849)         self,
2850)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2851)         caplog: pytest.LogCaptureFixture,
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

2853)         caplog.set_level(logging.INFO)
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2854)         runner = click.testing.CliRunner(mix_stderr=False)
2855)         with tests.isolated_config(
2856)             monkeypatch=monkeypatch,
2857)             runner=runner,
2858)         ):
2859)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2860)                 cli._config_filename(subsystem='old settings.json'),
2861)                 'w',
2862)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2863)             ) as fileobj:
2864)                 print(
2865)                     json.dumps(
2866)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
2867)                         indent=2,
2868)                     ),
2869)                     file=fileobj,
2870)                 )
2871)             _result = runner.invoke(
2872)                 cli.derivepassphrase_vault,
2873)                 ['--export', '-'],
2874)                 catch_exceptions=False,
2875)             )
2876)         result = tests.ReadableResult.parse(_result)
2877)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2878)         assert tests.deprecation_warning_emitted(
2879)             'v0.1-style config file', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2880)         ), 'expected known warning message in stderr'
Marco Ricci Fix usage of `--debug`, `--...

Marco Ricci authored 3 weeks ago

2881)         assert tests.deprecation_info_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2882)             'Successfully migrated to ', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2883)         ), 'expected known warning message in stderr'
2884) 
2885)     def test_300a_export_using_old_config_file_migration_error(
2886)         self,
2887)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2888)         caplog: pytest.LogCaptureFixture,
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2889)     ) -> None:
2890)         runner = click.testing.CliRunner(mix_stderr=False)
2891)         with tests.isolated_config(
2892)             monkeypatch=monkeypatch,
2893)             runner=runner,
2894)         ):
2895)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2896)                 cli._config_filename(subsystem='old settings.json'),
2897)                 'w',
2898)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2899)             ) as fileobj:
2900)                 print(
2901)                     json.dumps(
2902)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
2903)                         indent=2,
2904)                     ),
2905)                     file=fileobj,
2906)                 )
2907) 
2908)             def raiser(*_args: Any, **_kwargs: Any) -> None:
2909)                 raise OSError(
2910)                     errno.EACCES,
2911)                     os.strerror(errno.EACCES),
2912)                     cli._config_filename(subsystem='vault'),
2913)                 )
2914) 
2915)             monkeypatch.setattr(os, 'replace', raiser)
2916)             _result = runner.invoke(
2917)                 cli.derivepassphrase_vault,
2918)                 ['--export', '-'],
2919)                 catch_exceptions=False,
2920)             )
2921)         result = tests.ReadableResult.parse(_result)
2922)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2923)         assert tests.deprecation_warning_emitted(
2924)             'v0.1-style config file', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

2926)         assert tests.warning_emitted(
2927)             'Failed to migrate to ', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2928)         ), 'expected known warning message in stderr'
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2929) 
2930) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2931) _known_services = (DUMMY_SERVICE, 'email', 'bank', 'work')
2932) _valid_properties = (
2933)     'length',
2934)     'repeat',
2935)     'upper',
2936)     'lower',
2937)     'number',
2938)     'space',
2939)     'dash',
2940)     'symbol',
2941) )
2942) 
2943) 
2944) def _build_reduced_vault_config_settings(
2945)     config: _types.VaultConfigServicesSettings,
2946)     keys_to_purge: frozenset[str],
2947) ) -> _types.VaultConfigServicesSettings:
2948)     config2 = copy.deepcopy(config)
2949)     for key in keys_to_purge:
2950)         config2.pop(key, None)  # type: ignore[misc]
2951)     return config2
2952) 
2953) 
2954) _services_strategy = strategies.builds(
2955)     _build_reduced_vault_config_settings,
2956)     tests.vault_full_service_config(),
2957)     strategies.sets(
2958)         strategies.sampled_from(_valid_properties),
2959)         max_size=7,
2960)     ),
2961) )
2962) 
2963) 
2964) def _assemble_config(
2965)     global_data: _types.VaultConfigGlobalSettings,
2966)     service_data: list[tuple[str, _types.VaultConfigServicesSettings]],
2967) ) -> _types.VaultConfig:
2968)     services_dict = dict(service_data)
2969)     return (
2970)         {'global': global_data, 'services': services_dict}
2971)         if global_data
2972)         else {'services': services_dict}
2973)     )
2974) 
2975) 
2976) @strategies.composite
2977) def _draw_service_name_and_data(
2978)     draw: hypothesis.strategies.DrawFn,
2979)     num_entries: int,
2980) ) -> tuple[tuple[str, _types.VaultConfigServicesSettings], ...]:
2981)     possible_services = list(_known_services)
2982)     selected_services: list[str] = []
2983)     for _ in range(num_entries):
2984)         selected_services.append(
2985)             draw(strategies.sampled_from(possible_services))
2986)         )
2987)         possible_services.remove(selected_services[-1])
2988)     return tuple(
2989)         (service, draw(_services_strategy)) for service in selected_services
2990)     )
2991) 
2992) 
2993) _vault_full_config = strategies.builds(
2994)     _assemble_config,
2995)     _services_strategy,
2996)     strategies.integers(
2997)         min_value=2,
2998)         max_value=4,
2999)     ).flatmap(_draw_service_name_and_data),
3000) )
3001) 
3002) 
Marco Ricci Actually correctly implemen...

Marco Ricci authored 4 weeks ago

3003) @tests.hypothesis_settings_coverage_compatible
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3004) class ConfigManagementStateMachine(stateful.RuleBasedStateMachine):
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3005)     def __init__(self) -> None:
3006)         super().__init__()
3007)         self.runner = click.testing.CliRunner(mix_stderr=False)
3008)         self.exit_stack = contextlib.ExitStack().__enter__()
3009)         self.monkeypatch = self.exit_stack.enter_context(
3010)             pytest.MonkeyPatch().context()
3011)         )
3012)         self.isolated_config = self.exit_stack.enter_context(
3013)             tests.isolated_vault_config(
3014)                 monkeypatch=self.monkeypatch,
3015)                 runner=self.runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

3016)                 vault_config={'services': {}},
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3017)             )
3018)         )
3019) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3020)     setting = stateful.Bundle('setting')
3021)     configuration = stateful.Bundle('configuration')
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3022) 
3023)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3024)         target=configuration,
3025)         configs=strategies.lists(
3026)             _vault_full_config,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3027)             min_size=8,
3028)             max_size=8,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3029)         ),
3030)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3031)     def declare_initial_configs(
3032)         self,
3033)         configs: Iterable[_types.VaultConfig],
3034)     ) -> Iterable[_types.VaultConfig]:
3035)         return stateful.multiple(*configs)
Marco Ricci Test config merging with pa...

Marco Ricci authored 4 weeks ago

3036) 
3037)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3038)         target=setting,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3039)         configs=strategies.lists(
3040)             _vault_full_config,
3041)             min_size=4,
3042)             max_size=4,
Marco Ricci Fix formatting, some covera...

Marco Ricci authored 2 weeks ago

3043)         ),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3044)     )
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3045)     def extract_initial_settings(
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3046)         self,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3047)         configs: list[_types.VaultConfig],
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3048)     ) -> Iterable[_types.VaultConfigServicesSettings]:
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3049)         settings: list[_types.VaultConfigServicesSettings] = []
3050)         for c in configs:
3051)             settings.extend(c['services'].values())
3052)         return stateful.multiple(*map(copy.deepcopy, settings))
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3053) 
3054)     @staticmethod
3055)     def fold_configs(
3056)         c1: _types.VaultConfig, c2: _types.VaultConfig
3057)     ) -> _types.VaultConfig:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3058)         """Fold `c1` into `c2`, overriding the latter."""
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3059)         new_global_dict = c1.get('global', c2.get('global'))
3060)         if new_global_dict is not None:
3061)             return {
3062)                 'global': new_global_dict,
3063)                 'services': {**c2['services'], **c1['services']},
3064)             }
3065)         return {
3066)             'services': {**c2['services'], **c1['services']},
3067)         }
3068) 
3069)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3070)         target=configuration,
3071)         config=configuration,
3072)         setting=setting.filter(bool),
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3073)         maybe_unset=strategies.sets(
3074)             strategies.sampled_from(_valid_properties),
3075)             max_size=3,
3076)         ),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3077)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3078)     )
3079)     def set_globals(
3080)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3081)         config: _types.VaultConfig,
3082)         setting: _types.VaultConfigGlobalSettings,
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3083)         maybe_unset: set[str],
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3084)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3085)     ) -> _types.VaultConfig:
3086)         cli._save_config(config)
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3087)         config_global = config.get('global', {})
3088)         maybe_unset = set(maybe_unset) - setting.keys()
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3089)         if overwrite:
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3090)             config['global'] = config_global = {}
3091)         elif maybe_unset:
3092)             for key in maybe_unset:
3093)                 config_global.pop(key, None)  # type: ignore[misc]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3094)         config.setdefault('global', {}).update(setting)
3095)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3096)         # NOTE: This relies on settings_obj containing only the keys
3097)         # "length", "repeat", "upper", "lower", "number", "space",
3098)         # "dash" and "symbol".
3099)         _result = self.runner.invoke(
3100)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3101)             [
3102)                 '--config',
3103)                 '--overwrite-existing' if overwrite else '--merge-existing',
3104)             ]
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3105)             + [f'--unset={key}' for key in maybe_unset]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3106)             + [
3107)                 f'--{key}={value}'
3108)                 for key, value in setting.items()
3109)                 if key in _valid_properties
3110)             ],
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3111)             catch_exceptions=False,
3112)         )
3113)         result = tests.ReadableResult.parse(_result)
3114)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3115)         assert cli._load_config() == config
3116)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3117) 
3118)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3119)         target=configuration,
3120)         config=configuration,
3121)         service=strategies.sampled_from(_known_services),
3122)         setting=setting.filter(bool),
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3123)         maybe_unset=strategies.sets(
3124)             strategies.sampled_from(_valid_properties),
3125)             max_size=3,
3126)         ),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3127)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3128)     )
3129)     def set_service(
3130)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3131)         config: _types.VaultConfig,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3132)         service: str,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3133)         setting: _types.VaultConfigServicesSettings,
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3134)         maybe_unset: set[str],
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3135)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3136)     ) -> _types.VaultConfig:
3137)         cli._save_config(config)
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3138)         config_service = config['services'].get(service, {})
3139)         maybe_unset = set(maybe_unset) - setting.keys()
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3140)         if overwrite:
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3141)             config['services'][service] = config_service = {}
3142)         elif maybe_unset:
3143)             for key in maybe_unset:
3144)                 config_service.pop(key, None)  # type: ignore[misc]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3145)         config['services'].setdefault(service, {}).update(setting)
3146)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3147)         # NOTE: This relies on settings_obj containing only the keys
3148)         # "length", "repeat", "upper", "lower", "number", "space",
3149)         # "dash" and "symbol".
3150)         _result = self.runner.invoke(
3151)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3152)             [
3153)                 '--config',
3154)                 '--overwrite-existing' if overwrite else '--merge-existing',
3155)             ]
Marco Ricci Allow unsetting settings wh...

Marco Ricci authored 2 weeks ago

3156)             + [f'--unset={key}' for key in maybe_unset]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3157)             + [
3158)                 f'--{key}={value}'
3159)                 for key, value in setting.items()
3160)                 if key in _valid_properties
3161)             ]
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3162)             + ['--', service],
3163)             catch_exceptions=False,
3164)         )
3165)         result = tests.ReadableResult.parse(_result)
3166)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3167)         assert cli._load_config() == config
3168)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3169) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3170)     @stateful.rule(
3171)         target=configuration,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3172)         config=configuration,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3173)     )
3174)     def purge_global(
3175)         self,
3176)         config: _types.VaultConfig,
3177)     ) -> _types.VaultConfig:
3178)         cli._save_config(config)
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3179)         config.pop('global', None)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3180)         _result = self.runner.invoke(
3181)             cli.derivepassphrase_vault,
3182)             ['--delete-globals'],
3183)             input='y',
3184)             catch_exceptions=False,
3185)         )
3186)         result = tests.ReadableResult.parse(_result)
3187)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3188)         assert cli._load_config() == config
3189)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3190) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3191)     @stateful.rule(
3192)         target=configuration,
3193)         config_and_service=configuration.filter(
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3194)             lambda c: bool(c['services'])
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3195)         ).flatmap(
3196)             lambda c: strategies.tuples(
3197)                 strategies.just(c),
3198)                 strategies.sampled_from(tuple(c['services'].keys())),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3199)             )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3200)         ),
3201)     )
3202)     def purge_service(
3203)         self,
3204)         config_and_service: tuple[_types.VaultConfig, str],
3205)     ) -> _types.VaultConfig:
3206)         config, service = config_and_service
3207)         cli._save_config(config)
3208)         config['services'].pop(service, None)
3209)         _result = self.runner.invoke(
3210)             cli.derivepassphrase_vault,
3211)             ['--delete', '--', service],
3212)             input='y',
3213)             catch_exceptions=False,
3214)         )
3215)         result = tests.ReadableResult.parse(_result)
3216)         assert result.clean_exit(empty_stderr=False)
3217)         assert cli._load_config() == config
3218)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3219) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3220)     @stateful.rule(
3221)         target=configuration,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

3222)         config=configuration,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3223)     )
3224)     def purge_all(
3225)         self,
3226)         config: _types.VaultConfig,
3227)     ) -> _types.VaultConfig:
3228)         cli._save_config(config)
3229)         config = {'services': {}}
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3230)         _result = self.runner.invoke(
3231)             cli.derivepassphrase_vault,
3232)             ['--clear'],
3233)             input='y',
3234)             catch_exceptions=False,
3235)         )
3236)         result = tests.ReadableResult.parse(_result)
3237)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3238)         assert cli._load_config() == config
3239)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3240) 
3241)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3242)         target=configuration,
3243)         base_config=configuration,
3244)         config_to_import=configuration,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3245)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3246)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3247)     def import_configuration(
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3248)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3249)         base_config: _types.VaultConfig,
3250)         config_to_import: _types.VaultConfig,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3251)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3252)     ) -> _types.VaultConfig:
3253)         cli._save_config(base_config)
3254)         config = (
3255)             self.fold_configs(config_to_import, base_config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3256)             if not overwrite
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3257)             else config_to_import
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3258)         )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3259)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3260)         _result = self.runner.invoke(
3261)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

3262)             ['--import', '-']
3263)             + (['--overwrite-existing'] if overwrite else []),
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3264)             input=json.dumps(config_to_import),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3265)             catch_exceptions=False,
3266)         )
3267)         assert tests.ReadableResult.parse(_result).clean_exit(
3268)             empty_stderr=False
3269)         )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

3270)         assert cli._load_config() == config
3271)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

3272) 
3273)     def teardown(self) -> None:
3274)         self.exit_stack.close()
3275) 
3276)