c1bf00eadd1bf733ac25a25eafbe110d61936c54
Marco Ricci Change the author e-mail ad...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

5) from __future__ import annotations
6) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

10) import json
11) import os
Marco Ricci Create the configuration di...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

13) import socket
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 4 weeks ago

14) from typing import TYPE_CHECKING, cast
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

24) 
25) if TYPE_CHECKING:
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

43) TEST_CONFIGS = tests.TEST_CONFIGS
44) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

50) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

55)     check_success: bool
56) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

63)     check_success: bool
64) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

90) ]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

95)         True,
96)         DUMMY_PASSPHRASE,
97)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

202) 
203) 
Marco Ricci Fix missing consideration o...

Marco Ricci authored 4 weeks ago

204) def is_harmless_config_import_warning_line(line: str) -> bool:
205)     """Return true if the warning line is harmless, during config import."""
206)     possible_warnings = [
207)         'Replacing invalid value ',
208)         'Removing ineffective setting ',
209)         (
210)             'Setting a global passphrase is ineffective '
211)             'because a key is also set.'
212)         ),
213)         (
214)             'Setting a service passphrase is ineffective '
215)             'because a key is also set.'
216)         ),
217)     ]
218)     return any(  # pragma: no branch
219)         (' Warning: ' + w) in line for w in possible_warnings
220)     )
221) 
222) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

226)         with tests.isolated_config(
227)             monkeypatch=monkeypatch,
228)             runner=runner,
229)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

240) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

251)         with tests.isolated_config(
252)             monkeypatch=monkeypatch,
253)             runner=runner,
254)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

256)                 cli.derivepassphrase_vault,
Marco Ricci Isolate tests properly and...

Marco Ricci authored 3 months ago

257)                 [option, '0', '-p', DUMMY_SERVICE],
258)                 input=DUMMY_PASSPHRASE,
259)                 catch_exceptions=False,
260)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

267) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

268)     def test_202_disable_repetition(
269)         self, monkeypatch: pytest.MonkeyPatch
270)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

273)         with tests.isolated_config(
274)             monkeypatch=monkeypatch,
275)             runner=runner,
276)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

278)                 cli.derivepassphrase_vault,
Marco Ricci Isolate tests properly and...

Marco Ricci authored 3 months ago

279)                 ['--repeat', '0', '-p', DUMMY_SERVICE],
280)                 input=DUMMY_PASSPHRASE,
281)                 catch_exceptions=False,
282)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

283)             result = tests.ReadableResult.parse(_result)
284)         assert result.clean_exit(
285)             empty_stderr=True
286)         ), 'expected clean exit and empty stderr'
287)         passphrase = result.output.rstrip('\r\n')
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

293) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

294)     @pytest.mark.parametrize(
295)         'config',
296)         [
297)             pytest.param(
298)                 {
299)                     'global': {'key': DUMMY_KEY1_B64},
300)                     'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS},
301)                 },
302)                 id='global',
303)             ),
304)             pytest.param(
305)                 {
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

307)                     'services': {
308)                         DUMMY_SERVICE: {
309)                             'key': DUMMY_KEY1_B64,
310)                             **DUMMY_CONFIG_SETTINGS,
311)                         }
312)                     },
313)                 },
314)                 id='service',
315)             ),
316)         ],
317)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

318)     def test_204a_key_from_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

325)             monkeypatch=monkeypatch, runner=runner, config=config
326)         ):
327)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

331)                 cli.derivepassphrase_vault,
332)                 [DUMMY_SERVICE],
333)                 catch_exceptions=False,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

346) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

347)     def test_204b_key_from_command_line(
348)         self, monkeypatch: pytest.MonkeyPatch
349)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

352)             monkeypatch=monkeypatch,
353)             runner=runner,
354)             config={'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
355)         ):
356)             monkeypatch.setattr(
357)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
358)             )
359)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

366)                 catch_exceptions=False,
367)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

378) 
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

405)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Add test fixture for manual...

Marco Ricci authored 1 month ago

406)         running_ssh_agent: str,
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

407)         config: dict[str, Any],
408)         key_index: int,
409)     ) -> None:
Marco Ricci Add test fixture for manual...

Marco Ricci authored 1 month ago

410)         with monkeypatch.context():
411)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent)
412)             monkeypatch.setattr(
413)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

416)             runner = click.testing.CliRunner(mix_stderr=False)
417)             with tests.isolated_vault_config(
418)                 monkeypatch=monkeypatch, runner=runner, config=config
419)             ):
420)                 _result = runner.invoke(
421)                     cli.derivepassphrase_vault,
422)                     ['-k', DUMMY_SERVICE],
423)                     input=f'{key_index}\n',
424)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

425)         result = tests.ReadableResult.parse(_result)
426)         assert result.clean_exit(), 'expected clean exit'
427)         assert result.output, 'expected program output'
428)         assert result.stderr, 'expected stderr'
429)         assert (
430)             'Error:' not in result.stderr
431)         ), 'expected no error messages on stderr'
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

433)     def test_205_service_phrase_if_key_in_global_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

435)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Align behavior with vault c...

Marco Ricci authored 1 month ago

436)         running_ssh_agent: str,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

438)         with monkeypatch.context():
439)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent)
440)             monkeypatch.setattr(
441)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

443)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', tests.sign)
444)             runner = click.testing.CliRunner(mix_stderr=False)
445)             with tests.isolated_vault_config(
446)                 monkeypatch=monkeypatch,
447)                 runner=runner,
448)                 config={
449)                     'global': {'key': DUMMY_KEY1_B64},
450)                     'services': {
451)                         DUMMY_SERVICE: {
452)                             'phrase': DUMMY_PASSPHRASE.rstrip('\n'),
453)                             **DUMMY_CONFIG_SETTINGS,
454)                         }
455)                     },
456)                 },
457)             ):
458)                 _result = runner.invoke(
459)                     cli.derivepassphrase_vault,
460)                     [DUMMY_SERVICE],
461)                     catch_exceptions=False,
462)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

463)         result = tests.ReadableResult.parse(_result)
464)         assert result.clean_exit(), 'expected clean exit'
465)         assert _result.stdout_bytes, 'expected program output'
466)         last_line = _result.stdout_bytes.splitlines(True)[-1]
467)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

473) 
Marco Ricci Fix missing consideration o...

Marco Ricci authored 4 weeks ago

474)     @pytest.mark.parametrize(
475)         'config',
476)         [
477)             {
478)                 'services': {
479)                     DUMMY_SERVICE: {
480)                         'key': DUMMY_KEY1_B64,
481)                         **DUMMY_CONFIG_SETTINGS,
482)                     },
483)                 },
484)             },
485)             {
486)                 'global': {'key': DUMMY_KEY1_B64},
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 4 weeks ago

488)             },
489)         ],
490)     )
491)     def test_206_setting_service_phrase_thus_overriding_key_in_config(
492)         self,
493)         monkeypatch: pytest.MonkeyPatch,
494)         running_ssh_agent: str,
495)         config: _types.VaultConfig,
496)     ) -> None:
497)         with monkeypatch.context():
498)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent)
499)             monkeypatch.setattr(
500)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
501)             )
502)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', tests.sign)
503)             runner = click.testing.CliRunner(mix_stderr=False)
504)             with tests.isolated_vault_config(
505)                 monkeypatch=monkeypatch,
506)                 runner=runner,
507)                 config=config,
508)             ):
509)                 _result = runner.invoke(
510)                     cli.derivepassphrase_vault,
511)                     ['--config', '-p', '--', DUMMY_SERVICE],
512)                     input=DUMMY_PASSPHRASE,
513)                     catch_exceptions=False,
514)                 )
515)         result = tests.ReadableResult.parse(_result)
516)         assert result.clean_exit(), 'expected clean exit'
517)         assert not result.output.strip(), 'expected no program output'
518)         assert result.stderr, 'expected known error output'
519)         err_lines = result.stderr.splitlines(False)
520)         assert err_lines[0].startswith('Passphrase:')
521)         assert any(  # pragma: no branch
522)             ' Warning: Setting a service passphrase is ineffective ' in line
523)             for line in err_lines
524)         ), 'expected known warning message'
525)         assert all(  # pragma: no branch
526)             is_harmless_config_import_warning_line(line)
527)             for line in result.stderr.splitlines(True)
528)         ), 'unexpected error output'
529) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

530)     @pytest.mark.parametrize(
531)         'option',
532)         [
533)             '--lower',
534)             '--upper',
535)             '--number',
536)             '--space',
537)             '--dash',
538)             '--symbol',
539)             '--repeat',
540)             '--length',
541)         ],
542)     )
Marco Ricci Isolate tests properly and...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

547)         with tests.isolated_config(
548)             monkeypatch=monkeypatch,
549)             runner=runner,
550)         ):
551)             for value in '-42', 'invalid':
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

553)                     cli.derivepassphrase_vault,
Marco Ricci Isolate tests properly and...

Marco Ricci authored 3 months ago

554)                     [option, value, '-p', DUMMY_SERVICE],
555)                     input=DUMMY_PASSPHRASE,
556)                     catch_exceptions=False,
557)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

558)                 result = tests.ReadableResult.parse(_result)
559)                 assert result.error_exit(
560)                     error='Error: Invalid value'
561)                 ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

562) 
563)     @pytest.mark.parametrize(
564)         ['options', 'service', 'input', 'check_success'],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

565)         [
566)             (o.options, o.needs_service, o.input, o.check_success)
567)             for o in INTERESTING_OPTION_COMBINATIONS
568)             if not o.incompatible
569)         ],
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

570)     )
571)     def test_211_service_needed(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

582)             monkeypatch=monkeypatch,
583)             runner=runner,
584)             config={'global': {'phrase': 'abc'}, 'services': {}},
585)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

588)                 options if service else [*options, DUMMY_SERVICE],
589)                 input=input,
590)                 catch_exceptions=False,
591)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

599)                 assert result.error_exit(
600)                     error=err_msg
601)                 ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

603)                 assert result.clean_exit(
604)                     empty_stderr=True
605)                 ), 'expected clean exit'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

608)                 monkeypatch=monkeypatch,
609)                 runner=runner,
610)                 config={'global': {'phrase': 'abc'}, 'services': {}},
611)             ):
612)                 monkeypatch.setattr(
613)                     cli, '_prompt_for_passphrase', tests.auto_prompt
614)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

617)                     [*options, DUMMY_SERVICE] if service else options,
618)                     input=input,
619)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 weeks ago

624)     def test_211a_empty_service_name_causes_warning(
625)         self,
626)         monkeypatch: pytest.MonkeyPatch,
627)     ) -> None:
628)         def expected_warning_line(line: str) -> bool:
629)             return is_harmless_config_import_warning_line(line) or (
630)                 ' Warning: An empty SERVICE is not supported by vault(1)'
631)                 in line
632)             )
633) 
634)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
635)         runner = click.testing.CliRunner(mix_stderr=False)
636)         with tests.isolated_vault_config(
637)             monkeypatch=monkeypatch,
638)             runner=runner,
639)             config={'services': {}},
640)         ):
641)             _result = runner.invoke(
642)                 cli.derivepassphrase_vault,
643)                 ['--config', '--length=30', '--', ''],
644)                 catch_exceptions=False,
645)             )
646)             result = tests.ReadableResult.parse(_result)
647)             assert result.clean_exit(empty_stderr=False), 'expected clean exit'
648)             assert result.stderr is not None, 'expected known error output'
649)             assert all(
650)                 expected_warning_line(line)
651)                 for line in result.stderr.splitlines(False)
652)             ), 'expected known error output'
653)             assert cli._load_config() == {
654)                 'global': {'length': 30},
655)                 'services': {},
656)             }, 'requested configuration change was not applied'
657)             _result = runner.invoke(
658)                 cli.derivepassphrase_vault,
659)                 ['--import', '-'],
660)                 input=json.dumps({'services': {'': {'length': 40}}}),
661)                 catch_exceptions=False,
662)             )
663)             result = tests.ReadableResult.parse(_result)
664)             assert result.clean_exit(empty_stderr=False), 'expected clean exit'
665)             assert result.stderr is not None, 'expected known error output'
666)             assert all(
667)                 expected_warning_line(line)
668)                 for line in result.stderr.splitlines(False)
669)             ), 'expected known error output'
670)             assert cli._load_config() == {
671)                 'global': {'length': 30},
672)                 'services': {'': {'length': 40}},
673)             }, 'requested configuration change was not applied'
674) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

677)         [
678)             (o.options, o.needs_service)
679)             for o in INTERESTING_OPTION_COMBINATIONS
680)             if o.incompatible
681)         ],
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

683)     def test_212_incompatible_options(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

690)         with tests.isolated_config(
691)             monkeypatch=monkeypatch,
692)             runner=runner,
693)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

695)                 cli.derivepassphrase_vault,
Marco Ricci Isolate tests properly and...

Marco Ricci authored 3 months ago

696)                 [*options, DUMMY_SERVICE] if service else options,
697)                 input=DUMMY_PASSPHRASE,
698)                 catch_exceptions=False,
699)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

700)         result = tests.ReadableResult.parse(_result)
701)         assert result.error_exit(
702)             error='mutually exclusive with '
703)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

705)     @pytest.mark.parametrize(
706)         'config',
707)         [
708)             conf.config
Marco Ricci Fix missing consideration o...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 1 month ago

710)             if tests.is_valid_test_config(conf)
711)         ],
712)     )
713)     def test_213_import_config_success(
714)         self,
715)         monkeypatch: pytest.MonkeyPatch,
716)         config: Any,
717)     ) -> None:
718)         runner = click.testing.CliRunner(mix_stderr=False)
719)         with tests.isolated_vault_config(
720)             monkeypatch=monkeypatch,
721)             runner=runner,
722)             config={'services': {}},
723)         ):
724)             _result = runner.invoke(
725)                 cli.derivepassphrase_vault,
726)                 ['--import', '-'],
727)                 input=json.dumps(config),
728)                 catch_exceptions=False,
729)             )
730)             with open(
731)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
732)             ) as infile:
733)                 config2 = json.load(infile)
734)         result = tests.ReadableResult.parse(_result)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 weeks ago

737)         assert not result.stderr or all(  # pragma: no branch
738)             is_harmless_config_import_warning_line(line)
739)             for line in result.stderr.splitlines(True)
740)         ), 'unexpected error output'
Marco Ricci Align behavior with vault c...

Marco Ricci authored 1 month ago

741) 
742)     @hypothesis.given(
743)         conf=tests.smudged_vault_test_config(
744)             strategies.sampled_from(TEST_CONFIGS).filter(
745)                 tests.is_valid_test_config
746)             )
747)         )
748)     )
749)     def test_213a_import_config_success(
750)         self,
751)         conf: tests.VaultTestConfig,
752)     ) -> None:
753)         config = conf.config
754)         config2 = copy.deepcopy(config)
755)         _types.clean_up_falsy_vault_config_values(config2)
756)         runner = click.testing.CliRunner(mix_stderr=False)
757)         with tests.isolated_vault_config(
758)             monkeypatch=pytest.MonkeyPatch(),
759)             runner=runner,
760)             config={'services': {}},
761)         ):
762)             _result = runner.invoke(
763)                 cli.derivepassphrase_vault,
764)                 ['--import', '-'],
765)                 input=json.dumps(config),
766)                 catch_exceptions=False,
767)             )
768)             with open(
769)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
770)             ) as infile:
771)                 config3 = json.load(infile)
772)         result = tests.ReadableResult.parse(_result)
Marco Ricci Signal and list falsy value...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

775)         assert not result.stderr or all(
Marco Ricci Fix missing consideration o...

Marco Ricci authored 4 weeks ago

776)             is_harmless_config_import_warning_line(line)
Marco Ricci Signal and list falsy value...

Marco Ricci authored 1 month ago

777)             for line in result.stderr.splitlines(True)
778)         ), 'unexpected error output'
Marco Ricci Align behavior with vault c...

Marco Ricci authored 1 month ago

779) 
780)     def test_213b_import_bad_config_not_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

792)         result = tests.ReadableResult.parse(_result)
793)         assert result.error_exit(
794)             error='Invalid vault config'
795)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

797)     def test_213c_import_bad_config_not_json_data(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

809)         result = tests.ReadableResult.parse(_result)
810)         assert result.error_exit(
811)             error='cannot decode JSON'
812)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

814)     def test_213d_import_bad_config_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

834)         result = tests.ReadableResult.parse(_result)
835)         assert result.error_exit(
836)             error=os.strerror(errno.EISDIR)
837)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

838) 
839)     def test_214_export_settings_no_stored_settings(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

848)                 cli.derivepassphrase_vault,
849)                 ['--export', '-'],
850)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

855)     def test_214a_export_settings_bad_stored_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

861)             monkeypatch=monkeypatch, runner=runner, config={}
862)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

869)         result = tests.ReadableResult.parse(_result)
870)         assert result.error_exit(
871)             error='Cannot load config'
872)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

874)     def test_214b_export_settings_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

889)         result = tests.ReadableResult.parse(_result)
890)         assert result.error_exit(
891)             error='Cannot load config'
892)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

894)     def test_214c_export_settings_target_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

907)         result = tests.ReadableResult.parse(_result)
908)         assert result.error_exit(
909)             error='Cannot store config'
910)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

911) 
Marco Ricci Create the configuration di...

Marco Ricci authored 3 months ago

912)     def test_214d_export_settings_settings_directory_not_a_directory(
913)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

926)                 catch_exceptions=False,
927)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

928)         result = tests.ReadableResult.parse(_result)
929)         assert result.error_exit(
930)             error='Cannot load config'
931)         ), 'expected error exit and known error message'
Marco Ricci Create the configuration di...

Marco Ricci authored 3 months ago

932) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

933)     def test_220_edit_notes_successfully(
934)         self, monkeypatch: pytest.MonkeyPatch
935)     ) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

937) 
938) # - - - - - >8 - - - - - >8 - - - - - >8 - - - - - >8 - - - - -
939) contents go here
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

943)             monkeypatch=monkeypatch,
944)             runner=runner,
945)             config={'global': {'phrase': 'abc'}, 'services': {}},
946)         ):
947)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: edit_result)  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

949)                 cli.derivepassphrase_vault,
950)                 ['--notes', 'sv'],
951)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

959)             assert config == {
960)                 'global': {'phrase': 'abc'},
961)                 'services': {'sv': {'notes': 'contents go here'}},
962)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

963) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

964)     def test_221_edit_notes_noop(
965)         self, monkeypatch: pytest.MonkeyPatch
966)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

969)             monkeypatch=monkeypatch,
970)             runner=runner,
971)             config={'global': {'phrase': 'abc'}, 'services': {}},
972)         ):
973)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: None)  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

975)                 cli.derivepassphrase_vault,
976)                 ['--notes', 'sv'],
977)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

987)     def test_222_edit_notes_marker_removed(
988)         self, monkeypatch: pytest.MonkeyPatch
989)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

992)             monkeypatch=monkeypatch,
993)             runner=runner,
994)             config={'global': {'phrase': 'abc'}, 'services': {}},
995)         ):
996)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: 'long\ntext')  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

998)                 cli.derivepassphrase_vault,
999)                 ['--notes', 'sv'],
1000)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1008)             assert config == {
1009)                 'global': {'phrase': 'abc'},
1010)                 'services': {'sv': {'notes': 'long\ntext'}},
1011)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1012) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1013)     def test_223_edit_notes_abort(
1014)         self, monkeypatch: pytest.MonkeyPatch
1015)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1018)             monkeypatch=monkeypatch,
1019)             runner=runner,
1020)             config={'global': {'phrase': 'abc'}, 'services': {}},
1021)         ):
1022)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: '\n\n')  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1024)                 cli.derivepassphrase_vault,
1025)                 ['--notes', 'sv'],
1026)                 catch_exceptions=False,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1028)             result = tests.ReadableResult.parse(_result)
1029)             assert result.error_exit(
1030)                 error='user aborted request'
1031)             ), 'expected known error message'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1038)     @pytest.mark.parametrize(
1039)         ['command_line', 'input', 'result_config'],
1040)         [
1041)             (
1042)                 ['--phrase'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1044)                 {'global': {'phrase': 'my passphrase'}, 'services': {}},
1045)             ),
1046)             (
1047)                 ['--key'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 weeks ago

1049)                 {
1050)                     'global': {'key': DUMMY_KEY1_B64, 'phrase': 'abc'},
1051)                     'services': {},
1052)                 },
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1053)             ),
1054)             (
1055)                 ['--phrase', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1057)                 {
1058)                     'global': {'phrase': 'abc'},
1059)                     'services': {'sv': {'phrase': 'my passphrase'}},
1060)                 },
1061)             ),
1062)             (
1063)                 ['--key', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1065)                 {
1066)                     'global': {'phrase': 'abc'},
1067)                     'services': {'sv': {'key': DUMMY_KEY1_B64}},
1068)                 },
1069)             ),
1070)             (
1071)                 ['--key', '--length', '15', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1073)                 {
1074)                     'global': {'phrase': 'abc'},
1075)                     'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1076)                 },
1077)             ),
1078)         ],
1079)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1080)     def test_224_store_config_good(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1085)         result_config: Any,
1086)     ) -> None:
1087)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1089)             monkeypatch=monkeypatch,
1090)             runner=runner,
1091)             config={'global': {'phrase': 'abc'}, 'services': {}},
1092)         ):
1093)             monkeypatch.setattr(
1094)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1095)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1098)                 ['--config', *command_line],
1099)                 catch_exceptions=False,
1100)                 input=input,
1101)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1108)             assert (
1109)                 config == result_config
1110)             ), 'stored config does not match expectation'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1111) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1112)     @pytest.mark.parametrize(
1113)         ['command_line', 'input', 'err_text'],
1114)         [
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1116)             (
1117)                 ['sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1118)                 '',
1119)                 'Cannot update service settings without actual settings',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1120)             ),
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1121)             (['--phrase', 'sv'], '', 'No passphrase given'),
1122)             (['--key'], '', 'No valid SSH key selected'),
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1123)         ],
1124)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1125)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1129)         input: str,
1130)         err_text: str,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1134)             monkeypatch=monkeypatch,
1135)             runner=runner,
1136)             config={'global': {'phrase': 'abc'}, 'services': {}},
1137)         ):
1138)             monkeypatch.setattr(
1139)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1140)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1143)                 ['--config', *command_line],
1144)                 catch_exceptions=False,
1145)                 input=input,
1146)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1147)         result = tests.ReadableResult.parse(_result)
1148)         assert result.error_exit(
1149)             error=err_text
1150)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1151) 
1152)     def test_225a_store_config_fail_manual_no_ssh_key_selection(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1158)             monkeypatch=monkeypatch,
1159)             runner=runner,
1160)             config={'global': {'phrase': 'abc'}, 'services': {}},
1161)         ):
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1170)                 ['--key', '--config'],
1171)                 catch_exceptions=False,
1172)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1173)         result = tests.ReadableResult.parse(_result)
1174)         assert result.error_exit(
1175)             error=custom_error
1176)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

1178)     def test_225b_store_config_fail_manual_no_ssh_agent(
1179)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1186)             monkeypatch=monkeypatch,
1187)             runner=runner,
1188)             config={'global': {'phrase': 'abc'}, 'services': {}},
1189)         ):
1190)             monkeypatch.delenv('SSH_AUTH_SOCK', raising=False)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1193)                 ['--key', '--config'],
1194)                 catch_exceptions=False,
1195)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1196)         result = tests.ReadableResult.parse(_result)
1197)         assert result.error_exit(
1198)             error='Cannot find running SSH agent'
1199)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

1200) 
1201)     def test_225c_store_config_fail_manual_bad_ssh_agent_connection(
1202)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1207)             monkeypatch=monkeypatch,
1208)             runner=runner,
1209)             config={'global': {'phrase': 'abc'}, 'services': {}},
1210)         ):
1211)             monkeypatch.setenv('SSH_AUTH_SOCK', os.getcwd())
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1214)                 ['--key', '--config'],
1215)                 catch_exceptions=False,
1216)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1217)         result = tests.ReadableResult.parse(_result)
1218)         assert result.error_exit(
1219)             error='Cannot connect to SSH agent'
1220)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

1221) 
1222)     @pytest.mark.parametrize('try_race_free_implementation', [True, False])
1223)     def test_225d_store_config_fail_manual_read_only_file(
1224)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1226)         try_race_free_implementation: bool,
1227)     ) -> None:
1228)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1230)             monkeypatch=monkeypatch,
1231)             runner=runner,
1232)             config={'global': {'phrase': 'abc'}, 'services': {}},
1233)         ):
1234)             tests.make_file_readonly(
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1236)                 try_race_free_implementation=try_race_free_implementation,
1237)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1240)                 ['--config', '--length=15', DUMMY_SERVICE],
1241)                 catch_exceptions=False,
1242)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1243)         result = tests.ReadableResult.parse(_result)
1244)         assert result.error_exit(
1245)             error='Cannot store config'
1246)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

1247) 
1248)     def test_225e_store_config_fail_manual_custom_error(
1249)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1254)             monkeypatch=monkeypatch,
1255)             runner=runner,
1256)             config={'global': {'phrase': 'abc'}, 'services': {}},
1257)         ):
1258)             custom_error = 'custom error message'
1259) 
1260)             def raiser(config: Any) -> None:
1261)                 del config
1262)                 raise RuntimeError(custom_error)
1263) 
1264)             monkeypatch.setattr(cli, '_save_config', raiser)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1267)                 ['--config', '--length=15', DUMMY_SERVICE],
1268)                 catch_exceptions=False,
1269)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1270)         result = tests.ReadableResult.parse(_result)
1271)         assert result.error_exit(
1272)             error=custom_error
1273)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

1274) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1277)         with tests.isolated_config(
1278)             monkeypatch=monkeypatch,
1279)             runner=runner,
1280)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1284)         result = tests.ReadableResult.parse(_result)
1285)         assert result.error_exit(
1286)             error='SERVICE is required'
1287)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

1288) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1289)     def test_226a_no_passphrase_or_key(
1290)         self, monkeypatch: pytest.MonkeyPatch
1291)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1293)         with tests.isolated_config(
1294)             monkeypatch=monkeypatch,
1295)             runner=runner,
1296)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1298)                 cli.derivepassphrase_vault,
1299)                 [DUMMY_SERVICE],
1300)                 catch_exceptions=False,
Marco Ricci Isolate tests properly and...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1306) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1307)     def test_230_config_directory_nonexistant(
1308)         self, monkeypatch: pytest.MonkeyPatch
1309)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1311)         runner = click.testing.CliRunner(mix_stderr=False)
1312)         with tests.isolated_config(
1313)             monkeypatch=monkeypatch,
1314)             runner=runner,
1315)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1317)             os_makedirs_called = False
1318)             real_os_makedirs = os.makedirs
1319) 
1320)             def makedirs(*args: Any, **kwargs: Any) -> Any:
1321)                 nonlocal os_makedirs_called
1322)                 os_makedirs_called = True
1323)                 return real_os_makedirs(*args, **kwargs)
1324) 
1325)             monkeypatch.setattr(os, 'makedirs', makedirs)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1328)                 ['--config', '-p'],
1329)                 catch_exceptions=False,
1330)                 input='abc\n',
1331)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1341)                 config_readback = json.load(infile)
1342)             assert config_readback == {
1343)                 'global': {'phrase': 'abc'},
1344)                 'services': {},
1345)             }, 'config mismatch'
1346) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1347)     def test_230a_config_directory_not_a_file(
1348)         self, monkeypatch: pytest.MonkeyPatch
1349)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1351)         runner = click.testing.CliRunner(mix_stderr=False)
1352)         with tests.isolated_config(
1353)             monkeypatch=monkeypatch,
1354)             runner=runner,
1355)         ):
1356)             _save_config = cli._save_config
1357) 
1358)             def obstruct_config_saving(*args: Any, **kwargs: Any) -> Any:
1359)                 with contextlib.suppress(FileNotFoundError):
1360)                     shutil.rmtree('.derivepassphrase')
1361)                 with open(
1362)                     '.derivepassphrase', 'w', encoding='UTF-8'
1363)                 ) as outfile:
1364)                     print('Obstruction!!', file=outfile)
1365)                 monkeypatch.setattr(cli, '_save_config', _save_config)
1366)                 return _save_config(*args, **kwargs)
1367) 
1368)             monkeypatch.setattr(cli, '_save_config', obstruct_config_saving)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1371)                 ['--config', '-p'],
1372)                 catch_exceptions=False,
1373)                 input='abc\n',
1374)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1379) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1380)     def test_230b_store_config_custom_error(
1381)         self, monkeypatch: pytest.MonkeyPatch
1382)     ) -> None:
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

1383)         runner = click.testing.CliRunner(mix_stderr=False)
1384)         with tests.isolated_config(
1385)             monkeypatch=monkeypatch,
1386)             runner=runner,
1387)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1390)             def raiser(config: Any) -> None:
1391)                 del config
1392)                 raise RuntimeError(custom_error)
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1397)                 ['--config', '-p'],
1398)                 catch_exceptions=False,
1399)                 input='abc\n',
1400)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1408)         [
1409)             pytest.param(
1410)                 ['--import', '-'],
1411)                 json.dumps({
1412)                     'global': {'phrase': 'Du\u0308sseldorf'},
1413)                     'services': {},
1414)                 }),
Marco Ricci Signal and list falsy value...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

1416)                 id='global-NFC',
1417)             ),
1418)             pytest.param(
1419)                 ['--import', '-'],
1420)                 json.dumps({
1421)                     'services': {
1422)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1423)                         'weird entry name': {'phrase': 'Du\u0308sseldorf'},
1424)                     }
1425)                 }),
1426)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

1428)                     'is not NFC-normalized'
1429)                 ),
1430)                 id='service-weird-name-NFC',
1431)             ),
1432)             pytest.param(
1433)                 ['--config', '-p', DUMMY_SERVICE],
1434)                 'Du\u0308sseldorf',
1435)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

1437)                     f'is not NFC-normalized'
1438)                 ),
1439)                 id='config-NFC',
1440)             ),
1441)             pytest.param(
1442)                 ['-p', DUMMY_SERVICE],
1443)                 'Du\u0308sseldorf',
1444)                 'the interactive passphrase is not NFC-normalized',
1445)                 id='direct-input-NFC',
1446)             ),
1447)             pytest.param(
1448)                 ['--import', '-'],
1449)                 json.dumps({
1450)                     'global': {
1451)                         'unicode_normalization_form': 'NFD',
1452)                         'phrase': 'D\u00fcsseldorf',
1453)                     },
1454)                     'services': {},
1455)                 }),
Marco Ricci Signal and list falsy value...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

1457)                 id='global-NFD',
1458)             ),
1459)             pytest.param(
1460)                 ['--import', '-'],
1461)                 json.dumps({
1462)                     'global': {
1463)                         'unicode_normalization_form': 'NFD',
1464)                     },
1465)                     'services': {
1466)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1467)                         'weird entry name': {'phrase': 'D\u00fcsseldorf'},
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1469)                 }),
1470)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

1472)                     'is not NFD-normalized'
1473)                 ),
1474)                 id='service-weird-name-NFD',
1475)             ),
1476)         ],
1477)     )
1478)     def test_300_unicode_normalization_form_warning(
1479)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1480)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Allow all textual strings,...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1487)             monkeypatch=monkeypatch,
1488)             runner=runner,
1489)             config={'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}},
1490)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1493)                 command_line,
1494)                 catch_exceptions=False,
1495)                 input=input,
1496)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1497)         result = tests.ReadableResult.parse(_result)
1498)         assert result.clean_exit(), 'expected clean exit'
1499)         assert (
1500)             warning_message in result.stderr
1501)         ), 'expected known warning message in stderr'
Marco Ricci Allow all textual strings,...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1563)         runner = click.testing.CliRunner()
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

1564)         with (
Marco Ricci Modularize test helpers to...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1566)                 monkeypatch=monkeypatch, runner=runner, config={}
1567)             ),
1568)             pytest.raises(ValueError, match='Invalid vault config'),
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

1569)         ):
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1571) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1577)             # from https://montypython.fandom.com/wiki/Spam#The_menu
1578)             items = items or [
1579)                 'Egg and bacon',
1580)                 'Egg, sausage and bacon',
1581)                 'Egg and spam',
1582)                 'Egg, bacon and spam',
1583)                 'Egg, bacon, sausage and spam',
1584)                 'Spam, bacon, sausage and spam',
1585)                 'Spam, egg, spam, spam, bacon and spam',
1586)                 'Spam, spam, spam, egg and spam',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1587)                 (
1588)                     'Spam, spam, spam, spam, spam, spam, baked beans, '
1589)                     'spam, spam, spam and spam'
1590)                 ),
1591)                 (
1592)                     'Lobster thermidor aux crevettes with a mornay sauce '
1593)                     'garnished with truffle paté, brandy '
1594)                     'and a fried egg on top and spam'
1595)                 ),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1596)             ]
1597)             index = cli._prompt_for_selection(items, heading=heading)
1598)             click.echo('A fine choice: ', nl=False)
1599)             click.echo(items[index])
1600)             click.echo('(Note: Vikings strictly optional.)')
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

1603)         _result = runner.invoke(driver, [], input='9')
1604)         result = tests.ReadableResult.parse(_result)
1605)         assert result.clean_exit(
1606)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1607) Our menu:
1608) [1] Egg and bacon
1609) [2] Egg, sausage and bacon
1610) [3] Egg and spam
1611) [4] Egg, bacon and spam
1612) [5] Egg, bacon, sausage and spam
1613) [6] Spam, bacon, sausage and spam
1614) [7] Spam, egg, spam, spam, bacon and spam
1615) [8] Spam, spam, spam, egg and spam
1616) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1617) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
1618) Your selection? (1-10, leave empty to abort): 9
1619) A fine choice: Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1620) (Note: Vikings strictly optional.)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1626)         result = tests.ReadableResult.parse(_result)
1627)         assert result.error_exit(
1628)             error=IndexError
1629)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1631)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1633) [1] Egg and bacon
1634) [2] Egg, sausage and bacon
1635) [3] Egg and spam
1636) [4] Egg, bacon and spam
1637) [5] Egg, bacon, sausage and spam
1638) [6] Spam, bacon, sausage and spam
1639) [7] Spam, egg, spam, spam, bacon and spam
1640) [8] Spam, spam, spam, egg and spam
1641) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1642) [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 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1646) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1652)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1653)                 cli._prompt_for_selection(
1654)                     [item], heading='', single_choice_prompt=prompt
1655)                 )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1666)         result = tests.ReadableResult.parse(_result)
1667)         assert result.clean_exit(
1668)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1675)             driver,
1676)             ['Will replace with spam, okay? ' '(Please say "y" or "n".)'],
1677)             input='',
1678)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1679)         result = tests.ReadableResult.parse(_result)
1680)         assert result.error_exit(
1681)             error=IndexError
1682)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1684)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1688) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1691) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1695)         monkeypatch.setattr(
1696)             click,
1697)             'prompt',
1698)             lambda *a, **kw: json.dumps({'args': a, 'kwargs': kw}),
1699)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1701)         err_msg = 'missing arguments to passphrase prompt'
1702)         assert 'args' in res, err_msg
1703)         assert 'kwargs' in res, err_msg
1704)         assert res['args'][:1] == ['Passphrase'], err_msg
1705)         assert res['kwargs'].get('default') == '', err_msg
1706)         assert not res['kwargs'].get('show_default', True), err_msg
1707)         assert res['kwargs'].get('err'), err_msg
1708)         assert res['kwargs'].get('hide_input'), err_msg
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1709) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1710)     @pytest.mark.parametrize(
1711)         ['command_line', 'config', 'result_config'],
1712)         [
1713)             (
1714)                 ['--delete-globals'],
1715)                 {'global': {'phrase': 'abc'}, 'services': {}},
1716)                 {'services': {}},
1717)             ),
1718)             (
1719)                 ['--delete', DUMMY_SERVICE],
1720)                 {
1721)                     'global': {'phrase': 'abc'},
1722)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
1723)                 },
1724)                 {'global': {'phrase': 'abc'}, 'services': {}},
1725)             ),
1726)             (
1727)                 ['--clear'],
1728)                 {
1729)                     'global': {'phrase': 'abc'},
1730)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
1731)                 },
1732)                 {'services': {}},
1733)             ),
1734)         ],
1735)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1736)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1740)         config: _types.VaultConfig,
1741)         result_config: _types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1746)                 monkeypatch=monkeypatch, runner=runner, config=start_config
1747)             ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1749)                     cli.derivepassphrase_vault,
1750)                     command_line,
1751)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1760)                     config_readback = json.load(infile)
1761)                 assert config_readback == result_config
1762) 
1763)     def test_204_phrase_from_key_manually(self) -> None:
1764)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

1766)                 phrase=DUMMY_PHRASE_FROM_KEY1, **DUMMY_CONFIG_SETTINGS
1767)             ).generate(DUMMY_SERVICE)
1768)             == DUMMY_RESULT_KEY1
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1769)         )
1770) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1771)     @pytest.mark.parametrize(
1772)         ['vfunc', 'input'],
1773)         [
1774)             (cli._validate_occurrence_constraint, 20),
1775)             (cli._validate_length, 20),
1776)         ],
1777)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1778)     def test_210a_validate_constraints_manually(
1779)         self,
1780)         vfunc: Callable[[click.Context, click.Parameter, Any], int | None],
1781)         input: int,
1782)     ) -> None:
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1788)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1790)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Add test fixture for manual...

Marco Ricci authored 1 month ago

1791)         running_ssh_agent: str,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

1794)         with monkeypatch.context():
1795)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent)
1796)             monkeypatch.setattr(
1797)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
1798)             )
1799)             hint: ssh_agent.SSHAgentClient | socket.socket | None
Marco Ricci Add support for Python 3.9

Marco Ricci authored 1 month ago

1800)             # Use match/case here once Python 3.9 becomes unsupported.
1801)             if conn_hint == 'client':
1802)                 hint = ssh_agent.SSHAgentClient()
1803)             elif conn_hint == 'socket':
1804)                 hint = socket.socket(family=socket.AF_UNIX)
1805)                 hint.connect(running_ssh_agent)
1806)             else:
1807)                 assert conn_hint == 'none'
1808)                 hint = None
Marco Ricci Add test fixture for manual...

Marco Ricci authored 1 month ago

1809)             exception: Exception | None = None
1810)             try:
1811)                 list(cli._get_suitable_ssh_keys(hint))
1812)             except RuntimeError:  # pragma: no cover
1813)                 pass
1814)             except Exception as e:  # noqa: BLE001 # pragma: no cover
1815)                 exception = e
1816)             finally:
1817)                 assert (
1818)                     exception is None
1819)                 ), 'exception querying suitable SSH keys'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

1820) 
1821) 
1822) class TestCLITransition:
1823)     def test_100_help_output(self, monkeypatch: pytest.MonkeyPatch) -> None:
1824)         runner = click.testing.CliRunner(mix_stderr=False)
1825)         with tests.isolated_config(
1826)             monkeypatch=monkeypatch,
1827)             runner=runner,
1828)         ):
1829)             _result = runner.invoke(
1830)                 cli.derivepassphrase, ['--help'], catch_exceptions=False
1831)             )
1832)             result = tests.ReadableResult.parse(_result)
1833)         assert result.clean_exit(
1834)             empty_stderr=True, output='currently implemented subcommands'
1835)         ), 'expected clean exit, and known help text'
1836) 
1837)     def test_101_help_output_export(
1838)         self, monkeypatch: pytest.MonkeyPatch
1839)     ) -> None:
1840)         runner = click.testing.CliRunner(mix_stderr=False)
1841)         with tests.isolated_config(
1842)             monkeypatch=monkeypatch,
1843)             runner=runner,
1844)         ):
1845)             _result = runner.invoke(
1846)                 cli.derivepassphrase,
1847)                 ['export', '--help'],
1848)                 catch_exceptions=False,
1849)             )
1850)             result = tests.ReadableResult.parse(_result)
1851)         assert result.clean_exit(
1852)             empty_stderr=True, output='only available subcommand'
1853)         ), 'expected clean exit, and known help text'
1854) 
1855)     def test_102_help_output_export_vault(
1856)         self, monkeypatch: pytest.MonkeyPatch
1857)     ) -> None:
1858)         runner = click.testing.CliRunner(mix_stderr=False)
1859)         with tests.isolated_config(
1860)             monkeypatch=monkeypatch,
1861)             runner=runner,
1862)         ):
1863)             _result = runner.invoke(
1864)                 cli.derivepassphrase,
1865)                 ['export', 'vault', '--help'],
1866)                 catch_exceptions=False,
1867)             )
1868)             result = tests.ReadableResult.parse(_result)
1869)         assert result.clean_exit(
1870)             empty_stderr=True, output='Read the vault-native configuration'
1871)         ), 'expected clean exit, and known help text'
1872) 
1873)     def test_103_help_output_vault(
1874)         self, monkeypatch: pytest.MonkeyPatch
1875)     ) -> None:
1876)         runner = click.testing.CliRunner(mix_stderr=False)
1877)         with tests.isolated_config(
1878)             monkeypatch=monkeypatch,
1879)             runner=runner,
1880)         ):
1881)             _result = runner.invoke(
1882)                 cli.derivepassphrase,
1883)                 ['vault', '--help'],
1884)                 catch_exceptions=False,
1885)             )
1886)             result = tests.ReadableResult.parse(_result)
1887)         assert result.clean_exit(
1888)             empty_stderr=True, output='Password generation:\n'
1889)         ), 'expected clean exit, and option groups in help text'
1890)         assert result.clean_exit(
1891)             empty_stderr=True, output='Use NUMBER=0, e.g. "--symbol 0"'
1892)         ), 'expected clean exit, and option group epilog in help text'
1893) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

1894)     @pytest.mark.parametrize(
1895)         'config',
1896)         [
1897)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1898)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1899)             {
1900)                 'global': {'phrase': 'abc'},
1901)                 'services': {'sv': {'phrase': 'my passphrase'}},
1902)             },
1903)             {
1904)                 'global': {'phrase': 'abc'},
1905)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1906)             },
1907)             {
1908)                 'global': {'phrase': 'abc'},
1909)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1910)             },
1911)         ],
1912)     )
1913)     def test_110_load_config_backup(
1914)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1915)     ) -> None:
1916)         runner = click.testing.CliRunner()
1917)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
1918)             config_filename = cli._config_filename()
1919)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
1920)                 print(json.dumps(config, indent=2), file=fileobj)
1921)             assert cli._migrate_and_load_old_config()[0] == config
1922) 
1923)     @pytest.mark.parametrize(
1924)         'config',
1925)         [
1926)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1927)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1928)             {
1929)                 'global': {'phrase': 'abc'},
1930)                 'services': {'sv': {'phrase': 'my passphrase'}},
1931)             },
1932)             {
1933)                 'global': {'phrase': 'abc'},
1934)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1935)             },
1936)             {
1937)                 'global': {'phrase': 'abc'},
1938)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1939)             },
1940)         ],
1941)     )
1942)     def test_111_migrate_config(
1943)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1944)     ) -> None:
1945)         runner = click.testing.CliRunner()
1946)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
1947)             config_filename = cli._config_filename()
1948)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
1949)                 print(json.dumps(config, indent=2), file=fileobj)
1950)             assert cli._migrate_and_load_old_config() == (config, None)
1951) 
1952)     @pytest.mark.parametrize(
1953)         'config',
1954)         [
1955)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1956)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1957)             {
1958)                 'global': {'phrase': 'abc'},
1959)                 'services': {'sv': {'phrase': 'my passphrase'}},
1960)             },
1961)             {
1962)                 'global': {'phrase': 'abc'},
1963)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1964)             },
1965)             {
1966)                 'global': {'phrase': 'abc'},
1967)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1968)             },
1969)         ],
1970)     )
1971)     def test_112_migrate_config_error(
1972)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1973)     ) -> None:
1974)         runner = click.testing.CliRunner()
1975)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
1976)             config_filename = cli._config_filename()
1977)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
1978)                 print(json.dumps(config, indent=2), file=fileobj)
1979)             os.mkdir(cli._config_filename(subsystem='vault'))
1980)             config2, err = cli._migrate_and_load_old_config()
1981)             assert config2 == config
1982)             assert isinstance(err, OSError)
1983)             assert err.errno == errno.EISDIR
1984) 
1985)     @pytest.mark.parametrize(
1986)         'config',
1987)         [
1988)             {'global': '', 'services': {}},
1989)             {'global': 0, 'services': {}},
1990)             {
1991)                 'global': {'phrase': 'abc'},
1992)                 'services': False,
1993)             },
1994)             {
1995)                 'global': {'phrase': 'abc'},
1996)                 'services': True,
1997)             },
1998)             {
1999)                 'global': {'phrase': 'abc'},
2000)                 'services': None,
2001)             },
2002)         ],
2003)     )
2004)     def test_113_migrate_config_error_bad_config_value(
2005)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2006)     ) -> None:
2007)         runner = click.testing.CliRunner()
2008)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
2009)             config_filename = cli._config_filename()
2010)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2011)                 print(json.dumps(config, indent=2), file=fileobj)
2012)             with pytest.raises(ValueError, match=cli._INVALID_VAULT_CONFIG):
2013)                 cli._migrate_and_load_old_config()
2014) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

2015)     def test_200_forward_export_vault_path_parameter(
2016)         self, monkeypatch: pytest.MonkeyPatch
2017)     ) -> None:
2018)         pytest.importorskip('cryptography', minversion='38.0')
2019)         runner = click.testing.CliRunner(mix_stderr=False)
2020)         with tests.isolated_vault_exporter_config(
2021)             monkeypatch=monkeypatch,
2022)             runner=runner,
2023)             vault_config=tests.VAULT_V03_CONFIG,
2024)             vault_key=tests.VAULT_MASTER_KEY,
2025)         ):
2026)             monkeypatch.setenv('VAULT_KEY', tests.VAULT_MASTER_KEY)
2027)             _result = runner.invoke(
2028)                 cli.derivepassphrase,
2029)                 ['export', 'VAULT_PATH'],
2030)             )
2031)         result = tests.ReadableResult.parse(_result)
2032)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

2033)         assert (
2034)             result.stderr
2035)             == f"""\
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

2036) {cli.PROG_NAME}: Deprecation warning: A subcommand will be required in v1.0. See --help for available subcommands.
2037) {cli.PROG_NAME}: Warning: Defaulting to subcommand "vault".
2038) """  # noqa: E501
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

2039)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

2040)         assert json.loads(result.output) == tests.VAULT_V03_CONFIG_DATA
2041) 
2042)     @pytest.mark.parametrize(
2043)         'charset_name', ['lower', 'upper', 'number', 'space', 'dash', 'symbol']
2044)     )
2045)     def test_210_forward_vault_disable_character_set(
2046)         self, monkeypatch: pytest.MonkeyPatch, charset_name: str
2047)     ) -> None:
2048)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
2049)         option = f'--{charset_name}'
Marco Ricci Align behavior with vault c...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

2051)         runner = click.testing.CliRunner(mix_stderr=False)
2052)         with tests.isolated_config(
2053)             monkeypatch=monkeypatch,
2054)             runner=runner,
2055)         ):
2056)             _result = runner.invoke(
2057)                 cli.derivepassphrase,
2058)                 [option, '0', '-p', DUMMY_SERVICE],
2059)                 input=DUMMY_PASSPHRASE,
2060)                 catch_exceptions=False,
2061)             )
2062)             result = tests.ReadableResult.parse(_result)
2063)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

2064)         assert (
2065)             result.stderr
2066)             == f"""\
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

2067) {cli.PROG_NAME}: Deprecation warning: A subcommand will be required in v1.0. See --help for available subcommands.
2068) {cli.PROG_NAME}: Warning: Defaulting to subcommand "vault".
2069) """  # noqa: E501
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

2070)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

2071)         for c in charset:
2072)             assert (
2073)                 c not in result.output
2074)             ), f'derived password contains forbidden character {c!r}'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

2075) 
2076)     def test_300_export_using_old_config_file(
2077)         self,
2078)         monkeypatch: pytest.MonkeyPatch,
2079)     ) -> None:
2080)         runner = click.testing.CliRunner(mix_stderr=False)
2081)         with tests.isolated_config(
2082)             monkeypatch=monkeypatch,
2083)             runner=runner,
2084)         ):
2085)             with open(
2086)                 cli._config_filename(), 'w', encoding='UTF-8'
2087)             ) as fileobj:
2088)                 print(
2089)                     json.dumps(
2090)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
2091)                         indent=2,
2092)                     ),
2093)                     file=fileobj,
2094)                 )
2095)             _result = runner.invoke(
2096)                 cli.derivepassphrase_vault,
2097)                 ['--export', '-'],
2098)                 catch_exceptions=False,
2099)             )
2100)         result = tests.ReadableResult.parse(_result)
2101)         assert result.clean_exit(), 'expected clean exit'
2102)         assert (
2103)             'v0.1-style config file' in result.stderr
2104)         ), 'expected known warning message in stderr'
2105)         assert (
2106)             'Successfully migrated to ' in result.stderr
2107)         ), 'expected known warning message in stderr'
2108) 
2109)     def test_300a_export_using_old_config_file_migration_error(
2110)         self,
2111)         monkeypatch: pytest.MonkeyPatch,
2112)     ) -> None:
2113)         runner = click.testing.CliRunner(mix_stderr=False)
2114)         with tests.isolated_config(
2115)             monkeypatch=monkeypatch,
2116)             runner=runner,
2117)         ):
2118)             with open(
2119)                 cli._config_filename(), 'w', encoding='UTF-8'
2120)             ) as fileobj:
2121)                 print(
2122)                     json.dumps(
2123)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
2124)                         indent=2,
2125)                     ),
2126)                     file=fileobj,
2127)                 )
2128) 
2129)             def raiser(*_args: Any, **_kwargs: Any) -> None:
2130)                 raise OSError(
2131)                     errno.EACCES,
2132)                     os.strerror(errno.EACCES),
2133)                     cli._config_filename(subsystem='vault'),
2134)                 )
2135) 
2136)             monkeypatch.setattr(os, 'replace', raiser)
2137)             _result = runner.invoke(
2138)                 cli.derivepassphrase_vault,
2139)                 ['--export', '-'],
2140)                 catch_exceptions=False,
2141)             )
2142)         result = tests.ReadableResult.parse(_result)
2143)         assert result.clean_exit(), 'expected clean exit'
2144)         assert (
2145)             'v0.1-style config file' in result.stderr
2146)         ), 'expected known warning message in stderr'
2147)         assert (
2148)             'Warning: Failed to migrate to ' in result.stderr
2149)         ), 'expected known warning message in stderr'