f02b81ad6df6d92cdcbb3469a7010f5f340afe99
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 Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

9) import errno
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

14) import socket
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

15) import warnings
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

26) 
27) if TYPE_CHECKING:
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

45) TEST_CONFIGS = tests.TEST_CONFIGS
46) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

52) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

57)     check_success: bool
58) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

65)     check_success: bool
66) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

92) ]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

97)         True,
98)         DUMMY_PASSPHRASE,
99)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

204) 
205) 
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

213)     possible_warnings = [
214)         'Replacing invalid value ',
215)         'Removing ineffective setting ',
216)         (
217)             'Setting a global passphrase is ineffective '
218)             'because a key is also set.'
219)         ),
220)         (
221)             'Setting a service passphrase is ineffective '
222)             'because a key is also set.'
223)         ),
224)     ]
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

226) 
227) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

245) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

263)                 input=DUMMY_PASSPHRASE,
264)                 catch_exceptions=False,
265)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

272) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

285)                 input=DUMMY_PASSPHRASE,
286)                 catch_exceptions=False,
287)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

298) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

323)     def test_204a_key_from_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

331)         ):
332)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

351) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

357)             monkeypatch=monkeypatch,
358)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

371)                 catch_exceptions=False,
372)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

383) 
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

438)     def test_205_service_phrase_if_key_in_global_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

466)                     catch_exceptions=False,
467)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

478) 
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

479)     @pytest.mark.parametrize(
480)         'config',
481)         [
482)             {
483)                 'services': {
484)                     DUMMY_SERVICE: {
485)                         'key': DUMMY_KEY1_B64,
486)                         **DUMMY_CONFIG_SETTINGS,
487)                     },
488)                 },
489)             },
490)             {
491)                 'global': {'key': DUMMY_KEY1_B64},
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

492)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()},
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

493)             },
494)         ],
495)     )
496)     def test_206_setting_service_phrase_thus_overriding_key_in_config(
497)         self,
498)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

501)         config: _types.VaultConfig,
502)     ) -> None:
503)         with monkeypatch.context():
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

505)             monkeypatch.setattr(
506)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
507)             )
508)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', tests.sign)
509)             runner = click.testing.CliRunner(mix_stderr=False)
510)             with tests.isolated_vault_config(
511)                 monkeypatch=monkeypatch,
512)                 runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

514)             ):
515)                 _result = runner.invoke(
516)                     cli.derivepassphrase_vault,
517)                     ['--config', '-p', '--', DUMMY_SERVICE],
518)                     input=DUMMY_PASSPHRASE,
519)                     catch_exceptions=False,
520)                 )
521)         result = tests.ReadableResult.parse(_result)
522)         assert result.clean_exit(), 'expected clean exit'
523)         assert not result.output.strip(), 'expected no program output'
524)         assert result.stderr, 'expected known error output'
525)         err_lines = result.stderr.splitlines(False)
526)         assert err_lines[0].startswith('Passphrase:')
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

527)         assert tests.warning_emitted(
528)             'Setting a service passphrase is ineffective ',
529)             caplog.record_tuples,
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

531)         assert all(map(is_warning_line, result.stderr.splitlines(True)))
532)         assert all(
533)             map(is_harmless_config_import_warning, caplog.record_tuples)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

534)         ), 'unexpected error output'
535) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

536)     @pytest.mark.parametrize(
537)         'option',
538)         [
539)             '--lower',
540)             '--upper',
541)             '--number',
542)             '--space',
543)             '--dash',
544)             '--symbol',
545)             '--repeat',
546)             '--length',
547)         ],
548)     )
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

553)         with tests.isolated_config(
554)             monkeypatch=monkeypatch,
555)             runner=runner,
556)         ):
557)             for value in '-42', 'invalid':
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

561)                     input=DUMMY_PASSPHRASE,
562)                     catch_exceptions=False,
563)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

568) 
569)     @pytest.mark.parametrize(
570)         ['options', 'service', 'input', 'check_success'],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

571)         [
572)             (o.options, o.needs_service, o.input, o.check_success)
573)             for o in INTERESTING_OPTION_COMBINATIONS
574)             if not o.incompatible
575)         ],
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

576)     )
577)     def test_211_service_needed(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

588)             monkeypatch=monkeypatch,
589)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

595)                 input=input,
596)                 catch_exceptions=False,
597)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

605)                 assert result.error_exit(
606)                     error=err_msg
607)                 ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

609)                 assert result.clean_exit(
610)                     empty_stderr=True
611)                 ), 'expected clean exit'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

614)                 monkeypatch=monkeypatch,
615)                 runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

617)             ):
618)                 monkeypatch.setattr(
619)                     cli, '_prompt_for_passphrase', tests.auto_prompt
620)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

624)                     input=input,
625)                     catch_exceptions=False,
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)                 result = tests.ReadableResult.parse(_result)
628)             assert result.clean_exit(empty_stderr=True), 'expected clean exit'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 months ago

630)     def test_211a_empty_service_name_causes_warning(
631)         self,
632)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

635)         def is_expected_warning(record: tuple[str, int, str]) -> bool:
636)             return is_harmless_config_import_warning(
637)                 record
638)             ) or tests.warning_emitted(
639)                 'An empty SERVICE is not supported by vault(1)', [record]
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

640)             )
641) 
642)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
643)         runner = click.testing.CliRunner(mix_stderr=False)
644)         with tests.isolated_vault_config(
645)             monkeypatch=monkeypatch,
646)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

648)         ):
649)             _result = runner.invoke(
650)                 cli.derivepassphrase_vault,
651)                 ['--config', '--length=30', '--', ''],
652)                 catch_exceptions=False,
653)             )
654)             result = tests.ReadableResult.parse(_result)
655)             assert result.clean_exit(empty_stderr=False), 'expected clean exit'
656)             assert result.stderr is not None, 'expected known error output'
657)             assert all(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

659)             ), 'expected known error output'
660)             assert cli._load_config() == {
661)                 'global': {'length': 30},
662)                 'services': {},
663)             }, 'requested configuration change was not applied'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

665)             _result = runner.invoke(
666)                 cli.derivepassphrase_vault,
667)                 ['--import', '-'],
668)                 input=json.dumps({'services': {'': {'length': 40}}}),
669)                 catch_exceptions=False,
670)             )
671)             result = tests.ReadableResult.parse(_result)
672)             assert result.clean_exit(empty_stderr=False), 'expected clean exit'
673)             assert result.stderr is not None, 'expected known error output'
674)             assert all(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

676)             ), 'expected known error output'
677)             assert cli._load_config() == {
678)                 'global': {'length': 30},
679)                 'services': {'': {'length': 40}},
680)             }, 'requested configuration change was not applied'
681) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

684)         [
685)             (o.options, o.needs_service)
686)             for o in INTERESTING_OPTION_COMBINATIONS
687)             if o.incompatible
688)         ],
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

690)     def test_212_incompatible_options(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

697)         with tests.isolated_config(
698)             monkeypatch=monkeypatch,
699)             runner=runner,
700)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

704)                 input=DUMMY_PASSPHRASE,
705)                 catch_exceptions=False,
706)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

707)         result = tests.ReadableResult.parse(_result)
708)         assert result.error_exit(
709)             error='mutually exclusive with '
710)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

712)     @pytest.mark.parametrize(
713)         'config',
714)         [
715)             conf.config
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

717)             if tests.is_valid_test_config(conf)
718)         ],
719)     )
720)     def test_213_import_config_success(
721)         self,
722)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

724)         config: Any,
725)     ) -> None:
726)         runner = click.testing.CliRunner(mix_stderr=False)
727)         with tests.isolated_vault_config(
728)             monkeypatch=monkeypatch,
729)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

731)         ):
732)             _result = runner.invoke(
733)                 cli.derivepassphrase_vault,
734)                 ['--import', '-'],
735)                 input=json.dumps(config),
736)                 catch_exceptions=False,
737)             )
738)             with open(
739)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
740)             ) as infile:
741)                 config2 = json.load(infile)
742)         result = tests.ReadableResult.parse(_result)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

750)     @hypothesis.given(
751)         conf=tests.smudged_vault_test_config(
752)             strategies.sampled_from(TEST_CONFIGS).filter(
753)                 tests.is_valid_test_config
754)             )
755)         )
756)     )
757)     def test_213a_import_config_success(
758)         self,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

760)         conf: tests.VaultTestConfig,
761)     ) -> None:
762)         config = conf.config
763)         config2 = copy.deepcopy(config)
764)         _types.clean_up_falsy_vault_config_values(config2)
765)         runner = click.testing.CliRunner(mix_stderr=False)
766)         with tests.isolated_vault_config(
767)             monkeypatch=pytest.MonkeyPatch(),
768)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

770)         ):
771)             _result = runner.invoke(
772)                 cli.derivepassphrase_vault,
773)                 ['--import', '-'],
774)                 input=json.dumps(config),
775)                 catch_exceptions=False,
776)             )
777)             with open(
778)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
779)             ) as infile:
780)                 config3 = json.load(infile)
781)         result = tests.ReadableResult.parse(_result)
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

787) 
788)     def test_213b_import_bad_config_not_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

800)         result = tests.ReadableResult.parse(_result)
801)         assert result.error_exit(
802)             error='Invalid vault config'
803)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

805)     def test_213c_import_bad_config_not_json_data(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

817)         result = tests.ReadableResult.parse(_result)
818)         assert result.error_exit(
819)             error='cannot decode JSON'
820)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

822)     def test_213d_import_bad_config_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

842)         result = tests.ReadableResult.parse(_result)
843)         assert result.error_exit(
844)             error=os.strerror(errno.EISDIR)
845)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

846) 
847)     def test_214_export_settings_no_stored_settings(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

856)                 cli.derivepassphrase_vault,
857)                 ['--export', '-'],
858)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

863)     def test_214a_export_settings_bad_stored_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

877)         result = tests.ReadableResult.parse(_result)
878)         assert result.error_exit(
879)             error='Cannot load config'
880)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

882)     def test_214b_export_settings_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

902)     def test_214c_export_settings_target_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

915)         result = tests.ReadableResult.parse(_result)
916)         assert result.error_exit(
917)             error='Cannot store config'
918)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

919) 
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

920)     def test_214d_export_settings_settings_directory_not_a_directory(
921)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

934)                 catch_exceptions=False,
935)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

936)         result = tests.ReadableResult.parse(_result)
937)         assert result.error_exit(
938)             error='Cannot load config'
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

942) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

943)     def test_220_edit_notes_successfully(
944)         self, monkeypatch: pytest.MonkeyPatch
945)     ) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

947) 
948) # - - - - - >8 - - - - - >8 - - - - - >8 - - - - - >8 - - - - -
949) contents go here
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

953)             monkeypatch=monkeypatch,
954)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

969)             assert config == {
970)                 'global': {'phrase': 'abc'},
971)                 'services': {'sv': {'notes': 'contents go here'}},
972)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

973) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

974)     def test_221_edit_notes_noop(
975)         self, monkeypatch: pytest.MonkeyPatch
976)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

979)             monkeypatch=monkeypatch,
980)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1018)             assert config == {
1019)                 'global': {'phrase': 'abc'},
1020)                 'services': {'sv': {'notes': 'long\ntext'}},
1021)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1022) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1023)     def test_223_edit_notes_abort(
1024)         self, monkeypatch: pytest.MonkeyPatch
1025)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1028)             monkeypatch=monkeypatch,
1029)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1038)             result = tests.ReadableResult.parse(_result)
1039)             assert result.error_exit(
1040)                 error='user aborted request'
1041)             ), 'expected known error message'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1048)     @pytest.mark.parametrize(
1049)         ['command_line', 'input', 'result_config'],
1050)         [
1051)             (
1052)                 ['--phrase'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1054)                 {'global': {'phrase': 'my passphrase'}, 'services': {}},
1055)             ),
1056)             (
1057)                 ['--key'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

1059)                 {
1060)                     'global': {'key': DUMMY_KEY1_B64, 'phrase': 'abc'},
1061)                     'services': {},
1062)                 },
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1063)             ),
1064)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1067)                 {
1068)                     'global': {'phrase': 'abc'},
1069)                     'services': {'sv': {'phrase': 'my passphrase'}},
1070)                 },
1071)             ),
1072)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1075)                 {
1076)                     'global': {'phrase': 'abc'},
1077)                     'services': {'sv': {'key': DUMMY_KEY1_B64}},
1078)                 },
1079)             ),
1080)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1083)                 {
1084)                     'global': {'phrase': 'abc'},
1085)                     'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1086)                 },
1087)             ),
1088)         ],
1089)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1090)     def test_224_store_config_good(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1095)         result_config: Any,
1096)     ) -> None:
1097)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

1102)         ):
1103)             monkeypatch.setattr(
1104)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1105)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1108)                 ['--config', *command_line],
1109)                 catch_exceptions=False,
1110)                 input=input,
1111)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1118)             assert (
1119)                 config == result_config
1120)             ), 'stored config does not match expectation'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1121) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1122)     @pytest.mark.parametrize(
1123)         ['command_line', 'input', 'err_text'],
1124)         [
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1128)                 '',
1129)                 'Cannot update service settings without actual settings',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1133)         ],
1134)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1135)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1139)         input: str,
1140)         err_text: str,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1144)             monkeypatch=monkeypatch,
1145)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

1147)         ):
1148)             monkeypatch.setattr(
1149)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1150)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1153)                 ['--config', *command_line],
1154)                 catch_exceptions=False,
1155)                 input=input,
1156)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1157)         result = tests.ReadableResult.parse(_result)
1158)         assert result.error_exit(
1159)             error=err_text
1160)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1161) 
1162)     def test_225a_store_config_fail_manual_no_ssh_key_selection(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1168)             monkeypatch=monkeypatch,
1169)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1180)                 ['--key', '--config'],
1181)                 catch_exceptions=False,
1182)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1183)         result = tests.ReadableResult.parse(_result)
1184)         assert result.error_exit(
1185)             error=custom_error
1186)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

1188)     def test_225b_store_config_fail_manual_no_ssh_agent(
1189)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1196)             monkeypatch=monkeypatch,
1197)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1206)         result = tests.ReadableResult.parse(_result)
1207)         assert result.error_exit(
1208)             error='Cannot find running SSH agent'
1209)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1231) 
1232)     @pytest.mark.parametrize('try_race_free_implementation', [True, False])
1233)     def test_225d_store_config_fail_manual_read_only_file(
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)         try_race_free_implementation: bool,
1237)     ) -> None:
1238)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1243)         ):
1244)             tests.make_file_readonly(
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1246)                 try_race_free_implementation=try_race_free_implementation,
1247)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1251)                 catch_exceptions=False,
1252)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1253)         result = tests.ReadableResult.parse(_result)
1254)         assert result.error_exit(
1255)             error='Cannot store config'
1256)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1257) 
1258)     def test_225e_store_config_fail_manual_custom_error(
1259)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1267)         ):
1268)             custom_error = 'custom error message'
1269) 
1270)             def raiser(config: Any) -> None:
1271)                 del config
1272)                 raise RuntimeError(custom_error)
1273) 
1274)             monkeypatch.setattr(cli, '_save_config', raiser)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1278)                 catch_exceptions=False,
1279)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1280)         result = tests.ReadableResult.parse(_result)
1281)         assert result.error_exit(
1282)             error=custom_error
1283)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1284) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1287)         with tests.isolated_config(
1288)             monkeypatch=monkeypatch,
1289)             runner=runner,
1290)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1294)         result = tests.ReadableResult.parse(_result)
1295)         assert result.error_exit(
1296)             error='SERVICE is required'
1297)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

1298) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1299)     def test_226a_no_passphrase_or_key(
1300)         self, monkeypatch: pytest.MonkeyPatch
1301)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1303)         with tests.isolated_config(
1304)             monkeypatch=monkeypatch,
1305)             runner=runner,
1306)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1316) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1317)     def test_230_config_directory_nonexistant(
1318)         self, monkeypatch: pytest.MonkeyPatch
1319)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1321)         runner = click.testing.CliRunner(mix_stderr=False)
1322)         with tests.isolated_config(
1323)             monkeypatch=monkeypatch,
1324)             runner=runner,
1325)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1327)             os_makedirs_called = False
1328)             real_os_makedirs = os.makedirs
1329) 
1330)             def makedirs(*args: Any, **kwargs: Any) -> Any:
1331)                 nonlocal os_makedirs_called
1332)                 os_makedirs_called = True
1333)                 return real_os_makedirs(*args, **kwargs)
1334) 
1335)             monkeypatch.setattr(os, 'makedirs', makedirs)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1338)                 ['--config', '-p'],
1339)                 catch_exceptions=False,
1340)                 input='abc\n',
1341)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1351)                 config_readback = json.load(infile)
1352)             assert config_readback == {
1353)                 'global': {'phrase': 'abc'},
1354)                 'services': {},
1355)             }, 'config mismatch'
1356) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1357)     def test_230a_config_directory_not_a_file(
1358)         self, monkeypatch: pytest.MonkeyPatch
1359)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1361)         runner = click.testing.CliRunner(mix_stderr=False)
1362)         with tests.isolated_config(
1363)             monkeypatch=monkeypatch,
1364)             runner=runner,
1365)         ):
1366)             _save_config = cli._save_config
1367) 
1368)             def obstruct_config_saving(*args: Any, **kwargs: Any) -> Any:
1369)                 with contextlib.suppress(FileNotFoundError):
1370)                     shutil.rmtree('.derivepassphrase')
1371)                 with open(
1372)                     '.derivepassphrase', 'w', encoding='UTF-8'
1373)                 ) as outfile:
1374)                     print('Obstruction!!', file=outfile)
1375)                 monkeypatch.setattr(cli, '_save_config', _save_config)
1376)                 return _save_config(*args, **kwargs)
1377) 
1378)             monkeypatch.setattr(cli, '_save_config', obstruct_config_saving)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1381)                 ['--config', '-p'],
1382)                 catch_exceptions=False,
1383)                 input='abc\n',
1384)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1385)             result = tests.ReadableResult.parse(_result)
1386)             assert result.error_exit(
1387)                 error='Cannot store config'
1388)             ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1389) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1390)     def test_230b_store_config_custom_error(
1391)         self, monkeypatch: pytest.MonkeyPatch
1392)     ) -> None:
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1393)         runner = click.testing.CliRunner(mix_stderr=False)
1394)         with tests.isolated_config(
1395)             monkeypatch=monkeypatch,
1396)             runner=runner,
1397)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1400)             def raiser(config: Any) -> None:
1401)                 del config
1402)                 raise RuntimeError(custom_error)
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1407)                 ['--config', '-p'],
1408)                 catch_exceptions=False,
1409)                 input='abc\n',
1410)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1416)     @pytest.mark.parametrize(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1418)         [
1419)             pytest.param(
1420)                 ['--import', '-'],
1421)                 json.dumps({
1422)                     'global': {'phrase': 'Du\u0308sseldorf'},
1423)                     'services': {},
1424)                 }),
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1426)                 id='global-NFC',
1427)             ),
1428)             pytest.param(
1429)                 ['--import', '-'],
1430)                 json.dumps({
1431)                     'services': {
1432)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1433)                         'weird entry name': {'phrase': 'Du\u0308sseldorf'},
1434)                     }
1435)                 }),
1436)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1438)                     'is not NFC-normalized'
1439)                 ),
1440)                 id='service-weird-name-NFC',
1441)             ),
1442)             pytest.param(
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1444)                 'Du\u0308sseldorf',
1445)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1447)                     f'is not NFC-normalized'
1448)                 ),
1449)                 id='config-NFC',
1450)             ),
1451)             pytest.param(
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1453)                 'Du\u0308sseldorf',
1454)                 'the interactive passphrase is not NFC-normalized',
1455)                 id='direct-input-NFC',
1456)             ),
1457)             pytest.param(
1458)                 ['--import', '-'],
1459)                 json.dumps({
1460)                     'global': {
1461)                         'unicode_normalization_form': 'NFD',
1462)                         'phrase': 'D\u00fcsseldorf',
1463)                     },
1464)                     'services': {},
1465)                 }),
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1467)                 id='global-NFD',
1468)             ),
1469)             pytest.param(
1470)                 ['--import', '-'],
1471)                 json.dumps({
1472)                     'global': {
1473)                         'unicode_normalization_form': 'NFD',
1474)                     },
1475)                     'services': {
1476)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1477)                         'weird entry name': {'phrase': 'D\u00fcsseldorf'},
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1479)                 }),
1480)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1482)                     'is not NFD-normalized'
1483)                 ),
1484)                 id='service-weird-name-NFD',
1485)             ),
1486)         ],
1487)     )
1488)     def test_300_unicode_normalization_form_warning(
1489)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

1491)         caplog: pytest.LogCaptureFixture,
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1498)             monkeypatch=monkeypatch,
1499)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1500)             vault_config={
1501)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1502)             },
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1505)                 cli.derivepassphrase_vault,
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1506)                 command_line,
1507)                 catch_exceptions=False,
1508)                 input=input,
1509)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1515) 
Marco Ricci Fail gracefully if UNIX dom...

Marco Ricci authored 3 months ago

1516)     def test_400_missing_af_unix_support(
1517)         self,
1518)         monkeypatch: pytest.MonkeyPatch,
1519)     ) -> None:
1520)         runner = click.testing.CliRunner(mix_stderr=False)
1521)         with tests.isolated_vault_config(
1522)             monkeypatch=monkeypatch,
1523)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

1525)         ):
1526)             monkeypatch.setenv(
1527)                 'SSH_AUTH_SOCK', "the value doesn't even matter"
1528)             )
1529)             monkeypatch.delattr(socket, 'AF_UNIX', raising=False)
1530)             _result = runner.invoke(
1531)                 cli.derivepassphrase_vault,
1532)                 ['--key', '--config'],
1533)                 catch_exceptions=False,
1534)             )
1535)         result = tests.ReadableResult.parse(_result)
1536)         assert result.error_exit(
1537)             error='does not support UNIX domain sockets'
1538)         ), 'expected error exit and known error message'
1539) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

1542)     @pytest.mark.parametrize(
1543)         'config',
1544)         [
1545)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1546)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1547)             {
1548)                 'global': {'phrase': 'abc'},
1549)                 'services': {'sv': {'phrase': 'my passphrase'}},
1550)             },
1551)             {
1552)                 'global': {'phrase': 'abc'},
1553)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1554)             },
1555)             {
1556)                 'global': {'phrase': 'abc'},
1557)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1558)             },
1559)         ],
1560)     )
1561)     def test_100_load_config(
1562)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1563)     ) -> None:
1564)         runner = click.testing.CliRunner()
1565)         with tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

1567)         ):
1568)             config_filename = cli._config_filename(subsystem='vault')
1569)             with open(config_filename, encoding='UTF-8') as fileobj:
1570)                 assert json.load(fileobj) == config
1571)             assert cli._load_config() == config
1572) 
1573)     def test_110_save_bad_config(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

1577)         # Use parenthesized context manager expressions here once Python
1578)         # 3.9 becomes unsupported.
1579)         with contextlib.ExitStack() as stack:
1580)             stack.enter_context(
1581)                 tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

1583)                 )
1584)             )
1585)             stack.enter_context(
1586)                 pytest.raises(ValueError, match='Invalid vault config')
1587)             )
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1589) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1595)             # from https://montypython.fandom.com/wiki/Spam#The_menu
1596)             items = items or [
1597)                 'Egg and bacon',
1598)                 'Egg, sausage and bacon',
1599)                 'Egg and spam',
1600)                 'Egg, bacon and spam',
1601)                 'Egg, bacon, sausage and spam',
1602)                 'Spam, bacon, sausage and spam',
1603)                 'Spam, egg, spam, spam, bacon and spam',
1604)                 'Spam, spam, spam, egg and spam',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1605)                 (
1606)                     'Spam, spam, spam, spam, spam, spam, baked beans, '
1607)                     'spam, spam, spam and spam'
1608)                 ),
1609)                 (
1610)                     'Lobster thermidor aux crevettes with a mornay sauce '
1611)                     'garnished with truffle paté, brandy '
1612)                     'and a fried egg on top and spam'
1613)                 ),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1614)             ]
1615)             index = cli._prompt_for_selection(items, heading=heading)
1616)             click.echo('A fine choice: ', nl=False)
1617)             click.echo(items[index])
1618)             click.echo('(Note: Vikings strictly optional.)')
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

1621)         _result = runner.invoke(driver, [], input='9')
1622)         result = tests.ReadableResult.parse(_result)
1623)         assert result.clean_exit(
1624)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1625) Our menu:
1626) [1] Egg and bacon
1627) [2] Egg, sausage and bacon
1628) [3] Egg and spam
1629) [4] Egg, bacon and spam
1630) [5] Egg, bacon, sausage and spam
1631) [6] Spam, bacon, sausage and spam
1632) [7] Spam, egg, spam, spam, bacon and spam
1633) [8] Spam, spam, spam, egg and spam
1634) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1635) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
1636) Your selection? (1-10, leave empty to abort): 9
1637) A fine choice: Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1638) (Note: Vikings strictly optional.)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1644)         result = tests.ReadableResult.parse(_result)
1645)         assert result.error_exit(
1646)             error=IndexError
1647)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1649)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1651) [1] Egg and bacon
1652) [2] Egg, sausage and bacon
1653) [3] Egg and spam
1654) [4] Egg, bacon and spam
1655) [5] Egg, bacon, sausage and spam
1656) [6] Spam, bacon, sausage and spam
1657) [7] Spam, egg, spam, spam, bacon and spam
1658) [8] Spam, spam, spam, egg and spam
1659) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1660) [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

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1664) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1670)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1671)                 cli._prompt_for_selection(
1672)                     [item], heading='', single_choice_prompt=prompt
1673)                 )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1684)         result = tests.ReadableResult.parse(_result)
1685)         assert result.clean_exit(
1686)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

1695)             input='',
1696)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1697)         result = tests.ReadableResult.parse(_result)
1698)         assert result.error_exit(
1699)             error=IndexError
1700)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1702)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1706) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1709) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1713)         monkeypatch.setattr(
1714)             click,
1715)             'prompt',
1716)             lambda *a, **kw: json.dumps({'args': a, 'kwargs': kw}),
1717)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1719)         err_msg = 'missing arguments to passphrase prompt'
1720)         assert 'args' in res, err_msg
1721)         assert 'kwargs' in res, err_msg
1722)         assert res['args'][:1] == ['Passphrase'], err_msg
1723)         assert res['kwargs'].get('default') == '', err_msg
1724)         assert not res['kwargs'].get('show_default', True), err_msg
1725)         assert res['kwargs'].get('err'), err_msg
1726)         assert res['kwargs'].get('hide_input'), err_msg
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

1728)     def test_120_standard_logging_context_manager(
1729)         self,
1730)         caplog: pytest.LogCaptureFixture,
1731)         capsys: pytest.CaptureFixture[str],
1732)     ) -> None:
1733)         prog_name = cli.StandardCLILogging.prog_name
1734)         package_name = cli.StandardCLILogging.package_name
1735)         logger = logging.getLogger(package_name)
1736)         deprecation_logger = logging.getLogger(f'{package_name}.deprecation')
1737)         logging_cm = cli.StandardCLILogging.ensure_standard_logging()
1738)         with logging_cm:
1739)             assert (
1740)                 sum(
1741)                     1
1742)                     for h in logger.handlers
1743)                     if h is cli.StandardCLILogging.cli_handler
1744)                 )
1745)                 == 1
1746)             )
1747)             logger.warning('message 1')
1748)             with logging_cm:
1749)                 deprecation_logger.warning('message 2')
1750)                 assert (
1751)                     sum(
1752)                         1
1753)                         for h in logger.handlers
1754)                         if h is cli.StandardCLILogging.cli_handler
1755)                     )
1756)                     == 1
1757)                 )
1758)                 assert capsys.readouterr() == (
1759)                     '',
1760)                     (
1761)                         f'{prog_name}: Warning: message 1\n'
1762)                         f'{prog_name}: Deprecation warning: message 2\n'
1763)                     ),
1764)                 )
1765)             logger.warning('message 3')
1766)             assert (
1767)                 sum(
1768)                     1
1769)                     for h in logger.handlers
1770)                     if h is cli.StandardCLILogging.cli_handler
1771)                 )
1772)                 == 1
1773)             )
1774)             assert capsys.readouterr() == (
1775)                 '',
1776)                 f'{prog_name}: Warning: message 3\n',
1777)             )
1778)             assert caplog.record_tuples == [
1779)                 (package_name, logging.WARNING, 'message 1'),
1780)                 (f'{package_name}.deprecation', logging.WARNING, 'message 2'),
1781)                 (package_name, logging.WARNING, 'message 3'),
1782)             ]
1783) 
1784)     def test_121_standard_logging_warnings_context_manager(
1785)         self,
1786)         caplog: pytest.LogCaptureFixture,
1787)         capsys: pytest.CaptureFixture[str],
1788)     ) -> None:
1789)         warnings_cm = cli.StandardCLILogging.ensure_standard_warnings_logging()
1790)         THE_FUTURE = 'the future will be here sooner than you think'  # noqa: N806
1791)         JUST_TESTING = 'just testing whether warnings work'  # noqa: N806
1792)         with warnings_cm:
1793)             assert (
1794)                 sum(
1795)                     1
1796)                     for h in logging.getLogger('py.warnings').handlers
1797)                     if h is cli.StandardCLILogging.warnings_handler
1798)                 )
1799)                 == 1
1800)             )
1801)             warnings.warn(UserWarning(JUST_TESTING), stacklevel=1)
1802)             with warnings_cm:
1803)                 warnings.warn(FutureWarning(THE_FUTURE), stacklevel=1)
1804)                 _out, err = capsys.readouterr()
1805)                 err_lines = err.splitlines(True)
1806)                 assert any(
1807)                     f'UserWarning: {JUST_TESTING}' in line
1808)                     for line in err_lines
1809)                 )
1810)                 assert any(
1811)                     f'FutureWarning: {THE_FUTURE}' in line
1812)                     for line in err_lines
1813)                 )
1814)             warnings.warn(UserWarning(JUST_TESTING), stacklevel=1)
1815)             _out, err = capsys.readouterr()
1816)             err_lines = err.splitlines(True)
1817)             assert any(
1818)                 f'UserWarning: {JUST_TESTING}' in line for line in err_lines
1819)             )
1820)             assert not any(
1821)                 f'FutureWarning: {THE_FUTURE}' in line for line in err_lines
1822)             )
1823)             record_tuples = caplog.record_tuples
1824)             assert [tup[:2] for tup in record_tuples] == [
1825)                 ('py.warnings', logging.WARNING),
1826)                 ('py.warnings', logging.WARNING),
1827)                 ('py.warnings', logging.WARNING),
1828)             ]
1829)             assert f'UserWarning: {JUST_TESTING}' in record_tuples[0][2]
1830)             assert f'FutureWarning: {THE_FUTURE}' in record_tuples[1][2]
1831)             assert f'UserWarning: {JUST_TESTING}' in record_tuples[2][2]
1832) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1833)     @pytest.mark.parametrize(
1834)         ['command_line', 'config', 'result_config'],
1835)         [
1836)             (
1837)                 ['--delete-globals'],
1838)                 {'global': {'phrase': 'abc'}, 'services': {}},
1839)                 {'services': {}},
1840)             ),
1841)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

1843)                 {
1844)                     'global': {'phrase': 'abc'},
1845)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
1846)                 },
1847)                 {'global': {'phrase': 'abc'}, 'services': {}},
1848)             ),
1849)             (
1850)                 ['--clear'],
1851)                 {
1852)                     'global': {'phrase': 'abc'},
1853)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
1854)                 },
1855)                 {'services': {}},
1856)             ),
1857)         ],
1858)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1859)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1863)         config: _types.VaultConfig,
1864)         result_config: _types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

1869)                 monkeypatch=monkeypatch,
1870)                 runner=runner,
1871)                 vault_config=start_config,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1874)                     cli.derivepassphrase_vault,
1875)                     command_line,
1876)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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)                     empty_stderr=True
1881)                 ), 'expected clean exit'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

1885)                     config_readback = json.load(infile)
1886)                 assert config_readback == result_config
1887) 
1888)     def test_204_phrase_from_key_manually(self) -> None:
1889)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1891)                 phrase=DUMMY_PHRASE_FROM_KEY1, **DUMMY_CONFIG_SETTINGS
1892)             ).generate(DUMMY_SERVICE)
1893)             == DUMMY_RESULT_KEY1
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1894)         )
1895) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1896)     @pytest.mark.parametrize(
1897)         ['vfunc', 'input'],
1898)         [
1899)             (cli._validate_occurrence_constraint, 20),
1900)             (cli._validate_length, 20),
1901)         ],
1902)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1903)     def test_210a_validate_constraints_manually(
1904)         self,
1905)         vfunc: Callable[[click.Context, click.Parameter, Any], int | None],
1906)         input: int,
1907)     ) -> None:
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1913)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

1921)             monkeypatch.setattr(
1922)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
1923)             )
1924)             hint: ssh_agent.SSHAgentClient | socket.socket | None
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

1925)             # Use match/case here once Python 3.9 becomes unsupported.
1926)             if conn_hint == 'client':
1927)                 hint = ssh_agent.SSHAgentClient()
1928)             elif conn_hint == 'socket':
1929)                 hint = socket.socket(family=socket.AF_UNIX)
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

1931)             else:
1932)                 assert conn_hint == 'none'
1933)                 hint = None
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

1934)             exception: Exception | None = None
1935)             try:
1936)                 list(cli._get_suitable_ssh_keys(hint))
1937)             except RuntimeError:  # pragma: no cover
1938)                 pass
1939)             except Exception as e:  # noqa: BLE001 # pragma: no cover
1940)                 exception = e
1941)             finally:
1942)                 assert (
1943)                     exception is None
1944)                 ), 'exception querying suitable SSH keys'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1945) 
1946) 
1947) class TestCLITransition:
1948)     def test_100_help_output(self, monkeypatch: pytest.MonkeyPatch) -> None:
1949)         runner = click.testing.CliRunner(mix_stderr=False)
1950)         with tests.isolated_config(
1951)             monkeypatch=monkeypatch,
1952)             runner=runner,
1953)         ):
1954)             _result = runner.invoke(
1955)                 cli.derivepassphrase, ['--help'], catch_exceptions=False
1956)             )
1957)             result = tests.ReadableResult.parse(_result)
1958)         assert result.clean_exit(
1959)             empty_stderr=True, output='currently implemented subcommands'
1960)         ), 'expected clean exit, and known help text'
1961) 
1962)     def test_101_help_output_export(
1963)         self, monkeypatch: pytest.MonkeyPatch
1964)     ) -> None:
1965)         runner = click.testing.CliRunner(mix_stderr=False)
1966)         with tests.isolated_config(
1967)             monkeypatch=monkeypatch,
1968)             runner=runner,
1969)         ):
1970)             _result = runner.invoke(
1971)                 cli.derivepassphrase,
1972)                 ['export', '--help'],
1973)                 catch_exceptions=False,
1974)             )
1975)             result = tests.ReadableResult.parse(_result)
1976)         assert result.clean_exit(
1977)             empty_stderr=True, output='only available subcommand'
1978)         ), 'expected clean exit, and known help text'
1979) 
1980)     def test_102_help_output_export_vault(
1981)         self, monkeypatch: pytest.MonkeyPatch
1982)     ) -> None:
1983)         runner = click.testing.CliRunner(mix_stderr=False)
1984)         with tests.isolated_config(
1985)             monkeypatch=monkeypatch,
1986)             runner=runner,
1987)         ):
1988)             _result = runner.invoke(
1989)                 cli.derivepassphrase,
1990)                 ['export', 'vault', '--help'],
1991)                 catch_exceptions=False,
1992)             )
1993)             result = tests.ReadableResult.parse(_result)
1994)         assert result.clean_exit(
1995)             empty_stderr=True, output='Read the vault-native configuration'
1996)         ), 'expected clean exit, and known help text'
1997) 
1998)     def test_103_help_output_vault(
1999)         self, monkeypatch: pytest.MonkeyPatch
2000)     ) -> None:
2001)         runner = click.testing.CliRunner(mix_stderr=False)
2002)         with tests.isolated_config(
2003)             monkeypatch=monkeypatch,
2004)             runner=runner,
2005)         ):
2006)             _result = runner.invoke(
2007)                 cli.derivepassphrase,
2008)                 ['vault', '--help'],
2009)                 catch_exceptions=False,
2010)             )
2011)             result = tests.ReadableResult.parse(_result)
2012)         assert result.clean_exit(
2013)             empty_stderr=True, output='Password generation:\n'
2014)         ), 'expected clean exit, and option groups in help text'
2015)         assert result.clean_exit(
2016)             empty_stderr=True, output='Use NUMBER=0, e.g. "--symbol 0"'
2017)         ), 'expected clean exit, and option group epilog in help text'
2018) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2019)     @pytest.mark.parametrize(
2020)         'config',
2021)         [
2022)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2023)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2024)             {
2025)                 'global': {'phrase': 'abc'},
2026)                 'services': {'sv': {'phrase': 'my passphrase'}},
2027)             },
2028)             {
2029)                 'global': {'phrase': 'abc'},
2030)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2031)             },
2032)             {
2033)                 'global': {'phrase': 'abc'},
2034)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2035)             },
2036)         ],
2037)     )
2038)     def test_110_load_config_backup(
2039)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2040)     ) -> None:
2041)         runner = click.testing.CliRunner()
2042)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2043)             config_filename = cli._config_filename(
2044)                 subsystem='old settings.json'
2045)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2046)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2047)                 print(json.dumps(config, indent=2), file=fileobj)
2048)             assert cli._migrate_and_load_old_config()[0] == config
2049) 
2050)     @pytest.mark.parametrize(
2051)         'config',
2052)         [
2053)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2054)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2055)             {
2056)                 'global': {'phrase': 'abc'},
2057)                 'services': {'sv': {'phrase': 'my passphrase'}},
2058)             },
2059)             {
2060)                 'global': {'phrase': 'abc'},
2061)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2062)             },
2063)             {
2064)                 'global': {'phrase': 'abc'},
2065)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2066)             },
2067)         ],
2068)     )
2069)     def test_111_migrate_config(
2070)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2071)     ) -> None:
2072)         runner = click.testing.CliRunner()
2073)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2074)             config_filename = cli._config_filename(
2075)                 subsystem='old settings.json'
2076)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2077)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2078)                 print(json.dumps(config, indent=2), file=fileobj)
2079)             assert cli._migrate_and_load_old_config() == (config, None)
2080) 
2081)     @pytest.mark.parametrize(
2082)         'config',
2083)         [
2084)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2085)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2086)             {
2087)                 'global': {'phrase': 'abc'},
2088)                 'services': {'sv': {'phrase': 'my passphrase'}},
2089)             },
2090)             {
2091)                 'global': {'phrase': 'abc'},
2092)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2093)             },
2094)             {
2095)                 'global': {'phrase': 'abc'},
2096)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2097)             },
2098)         ],
2099)     )
2100)     def test_112_migrate_config_error(
2101)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2102)     ) -> None:
2103)         runner = click.testing.CliRunner()
2104)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2105)             config_filename = cli._config_filename(
2106)                 subsystem='old settings.json'
2107)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2108)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2109)                 print(json.dumps(config, indent=2), file=fileobj)
2110)             os.mkdir(cli._config_filename(subsystem='vault'))
2111)             config2, err = cli._migrate_and_load_old_config()
2112)             assert config2 == config
2113)             assert isinstance(err, OSError)
2114)             assert err.errno == errno.EISDIR
2115) 
2116)     @pytest.mark.parametrize(
2117)         'config',
2118)         [
2119)             {'global': '', 'services': {}},
2120)             {'global': 0, 'services': {}},
2121)             {
2122)                 'global': {'phrase': 'abc'},
2123)                 'services': False,
2124)             },
2125)             {
2126)                 'global': {'phrase': 'abc'},
2127)                 'services': True,
2128)             },
2129)             {
2130)                 'global': {'phrase': 'abc'},
2131)                 'services': None,
2132)             },
2133)         ],
2134)     )
2135)     def test_113_migrate_config_error_bad_config_value(
2136)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2137)     ) -> None:
2138)         runner = click.testing.CliRunner()
2139)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2140)             config_filename = cli._config_filename(
2141)                 subsystem='old settings.json'
2142)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2143)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2144)                 print(json.dumps(config, indent=2), file=fileobj)
2145)             with pytest.raises(ValueError, match=cli._INVALID_VAULT_CONFIG):
2146)                 cli._migrate_and_load_old_config()
2147) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

2149)         self,
2150)         monkeypatch: pytest.MonkeyPatch,
2151)         caplog: pytest.LogCaptureFixture,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2152)     ) -> None:
2153)         pytest.importorskip('cryptography', minversion='38.0')
2154)         runner = click.testing.CliRunner(mix_stderr=False)
2155)         with tests.isolated_vault_exporter_config(
2156)             monkeypatch=monkeypatch,
2157)             runner=runner,
2158)             vault_config=tests.VAULT_V03_CONFIG,
2159)             vault_key=tests.VAULT_MASTER_KEY,
2160)         ):
2161)             monkeypatch.setenv('VAULT_KEY', tests.VAULT_MASTER_KEY)
2162)             _result = runner.invoke(
2163)                 cli.derivepassphrase,
2164)                 ['export', 'VAULT_PATH'],
2165)             )
2166)         result = tests.ReadableResult.parse(_result)
2167)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2168)         assert tests.deprecation_warning_emitted(
2169)             'A subcommand will be required in v1.0', caplog.record_tuples
2170)         )
2171)         assert tests.warning_emitted(
2172)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

2173)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

2176)     def test_201_forward_export_vault_empty_commandline(
2177)         self,
2178)         monkeypatch: pytest.MonkeyPatch,
2179)         caplog: pytest.LogCaptureFixture,
2180)     ) -> None:
2181)         pytest.importorskip('cryptography', minversion='38.0')
2182)         runner = click.testing.CliRunner(mix_stderr=False)
2183)         with tests.isolated_config(
2184)             monkeypatch=monkeypatch,
2185)             runner=runner,
2186)         ):
2187)             _result = runner.invoke(
2188)                 cli.derivepassphrase,
2189)                 ['export'],
2190)             )
2191)         result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2192)         assert tests.deprecation_warning_emitted(
2193)             'A subcommand will be required in v1.0', caplog.record_tuples
2194)         )
2195)         assert tests.warning_emitted(
2196)             'Defaulting to subcommand "vault"', caplog.record_tuples
2197)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2198)         assert result.error_exit(
2199)             error="Missing argument 'PATH'"
2200)         ), 'expected error exit and known error type'
2201) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2202)     @pytest.mark.parametrize(
2203)         'charset_name', ['lower', 'upper', 'number', 'space', 'dash', 'symbol']
2204)     )
2205)     def test_210_forward_vault_disable_character_set(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2206)         self,
2207)         monkeypatch: pytest.MonkeyPatch,
2208)         caplog: pytest.LogCaptureFixture,
2209)         charset_name: str,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2222)                 input=DUMMY_PASSPHRASE,
2223)                 catch_exceptions=False,
2224)             )
2225)             result = tests.ReadableResult.parse(_result)
2226)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2227)         assert tests.deprecation_warning_emitted(
2228)             'A subcommand will be required in v1.0', caplog.record_tuples
2229)         )
2230)         assert tests.warning_emitted(
2231)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

2232)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2233)         for c in charset:
2234)             assert (
2235)                 c not in result.output
2236)             ), f'derived password contains forbidden character {c!r}'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2237) 
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2238)     def test_211_forward_vault_empty_command_line(
2239)         self,
2240)         monkeypatch: pytest.MonkeyPatch,
2241)         caplog: pytest.LogCaptureFixture,
2242)     ) -> None:
2243)         runner = click.testing.CliRunner(mix_stderr=False)
2244)         with tests.isolated_config(
2245)             monkeypatch=monkeypatch,
2246)             runner=runner,
2247)         ):
2248)             _result = runner.invoke(
2249)                 cli.derivepassphrase,
2250)                 [],
2251)                 input=DUMMY_PASSPHRASE,
2252)                 catch_exceptions=False,
2253)             )
2254)             result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2255)         assert tests.deprecation_warning_emitted(
2256)             'A subcommand will be required in v1.0', caplog.record_tuples
2257)         )
2258)         assert tests.warning_emitted(
2259)             'Defaulting to subcommand "vault"', caplog.record_tuples
2260)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2261)         assert result.error_exit(
2262)             error='SERVICE is required'
2263)         ), 'expected error exit and known error type'
2264) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2265)     def test_300_export_using_old_config_file(
2266)         self,
2267)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2271)         runner = click.testing.CliRunner(mix_stderr=False)
2272)         with tests.isolated_config(
2273)             monkeypatch=monkeypatch,
2274)             runner=runner,
2275)         ):
2276)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2277)                 cli._config_filename(subsystem='old settings.json'),
2278)                 'w',
2279)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2280)             ) as fileobj:
2281)                 print(
2282)                     json.dumps(
2283)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
2284)                         indent=2,
2285)                     ),
2286)                     file=fileobj,
2287)                 )
2288)             _result = runner.invoke(
2289)                 cli.derivepassphrase_vault,
2290)                 ['--export', '-'],
2291)                 catch_exceptions=False,
2292)             )
2293)         result = tests.ReadableResult.parse(_result)
2294)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2300)         ), 'expected known warning message in stderr'
2301) 
2302)     def test_300a_export_using_old_config_file_migration_error(
2303)         self,
2304)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2306)     ) -> None:
2307)         runner = click.testing.CliRunner(mix_stderr=False)
2308)         with tests.isolated_config(
2309)             monkeypatch=monkeypatch,
2310)             runner=runner,
2311)         ):
2312)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2313)                 cli._config_filename(subsystem='old settings.json'),
2314)                 'w',
2315)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2316)             ) as fileobj:
2317)                 print(
2318)                     json.dumps(
2319)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
2320)                         indent=2,
2321)                     ),
2322)                     file=fileobj,
2323)                 )
2324) 
2325)             def raiser(*_args: Any, **_kwargs: Any) -> None:
2326)                 raise OSError(
2327)                     errno.EACCES,
2328)                     os.strerror(errno.EACCES),
2329)                     cli._config_filename(subsystem='vault'),
2330)                 )
2331) 
2332)             monkeypatch.setattr(os, 'replace', raiser)
2333)             _result = runner.invoke(
2334)                 cli.derivepassphrase_vault,
2335)                 ['--export', '-'],
2336)                 catch_exceptions=False,
2337)             )
2338)         result = tests.ReadableResult.parse(_result)
2339)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

2346) 
2347) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2348) _known_services = (DUMMY_SERVICE, 'email', 'bank', 'work')
2349) _valid_properties = (
2350)     'length',
2351)     'repeat',
2352)     'upper',
2353)     'lower',
2354)     'number',
2355)     'space',
2356)     'dash',
2357)     'symbol',
2358) )
2359) 
2360) 
2361) def _build_reduced_vault_config_settings(
2362)     config: _types.VaultConfigServicesSettings,
2363)     keys_to_purge: frozenset[str],
2364) ) -> _types.VaultConfigServicesSettings:
2365)     config2 = copy.deepcopy(config)
2366)     for key in keys_to_purge:
2367)         config2.pop(key, None)  # type: ignore[misc]
2368)     return config2
2369) 
2370) 
2371) _services_strategy = strategies.builds(
2372)     _build_reduced_vault_config_settings,
2373)     tests.vault_full_service_config(),
2374)     strategies.sets(
2375)         strategies.sampled_from(_valid_properties),
2376)         max_size=7,
2377)     ),
2378) )
2379) 
2380) 
2381) def _assemble_config(
2382)     global_data: _types.VaultConfigGlobalSettings,
2383)     service_data: list[tuple[str, _types.VaultConfigServicesSettings]],
2384) ) -> _types.VaultConfig:
2385)     services_dict = dict(service_data)
2386)     return (
2387)         {'global': global_data, 'services': services_dict}
2388)         if global_data
2389)         else {'services': services_dict}
2390)     )
2391) 
2392) 
2393) @strategies.composite
2394) def _draw_service_name_and_data(
2395)     draw: hypothesis.strategies.DrawFn,
2396)     num_entries: int,
2397) ) -> tuple[tuple[str, _types.VaultConfigServicesSettings], ...]:
2398)     possible_services = list(_known_services)
2399)     selected_services: list[str] = []
2400)     for _ in range(num_entries):
2401)         selected_services.append(
2402)             draw(strategies.sampled_from(possible_services))
2403)         )
2404)         possible_services.remove(selected_services[-1])
2405)     return tuple(
2406)         (service, draw(_services_strategy)) for service in selected_services
2407)     )
2408) 
2409) 
2410) _vault_full_config = strategies.builds(
2411)     _assemble_config,
2412)     _services_strategy,
2413)     strategies.integers(
2414)         min_value=2,
2415)         max_value=4,
2416)     ).flatmap(_draw_service_name_and_data),
2417) )
2418) 
2419) 
Marco Ricci Actually correctly implemen...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2422)     def __init__(self) -> None:
2423)         super().__init__()
2424)         self.runner = click.testing.CliRunner(mix_stderr=False)
2425)         self.exit_stack = contextlib.ExitStack().__enter__()
2426)         self.monkeypatch = self.exit_stack.enter_context(
2427)             pytest.MonkeyPatch().context()
2428)         )
2429)         self.isolated_config = self.exit_stack.enter_context(
2430)             tests.isolated_vault_config(
2431)                 monkeypatch=self.monkeypatch,
2432)                 runner=self.runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

2434)             )
2435)         )
2436) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2437)     setting = stateful.Bundle('setting')
2438)     configuration = stateful.Bundle('configuration')
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2439) 
2440)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2441)         target=configuration,
2442)         configs=strategies.lists(
2443)             _vault_full_config,
2444)             min_size=4,
2445)             max_size=4,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2446)         ),
2447)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2448)     def declare_initial_configs(
2449)         self,
2450)         configs: Iterable[_types.VaultConfig],
2451)     ) -> Iterable[_types.VaultConfig]:
2452)         return stateful.multiple(*configs)
Marco Ricci Test config merging with pa...

Marco Ricci authored 4 weeks ago

2453) 
2454)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2455)         target=setting,
2456)         config=_vault_full_config,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

2458)     def extract_initial_settings(
2459)         self,
2460)         config: _types.VaultConfig,
2461)     ) -> Iterable[_types.VaultConfigServicesSettings]:
2462)         return stateful.multiple(
2463)             *map(copy.deepcopy, config['services'].values())
2464)         )
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2465) 
2466)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2467)         target=configuration,
2468)         config=_vault_full_config,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

2470)     def declare_config(
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2473)     ) -> _types.VaultConfig:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2474)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2475) 
2476)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2477)         target=setting,
2478)         config=_vault_full_config,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

2480)     def extract_settings(
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

2482)         config: _types.VaultConfig,
2483)     ) -> Iterable[_types.VaultConfigServicesSettings]:
2484)         return stateful.multiple(
2485)             *map(copy.deepcopy, config['services'].values())
2486)         )
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2487) 
2488)     @staticmethod
2489)     def fold_configs(
2490)         c1: _types.VaultConfig, c2: _types.VaultConfig
2491)     ) -> _types.VaultConfig:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2493)         new_global_dict = c1.get('global', c2.get('global'))
2494)         if new_global_dict is not None:
2495)             return {
2496)                 'global': new_global_dict,
2497)                 'services': {**c2['services'], **c1['services']},
2498)             }
2499)         return {
2500)             'services': {**c2['services'], **c1['services']},
2501)         }
2502) 
2503)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2504)         target=configuration,
2505)         config=configuration,
2506)         setting=setting.filter(bool),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2508)     )
2509)     def set_globals(
2510)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2511)         config: _types.VaultConfig,
2512)         setting: _types.VaultConfigGlobalSettings,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

2514)     ) -> _types.VaultConfig:
2515)         cli._save_config(config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2516)         if overwrite:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2517)             config['global'] = {}
2518)         config.setdefault('global', {}).update(setting)
2519)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2520)         # NOTE: This relies on settings_obj containing only the keys
2521)         # "length", "repeat", "upper", "lower", "number", "space",
2522)         # "dash" and "symbol".
2523)         _result = self.runner.invoke(
2524)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2525)             [
2526)                 '--config',
2527)                 '--overwrite-existing' if overwrite else '--merge-existing',
2528)             ]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2529)             + [
2530)                 f'--{key}={value}'
2531)                 for key, value in setting.items()
2532)                 if key in _valid_properties
2533)             ],
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2534)             catch_exceptions=False,
2535)         )
2536)         result = tests.ReadableResult.parse(_result)
2537)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2540) 
2541)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2542)         target=configuration,
2543)         config=configuration,
2544)         service=strategies.sampled_from(_known_services),
2545)         setting=setting.filter(bool),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2547)     )
2548)     def set_service(
2549)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

2552)         setting: _types.VaultConfigServicesSettings,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

2554)     ) -> _types.VaultConfig:
2555)         cli._save_config(config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2556)         if overwrite:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2560)         # NOTE: This relies on settings_obj containing only the keys
2561)         # "length", "repeat", "upper", "lower", "number", "space",
2562)         # "dash" and "symbol".
2563)         _result = self.runner.invoke(
2564)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2565)             [
2566)                 '--config',
2567)                 '--overwrite-existing' if overwrite else '--merge-existing',
2568)             ]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2569)             + [
2570)                 f'--{key}={value}'
2571)                 for key, value in setting.items()
2572)                 if key in _valid_properties
2573)             ]
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2574)             + ['--', service],
2575)             catch_exceptions=False,
2576)         )
2577)         result = tests.ReadableResult.parse(_result)
2578)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2581) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2582)     @stateful.rule(
2583)         target=configuration,
2584)         config=configuration.filter(lambda c: 'global' in c),
2585)     )
2586)     def purge_global(
2587)         self,
2588)         config: _types.VaultConfig,
2589)     ) -> _types.VaultConfig:
2590)         cli._save_config(config)
2591)         config.pop('global')
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2592)         _result = self.runner.invoke(
2593)             cli.derivepassphrase_vault,
2594)             ['--delete-globals'],
2595)             input='y',
2596)             catch_exceptions=False,
2597)         )
2598)         result = tests.ReadableResult.parse(_result)
2599)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2602) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2603)     @stateful.rule(
2604)         target=configuration,
2605)         config_and_service=configuration.filter(
2606)             lambda c: len(c['services']) > 1
2607)         ).flatmap(
2608)             lambda c: strategies.tuples(
2609)                 strategies.just(c),
2610)                 strategies.sampled_from(tuple(c['services'].keys())),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

2612)         ),
2613)     )
2614)     def purge_service(
2615)         self,
2616)         config_and_service: tuple[_types.VaultConfig, str],
2617)     ) -> _types.VaultConfig:
2618)         config, service = config_and_service
2619)         cli._save_config(config)
2620)         config['services'].pop(service, None)
2621)         _result = self.runner.invoke(
2622)             cli.derivepassphrase_vault,
2623)             ['--delete', '--', service],
2624)             input='y',
2625)             catch_exceptions=False,
2626)         )
2627)         result = tests.ReadableResult.parse(_result)
2628)         assert result.clean_exit(empty_stderr=False)
2629)         assert cli._load_config() == config
2630)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2631) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2632)     @stateful.rule(
2633)         target=configuration,
2634)         config=configuration.filter(lambda c: 0 < len(c['services']) < 5),
2635)     )
2636)     def purge_all(
2637)         self,
2638)         config: _types.VaultConfig,
2639)     ) -> _types.VaultConfig:
2640)         cli._save_config(config)
2641)         config = {'services': {}}
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2642)         _result = self.runner.invoke(
2643)             cli.derivepassphrase_vault,
2644)             ['--clear'],
2645)             input='y',
2646)             catch_exceptions=False,
2647)         )
2648)         result = tests.ReadableResult.parse(_result)
2649)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2652) 
2653)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2654)         target=configuration,
2655)         base_config=configuration,
2656)         config_to_import=configuration,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

2661)         base_config: _types.VaultConfig,
2662)         config_to_import: _types.VaultConfig,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

2664)     ) -> _types.VaultConfig:
2665)         cli._save_config(base_config)
2666)         config = (
2667)             self.fold_configs(config_to_import, base_config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2677)             catch_exceptions=False,
2678)         )
2679)         assert tests.ReadableResult.parse(_result).clean_exit(
2680)             empty_stderr=False
2681)         )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2684) 
2685)     def teardown(self) -> None:
2686)         self.exit_stack.close()
2687) 
2688)