b9849af1b001d25ac62165f88778cfa18aacb547
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 Reformat everything with ruff

Marco Ricci authored 5 months ago

330)             monkeypatch=monkeypatch, runner=runner, config=config
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,
359)             config={'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
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(
423)                 monkeypatch=monkeypatch, runner=runner, config=config
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,
453)                 config={
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,
513)                 config=config,
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,
590)             config={'global': {'phrase': 'abc'}, 'services': {}},
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,
616)                 config={'global': {'phrase': 'abc'}, 'services': {}},
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,
647)             config={'services': {}},
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,
730)             config={'services': {}},
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,
769)             config={'services': {}},
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 Reformat everything with ruff

Marco Ricci authored 5 months ago

869)             monkeypatch=monkeypatch, runner=runner, config={}
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'
939)         ), 'expected error exit and known error message'
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

940) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

945) 
946) # - - - - - >8 - - - - - >8 - - - - - >8 - - - - - >8 - - - - -
947) contents go here
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

951)             monkeypatch=monkeypatch,
952)             runner=runner,
953)             config={'global': {'phrase': 'abc'}, 'services': {}},
954)         ):
955)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: edit_result)  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

971) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

977)             monkeypatch=monkeypatch,
978)             runner=runner,
979)             config={'global': {'phrase': 'abc'}, 'services': {}},
980)         ):
981)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: None)  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1000)             monkeypatch=monkeypatch,
1001)             runner=runner,
1002)             config={'global': {'phrase': 'abc'}, 'services': {}},
1003)         ):
1004)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: 'long\ntext')  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1020) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1026)             monkeypatch=monkeypatch,
1027)             runner=runner,
1028)             config={'global': {'phrase': 'abc'}, 'services': {}},
1029)         ):
1030)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: '\n\n')  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 5 months ago

1061)             ),
1062)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1088)     def test_224_store_config_good(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1097)             monkeypatch=monkeypatch,
1098)             runner=runner,
1099)             config={'global': {'phrase': 'abc'}, 'services': {}},
1100)         ):
1101)             monkeypatch.setattr(
1102)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1103)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1119) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1126)                 '',
1127)                 'Cannot update service settings without actual settings',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1131)         ],
1132)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1133)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1137)         input: str,
1138)         err_text: str,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1142)             monkeypatch=monkeypatch,
1143)             runner=runner,
1144)             config={'global': {'phrase': 'abc'}, 'services': {}},
1145)         ):
1146)             monkeypatch.setattr(
1147)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1148)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1159) 
1160)     def test_225a_store_config_fail_manual_no_ssh_key_selection(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1166)             monkeypatch=monkeypatch,
1167)             runner=runner,
1168)             config={'global': {'phrase': 'abc'}, 'services': {}},
1169)         ):
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

1186)     def test_225b_store_config_fail_manual_no_ssh_agent(
1187)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1194)             monkeypatch=monkeypatch,
1195)             runner=runner,
1196)             config={'global': {'phrase': 'abc'}, 'services': {}},
1197)         ):
1198)             monkeypatch.delenv('SSH_AUTH_SOCK', raising=False)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1208) 
1209)     def test_225c_store_config_fail_manual_bad_ssh_agent_connection(
1210)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1215)             monkeypatch=monkeypatch,
1216)             runner=runner,
1217)             config={'global': {'phrase': 'abc'}, 'services': {}},
1218)         ):
1219)             monkeypatch.setenv('SSH_AUTH_SOCK', os.getcwd())
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1229) 
1230)     @pytest.mark.parametrize('try_race_free_implementation', [True, False])
1231)     def test_225d_store_config_fail_manual_read_only_file(
1232)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1234)         try_race_free_implementation: bool,
1235)     ) -> None:
1236)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1238)             monkeypatch=monkeypatch,
1239)             runner=runner,
1240)             config={'global': {'phrase': 'abc'}, 'services': {}},
1241)         ):
1242)             tests.make_file_readonly(
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1244)                 try_race_free_implementation=try_race_free_implementation,
1245)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1249)                 catch_exceptions=False,
1250)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1255) 
1256)     def test_225e_store_config_fail_manual_custom_error(
1257)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1262)             monkeypatch=monkeypatch,
1263)             runner=runner,
1264)             config={'global': {'phrase': 'abc'}, 'services': {}},
1265)         ):
1266)             custom_error = 'custom error message'
1267) 
1268)             def raiser(config: Any) -> None:
1269)                 del config
1270)                 raise RuntimeError(custom_error)
1271) 
1272)             monkeypatch.setattr(cli, '_save_config', raiser)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1276)                 catch_exceptions=False,
1277)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1282) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1296) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1314) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1387) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

1442)                 'Du\u0308sseldorf',
1443)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1477)                 }),
1478)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1496)             monkeypatch=monkeypatch,
1497)             runner=runner,
1498)             config={'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}},
1499)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1502)                 command_line,
1503)                 catch_exceptions=False,
1504)                 input=input,
1505)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1512)     def test_400_missing_af_unix_support(
1513)         self,
1514)         monkeypatch: pytest.MonkeyPatch,
1515)     ) -> None:
1516)         runner = click.testing.CliRunner(mix_stderr=False)
1517)         with tests.isolated_vault_config(
1518)             monkeypatch=monkeypatch,
1519)             runner=runner,
1520)             config={'global': {'phrase': 'abc'}, 'services': {}},
1521)         ):
1522)             monkeypatch.setenv(
1523)                 'SSH_AUTH_SOCK', "the value doesn't even matter"
1524)             )
1525)             monkeypatch.delattr(socket, 'AF_UNIX', raising=False)
1526)             _result = runner.invoke(
1527)                 cli.derivepassphrase_vault,
1528)                 ['--key', '--config'],
1529)                 catch_exceptions=False,
1530)             )
1531)         result = tests.ReadableResult.parse(_result)
1532)         assert result.error_exit(
1533)             error='does not support UNIX domain sockets'
1534)         ), 'expected error exit and known error message'
1535) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

1538)     @pytest.mark.parametrize(
1539)         'config',
1540)         [
1541)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1542)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1543)             {
1544)                 'global': {'phrase': 'abc'},
1545)                 'services': {'sv': {'phrase': 'my passphrase'}},
1546)             },
1547)             {
1548)                 'global': {'phrase': 'abc'},
1549)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1550)             },
1551)             {
1552)                 'global': {'phrase': 'abc'},
1553)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1554)             },
1555)         ],
1556)     )
1557)     def test_100_load_config(
1558)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1559)     ) -> None:
1560)         runner = click.testing.CliRunner()
1561)         with tests.isolated_vault_config(
1562)             monkeypatch=monkeypatch, runner=runner, config=config
1563)         ):
1564)             config_filename = cli._config_filename(subsystem='vault')
1565)             with open(config_filename, encoding='UTF-8') as fileobj:
1566)                 assert json.load(fileobj) == config
1567)             assert cli._load_config() == config
1568) 
1569)     def test_110_save_bad_config(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

1573)         # Use parenthesized context manager expressions here once Python
1574)         # 3.9 becomes unsupported.
1575)         with contextlib.ExitStack() as stack:
1576)             stack.enter_context(
1577)                 tests.isolated_vault_config(
1578)                     monkeypatch=monkeypatch, runner=runner, config={}
1579)                 )
1580)             )
1581)             stack.enter_context(
1582)                 pytest.raises(ValueError, match='Invalid vault config')
1583)             )
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1585) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

1617)         _result = runner.invoke(driver, [], input='9')
1618)         result = tests.ReadableResult.parse(_result)
1619)         assert result.clean_exit(
1620)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1640)         result = tests.ReadableResult.parse(_result)
1641)         assert result.error_exit(
1642)             error=IndexError
1643)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1645)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1660) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1666)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1667)                 cli._prompt_for_selection(
1668)                     [item], heading='', single_choice_prompt=prompt
1669)                 )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1680)         result = tests.ReadableResult.parse(_result)
1681)         assert result.clean_exit(
1682)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

1691)             input='',
1692)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1693)         result = tests.ReadableResult.parse(_result)
1694)         assert result.error_exit(
1695)             error=IndexError
1696)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1698)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1702) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1705) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1709)         monkeypatch.setattr(
1710)             click,
1711)             'prompt',
1712)             lambda *a, **kw: json.dumps({'args': a, 'kwargs': kw}),
1713)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1855)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1859)         config: _types.VaultConfig,
1860)         result_config: _types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1865)                 monkeypatch=monkeypatch, runner=runner, config=start_config
1866)             ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1868)                     cli.derivepassphrase_vault,
1869)                     command_line,
1870)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

1879)                     config_readback = json.load(infile)
1880)                 assert config_readback == result_config
1881) 
1882)     def test_204_phrase_from_key_manually(self) -> None:
1883)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1885)                 phrase=DUMMY_PHRASE_FROM_KEY1, **DUMMY_CONFIG_SETTINGS
1886)             ).generate(DUMMY_SERVICE)
1887)             == DUMMY_RESULT_KEY1
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1888)         )
1889) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1890)     @pytest.mark.parametrize(
1891)         ['vfunc', 'input'],
1892)         [
1893)             (cli._validate_occurrence_constraint, 20),
1894)             (cli._validate_length, 20),
1895)         ],
1896)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1897)     def test_210a_validate_constraints_manually(
1898)         self,
1899)         vfunc: Callable[[click.Context, click.Parameter, Any], int | None],
1900)         input: int,
1901)     ) -> None:
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1907)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

1915)             monkeypatch.setattr(
1916)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
1917)             )
1918)             hint: ssh_agent.SSHAgentClient | socket.socket | None
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

1919)             # Use match/case here once Python 3.9 becomes unsupported.
1920)             if conn_hint == 'client':
1921)                 hint = ssh_agent.SSHAgentClient()
1922)             elif conn_hint == 'socket':
1923)                 hint = socket.socket(family=socket.AF_UNIX)
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

1925)             else:
1926)                 assert conn_hint == 'none'
1927)                 hint = None
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

1928)             exception: Exception | None = None
1929)             try:
1930)                 list(cli._get_suitable_ssh_keys(hint))
1931)             except RuntimeError:  # pragma: no cover
1932)                 pass
1933)             except Exception as e:  # noqa: BLE001 # pragma: no cover
1934)                 exception = e
1935)             finally:
1936)                 assert (
1937)                     exception is None
1938)                 ), 'exception querying suitable SSH keys'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

2037)             config_filename = cli._config_filename(
2038)                 subsystem='old settings.json'
2039)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

2068)             config_filename = cli._config_filename(
2069)                 subsystem='old settings.json'
2070)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

2099)             config_filename = cli._config_filename(
2100)                 subsystem='old settings.json'
2101)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

2134)             config_filename = cli._config_filename(
2135)                 subsystem='old settings.json'
2136)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2137)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2138)                 print(json.dumps(config, indent=2), file=fileobj)
2139)             with pytest.raises(ValueError, match=cli._INVALID_VAULT_CONFIG):
2140)                 cli._migrate_and_load_old_config()
2141) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

2143)         self,
2144)         monkeypatch: pytest.MonkeyPatch,
2145)         caplog: pytest.LogCaptureFixture,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

2162)         assert tests.deprecation_warning_emitted(
2163)             'A subcommand will be required in v1.0', caplog.record_tuples
2164)         )
2165)         assert tests.warning_emitted(
2166)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

2167)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

2186)         assert tests.deprecation_warning_emitted(
2187)             'A subcommand will be required in v1.0', caplog.record_tuples
2188)         )
2189)         assert tests.warning_emitted(
2190)             'Defaulting to subcommand "vault"', caplog.record_tuples
2191)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2192)         assert result.error_exit(
2193)             error="Missing argument 'PATH'"
2194)         ), 'expected error exit and known error type'
2195) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2196)     @pytest.mark.parametrize(
2197)         'charset_name', ['lower', 'upper', 'number', 'space', 'dash', 'symbol']
2198)     )
2199)     def test_210_forward_vault_disable_character_set(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2200)         self,
2201)         monkeypatch: pytest.MonkeyPatch,
2202)         caplog: pytest.LogCaptureFixture,
2203)         charset_name: str,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

2208)         runner = click.testing.CliRunner(mix_stderr=False)
2209)         with tests.isolated_config(
2210)             monkeypatch=monkeypatch,
2211)             runner=runner,
2212)         ):
2213)             _result = runner.invoke(
2214)                 cli.derivepassphrase,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2216)                 input=DUMMY_PASSPHRASE,
2217)                 catch_exceptions=False,
2218)             )
2219)             result = tests.ReadableResult.parse(_result)
2220)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2221)         assert tests.deprecation_warning_emitted(
2222)             'A subcommand will be required in v1.0', caplog.record_tuples
2223)         )
2224)         assert tests.warning_emitted(
2225)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

2226)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2227)         for c in charset:
2228)             assert (
2229)                 c not in result.output
2230)             ), f'derived password contains forbidden character {c!r}'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2231) 
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2232)     def test_211_forward_vault_empty_command_line(
2233)         self,
2234)         monkeypatch: pytest.MonkeyPatch,
2235)         caplog: pytest.LogCaptureFixture,
2236)     ) -> None:
2237)         runner = click.testing.CliRunner(mix_stderr=False)
2238)         with tests.isolated_config(
2239)             monkeypatch=monkeypatch,
2240)             runner=runner,
2241)         ):
2242)             _result = runner.invoke(
2243)                 cli.derivepassphrase,
2244)                 [],
2245)                 input=DUMMY_PASSPHRASE,
2246)                 catch_exceptions=False,
2247)             )
2248)             result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2249)         assert tests.deprecation_warning_emitted(
2250)             'A subcommand will be required in v1.0', caplog.record_tuples
2251)         )
2252)         assert tests.warning_emitted(
2253)             'Defaulting to subcommand "vault"', caplog.record_tuples
2254)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2255)         assert result.error_exit(
2256)             error='SERVICE is required'
2257)         ), 'expected error exit and known error type'
2258) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2259)     def test_300_export_using_old_config_file(
2260)         self,
2261)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2265)         runner = click.testing.CliRunner(mix_stderr=False)
2266)         with tests.isolated_config(
2267)             monkeypatch=monkeypatch,
2268)             runner=runner,
2269)         ):
2270)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2271)                 cli._config_filename(subsystem='old settings.json'),
2272)                 'w',
2273)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2274)             ) as fileobj:
2275)                 print(
2276)                     json.dumps(
2277)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
2278)                         indent=2,
2279)                     ),
2280)                     file=fileobj,
2281)                 )
2282)             _result = runner.invoke(
2283)                 cli.derivepassphrase_vault,
2284)                 ['--export', '-'],
2285)                 catch_exceptions=False,
2286)             )
2287)         result = tests.ReadableResult.parse(_result)
2288)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2294)         ), 'expected known warning message in stderr'
2295) 
2296)     def test_300a_export_using_old_config_file_migration_error(
2297)         self,
2298)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2300)     ) -> None:
2301)         runner = click.testing.CliRunner(mix_stderr=False)
2302)         with tests.isolated_config(
2303)             monkeypatch=monkeypatch,
2304)             runner=runner,
2305)         ):
2306)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2307)                 cli._config_filename(subsystem='old settings.json'),
2308)                 'w',
2309)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2310)             ) as fileobj:
2311)                 print(
2312)                     json.dumps(
2313)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
2314)                         indent=2,
2315)                     ),
2316)                     file=fileobj,
2317)                 )
2318) 
2319)             def raiser(*_args: Any, **_kwargs: Any) -> None:
2320)                 raise OSError(
2321)                     errno.EACCES,
2322)                     os.strerror(errno.EACCES),
2323)                     cli._config_filename(subsystem='vault'),
2324)                 )
2325) 
2326)             monkeypatch.setattr(os, 'replace', raiser)
2327)             _result = runner.invoke(
2328)                 cli.derivepassphrase_vault,
2329)                 ['--export', '-'],
2330)                 catch_exceptions=False,
2331)             )
2332)         result = tests.ReadableResult.parse(_result)
2333)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

2340) 
2341) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2342) _known_services = (DUMMY_SERVICE, 'email', 'bank', 'work')
2343) _valid_properties = (
2344)     'length',
2345)     'repeat',
2346)     'upper',
2347)     'lower',
2348)     'number',
2349)     'space',
2350)     'dash',
2351)     'symbol',
2352) )
2353) 
2354) 
2355) def _build_reduced_vault_config_settings(
2356)     config: _types.VaultConfigServicesSettings,
2357)     keys_to_purge: frozenset[str],
2358) ) -> _types.VaultConfigServicesSettings:
2359)     config2 = copy.deepcopy(config)
2360)     for key in keys_to_purge:
2361)         config2.pop(key, None)  # type: ignore[misc]
2362)     return config2
2363) 
2364) 
2365) _services_strategy = strategies.builds(
2366)     _build_reduced_vault_config_settings,
2367)     tests.vault_full_service_config(),
2368)     strategies.sets(
2369)         strategies.sampled_from(_valid_properties),
2370)         max_size=7,
2371)     ),
2372) )
2373) 
2374) 
2375) def _assemble_config(
2376)     global_data: _types.VaultConfigGlobalSettings,
2377)     service_data: list[tuple[str, _types.VaultConfigServicesSettings]],
2378) ) -> _types.VaultConfig:
2379)     services_dict = dict(service_data)
2380)     return (
2381)         {'global': global_data, 'services': services_dict}
2382)         if global_data
2383)         else {'services': services_dict}
2384)     )
2385) 
2386) 
2387) @strategies.composite
2388) def _draw_service_name_and_data(
2389)     draw: hypothesis.strategies.DrawFn,
2390)     num_entries: int,
2391) ) -> tuple[tuple[str, _types.VaultConfigServicesSettings], ...]:
2392)     possible_services = list(_known_services)
2393)     selected_services: list[str] = []
2394)     for _ in range(num_entries):
2395)         selected_services.append(
2396)             draw(strategies.sampled_from(possible_services))
2397)         )
2398)         possible_services.remove(selected_services[-1])
2399)     return tuple(
2400)         (service, draw(_services_strategy)) for service in selected_services
2401)     )
2402) 
2403) 
2404) _vault_full_config = strategies.builds(
2405)     _assemble_config,
2406)     _services_strategy,
2407)     strategies.integers(
2408)         min_value=2,
2409)         max_value=4,
2410)     ).flatmap(_draw_service_name_and_data),
2411) )
2412) 
2413) 
Marco Ricci Actually correctly implemen...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2416)     def __init__(self) -> None:
2417)         super().__init__()
2418)         self.runner = click.testing.CliRunner(mix_stderr=False)
2419)         self.exit_stack = contextlib.ExitStack().__enter__()
2420)         self.monkeypatch = self.exit_stack.enter_context(
2421)             pytest.MonkeyPatch().context()
2422)         )
2423)         self.isolated_config = self.exit_stack.enter_context(
2424)             tests.isolated_vault_config(
2425)                 monkeypatch=self.monkeypatch,
2426)                 runner=self.runner,
2427)                 config={'services': {}},
2428)             )
2429)         )
2430) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2431)     setting = stateful.Bundle('setting')
2432)     configuration = stateful.Bundle('configuration')
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2433) 
2434)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2435)         target=configuration,
2436)         configs=strategies.lists(
2437)             _vault_full_config,
2438)             min_size=4,
2439)             max_size=4,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2440)         ),
2441)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2442)     def declare_initial_configs(
2443)         self,
2444)         configs: Iterable[_types.VaultConfig],
2445)     ) -> Iterable[_types.VaultConfig]:
2446)         return stateful.multiple(*configs)
Marco Ricci Test config merging with pa...

Marco Ricci authored 4 weeks ago

2447) 
2448)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2449)         target=setting,
2450)         config=_vault_full_config,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

2452)     def extract_initial_settings(
2453)         self,
2454)         config: _types.VaultConfig,
2455)     ) -> Iterable[_types.VaultConfigServicesSettings]:
2456)         return stateful.multiple(
2457)             *map(copy.deepcopy, config['services'].values())
2458)         )
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2459) 
2460)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2461)         target=configuration,
2462)         config=_vault_full_config,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

2464)     def declare_config(
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2467)     ) -> _types.VaultConfig:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2468)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2469) 
2470)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2471)         target=setting,
2472)         config=_vault_full_config,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

2474)     def extract_settings(
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

2476)         config: _types.VaultConfig,
2477)     ) -> Iterable[_types.VaultConfigServicesSettings]:
2478)         return stateful.multiple(
2479)             *map(copy.deepcopy, config['services'].values())
2480)         )
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2481) 
2482)     @staticmethod
2483)     def fold_configs(
2484)         c1: _types.VaultConfig, c2: _types.VaultConfig
2485)     ) -> _types.VaultConfig:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2487)         new_global_dict = c1.get('global', c2.get('global'))
2488)         if new_global_dict is not None:
2489)             return {
2490)                 'global': new_global_dict,
2491)                 'services': {**c2['services'], **c1['services']},
2492)             }
2493)         return {
2494)             'services': {**c2['services'], **c1['services']},
2495)         }
2496) 
2497)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2498)         target=configuration,
2499)         config=configuration,
2500)         setting=setting.filter(bool),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2502)     )
2503)     def set_globals(
2504)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2505)         config: _types.VaultConfig,
2506)         setting: _types.VaultConfigGlobalSettings,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

2508)     ) -> _types.VaultConfig:
2509)         cli._save_config(config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2510)         if overwrite:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2511)             config['global'] = {}
2512)         config.setdefault('global', {}).update(setting)
2513)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2514)         # NOTE: This relies on settings_obj containing only the keys
2515)         # "length", "repeat", "upper", "lower", "number", "space",
2516)         # "dash" and "symbol".
2517)         _result = self.runner.invoke(
2518)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2519)             [
2520)                 '--config',
2521)                 '--overwrite-existing' if overwrite else '--merge-existing',
2522)             ]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2523)             + [
2524)                 f'--{key}={value}'
2525)                 for key, value in setting.items()
2526)                 if key in _valid_properties
2527)             ],
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2528)             catch_exceptions=False,
2529)         )
2530)         result = tests.ReadableResult.parse(_result)
2531)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2534) 
2535)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2536)         target=configuration,
2537)         config=configuration,
2538)         service=strategies.sampled_from(_known_services),
2539)         setting=setting.filter(bool),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2541)     )
2542)     def set_service(
2543)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

2546)         setting: _types.VaultConfigServicesSettings,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

2548)     ) -> _types.VaultConfig:
2549)         cli._save_config(config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2550)         if overwrite:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2554)         # NOTE: This relies on settings_obj containing only the keys
2555)         # "length", "repeat", "upper", "lower", "number", "space",
2556)         # "dash" and "symbol".
2557)         _result = self.runner.invoke(
2558)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2559)             [
2560)                 '--config',
2561)                 '--overwrite-existing' if overwrite else '--merge-existing',
2562)             ]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2563)             + [
2564)                 f'--{key}={value}'
2565)                 for key, value in setting.items()
2566)                 if key in _valid_properties
2567)             ]
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2568)             + ['--', service],
2569)             catch_exceptions=False,
2570)         )
2571)         result = tests.ReadableResult.parse(_result)
2572)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2575) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2576)     @stateful.rule(
2577)         target=configuration,
2578)         config=configuration.filter(lambda c: 'global' in c),
2579)     )
2580)     def purge_global(
2581)         self,
2582)         config: _types.VaultConfig,
2583)     ) -> _types.VaultConfig:
2584)         cli._save_config(config)
2585)         config.pop('global')
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2586)         _result = self.runner.invoke(
2587)             cli.derivepassphrase_vault,
2588)             ['--delete-globals'],
2589)             input='y',
2590)             catch_exceptions=False,
2591)         )
2592)         result = tests.ReadableResult.parse(_result)
2593)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2596) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2597)     @stateful.rule(
2598)         target=configuration,
2599)         config_and_service=configuration.filter(
2600)             lambda c: len(c['services']) > 1
2601)         ).flatmap(
2602)             lambda c: strategies.tuples(
2603)                 strategies.just(c),
2604)                 strategies.sampled_from(tuple(c['services'].keys())),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

2606)         ),
2607)     )
2608)     def purge_service(
2609)         self,
2610)         config_and_service: tuple[_types.VaultConfig, str],
2611)     ) -> _types.VaultConfig:
2612)         config, service = config_and_service
2613)         cli._save_config(config)
2614)         config['services'].pop(service, None)
2615)         _result = self.runner.invoke(
2616)             cli.derivepassphrase_vault,
2617)             ['--delete', '--', service],
2618)             input='y',
2619)             catch_exceptions=False,
2620)         )
2621)         result = tests.ReadableResult.parse(_result)
2622)         assert result.clean_exit(empty_stderr=False)
2623)         assert cli._load_config() == config
2624)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2625) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2626)     @stateful.rule(
2627)         target=configuration,
2628)         config=configuration.filter(lambda c: 0 < len(c['services']) < 5),
2629)     )
2630)     def purge_all(
2631)         self,
2632)         config: _types.VaultConfig,
2633)     ) -> _types.VaultConfig:
2634)         cli._save_config(config)
2635)         config = {'services': {}}
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2636)         _result = self.runner.invoke(
2637)             cli.derivepassphrase_vault,
2638)             ['--clear'],
2639)             input='y',
2640)             catch_exceptions=False,
2641)         )
2642)         result = tests.ReadableResult.parse(_result)
2643)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2646) 
2647)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2648)         target=configuration,
2649)         base_config=configuration,
2650)         config_to_import=configuration,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

2655)         base_config: _types.VaultConfig,
2656)         config_to_import: _types.VaultConfig,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

2658)     ) -> _types.VaultConfig:
2659)         cli._save_config(base_config)
2660)         config = (
2661)             self.fold_configs(config_to_import, base_config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2671)             catch_exceptions=False,
2672)         )
2673)         assert tests.ReadableResult.parse(_result).clean_exit(
2674)             empty_stderr=False
2675)         )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 2 months ago

2678) 
2679)     def teardown(self) -> None:
2680)         self.exit_stack.close()
2681) 
2682)