8e7790551f023105c34a02df27bf6358e6d06d52
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 Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 6 months ago

13) import os
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

17) import warnings
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

18) from typing import TYPE_CHECKING, NoReturn
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

28) 
29) if TYPE_CHECKING:
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

30)     from collections.abc import Callable, Iterable
Marco Ricci Add prototype command-line...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

43) DUMMY_KEY2_B64 = tests.DUMMY_KEY2_B64
44) DUMMY_KEY3 = tests.DUMMY_KEY3
45) DUMMY_KEY3_B64 = tests.DUMMY_KEY3_B64
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

47) TEST_CONFIGS = tests.TEST_CONFIGS
48) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

54) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

59)     check_success: bool
60) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

67)     check_success: bool
68) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

83)     ('--notes',),
84)     ('--config',),
85)     ('--delete',),
86)     ('--delete-globals',),
87)     ('--clear',),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

94) ]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

99)         True,
100)         DUMMY_PASSPHRASE,
101)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

141)         [('--delete',), ('--delete-globals',), ('--clear',), *STORAGE_OPTIONS],
142)         None,
143)         DUMMY_PASSPHRASE,
144)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

153)         [('--import', '-')], False, None
154)     ),
155)     ('--import', '-'): IncompatibleConfiguration([], False, None),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

178) for opt, config in INCOMPATIBLE.items():
179)     for opt2 in config.other_options:
180)         INTERESTING_OPTION_COMBINATIONS.extend([
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

195)         ])
196) for opt, config in SINGLES.items():
197)     INTERESTING_OPTION_COMBINATIONS.append(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

206) 
207) 
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

225)         ),
226)     ]
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

228) 
229) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

233)         with tests.isolated_config(
234)             monkeypatch=monkeypatch,
235)             runner=runner,
236)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

240)             result = tests.ReadableResult.parse(_result)
241)         assert result.clean_exit(
242)             empty_stderr=True, output='Password generation:\n'
243)         ), 'expected clean exit, and option groups in help text'
244)         assert result.clean_exit(
245)             empty_stderr=True, output='Use NUMBER=0, e.g. "--symbol 0"'
246)         ), 'expected clean exit, and option group epilog in help text'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

247) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

258)         with tests.isolated_config(
259)             monkeypatch=monkeypatch,
260)             runner=runner,
261)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

265)                 input=DUMMY_PASSPHRASE,
266)                 catch_exceptions=False,
267)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

274) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

275)     def test_202_disable_repetition(
276)         self, monkeypatch: pytest.MonkeyPatch
277)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

280)         with tests.isolated_config(
281)             monkeypatch=monkeypatch,
282)             runner=runner,
283)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

287)                 input=DUMMY_PASSPHRASE,
288)                 catch_exceptions=False,
289)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

290)             result = tests.ReadableResult.parse(_result)
291)         assert result.clean_exit(
292)             empty_stderr=True
293)         ), 'expected clean exit and empty stderr'
294)         passphrase = result.output.rstrip('\r\n')
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

300) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

301)     @pytest.mark.parametrize(
302)         'config',
303)         [
304)             pytest.param(
305)                 {
306)                     'global': {'key': DUMMY_KEY1_B64},
307)                     'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS},
308)                 },
309)                 id='global',
310)             ),
311)             pytest.param(
312)                 {
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

314)                     'services': {
315)                         DUMMY_SERVICE: {
316)                             'key': DUMMY_KEY1_B64,
317)                             **DUMMY_CONFIG_SETTINGS,
318)                         }
319)                     },
320)                 },
321)                 id='service',
322)             ),
323)         ],
324)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

325)     def test_204a_key_from_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

333)         ):
334)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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)                 ['--', DUMMY_SERVICE],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

342)         result = tests.ReadableResult.parse(_result)
343)         assert result.clean_exit(
344)             empty_stderr=True
345)         ), 'expected clean exit and empty stderr'
346)         assert _result.stdout_bytes
347)         assert (
348)             _result.stdout_bytes.rstrip(b'\n') != DUMMY_RESULT_PASSPHRASE
349)         ), 'known false output: phrase-based instead of key-based'
350)         assert (
351)             _result.stdout_bytes.rstrip(b'\n') == DUMMY_RESULT_KEY1
352)         ), 'expected known output'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

353) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

354)     def test_204b_key_from_command_line(
355)         self, monkeypatch: pytest.MonkeyPatch
356)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

359)             monkeypatch=monkeypatch,
360)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

362)         ):
363)             monkeypatch.setattr(
364)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
365)             )
366)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

373)                 catch_exceptions=False,
374)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

375)         result = tests.ReadableResult.parse(_result)
376)         assert result.clean_exit(), 'expected clean exit'
377)         assert _result.stdout_bytes, 'expected program output'
378)         last_line = _result.stdout_bytes.splitlines(True)[-1]
379)         assert (
380)             last_line.rstrip(b'\n') != DUMMY_RESULT_PASSPHRASE
381)         ), 'known false output: phrase-based instead of key-based'
382)         assert (
383)             last_line.rstrip(b'\n') == DUMMY_RESULT_KEY1
384)         ), 'expected known output'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

385) 
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 5 months ago

386)     @pytest.mark.parametrize(
387)         'config',
388)         [
389)             pytest.param(
390)                 {
391)                     'global': {'key': DUMMY_KEY1_B64},
392)                     'services': {DUMMY_SERVICE: {}},
393)                 },
394)                 id='global_config',
395)             ),
396)             pytest.param(
397)                 {'services': {DUMMY_SERVICE: {'key': DUMMY_KEY2_B64}}},
398)                 id='service_config',
399)             ),
400)             pytest.param(
401)                 {
402)                     'global': {'key': DUMMY_KEY1_B64},
403)                     'services': {DUMMY_SERVICE: {'key': DUMMY_KEY2_B64}},
404)                 },
405)                 id='full_config',
406)             ),
407)         ],
408)     )
409)     @pytest.mark.parametrize('key_index', [1, 2, 3], ids=lambda i: f'index{i}')
410)     def test_204c_key_override_on_command_line(
411)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

414)         config: dict[str, Any],
415)         key_index: int,
416)     ) -> None:
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

426)             ):
427)                 _result = runner.invoke(
428)                     cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

432)         result = tests.ReadableResult.parse(_result)
433)         assert result.clean_exit(), 'expected clean exit'
434)         assert result.output, 'expected program output'
435)         assert result.stderr, 'expected stderr'
436)         assert (
437)             'Error:' not in result.stderr
438)         ), 'expected no error messages on stderr'
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

440)     def test_205_service_phrase_if_key_in_global_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

450)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', tests.sign)
451)             runner = click.testing.CliRunner(mix_stderr=False)
452)             with tests.isolated_vault_config(
453)                 monkeypatch=monkeypatch,
454)                 runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

456)                     'global': {'key': DUMMY_KEY1_B64},
457)                     'services': {
458)                         DUMMY_SERVICE: {
459)                             'phrase': DUMMY_PASSPHRASE.rstrip('\n'),
460)                             **DUMMY_CONFIG_SETTINGS,
461)                         }
462)                     },
463)                 },
464)             ):
465)                 _result = runner.invoke(
466)                     cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

468)                     catch_exceptions=False,
469)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

470)         result = tests.ReadableResult.parse(_result)
471)         assert result.clean_exit(), 'expected clean exit'
472)         assert _result.stdout_bytes, 'expected program output'
473)         last_line = _result.stdout_bytes.splitlines(True)[-1]
474)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

480) 
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 weeks ago

484)             pytest.param(
485)                 {
486)                     'global': {'key': DUMMY_KEY1_B64},
487)                     'services': {},
488)                 },
489)                 ['--config', '-p'],
490)                 id='global',
491)             ),
492)             pytest.param(
493)                 {
494)                     'services': {
495)                         DUMMY_SERVICE: {
496)                             'key': DUMMY_KEY1_B64,
497)                             **DUMMY_CONFIG_SETTINGS,
498)                         },
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

499)                     },
500)                 },
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 3 weeks ago

501)                 ['--config', '-p', '--', DUMMY_SERVICE],
502)                 id='service',
503)             ),
504)             pytest.param(
505)                 {
506)                     'global': {'key': DUMMY_KEY1_B64},
507)                     'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()},
508)                 },
509)                 ['--config', '-p', '--', DUMMY_SERVICE],
510)                 id='service-over-global',
511)             ),
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

512)         ],
513)     )
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

515)         self,
516)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

524)             monkeypatch.setattr(
525)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
526)             )
527)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', tests.sign)
528)             runner = click.testing.CliRunner(mix_stderr=False)
529)             with tests.isolated_vault_config(
530)                 monkeypatch=monkeypatch,
531)                 runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

533)             ):
534)                 _result = runner.invoke(
535)                     cli.derivepassphrase_vault,
Marco Ricci Fix empty key handling in `...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

537)                     input=DUMMY_PASSPHRASE,
538)                     catch_exceptions=False,
539)                 )
540)         result = tests.ReadableResult.parse(_result)
541)         assert result.clean_exit(), 'expected clean exit'
542)         assert not result.output.strip(), 'expected no program output'
543)         assert result.stderr, 'expected known error output'
544)         err_lines = result.stderr.splitlines(False)
545)         assert err_lines[0].startswith('Passphrase:')
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 weeks ago

549)         ) or tests.warning_emitted(
550)             'Setting a global passphrase is ineffective ',
551)             caplog.record_tuples,
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

553)         assert all(map(is_warning_line, result.stderr.splitlines(True)))
554)         assert all(
555)             map(is_harmless_config_import_warning, caplog.record_tuples)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

556)         ), 'unexpected error output'
557) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

558)     @pytest.mark.parametrize(
559)         'option',
560)         [
561)             '--lower',
562)             '--upper',
563)             '--number',
564)             '--space',
565)             '--dash',
566)             '--symbol',
567)             '--repeat',
568)             '--length',
569)         ],
570)     )
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

575)         with tests.isolated_config(
576)             monkeypatch=monkeypatch,
577)             runner=runner,
578)         ):
579)             for value in '-42', 'invalid':
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

583)                     input=DUMMY_PASSPHRASE,
584)                     catch_exceptions=False,
585)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

590) 
591)     @pytest.mark.parametrize(
592)         ['options', 'service', 'input', 'check_success'],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

593)         [
594)             (o.options, o.needs_service, o.input, o.check_success)
595)             for o in INTERESTING_OPTION_COMBINATIONS
596)             if not o.incompatible
597)         ],
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

598)     )
599)     def test_211_service_needed(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

610)             monkeypatch=monkeypatch,
611)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

617)                 input=input,
618)                 catch_exceptions=False,
619)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

627)                 assert result.error_exit(
628)                     error=err_msg
629)                 ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

631)                 assert result.clean_exit(
632)                     empty_stderr=True
633)                 ), 'expected clean exit'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

636)                 monkeypatch=monkeypatch,
637)                 runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

639)             ):
640)                 monkeypatch.setattr(
641)                     cli, '_prompt_for_passphrase', tests.auto_prompt
642)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

646)                     input=input,
647)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 months ago

652)     def test_211a_empty_service_name_causes_warning(
653)         self,
654)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

657)         def is_expected_warning(record: tuple[str, int, str]) -> bool:
658)             return is_harmless_config_import_warning(
659)                 record
660)             ) or tests.warning_emitted(
661)                 'An empty SERVICE is not supported by vault(1)', [record]
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

662)             )
663) 
664)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
665)         runner = click.testing.CliRunner(mix_stderr=False)
666)         with tests.isolated_vault_config(
667)             monkeypatch=monkeypatch,
668)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

670)         ):
671)             _result = runner.invoke(
672)                 cli.derivepassphrase_vault,
673)                 ['--config', '--length=30', '--', ''],
674)                 catch_exceptions=False,
675)             )
676)             result = tests.ReadableResult.parse(_result)
677)             assert result.clean_exit(empty_stderr=False), 'expected clean exit'
678)             assert result.stderr is not None, 'expected known error output'
679)             assert all(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

681)             ), 'expected known error output'
682)             assert cli._load_config() == {
683)                 'global': {'length': 30},
684)                 'services': {},
685)             }, 'requested configuration change was not applied'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

687)             _result = runner.invoke(
688)                 cli.derivepassphrase_vault,
689)                 ['--import', '-'],
690)                 input=json.dumps({'services': {'': {'length': 40}}}),
691)                 catch_exceptions=False,
692)             )
693)             result = tests.ReadableResult.parse(_result)
694)             assert result.clean_exit(empty_stderr=False), 'expected clean exit'
695)             assert result.stderr is not None, 'expected known error output'
696)             assert all(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

698)             ), 'expected known error output'
699)             assert cli._load_config() == {
700)                 'global': {'length': 30},
701)                 'services': {'': {'length': 40}},
702)             }, 'requested configuration change was not applied'
703) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

706)         [
707)             (o.options, o.needs_service)
708)             for o in INTERESTING_OPTION_COMBINATIONS
709)             if o.incompatible
710)         ],
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

712)     def test_212_incompatible_options(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

719)         with tests.isolated_config(
720)             monkeypatch=monkeypatch,
721)             runner=runner,
722)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

726)                 input=DUMMY_PASSPHRASE,
727)                 catch_exceptions=False,
728)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

729)         result = tests.ReadableResult.parse(_result)
730)         assert result.error_exit(
731)             error='mutually exclusive with '
732)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

734)     @pytest.mark.parametrize(
735)         'config',
736)         [
737)             conf.config
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

739)             if tests.is_valid_test_config(conf)
740)         ],
741)     )
742)     def test_213_import_config_success(
743)         self,
744)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

746)         config: Any,
747)     ) -> None:
748)         runner = click.testing.CliRunner(mix_stderr=False)
749)         with tests.isolated_vault_config(
750)             monkeypatch=monkeypatch,
751)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

753)         ):
754)             _result = runner.invoke(
755)                 cli.derivepassphrase_vault,
756)                 ['--import', '-'],
757)                 input=json.dumps(config),
758)                 catch_exceptions=False,
759)             )
760)             with open(
761)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
762)             ) as infile:
763)                 config2 = json.load(infile)
764)         result = tests.ReadableResult.parse(_result)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

772)     @hypothesis.given(
773)         conf=tests.smudged_vault_test_config(
774)             strategies.sampled_from(TEST_CONFIGS).filter(
775)                 tests.is_valid_test_config
776)             )
777)         )
778)     )
779)     def test_213a_import_config_success(
780)         self,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

782)         conf: tests.VaultTestConfig,
783)     ) -> None:
784)         config = conf.config
785)         config2 = copy.deepcopy(config)
786)         _types.clean_up_falsy_vault_config_values(config2)
787)         runner = click.testing.CliRunner(mix_stderr=False)
788)         with tests.isolated_vault_config(
789)             monkeypatch=pytest.MonkeyPatch(),
790)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

792)         ):
793)             _result = runner.invoke(
794)                 cli.derivepassphrase_vault,
795)                 ['--import', '-'],
796)                 input=json.dumps(config),
797)                 catch_exceptions=False,
798)             )
799)             with open(
800)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
801)             ) as infile:
802)                 config3 = json.load(infile)
803)         result = tests.ReadableResult.parse(_result)
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

809) 
810)     def test_213b_import_bad_config_not_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

822)         result = tests.ReadableResult.parse(_result)
823)         assert result.error_exit(
824)             error='Invalid vault config'
825)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

827)     def test_213c_import_bad_config_not_json_data(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

839)         result = tests.ReadableResult.parse(_result)
840)         assert result.error_exit(
841)             error='cannot decode JSON'
842)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

844)     def test_213d_import_bad_config_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

864)         result = tests.ReadableResult.parse(_result)
865)         assert result.error_exit(
866)             error=os.strerror(errno.EISDIR)
867)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

868) 
869)     def test_214_export_settings_no_stored_settings(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

878)                 cli.derivepassphrase_vault,
879)                 ['--export', '-'],
880)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

885)     def test_214a_export_settings_bad_stored_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

895)                 ['--export', '-'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

899)         result = tests.ReadableResult.parse(_result)
900)         assert result.error_exit(
901)             error='Cannot load config'
902)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

904)     def test_214b_export_settings_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

915)                 ['--export', '-'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

919)         result = tests.ReadableResult.parse(_result)
920)         assert result.error_exit(
921)             error='Cannot load config'
922)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

924)     def test_214c_export_settings_target_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

937)         result = tests.ReadableResult.parse(_result)
938)         assert result.error_exit(
939)             error='Cannot store config'
940)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

941) 
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

942)     def test_214d_export_settings_settings_directory_not_a_directory(
943)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

944)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

954)                 ['--export', '-'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

956)                 catch_exceptions=False,
957)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

958)         result = tests.ReadableResult.parse(_result)
959)         assert result.error_exit(
960)             error='Cannot load config'
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

961)         ) or result.error_exit(
962)             error='Cannot load user config'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

964) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

965)     def test_220_edit_notes_successfully(
966)         self, monkeypatch: pytest.MonkeyPatch
967)     ) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

969) 
970) # - - - - - >8 - - - - - >8 - - - - - >8 - - - - - >8 - - - - -
971) contents go here
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

975)             monkeypatch=monkeypatch,
976)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

991)             assert config == {
992)                 'global': {'phrase': 'abc'},
993)                 'services': {'sv': {'notes': 'contents go here'}},
994)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

995) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

996)     def test_221_edit_notes_noop(
997)         self, monkeypatch: pytest.MonkeyPatch
998)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1001)             monkeypatch=monkeypatch,
1002)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

1019)     def test_222_edit_notes_marker_removed(
1020)         self, monkeypatch: pytest.MonkeyPatch
1021)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1024)             monkeypatch=monkeypatch,
1025)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1040)             assert config == {
1041)                 'global': {'phrase': 'abc'},
1042)                 'services': {'sv': {'notes': 'long\ntext'}},
1043)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1044) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1045)     def test_223_edit_notes_abort(
1046)         self, monkeypatch: pytest.MonkeyPatch
1047)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1050)             monkeypatch=monkeypatch,
1051)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1060)             result = tests.ReadableResult.parse(_result)
1061)             assert result.error_exit(
1062)                 error='user aborted request'
1063)             ), 'expected known error message'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1070)     @pytest.mark.parametrize(
1071)         ['command_line', 'input', 'result_config'],
1072)         [
1073)             (
1074)                 ['--phrase'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1076)                 {'global': {'phrase': 'my passphrase'}, 'services': {}},
1077)             ),
1078)             (
1079)                 ['--key'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

1081)                 {
1082)                     'global': {'key': DUMMY_KEY1_B64, 'phrase': 'abc'},
1083)                     'services': {},
1084)                 },
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1085)             ),
1086)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1089)                 {
1090)                     'global': {'phrase': 'abc'},
1091)                     'services': {'sv': {'phrase': 'my passphrase'}},
1092)                 },
1093)             ),
1094)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1097)                 {
1098)                     'global': {'phrase': 'abc'},
1099)                     'services': {'sv': {'key': DUMMY_KEY1_B64}},
1100)                 },
1101)             ),
1102)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1105)                 {
1106)                     'global': {'phrase': 'abc'},
1107)                     'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1108)                 },
1109)             ),
1110)         ],
1111)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1112)     def test_224_store_config_good(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1117)         result_config: Any,
1118)     ) -> None:
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(
1126)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1127)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1130)                 ['--config', *command_line],
1131)                 catch_exceptions=False,
1132)                 input=input,
1133)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1140)             assert (
1141)                 config == result_config
1142)             ), 'stored config does not match expectation'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1143) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1144)     @pytest.mark.parametrize(
1145)         ['command_line', 'input', 'err_text'],
1146)         [
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1150)                 '',
1151)                 'Cannot update service settings without actual settings',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1152)             ),
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1153)             (['--phrase', '--', 'sv'], '', 'No passphrase given'),
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1155)         ],
1156)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1157)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1161)         input: str,
1162)         err_text: str,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1166)             monkeypatch=monkeypatch,
1167)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

1169)         ):
1170)             monkeypatch.setattr(
1171)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1172)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1175)                 ['--config', *command_line],
1176)                 catch_exceptions=False,
1177)                 input=input,
1178)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1179)         result = tests.ReadableResult.parse(_result)
1180)         assert result.error_exit(
1181)             error=err_text
1182)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1183) 
1184)     def test_225a_store_config_fail_manual_no_ssh_key_selection(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1190)             monkeypatch=monkeypatch,
1191)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1202)                 ['--key', '--config'],
1203)                 catch_exceptions=False,
1204)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1205)         result = tests.ReadableResult.parse(_result)
1206)         assert result.error_exit(
1207)             error=custom_error
1208)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

1210)     def test_225b_store_config_fail_manual_no_ssh_agent(
1211)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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 Add missing tests for rewor...

Marco Ricci authored 4 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 Add missing tests for rewor...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1225)                 ['--key', '--config'],
1226)                 catch_exceptions=False,
1227)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1228)         result = tests.ReadableResult.parse(_result)
1229)         assert result.error_exit(
1230)             error='Cannot find running SSH agent'
1231)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1232) 
1233)     def test_225c_store_config_fail_manual_bad_ssh_agent_connection(
1234)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1239)             monkeypatch=monkeypatch,
1240)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1246)                 ['--key', '--config'],
1247)                 catch_exceptions=False,
1248)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1249)         result = tests.ReadableResult.parse(_result)
1250)         assert result.error_exit(
1251)             error='Cannot connect to SSH agent'
1252)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1253) 
1254)     @pytest.mark.parametrize('try_race_free_implementation', [True, False])
1255)     def test_225d_store_config_fail_manual_read_only_file(
1256)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1258)         try_race_free_implementation: bool,
1259)     ) -> None:
1260)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1265)         ):
1266)             tests.make_file_readonly(
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1268)                 try_race_free_implementation=try_race_free_implementation,
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 Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1273)                 catch_exceptions=False,
1274)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1275)         result = tests.ReadableResult.parse(_result)
1276)         assert result.error_exit(
1277)             error='Cannot store config'
1278)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1279) 
1280)     def test_225e_store_config_fail_manual_custom_error(
1281)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1289)         ):
1290)             custom_error = 'custom error message'
1291) 
1292)             def raiser(config: Any) -> None:
1293)                 del config
1294)                 raise RuntimeError(custom_error)
1295) 
1296)             monkeypatch.setattr(cli, '_save_config', 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 Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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 Add missing tests for rewor...

Marco Ricci authored 4 months ago

1306) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1309)         with tests.isolated_config(
1310)             monkeypatch=monkeypatch,
1311)             runner=runner,
1312)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1316)         result = tests.ReadableResult.parse(_result)
1317)         assert result.error_exit(
1318)             error='SERVICE is required'
1319)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

1320) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1321)     def test_226a_no_passphrase_or_key(
1322)         self, monkeypatch: pytest.MonkeyPatch
1323)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1325)         with tests.isolated_config(
1326)             monkeypatch=monkeypatch,
1327)             runner=runner,
1328)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1338) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1339)     def test_230_config_directory_nonexistant(
1340)         self, monkeypatch: pytest.MonkeyPatch
1341)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1343)         runner = click.testing.CliRunner(mix_stderr=False)
1344)         with tests.isolated_config(
1345)             monkeypatch=monkeypatch,
1346)             runner=runner,
1347)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1349)             os_makedirs_called = False
1350)             real_os_makedirs = os.makedirs
1351) 
1352)             def makedirs(*args: Any, **kwargs: Any) -> Any:
1353)                 nonlocal os_makedirs_called
1354)                 os_makedirs_called = True
1355)                 return real_os_makedirs(*args, **kwargs)
1356) 
1357)             monkeypatch.setattr(os, 'makedirs', makedirs)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1360)                 ['--config', '-p'],
1361)                 catch_exceptions=False,
1362)                 input='abc\n',
1363)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1373)                 config_readback = json.load(infile)
1374)             assert config_readback == {
1375)                 'global': {'phrase': 'abc'},
1376)                 'services': {},
1377)             }, 'config mismatch'
1378) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1379)     def test_230a_config_directory_not_a_file(
1380)         self, monkeypatch: pytest.MonkeyPatch
1381)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1383)         runner = click.testing.CliRunner(mix_stderr=False)
1384)         with tests.isolated_config(
1385)             monkeypatch=monkeypatch,
1386)             runner=runner,
1387)         ):
1388)             _save_config = cli._save_config
1389) 
1390)             def obstruct_config_saving(*args: Any, **kwargs: Any) -> Any:
1391)                 with contextlib.suppress(FileNotFoundError):
1392)                     shutil.rmtree('.derivepassphrase')
1393)                 with open(
1394)                     '.derivepassphrase', 'w', encoding='UTF-8'
1395)                 ) as outfile:
1396)                     print('Obstruction!!', file=outfile)
1397)                 monkeypatch.setattr(cli, '_save_config', _save_config)
1398)                 return _save_config(*args, **kwargs)
1399) 
1400)             monkeypatch.setattr(cli, '_save_config', obstruct_config_saving)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1403)                 ['--config', '-p'],
1404)                 catch_exceptions=False,
1405)                 input='abc\n',
1406)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1407)             result = tests.ReadableResult.parse(_result)
1408)             assert result.error_exit(
1409)                 error='Cannot store config'
1410)             ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1411) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1412)     def test_230b_store_config_custom_error(
1413)         self, monkeypatch: pytest.MonkeyPatch
1414)     ) -> None:
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1415)         runner = click.testing.CliRunner(mix_stderr=False)
1416)         with tests.isolated_config(
1417)             monkeypatch=monkeypatch,
1418)             runner=runner,
1419)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1422)             def raiser(config: Any) -> None:
1423)                 del config
1424)                 raise RuntimeError(custom_error)
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1429)                 ['--config', '-p'],
1430)                 catch_exceptions=False,
1431)                 input='abc\n',
1432)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1440)         [
1441)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1443)                 ['--import', '-'],
1444)                 json.dumps({
1445)                     'global': {'phrase': 'Du\u0308sseldorf'},
1446)                     'services': {},
1447)                 }),
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1449)                 id='global-NFC',
1450)             ),
1451)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1453)                 ['--import', '-'],
1454)                 json.dumps({
1455)                     'services': {
1456)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1457)                         'weird entry name': {'phrase': 'Du\u0308sseldorf'},
1458)                     }
1459)                 }),
1460)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1462)                     'is not NFC-normalized'
1463)                 ),
1464)                 id='service-weird-name-NFC',
1465)             ),
1466)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1469)                 'Du\u0308sseldorf',
1470)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1472)                     f'is not NFC-normalized'
1473)                 ),
1474)                 id='config-NFC',
1475)             ),
1476)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1481)                 id='direct-input-NFC',
1482)             ),
1483)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1484)                 textwrap.dedent(r"""
1485)                 [vault]
1486)                 default-unicode-normalization-form = 'NFD'
1487)                 """),
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1488)                 ['--import', '-'],
1489)                 json.dumps({
1490)                     'global': {
1491)                         'phrase': 'D\u00fcsseldorf',
1492)                     },
1493)                     'services': {},
1494)                 }),
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1496)                 id='global-NFD',
1497)             ),
1498)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1499)                 textwrap.dedent(r"""
1500)                 [vault]
1501)                 default-unicode-normalization-form = 'NFD'
1502)                 """),
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1503)                 ['--import', '-'],
1504)                 json.dumps({
1505)                     'services': {
1506)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1507)                         'weird entry name': {'phrase': 'D\u00fcsseldorf'},
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1509)                 }),
1510)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1512)                     'is not NFD-normalized'
1513)                 ),
1514)                 id='service-weird-name-NFD',
1515)             ),
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1516)             pytest.param(
1517)                 textwrap.dedent(r"""
1518)                 [vault.unicode-normalization-form]
1519)                 'weird entry name 2' = 'NFKD'
1520)                 """),
1521)                 ['--import', '-'],
1522)                 json.dumps({
1523)                     'services': {
1524)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1525)                         'weird entry name 1': {'phrase': 'D\u00fcsseldorf'},
1526)                         'weird entry name 2': {'phrase': 'D\u00fcsseldorf'},
1527)                     },
1528)                 }),
1529)                 (
1530)                     'the $.services["weird entry name 2"] passphrase '
1531)                     'is not NFKD-normalized'
1532)                 ),
1533)                 id='service-weird-name-2-NFKD',
1534)             ),
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1535)         ],
1536)     )
1537)     def test_300_unicode_normalization_form_warning(
1538)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1548)             monkeypatch=monkeypatch,
1549)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1550)             vault_config={
1551)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1552)             },
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1558)                 catch_exceptions=False,
1559)                 input=input,
1560)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1566) 
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1567)     @pytest.mark.parametrize(
1568)         ['main_config', 'command_line', 'input', 'error_message'],
1569)         [
1570)             pytest.param(
1571)                 textwrap.dedent(r"""
1572)                 [vault]
1573)                 default-unicode-normalization-form = 'XXX'
1574)                 """),
1575)                 ['--import', '-'],
1576)                 json.dumps({
1577)                     'services': {
1578)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1579)                         'with_normalization': {'phrase': 'D\u00fcsseldorf'},
1580)                     },
1581)                 }),
1582)                 (
1583)                     "Invalid value 'XXX' for config key "
1584)                     "vault.default-unicode-normalization-form"
1585)                 ),
1586)                 id='global',
1587)             ),
1588)             pytest.param(
1589)                 textwrap.dedent(r"""
1590)                 [vault.unicode-normalization-form]
1591)                 with_normalization = 'XXX'
1592)                 """),
1593)                 ['--import', '-'],
1594)                 json.dumps({
1595)                     'services': {
1596)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1597)                         'with_normalization': {'phrase': 'D\u00fcsseldorf'},
1598)                     },
1599)                 }),
1600)                 (
1601)                     "Invalid value 'XXX' for config key "
1602)                     "vault.with_normalization.unicode-normalization-form"
1603)                 ),
1604)                 id='service',
1605)             ),
1606)         ],
1607)     )
1608)     def test_301_unicode_normalization_form_error(
1609)         self,
1610)         monkeypatch: pytest.MonkeyPatch,
1611)         main_config: str,
1612)         command_line: list[str],
1613)         input: str | None,
1614)         error_message: str,
1615)     ) -> None:
1616)         runner = click.testing.CliRunner(mix_stderr=False)
1617)         with tests.isolated_vault_config(
1618)             monkeypatch=monkeypatch,
1619)             runner=runner,
1620)             vault_config={
1621)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1622)             },
1623)             main_config_str=main_config,
1624)         ):
1625)             _result = runner.invoke(
1626)                 cli.derivepassphrase_vault,
1627)                 command_line,
1628)                 catch_exceptions=False,
1629)                 input=input,
1630)             )
1631)         result = tests.ReadableResult.parse(_result)
1632)         assert result.error_exit(
1633)             error='The configuration file is invalid.'
1634)         ), 'expected error exit and known error message'
1635)         assert result.error_exit(
1636)             error=error_message
1637)         ), 'expected error exit and known error message'
1638) 
1639)     @pytest.mark.parametrize(
1640)         'command_line',
1641)         [
1642)             pytest.param(
1643)                 ['--config', '--phrase'],
1644)                 id='configure global passphrase',
1645)             ),
1646)             pytest.param(
1647)                 ['--phrase', '--', DUMMY_SERVICE],
1648)                 id='interactive passphrase',
1649)             ),
1650)         ],
1651)     )
1652)     def test_301a_unicode_normalization_form_error_from_stored_config(
1653)         self,
1654)         monkeypatch: pytest.MonkeyPatch,
1655)         command_line: list[str],
1656)     ) -> None:
1657)         runner = click.testing.CliRunner(mix_stderr=False)
1658)         with tests.isolated_vault_config(
1659)             monkeypatch=monkeypatch,
1660)             runner=runner,
1661)             vault_config={
1662)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1663)             },
1664)             main_config_str=textwrap.dedent("""
1665)             [vault]
1666)             default-unicode-normalization-form = 'XXX'
1667)             """),
1668)         ):
1669)             _result = runner.invoke(
1670)                 cli.derivepassphrase_vault,
1671)                 command_line,
1672)                 input=DUMMY_PASSPHRASE,
1673)                 catch_exceptions=False,
1674)             )
1675)             result = tests.ReadableResult.parse(_result)
1676)             assert result.error_exit(
1677)                 error='The configuration file is invalid.'
1678)             ), 'expected error exit and known error message'
1679)             assert result.error_exit(
1680)                 error=(
1681)                     "Invalid value 'XXX' for config key "
1682)                     "vault.default-unicode-normalization-form"
1683)                 ),
1684)             ), 'expected error exit and known error message'
1685) 
1686)     def test_310_bad_user_config_file(
1687)         self,
1688)         monkeypatch: pytest.MonkeyPatch,
1689)     ) -> None:
1690)         runner = click.testing.CliRunner(mix_stderr=False)
1691)         with tests.isolated_vault_config(
1692)             monkeypatch=monkeypatch,
1693)             runner=runner,
1694)             vault_config={'services': {}},
1695)             main_config_str=textwrap.dedent("""
1696)             This file is not valid TOML.
1697)             """),
1698)         ):
1699)             _result = runner.invoke(
1700)                 cli.derivepassphrase_vault,
1701)                 ['--phrase', '--', DUMMY_SERVICE],
1702)                 input=DUMMY_PASSPHRASE,
1703)                 catch_exceptions=False,
1704)             )
1705)             result = tests.ReadableResult.parse(_result)
1706)             assert result.error_exit(
1707)                 error='Cannot load user config:'
1708)             ), 'expected error exit and known error message'
1709) 
Marco Ricci Fail gracefully if UNIX dom...

Marco Ricci authored 3 months ago

1710)     def test_400_missing_af_unix_support(
1711)         self,
1712)         monkeypatch: pytest.MonkeyPatch,
1713)     ) -> None:
1714)         runner = click.testing.CliRunner(mix_stderr=False)
1715)         with tests.isolated_vault_config(
1716)             monkeypatch=monkeypatch,
1717)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

1719)         ):
1720)             monkeypatch.setenv(
1721)                 'SSH_AUTH_SOCK', "the value doesn't even matter"
1722)             )
1723)             monkeypatch.delattr(socket, 'AF_UNIX', raising=False)
1724)             _result = runner.invoke(
1725)                 cli.derivepassphrase_vault,
1726)                 ['--key', '--config'],
1727)                 catch_exceptions=False,
1728)             )
1729)         result = tests.ReadableResult.parse(_result)
1730)         assert result.error_exit(
1731)             error='does not support UNIX domain sockets'
1732)         ), 'expected error exit and known error message'
1733) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

1736)     @pytest.mark.parametrize(
1737)         'config',
1738)         [
1739)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1740)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1741)             {
1742)                 'global': {'phrase': 'abc'},
1743)                 'services': {'sv': {'phrase': 'my passphrase'}},
1744)             },
1745)             {
1746)                 'global': {'phrase': 'abc'},
1747)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1748)             },
1749)             {
1750)                 'global': {'phrase': 'abc'},
1751)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1752)             },
1753)         ],
1754)     )
1755)     def test_100_load_config(
1756)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1757)     ) -> None:
1758)         runner = click.testing.CliRunner()
1759)         with tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

1761)         ):
1762)             config_filename = cli._config_filename(subsystem='vault')
1763)             with open(config_filename, encoding='UTF-8') as fileobj:
1764)                 assert json.load(fileobj) == config
1765)             assert cli._load_config() == config
1766) 
1767)     def test_110_save_bad_config(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

1771)         # Use parenthesized context manager expressions here once Python
1772)         # 3.9 becomes unsupported.
1773)         with contextlib.ExitStack() as stack:
1774)             stack.enter_context(
1775)                 tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

1777)                 )
1778)             )
1779)             stack.enter_context(
1780)                 pytest.raises(ValueError, match='Invalid vault config')
1781)             )
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1783) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1789)             # from https://montypython.fandom.com/wiki/Spam#The_menu
1790)             items = items or [
1791)                 'Egg and bacon',
1792)                 'Egg, sausage and bacon',
1793)                 'Egg and spam',
1794)                 'Egg, bacon and spam',
1795)                 'Egg, bacon, sausage and spam',
1796)                 'Spam, bacon, sausage and spam',
1797)                 'Spam, egg, spam, spam, bacon and spam',
1798)                 'Spam, spam, spam, egg and spam',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1799)                 (
1800)                     'Spam, spam, spam, spam, spam, spam, baked beans, '
1801)                     'spam, spam, spam and spam'
1802)                 ),
1803)                 (
1804)                     'Lobster thermidor aux crevettes with a mornay sauce '
1805)                     'garnished with truffle paté, brandy '
1806)                     'and a fried egg on top and spam'
1807)                 ),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1808)             ]
1809)             index = cli._prompt_for_selection(items, heading=heading)
1810)             click.echo('A fine choice: ', nl=False)
1811)             click.echo(items[index])
1812)             click.echo('(Note: Vikings strictly optional.)')
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

1815)         _result = runner.invoke(driver, [], input='9')
1816)         result = tests.ReadableResult.parse(_result)
1817)         assert result.clean_exit(
1818)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1819) Our menu:
1820) [1] Egg and bacon
1821) [2] Egg, sausage and bacon
1822) [3] Egg and spam
1823) [4] Egg, bacon and spam
1824) [5] Egg, bacon, sausage and spam
1825) [6] Spam, bacon, sausage and spam
1826) [7] Spam, egg, spam, spam, bacon and spam
1827) [8] Spam, spam, spam, egg and spam
1828) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1829) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
1830) Your selection? (1-10, leave empty to abort): 9
1831) A fine choice: Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1832) (Note: Vikings strictly optional.)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1833) """  # noqa: E501
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1838)         result = tests.ReadableResult.parse(_result)
1839)         assert result.error_exit(
1840)             error=IndexError
1841)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1843)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1845) [1] Egg and bacon
1846) [2] Egg, sausage and bacon
1847) [3] Egg and spam
1848) [4] Egg, bacon and spam
1849) [5] Egg, bacon, sausage and spam
1850) [6] Spam, bacon, sausage and spam
1851) [7] Spam, egg, spam, spam, bacon and spam
1852) [8] Spam, spam, spam, egg and spam
1853) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1854) [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

1855) Your selection? (1-10, leave empty to abort):\x20
1856) """  # noqa: E501
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1858) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1864)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1865)                 cli._prompt_for_selection(
1866)                     [item], heading='', single_choice_prompt=prompt
1867)                 )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1878)         result = tests.ReadableResult.parse(_result)
1879)         assert result.clean_exit(
1880)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

1889)             input='',
1890)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1891)         result = tests.ReadableResult.parse(_result)
1892)         assert result.error_exit(
1893)             error=IndexError
1894)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1896)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1900) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1903) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1907)         monkeypatch.setattr(
1908)             click,
1909)             'prompt',
1910)             lambda *a, **kw: json.dumps({'args': a, 'kwargs': kw}),
1911)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1913)         err_msg = 'missing arguments to passphrase prompt'
1914)         assert 'args' in res, err_msg
1915)         assert 'kwargs' in res, err_msg
1916)         assert res['args'][:1] == ['Passphrase'], err_msg
1917)         assert res['kwargs'].get('default') == '', err_msg
1918)         assert not res['kwargs'].get('show_default', True), err_msg
1919)         assert res['kwargs'].get('err'), err_msg
1920)         assert res['kwargs'].get('hide_input'), err_msg
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

1922)     def test_120_standard_logging_context_manager(
1923)         self,
1924)         caplog: pytest.LogCaptureFixture,
1925)         capsys: pytest.CaptureFixture[str],
1926)     ) -> None:
1927)         prog_name = cli.StandardCLILogging.prog_name
1928)         package_name = cli.StandardCLILogging.package_name
1929)         logger = logging.getLogger(package_name)
1930)         deprecation_logger = logging.getLogger(f'{package_name}.deprecation')
1931)         logging_cm = cli.StandardCLILogging.ensure_standard_logging()
1932)         with logging_cm:
1933)             assert (
1934)                 sum(
1935)                     1
1936)                     for h in logger.handlers
1937)                     if h is cli.StandardCLILogging.cli_handler
1938)                 )
1939)                 == 1
1940)             )
1941)             logger.warning('message 1')
1942)             with logging_cm:
1943)                 deprecation_logger.warning('message 2')
1944)                 assert (
1945)                     sum(
1946)                         1
1947)                         for h in logger.handlers
1948)                         if h is cli.StandardCLILogging.cli_handler
1949)                     )
1950)                     == 1
1951)                 )
1952)                 assert capsys.readouterr() == (
1953)                     '',
1954)                     (
1955)                         f'{prog_name}: Warning: message 1\n'
1956)                         f'{prog_name}: Deprecation warning: message 2\n'
1957)                     ),
1958)                 )
1959)             logger.warning('message 3')
1960)             assert (
1961)                 sum(
1962)                     1
1963)                     for h in logger.handlers
1964)                     if h is cli.StandardCLILogging.cli_handler
1965)                 )
1966)                 == 1
1967)             )
1968)             assert capsys.readouterr() == (
1969)                 '',
1970)                 f'{prog_name}: Warning: message 3\n',
1971)             )
1972)             assert caplog.record_tuples == [
1973)                 (package_name, logging.WARNING, 'message 1'),
1974)                 (f'{package_name}.deprecation', logging.WARNING, 'message 2'),
1975)                 (package_name, logging.WARNING, 'message 3'),
1976)             ]
1977) 
1978)     def test_121_standard_logging_warnings_context_manager(
1979)         self,
1980)         caplog: pytest.LogCaptureFixture,
1981)         capsys: pytest.CaptureFixture[str],
1982)     ) -> None:
1983)         warnings_cm = cli.StandardCLILogging.ensure_standard_warnings_logging()
1984)         THE_FUTURE = 'the future will be here sooner than you think'  # noqa: N806
1985)         JUST_TESTING = 'just testing whether warnings work'  # noqa: N806
1986)         with warnings_cm:
1987)             assert (
1988)                 sum(
1989)                     1
1990)                     for h in logging.getLogger('py.warnings').handlers
1991)                     if h is cli.StandardCLILogging.warnings_handler
1992)                 )
1993)                 == 1
1994)             )
1995)             warnings.warn(UserWarning(JUST_TESTING), stacklevel=1)
1996)             with warnings_cm:
1997)                 warnings.warn(FutureWarning(THE_FUTURE), stacklevel=1)
1998)                 _out, err = capsys.readouterr()
1999)                 err_lines = err.splitlines(True)
2000)                 assert any(
2001)                     f'UserWarning: {JUST_TESTING}' in line
2002)                     for line in err_lines
2003)                 )
2004)                 assert any(
2005)                     f'FutureWarning: {THE_FUTURE}' in line
2006)                     for line in err_lines
2007)                 )
2008)             warnings.warn(UserWarning(JUST_TESTING), stacklevel=1)
2009)             _out, err = capsys.readouterr()
2010)             err_lines = err.splitlines(True)
2011)             assert any(
2012)                 f'UserWarning: {JUST_TESTING}' in line for line in err_lines
2013)             )
2014)             assert not any(
2015)                 f'FutureWarning: {THE_FUTURE}' in line for line in err_lines
2016)             )
2017)             record_tuples = caplog.record_tuples
2018)             assert [tup[:2] for tup in record_tuples] == [
2019)                 ('py.warnings', logging.WARNING),
2020)                 ('py.warnings', logging.WARNING),
2021)                 ('py.warnings', logging.WARNING),
2022)             ]
2023)             assert f'UserWarning: {JUST_TESTING}' in record_tuples[0][2]
2024)             assert f'FutureWarning: {THE_FUTURE}' in record_tuples[1][2]
2025)             assert f'UserWarning: {JUST_TESTING}' in record_tuples[2][2]
2026) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2027)     @pytest.mark.parametrize(
2028)         ['command_line', 'config', 'result_config'],
2029)         [
2030)             (
2031)                 ['--delete-globals'],
2032)                 {'global': {'phrase': 'abc'}, 'services': {}},
2033)                 {'services': {}},
2034)             ),
2035)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

2037)                 {
2038)                     'global': {'phrase': 'abc'},
2039)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
2040)                 },
2041)                 {'global': {'phrase': 'abc'}, 'services': {}},
2042)             ),
2043)             (
2044)                 ['--clear'],
2045)                 {
2046)                     'global': {'phrase': 'abc'},
2047)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
2048)                 },
2049)                 {'services': {}},
2050)             ),
2051)         ],
2052)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2053)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

2057)         config: _types.VaultConfig,
2058)         result_config: _types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

2063)                 monkeypatch=monkeypatch,
2064)                 runner=runner,
2065)                 vault_config=start_config,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

2068)                     cli.derivepassphrase_vault,
2069)                     command_line,
2070)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

2079)                     config_readback = json.load(infile)
2080)                 assert config_readback == result_config
2081) 
2082)     def test_204_phrase_from_key_manually(self) -> None:
2083)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

2085)                 phrase=DUMMY_PHRASE_FROM_KEY1, **DUMMY_CONFIG_SETTINGS
2086)             ).generate(DUMMY_SERVICE)
2087)             == DUMMY_RESULT_KEY1
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2088)         )
2089) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2090)     @pytest.mark.parametrize(
2091)         ['vfunc', 'input'],
2092)         [
2093)             (cli._validate_occurrence_constraint, 20),
2094)             (cli._validate_length, 20),
2095)         ],
2096)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2097)     def test_210a_validate_constraints_manually(
2098)         self,
2099)         vfunc: Callable[[click.Context, click.Parameter, Any], int | None],
2100)         input: int,
2101)     ) -> None:
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

2107)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2115)             monkeypatch.setattr(
2116)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
2117)             )
2118)             hint: ssh_agent.SSHAgentClient | socket.socket | None
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

2119)             # Use match/case here once Python 3.9 becomes unsupported.
2120)             if conn_hint == 'client':
2121)                 hint = ssh_agent.SSHAgentClient()
2122)             elif conn_hint == 'socket':
2123)                 hint = socket.socket(family=socket.AF_UNIX)
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2125)             else:
2126)                 assert conn_hint == 'none'
2127)                 hint = None
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

2128)             exception: Exception | None = None
2129)             try:
2130)                 list(cli._get_suitable_ssh_keys(hint))
2131)             except RuntimeError:  # pragma: no cover
2132)                 pass
2133)             except Exception as e:  # noqa: BLE001 # pragma: no cover
2134)                 exception = e
2135)             finally:
2136)                 assert (
2137)                     exception is None
2138)                 ), 'exception querying suitable SSH keys'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

2140)     def test_400_key_to_phrase(
2141)         self,
2142)         monkeypatch: pytest.MonkeyPatch,
2143)         skip_if_no_af_unix_support: None,
2144)         ssh_agent_client_with_test_keys_loaded: ssh_agent.SSHAgentClient,
2145)     ) -> None:
2146) 
2147)         class CustomError(RuntimeError):
2148)             pass
2149) 
2150)         def err(*args: Any, **_kwargs: Any) -> NoReturn:
2151)             args = args or ('custom error message',)
2152)             raise CustomError(*args)
2153) 
2154)         def fail(*_args: Any, **_kwargs: Any) -> Any:
2155)             raise ssh_agent.SSHAgentFailedError(
2156)                 _types.SSH_AGENT.FAILURE.value,
2157)                 b'',
2158)             )
2159) 
2160)         del skip_if_no_af_unix_support
2161)         monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', fail)
2162)         loaded_keys = list(ssh_agent_client_with_test_keys_loaded.list_keys())
2163)         loaded_key = base64.standard_b64encode(loaded_keys[0][0])
2164)         with monkeypatch.context() as mp:
2165)             mp.setattr(
2166)                 ssh_agent.SSHAgentClient,
2167)                 'list_keys',
2168)                 lambda *_a, **_kw: [],
2169)             )
2170)             with pytest.raises(CustomError, match='not loaded into the agent'):
2171)                 cli._key_to_phrase(loaded_key, error_callback=err)
2172)         with monkeypatch.context() as mp:
2173)             mp.setattr(ssh_agent.SSHAgentClient, 'list_keys', fail)
2174)             with pytest.raises(
2175)                 CustomError, match='SSH agent failed to complete'
2176)             ):
2177)                 cli._key_to_phrase(loaded_key, error_callback=err)
2178)         with monkeypatch.context() as mp:
2179)             mp.setattr(ssh_agent.SSHAgentClient, 'list_keys', err)
2180)             with pytest.raises(
2181)                 CustomError, match='SSH agent failed to complete'
2182)             ) as excinfo:
2183)                 cli._key_to_phrase(loaded_key, error_callback=err)
2184)             assert excinfo.value.args
2185)             assert isinstance(
2186)                 excinfo.value.args[0], ssh_agent.SSHAgentFailedError
2187)             )
2188)             assert excinfo.value.args[0].__context__ is not None
2189)             assert isinstance(excinfo.value.args[0].__context__, CustomError)
2190)         with monkeypatch.context() as mp:
2191)             mp.delenv('SSH_AUTH_SOCK', raising=True)
2192)             with pytest.raises(
2193)                 CustomError, match='Cannot find running SSH agent'
2194)             ):
2195)                 cli._key_to_phrase(loaded_key, error_callback=err)
2196)         with monkeypatch.context() as mp:
2197)             mp.setenv(
2198)                 'SSH_AUTH_SOCK', os.environ['SSH_AUTH_SOCK'] + '~'
2199)             )
2200)             with pytest.raises(
2201)                 CustomError, match='Cannot connect to SSH agent'
2202)             ):
2203)                 cli._key_to_phrase(loaded_key, error_callback=err)
2204)         with monkeypatch.context() as mp:
2205)             mp.delattr(socket, 'AF_UNIX', raising=True)
2206)             with pytest.raises(
2207)                 CustomError, match='does not support UNIX domain sockets'
2208)             ):
2209)                 cli._key_to_phrase(loaded_key, error_callback=err)
2210) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2211) 
2212) class TestCLITransition:
2213)     def test_100_help_output(self, monkeypatch: pytest.MonkeyPatch) -> None:
2214)         runner = click.testing.CliRunner(mix_stderr=False)
2215)         with tests.isolated_config(
2216)             monkeypatch=monkeypatch,
2217)             runner=runner,
2218)         ):
2219)             _result = runner.invoke(
2220)                 cli.derivepassphrase, ['--help'], catch_exceptions=False
2221)             )
2222)             result = tests.ReadableResult.parse(_result)
2223)         assert result.clean_exit(
2224)             empty_stderr=True, output='currently implemented subcommands'
2225)         ), 'expected clean exit, and known help text'
2226) 
2227)     def test_101_help_output_export(
2228)         self, monkeypatch: pytest.MonkeyPatch
2229)     ) -> None:
2230)         runner = click.testing.CliRunner(mix_stderr=False)
2231)         with tests.isolated_config(
2232)             monkeypatch=monkeypatch,
2233)             runner=runner,
2234)         ):
2235)             _result = runner.invoke(
2236)                 cli.derivepassphrase,
2237)                 ['export', '--help'],
2238)                 catch_exceptions=False,
2239)             )
2240)             result = tests.ReadableResult.parse(_result)
2241)         assert result.clean_exit(
2242)             empty_stderr=True, output='only available subcommand'
2243)         ), 'expected clean exit, and known help text'
2244) 
2245)     def test_102_help_output_export_vault(
2246)         self, monkeypatch: pytest.MonkeyPatch
2247)     ) -> None:
2248)         runner = click.testing.CliRunner(mix_stderr=False)
2249)         with tests.isolated_config(
2250)             monkeypatch=monkeypatch,
2251)             runner=runner,
2252)         ):
2253)             _result = runner.invoke(
2254)                 cli.derivepassphrase,
2255)                 ['export', 'vault', '--help'],
2256)                 catch_exceptions=False,
2257)             )
2258)             result = tests.ReadableResult.parse(_result)
2259)         assert result.clean_exit(
2260)             empty_stderr=True, output='Read the vault-native configuration'
2261)         ), 'expected clean exit, and known help text'
2262) 
2263)     def test_103_help_output_vault(
2264)         self, monkeypatch: pytest.MonkeyPatch
2265)     ) -> None:
2266)         runner = click.testing.CliRunner(mix_stderr=False)
2267)         with tests.isolated_config(
2268)             monkeypatch=monkeypatch,
2269)             runner=runner,
2270)         ):
2271)             _result = runner.invoke(
2272)                 cli.derivepassphrase,
2273)                 ['vault', '--help'],
2274)                 catch_exceptions=False,
2275)             )
2276)             result = tests.ReadableResult.parse(_result)
2277)         assert result.clean_exit(
2278)             empty_stderr=True, output='Password generation:\n'
2279)         ), 'expected clean exit, and option groups in help text'
2280)         assert result.clean_exit(
2281)             empty_stderr=True, output='Use NUMBER=0, e.g. "--symbol 0"'
2282)         ), 'expected clean exit, and option group epilog in help text'
2283) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2284)     @pytest.mark.parametrize(
2285)         'config',
2286)         [
2287)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2288)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2289)             {
2290)                 'global': {'phrase': 'abc'},
2291)                 'services': {'sv': {'phrase': 'my passphrase'}},
2292)             },
2293)             {
2294)                 'global': {'phrase': 'abc'},
2295)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2296)             },
2297)             {
2298)                 'global': {'phrase': 'abc'},
2299)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2300)             },
2301)         ],
2302)     )
2303)     def test_110_load_config_backup(
2304)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2305)     ) -> None:
2306)         runner = click.testing.CliRunner()
2307)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2308)             config_filename = cli._config_filename(
2309)                 subsystem='old settings.json'
2310)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2311)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2312)                 print(json.dumps(config, indent=2), file=fileobj)
2313)             assert cli._migrate_and_load_old_config()[0] == config
2314) 
2315)     @pytest.mark.parametrize(
2316)         'config',
2317)         [
2318)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2319)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2320)             {
2321)                 'global': {'phrase': 'abc'},
2322)                 'services': {'sv': {'phrase': 'my passphrase'}},
2323)             },
2324)             {
2325)                 'global': {'phrase': 'abc'},
2326)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2327)             },
2328)             {
2329)                 'global': {'phrase': 'abc'},
2330)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2331)             },
2332)         ],
2333)     )
2334)     def test_111_migrate_config(
2335)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2336)     ) -> None:
2337)         runner = click.testing.CliRunner()
2338)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2339)             config_filename = cli._config_filename(
2340)                 subsystem='old settings.json'
2341)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2342)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2343)                 print(json.dumps(config, indent=2), file=fileobj)
2344)             assert cli._migrate_and_load_old_config() == (config, None)
2345) 
2346)     @pytest.mark.parametrize(
2347)         'config',
2348)         [
2349)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2350)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2351)             {
2352)                 'global': {'phrase': 'abc'},
2353)                 'services': {'sv': {'phrase': 'my passphrase'}},
2354)             },
2355)             {
2356)                 'global': {'phrase': 'abc'},
2357)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2358)             },
2359)             {
2360)                 'global': {'phrase': 'abc'},
2361)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2362)             },
2363)         ],
2364)     )
2365)     def test_112_migrate_config_error(
2366)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2367)     ) -> None:
2368)         runner = click.testing.CliRunner()
2369)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2370)             config_filename = cli._config_filename(
2371)                 subsystem='old settings.json'
2372)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2373)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2374)                 print(json.dumps(config, indent=2), file=fileobj)
2375)             os.mkdir(cli._config_filename(subsystem='vault'))
2376)             config2, err = cli._migrate_and_load_old_config()
2377)             assert config2 == config
2378)             assert isinstance(err, OSError)
2379)             assert err.errno == errno.EISDIR
2380) 
2381)     @pytest.mark.parametrize(
2382)         'config',
2383)         [
2384)             {'global': '', 'services': {}},
2385)             {'global': 0, 'services': {}},
2386)             {
2387)                 'global': {'phrase': 'abc'},
2388)                 'services': False,
2389)             },
2390)             {
2391)                 'global': {'phrase': 'abc'},
2392)                 'services': True,
2393)             },
2394)             {
2395)                 'global': {'phrase': 'abc'},
2396)                 'services': None,
2397)             },
2398)         ],
2399)     )
2400)     def test_113_migrate_config_error_bad_config_value(
2401)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2402)     ) -> None:
2403)         runner = click.testing.CliRunner()
2404)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2405)             config_filename = cli._config_filename(
2406)                 subsystem='old settings.json'
2407)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2408)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2409)                 print(json.dumps(config, indent=2), file=fileobj)
2410)             with pytest.raises(ValueError, match=cli._INVALID_VAULT_CONFIG):
2411)                 cli._migrate_and_load_old_config()
2412) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

2414)         self,
2415)         monkeypatch: pytest.MonkeyPatch,
2416)         caplog: pytest.LogCaptureFixture,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2417)     ) -> None:
2418)         pytest.importorskip('cryptography', minversion='38.0')
2419)         runner = click.testing.CliRunner(mix_stderr=False)
2420)         with tests.isolated_vault_exporter_config(
2421)             monkeypatch=monkeypatch,
2422)             runner=runner,
2423)             vault_config=tests.VAULT_V03_CONFIG,
2424)             vault_key=tests.VAULT_MASTER_KEY,
2425)         ):
2426)             monkeypatch.setenv('VAULT_KEY', tests.VAULT_MASTER_KEY)
2427)             _result = runner.invoke(
2428)                 cli.derivepassphrase,
2429)                 ['export', 'VAULT_PATH'],
2430)             )
2431)         result = tests.ReadableResult.parse(_result)
2432)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2433)         assert tests.deprecation_warning_emitted(
2434)             'A subcommand will be required in v1.0', caplog.record_tuples
2435)         )
2436)         assert tests.warning_emitted(
2437)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

2438)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

2441)     def test_201_forward_export_vault_empty_commandline(
2442)         self,
2443)         monkeypatch: pytest.MonkeyPatch,
2444)         caplog: pytest.LogCaptureFixture,
2445)     ) -> None:
2446)         pytest.importorskip('cryptography', minversion='38.0')
2447)         runner = click.testing.CliRunner(mix_stderr=False)
2448)         with tests.isolated_config(
2449)             monkeypatch=monkeypatch,
2450)             runner=runner,
2451)         ):
2452)             _result = runner.invoke(
2453)                 cli.derivepassphrase,
2454)                 ['export'],
2455)             )
2456)         result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2457)         assert tests.deprecation_warning_emitted(
2458)             'A subcommand will be required in v1.0', caplog.record_tuples
2459)         )
2460)         assert tests.warning_emitted(
2461)             'Defaulting to subcommand "vault"', caplog.record_tuples
2462)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2463)         assert result.error_exit(
2464)             error="Missing argument 'PATH'"
2465)         ), 'expected error exit and known error type'
2466) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2467)     @pytest.mark.parametrize(
2468)         'charset_name', ['lower', 'upper', 'number', 'space', 'dash', 'symbol']
2469)     )
2470)     def test_210_forward_vault_disable_character_set(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2471)         self,
2472)         monkeypatch: pytest.MonkeyPatch,
2473)         caplog: pytest.LogCaptureFixture,
2474)         charset_name: str,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

2479)         runner = click.testing.CliRunner(mix_stderr=False)
2480)         with tests.isolated_config(
2481)             monkeypatch=monkeypatch,
2482)             runner=runner,
2483)         ):
2484)             _result = runner.invoke(
2485)                 cli.derivepassphrase,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2487)                 input=DUMMY_PASSPHRASE,
2488)                 catch_exceptions=False,
2489)             )
2490)             result = tests.ReadableResult.parse(_result)
2491)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2492)         assert tests.deprecation_warning_emitted(
2493)             'A subcommand will be required in v1.0', caplog.record_tuples
2494)         )
2495)         assert tests.warning_emitted(
2496)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

2497)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2498)         for c in charset:
2499)             assert (
2500)                 c not in result.output
2501)             ), f'derived password contains forbidden character {c!r}'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2502) 
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2503)     def test_211_forward_vault_empty_command_line(
2504)         self,
2505)         monkeypatch: pytest.MonkeyPatch,
2506)         caplog: pytest.LogCaptureFixture,
2507)     ) -> None:
2508)         runner = click.testing.CliRunner(mix_stderr=False)
2509)         with tests.isolated_config(
2510)             monkeypatch=monkeypatch,
2511)             runner=runner,
2512)         ):
2513)             _result = runner.invoke(
2514)                 cli.derivepassphrase,
2515)                 [],
2516)                 input=DUMMY_PASSPHRASE,
2517)                 catch_exceptions=False,
2518)             )
2519)             result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2520)         assert tests.deprecation_warning_emitted(
2521)             'A subcommand will be required in v1.0', caplog.record_tuples
2522)         )
2523)         assert tests.warning_emitted(
2524)             'Defaulting to subcommand "vault"', caplog.record_tuples
2525)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2526)         assert result.error_exit(
2527)             error='SERVICE is required'
2528)         ), 'expected error exit and known error type'
2529) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2530)     def test_300_export_using_old_config_file(
2531)         self,
2532)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2536)         runner = click.testing.CliRunner(mix_stderr=False)
2537)         with tests.isolated_config(
2538)             monkeypatch=monkeypatch,
2539)             runner=runner,
2540)         ):
2541)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2542)                 cli._config_filename(subsystem='old settings.json'),
2543)                 'w',
2544)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2545)             ) as fileobj:
2546)                 print(
2547)                     json.dumps(
2548)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
2549)                         indent=2,
2550)                     ),
2551)                     file=fileobj,
2552)                 )
2553)             _result = runner.invoke(
2554)                 cli.derivepassphrase_vault,
2555)                 ['--export', '-'],
2556)                 catch_exceptions=False,
2557)             )
2558)         result = tests.ReadableResult.parse(_result)
2559)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2565)         ), 'expected known warning message in stderr'
2566) 
2567)     def test_300a_export_using_old_config_file_migration_error(
2568)         self,
2569)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2571)     ) -> None:
2572)         runner = click.testing.CliRunner(mix_stderr=False)
2573)         with tests.isolated_config(
2574)             monkeypatch=monkeypatch,
2575)             runner=runner,
2576)         ):
2577)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2578)                 cli._config_filename(subsystem='old settings.json'),
2579)                 'w',
2580)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2581)             ) as fileobj:
2582)                 print(
2583)                     json.dumps(
2584)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
2585)                         indent=2,
2586)                     ),
2587)                     file=fileobj,
2588)                 )
2589) 
2590)             def raiser(*_args: Any, **_kwargs: Any) -> None:
2591)                 raise OSError(
2592)                     errno.EACCES,
2593)                     os.strerror(errno.EACCES),
2594)                     cli._config_filename(subsystem='vault'),
2595)                 )
2596) 
2597)             monkeypatch.setattr(os, 'replace', raiser)
2598)             _result = runner.invoke(
2599)                 cli.derivepassphrase_vault,
2600)                 ['--export', '-'],
2601)                 catch_exceptions=False,
2602)             )
2603)         result = tests.ReadableResult.parse(_result)
2604)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

2611) 
2612) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2613) _known_services = (DUMMY_SERVICE, 'email', 'bank', 'work')
2614) _valid_properties = (
2615)     'length',
2616)     'repeat',
2617)     'upper',
2618)     'lower',
2619)     'number',
2620)     'space',
2621)     'dash',
2622)     'symbol',
2623) )
2624) 
2625) 
2626) def _build_reduced_vault_config_settings(
2627)     config: _types.VaultConfigServicesSettings,
2628)     keys_to_purge: frozenset[str],
2629) ) -> _types.VaultConfigServicesSettings:
2630)     config2 = copy.deepcopy(config)
2631)     for key in keys_to_purge:
2632)         config2.pop(key, None)  # type: ignore[misc]
2633)     return config2
2634) 
2635) 
2636) _services_strategy = strategies.builds(
2637)     _build_reduced_vault_config_settings,
2638)     tests.vault_full_service_config(),
2639)     strategies.sets(
2640)         strategies.sampled_from(_valid_properties),
2641)         max_size=7,
2642)     ),
2643) )
2644) 
2645) 
2646) def _assemble_config(
2647)     global_data: _types.VaultConfigGlobalSettings,
2648)     service_data: list[tuple[str, _types.VaultConfigServicesSettings]],
2649) ) -> _types.VaultConfig:
2650)     services_dict = dict(service_data)
2651)     return (
2652)         {'global': global_data, 'services': services_dict}
2653)         if global_data
2654)         else {'services': services_dict}
2655)     )
2656) 
2657) 
2658) @strategies.composite
2659) def _draw_service_name_and_data(
2660)     draw: hypothesis.strategies.DrawFn,
2661)     num_entries: int,
2662) ) -> tuple[tuple[str, _types.VaultConfigServicesSettings], ...]:
2663)     possible_services = list(_known_services)
2664)     selected_services: list[str] = []
2665)     for _ in range(num_entries):
2666)         selected_services.append(
2667)             draw(strategies.sampled_from(possible_services))
2668)         )
2669)         possible_services.remove(selected_services[-1])
2670)     return tuple(
2671)         (service, draw(_services_strategy)) for service in selected_services
2672)     )
2673) 
2674) 
2675) _vault_full_config = strategies.builds(
2676)     _assemble_config,
2677)     _services_strategy,
2678)     strategies.integers(
2679)         min_value=2,
2680)         max_value=4,
2681)     ).flatmap(_draw_service_name_and_data),
2682) )
2683) 
2684) 
Marco Ricci Actually correctly implemen...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2687)     def __init__(self) -> None:
2688)         super().__init__()
2689)         self.runner = click.testing.CliRunner(mix_stderr=False)
2690)         self.exit_stack = contextlib.ExitStack().__enter__()
2691)         self.monkeypatch = self.exit_stack.enter_context(
2692)             pytest.MonkeyPatch().context()
2693)         )
2694)         self.isolated_config = self.exit_stack.enter_context(
2695)             tests.isolated_vault_config(
2696)                 monkeypatch=self.monkeypatch,
2697)                 runner=self.runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

2699)             )
2700)         )
2701) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2702)     setting = stateful.Bundle('setting')
2703)     configuration = stateful.Bundle('configuration')
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2704) 
2705)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2706)         target=configuration,
2707)         configs=strategies.lists(
2708)             _vault_full_config,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

2709)             min_size=8,
2710)             max_size=8,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2711)         ),
2712)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2713)     def declare_initial_configs(
2714)         self,
2715)         configs: Iterable[_types.VaultConfig],
2716)     ) -> Iterable[_types.VaultConfig]:
2717)         return stateful.multiple(*configs)
Marco Ricci Test config merging with pa...

Marco Ricci authored 4 weeks ago

2718) 
2719)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 weeks ago

2721)         configs=strategies.lists(
2722)             _vault_full_config,
2723)             min_size=4,
2724)             max_size=4,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2725)         )
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2726)     )
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 2 months ago

2735) 
2736)     @staticmethod
2737)     def fold_configs(
2738)         c1: _types.VaultConfig, c2: _types.VaultConfig
2739)     ) -> _types.VaultConfig:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2741)         new_global_dict = c1.get('global', c2.get('global'))
2742)         if new_global_dict is not None:
2743)             return {
2744)                 'global': new_global_dict,
2745)                 'services': {**c2['services'], **c1['services']},
2746)             }
2747)         return {
2748)             'services': {**c2['services'], **c1['services']},
2749)         }
2750) 
2751)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2752)         target=configuration,
2753)         config=configuration,
2754)         setting=setting.filter(bool),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2756)     )
2757)     def set_globals(
2758)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2759)         config: _types.VaultConfig,
2760)         setting: _types.VaultConfigGlobalSettings,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

2762)     ) -> _types.VaultConfig:
2763)         cli._save_config(config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2764)         if overwrite:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2765)             config['global'] = {}
2766)         config.setdefault('global', {}).update(setting)
2767)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2768)         # NOTE: This relies on settings_obj containing only the keys
2769)         # "length", "repeat", "upper", "lower", "number", "space",
2770)         # "dash" and "symbol".
2771)         _result = self.runner.invoke(
2772)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2773)             [
2774)                 '--config',
2775)                 '--overwrite-existing' if overwrite else '--merge-existing',
2776)             ]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2777)             + [
2778)                 f'--{key}={value}'
2779)                 for key, value in setting.items()
2780)                 if key in _valid_properties
2781)             ],
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2782)             catch_exceptions=False,
2783)         )
2784)         result = tests.ReadableResult.parse(_result)
2785)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2788) 
2789)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2790)         target=configuration,
2791)         config=configuration,
2792)         service=strategies.sampled_from(_known_services),
2793)         setting=setting.filter(bool),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2795)     )
2796)     def set_service(
2797)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

2800)         setting: _types.VaultConfigServicesSettings,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

2802)     ) -> _types.VaultConfig:
2803)         cli._save_config(config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2804)         if overwrite:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2808)         # NOTE: This relies on settings_obj containing only the keys
2809)         # "length", "repeat", "upper", "lower", "number", "space",
2810)         # "dash" and "symbol".
2811)         _result = self.runner.invoke(
2812)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2813)             [
2814)                 '--config',
2815)                 '--overwrite-existing' if overwrite else '--merge-existing',
2816)             ]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2817)             + [
2818)                 f'--{key}={value}'
2819)                 for key, value in setting.items()
2820)                 if key in _valid_properties
2821)             ]
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2822)             + ['--', service],
2823)             catch_exceptions=False,
2824)         )
2825)         result = tests.ReadableResult.parse(_result)
2826)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2829) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2830)     @stateful.rule(
2831)         target=configuration,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 weeks ago

2833)     )
2834)     def purge_global(
2835)         self,
2836)         config: _types.VaultConfig,
2837)     ) -> _types.VaultConfig:
2838)         cli._save_config(config)
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 2 months ago

2840)         _result = self.runner.invoke(
2841)             cli.derivepassphrase_vault,
2842)             ['--delete-globals'],
2843)             input='y',
2844)             catch_exceptions=False,
2845)         )
2846)         result = tests.ReadableResult.parse(_result)
2847)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2850) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2851)     @stateful.rule(
2852)         target=configuration,
2853)         config_and_service=configuration.filter(
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 weeks ago

2855)         ).flatmap(
2856)             lambda c: strategies.tuples(
2857)                 strategies.just(c),
2858)                 strategies.sampled_from(tuple(c['services'].keys())),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

2860)         ),
2861)     )
2862)     def purge_service(
2863)         self,
2864)         config_and_service: tuple[_types.VaultConfig, str],
2865)     ) -> _types.VaultConfig:
2866)         config, service = config_and_service
2867)         cli._save_config(config)
2868)         config['services'].pop(service, None)
2869)         _result = self.runner.invoke(
2870)             cli.derivepassphrase_vault,
2871)             ['--delete', '--', service],
2872)             input='y',
2873)             catch_exceptions=False,
2874)         )
2875)         result = tests.ReadableResult.parse(_result)
2876)         assert result.clean_exit(empty_stderr=False)
2877)         assert cli._load_config() == config
2878)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2879) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2880)     @stateful.rule(
2881)         target=configuration,
Marco Ricci Rework `ConfigManagementSta...

Marco Ricci authored 2 weeks ago

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

Marco Ricci authored 4 weeks ago

2883)     )
2884)     def purge_all(
2885)         self,
2886)         config: _types.VaultConfig,
2887)     ) -> _types.VaultConfig:
2888)         cli._save_config(config)
2889)         config = {'services': {}}
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2890)         _result = self.runner.invoke(
2891)             cli.derivepassphrase_vault,
2892)             ['--clear'],
2893)             input='y',
2894)             catch_exceptions=False,
2895)         )
2896)         result = tests.ReadableResult.parse(_result)
2897)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2900) 
2901)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2902)         target=configuration,
2903)         base_config=configuration,
2904)         config_to_import=configuration,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

2909)         base_config: _types.VaultConfig,
2910)         config_to_import: _types.VaultConfig,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

2912)     ) -> _types.VaultConfig:
2913)         cli._save_config(base_config)
2914)         config = (
2915)             self.fold_configs(config_to_import, base_config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2925)             catch_exceptions=False,
2926)         )
2927)         assert tests.ReadableResult.parse(_result).clean_exit(
2928)             empty_stderr=False
2929)         )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2932) 
2933)     def teardown(self) -> None:
2934)         self.exit_stack.close()
2935) 
2936)