798ddc103c6c03835394733aeca128b970aacd06
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 Remove `click` handling of...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

12) import socket
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

15) import click.testing
16) import pytest
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

17) from typing_extensions import NamedTuple
18) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

21) 
22) if TYPE_CHECKING:
23)     from collections.abc import Callable
24) 
25)     from typing_extensions import Any
Marco Ricci Add prototype command-line...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

41) 
42) 
43) class IncompatibleConfiguration(NamedTuple):
44)     other_options: list[tuple[str, ...]]
45)     needs_service: bool | None
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

47) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

52)     check_success: bool
53) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

60)     check_success: bool
61) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

76)     ('--notes',),
77)     ('--config',),
78)     ('--delete',),
79)     ('--delete-globals',),
80)     ('--clear',),
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

87) ]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

92)         True,
93)         DUMMY_PASSPHRASE,
94)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

134)         [('--delete',), ('--delete-globals',), ('--clear',), *STORAGE_OPTIONS],
135)         None,
136)         DUMMY_PASSPHRASE,
137)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

146)         [('--import', '-')], False, None
147)     ),
148)     ('--import', '-'): IncompatibleConfiguration([], False, None),
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

171) for opt, config in INCOMPATIBLE.items():
172)     for opt2 in config.other_options:
173)         INTERESTING_OPTION_COMBINATIONS.extend([
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

188)         ])
189) for opt, config in SINGLES.items():
190)     INTERESTING_OPTION_COMBINATIONS.append(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

199) 
200) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

204)         with tests.isolated_config(
205)             monkeypatch=monkeypatch,
206)             runner=runner,
207)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

211)             result = tests.ReadableResult.parse(_result)
212)         assert result.clean_exit(
213)             empty_stderr=True, output='Password generation:\n'
214)         ), 'expected clean exit, and option groups in help text'
215)         assert result.clean_exit(
216)             empty_stderr=True, output='Use NUMBER=0, e.g. "--symbol 0"'
217)         ), 'expected clean exit, and option group epilog in help text'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

218) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

235)                 [option, '0', '-p', DUMMY_SERVICE],
236)                 input=DUMMY_PASSPHRASE,
237)                 catch_exceptions=False,
238)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

245) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

246)     def test_202_disable_repetition(
247)         self, monkeypatch: pytest.MonkeyPatch
248)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

249)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
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)                 ['--repeat', '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(
263)             empty_stderr=True
264)         ), 'expected clean exit and empty stderr'
265)         passphrase = result.output.rstrip('\r\n')
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

271) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

272)     @pytest.mark.parametrize(
273)         'config',
274)         [
275)             pytest.param(
276)                 {
277)                     'global': {'key': DUMMY_KEY1_B64},
278)                     'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS},
279)                 },
280)                 id='global',
281)             ),
282)             pytest.param(
283)                 {
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

285)                     'services': {
286)                         DUMMY_SERVICE: {
287)                             'key': DUMMY_KEY1_B64,
288)                             **DUMMY_CONFIG_SETTINGS,
289)                         }
290)                     },
291)                 },
292)                 id='service',
293)             ),
294)         ],
295)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

296)     def test_204a_key_from_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

303)             monkeypatch=monkeypatch, runner=runner, config=config
304)         ):
305)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

309)                 cli.derivepassphrase_vault,
310)                 [DUMMY_SERVICE],
311)                 catch_exceptions=False,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

313)         result = tests.ReadableResult.parse(_result)
314)         assert result.clean_exit(
315)             empty_stderr=True
316)         ), 'expected clean exit and empty stderr'
317)         assert _result.stdout_bytes
318)         assert (
319)             _result.stdout_bytes.rstrip(b'\n') != DUMMY_RESULT_PASSPHRASE
320)         ), 'known false output: phrase-based instead of key-based'
321)         assert (
322)             _result.stdout_bytes.rstrip(b'\n') == DUMMY_RESULT_KEY1
323)         ), 'expected known output'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

324) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

325)     def test_204b_key_from_command_line(
326)         self, monkeypatch: pytest.MonkeyPatch
327)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

330)             monkeypatch=monkeypatch,
331)             runner=runner,
332)             config={'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
333)         ):
334)             monkeypatch.setattr(
335)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
336)             )
337)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

344)                 catch_exceptions=False,
345)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

346)         result = tests.ReadableResult.parse(_result)
347)         assert result.clean_exit(), 'expected clean exit'
348)         assert _result.stdout_bytes, 'expected program output'
349)         last_line = _result.stdout_bytes.splitlines(True)[-1]
350)         assert (
351)             last_line.rstrip(b'\n') != DUMMY_RESULT_PASSPHRASE
352)         ), 'known false output: phrase-based instead of key-based'
353)         assert (
354)             last_line.rstrip(b'\n') == DUMMY_RESULT_KEY1
355)         ), 'expected known output'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

356) 
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

357)     @pytest.mark.parametrize(
358)         'config',
359)         [
360)             pytest.param(
361)                 {
362)                     'global': {'key': DUMMY_KEY1_B64},
363)                     'services': {DUMMY_SERVICE: {}},
364)                 },
365)                 id='global_config',
366)             ),
367)             pytest.param(
368)                 {'services': {DUMMY_SERVICE: {'key': DUMMY_KEY2_B64}}},
369)                 id='service_config',
370)             ),
371)             pytest.param(
372)                 {
373)                     'global': {'key': DUMMY_KEY1_B64},
374)                     'services': {DUMMY_SERVICE: {'key': DUMMY_KEY2_B64}},
375)                 },
376)                 id='full_config',
377)             ),
378)         ],
379)     )
380)     @pytest.mark.parametrize('key_index', [1, 2, 3], ids=lambda i: f'index{i}')
381)     def test_204c_key_override_on_command_line(
382)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

385)         config: dict[str, Any],
386)         key_index: int,
387)     ) -> None:
Marco Ricci Add test fixture for manual...

Marco Ricci authored 1 month ago

388)         with monkeypatch.context():
389)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent)
390)             monkeypatch.setattr(
391)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

394)             runner = click.testing.CliRunner(mix_stderr=False)
395)             with tests.isolated_vault_config(
396)                 monkeypatch=monkeypatch, runner=runner, config=config
397)             ):
398)                 _result = runner.invoke(
399)                     cli.derivepassphrase_vault,
400)                     ['-k', DUMMY_SERVICE],
401)                     input=f'{key_index}\n',
402)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

403)         result = tests.ReadableResult.parse(_result)
404)         assert result.clean_exit(), 'expected clean exit'
405)         assert result.output, 'expected program output'
406)         assert result.stderr, 'expected stderr'
407)         assert (
408)             'Error:' not in result.stderr
409)         ), 'expected no error messages on stderr'
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

411)     def test_205_service_phrase_if_key_in_global_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

416)         with monkeypatch.context():
417)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent)
418)             monkeypatch.setattr(
419)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

421)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', tests.sign)
422)             runner = click.testing.CliRunner(mix_stderr=False)
423)             with tests.isolated_vault_config(
424)                 monkeypatch=monkeypatch,
425)                 runner=runner,
426)                 config={
427)                     'global': {'key': DUMMY_KEY1_B64},
428)                     'services': {
429)                         DUMMY_SERVICE: {
430)                             'phrase': DUMMY_PASSPHRASE.rstrip('\n'),
431)                             **DUMMY_CONFIG_SETTINGS,
432)                         }
433)                     },
434)                 },
435)             ):
436)                 _result = runner.invoke(
437)                     cli.derivepassphrase_vault,
438)                     [DUMMY_SERVICE],
439)                     catch_exceptions=False,
440)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

441)         result = tests.ReadableResult.parse(_result)
442)         assert result.clean_exit(), 'expected clean exit'
443)         assert _result.stdout_bytes, 'expected program output'
444)         last_line = _result.stdout_bytes.splitlines(True)[-1]
445)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

451) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

452)     @pytest.mark.parametrize(
453)         'option',
454)         [
455)             '--lower',
456)             '--upper',
457)             '--number',
458)             '--space',
459)             '--dash',
460)             '--symbol',
461)             '--repeat',
462)             '--length',
463)         ],
464)     )
Marco Ricci Isolate tests properly and...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

469)         with tests.isolated_config(
470)             monkeypatch=monkeypatch,
471)             runner=runner,
472)         ):
473)             for value in '-42', 'invalid':
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

476)                     [option, value, '-p', DUMMY_SERVICE],
477)                     input=DUMMY_PASSPHRASE,
478)                     catch_exceptions=False,
479)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

480)                 result = tests.ReadableResult.parse(_result)
481)                 assert result.error_exit(
482)                     error='Error: Invalid value'
483)                 ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

484) 
485)     @pytest.mark.parametrize(
486)         ['options', 'service', 'input', 'check_success'],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

487)         [
488)             (o.options, o.needs_service, o.input, o.check_success)
489)             for o in INTERESTING_OPTION_COMBINATIONS
490)             if not o.incompatible
491)         ],
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

492)     )
493)     def test_211_service_needed(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

504)             monkeypatch=monkeypatch,
505)             runner=runner,
506)             config={'global': {'phrase': 'abc'}, 'services': {}},
507)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

510)                 options if service else [*options, DUMMY_SERVICE],
511)                 input=input,
512)                 catch_exceptions=False,
513)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

521)                 assert result.error_exit(
522)                     error=err_msg
523)                 ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

525)                 assert result.clean_exit(
526)                     empty_stderr=True
527)                 ), 'expected clean exit'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

530)                 monkeypatch=monkeypatch,
531)                 runner=runner,
532)                 config={'global': {'phrase': 'abc'}, 'services': {}},
533)             ):
534)                 monkeypatch.setattr(
535)                     cli, '_prompt_for_passphrase', tests.auto_prompt
536)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

539)                     [*options, DUMMY_SERVICE] if service else options,
540)                     input=input,
541)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

548)         [
549)             (o.options, o.needs_service)
550)             for o in INTERESTING_OPTION_COMBINATIONS
551)             if o.incompatible
552)         ],
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

554)     def test_212_incompatible_options(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

561)         with tests.isolated_config(
562)             monkeypatch=monkeypatch,
563)             runner=runner,
564)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

567)                 [*options, DUMMY_SERVICE] if service else options,
568)                 input=DUMMY_PASSPHRASE,
569)                 catch_exceptions=False,
570)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

571)         result = tests.ReadableResult.parse(_result)
572)         assert result.error_exit(
573)             error='mutually exclusive with '
574)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

576)     def test_213_import_bad_config_not_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

588)         result = tests.ReadableResult.parse(_result)
589)         assert result.error_exit(
590)             error='Invalid vault config'
591)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

593)     def test_213a_import_bad_config_not_json_data(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

605)         result = tests.ReadableResult.parse(_result)
606)         assert result.error_exit(
607)             error='cannot decode JSON'
608)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

610)     def test_213b_import_bad_config_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

630)         result = tests.ReadableResult.parse(_result)
631)         assert result.error_exit(
632)             error=os.strerror(errno.EISDIR)
633)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

634) 
635)     def test_214_export_settings_no_stored_settings(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

644)                 cli.derivepassphrase_vault,
645)                 ['--export', '-'],
646)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

651)     def test_214a_export_settings_bad_stored_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

665)         result = tests.ReadableResult.parse(_result)
666)         assert result.error_exit(
667)             error='Cannot load config'
668)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

670)     def test_214b_export_settings_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

685)         result = tests.ReadableResult.parse(_result)
686)         assert result.error_exit(
687)             error='Cannot load config'
688)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

690)     def test_214c_export_settings_target_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

703)         result = tests.ReadableResult.parse(_result)
704)         assert result.error_exit(
705)             error='Cannot store config'
706)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

707) 
Marco Ricci Create the configuration di...

Marco Ricci authored 3 months ago

708)     def test_214d_export_settings_settings_directory_not_a_directory(
709)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

722)                 catch_exceptions=False,
723)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

724)         result = tests.ReadableResult.parse(_result)
725)         assert result.error_exit(
726)             error='Cannot load config'
727)         ), 'expected error exit and known error message'
Marco Ricci Create the configuration di...

Marco Ricci authored 3 months ago

728) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

729)     def test_220_edit_notes_successfully(
730)         self, monkeypatch: pytest.MonkeyPatch
731)     ) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

733) 
734) # - - - - - >8 - - - - - >8 - - - - - >8 - - - - - >8 - - - - -
735) contents go here
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

739)             monkeypatch=monkeypatch,
740)             runner=runner,
741)             config={'global': {'phrase': 'abc'}, 'services': {}},
742)         ):
743)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: edit_result)  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

745)                 cli.derivepassphrase_vault,
746)                 ['--notes', 'sv'],
747)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

755)             assert config == {
756)                 'global': {'phrase': 'abc'},
757)                 'services': {'sv': {'notes': 'contents go here'}},
758)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

759) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

760)     def test_221_edit_notes_noop(
761)         self, monkeypatch: pytest.MonkeyPatch
762)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

765)             monkeypatch=monkeypatch,
766)             runner=runner,
767)             config={'global': {'phrase': 'abc'}, 'services': {}},
768)         ):
769)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: None)  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

771)                 cli.derivepassphrase_vault,
772)                 ['--notes', 'sv'],
773)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

783)     def test_222_edit_notes_marker_removed(
784)         self, monkeypatch: pytest.MonkeyPatch
785)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

788)             monkeypatch=monkeypatch,
789)             runner=runner,
790)             config={'global': {'phrase': 'abc'}, 'services': {}},
791)         ):
792)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: 'long\ntext')  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

794)                 cli.derivepassphrase_vault,
795)                 ['--notes', 'sv'],
796)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

804)             assert config == {
805)                 'global': {'phrase': 'abc'},
806)                 'services': {'sv': {'notes': 'long\ntext'}},
807)             }
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)     def test_223_edit_notes_abort(
810)         self, monkeypatch: pytest.MonkeyPatch
811)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

814)             monkeypatch=monkeypatch,
815)             runner=runner,
816)             config={'global': {'phrase': 'abc'}, 'services': {}},
817)         ):
818)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: '\n\n')  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

820)                 cli.derivepassphrase_vault,
821)                 ['--notes', 'sv'],
822)                 catch_exceptions=False,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

824)             result = tests.ReadableResult.parse(_result)
825)             assert result.error_exit(
826)                 error='user aborted request'
827)             ), 'expected known error message'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

834)     @pytest.mark.parametrize(
835)         ['command_line', 'input', 'result_config'],
836)         [
837)             (
838)                 ['--phrase'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

840)                 {'global': {'phrase': 'my passphrase'}, 'services': {}},
841)             ),
842)             (
843)                 ['--key'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

845)                 {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
846)             ),
847)             (
848)                 ['--phrase', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

850)                 {
851)                     'global': {'phrase': 'abc'},
852)                     'services': {'sv': {'phrase': 'my passphrase'}},
853)                 },
854)             ),
855)             (
856)                 ['--key', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

858)                 {
859)                     'global': {'phrase': 'abc'},
860)                     'services': {'sv': {'key': DUMMY_KEY1_B64}},
861)                 },
862)             ),
863)             (
864)                 ['--key', '--length', '15', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

866)                 {
867)                     'global': {'phrase': 'abc'},
868)                     'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
869)                 },
870)             ),
871)         ],
872)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

873)     def test_224_store_config_good(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

878)         result_config: Any,
879)     ) -> None:
880)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

882)             monkeypatch=monkeypatch,
883)             runner=runner,
884)             config={'global': {'phrase': 'abc'}, 'services': {}},
885)         ):
886)             monkeypatch.setattr(
887)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
888)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

891)                 ['--config', *command_line],
892)                 catch_exceptions=False,
893)                 input=input,
894)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

901)             assert (
902)                 config == result_config
903)             ), 'stored config does not match expectation'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

904) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

905)     @pytest.mark.parametrize(
906)         ['command_line', 'input', 'err_text'],
907)         [
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

909)             (
910)                 ['sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

911)                 '',
912)                 'Cannot update service settings without actual settings',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

916)         ],
917)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

918)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

922)         input: str,
923)         err_text: str,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

927)             monkeypatch=monkeypatch,
928)             runner=runner,
929)             config={'global': {'phrase': 'abc'}, 'services': {}},
930)         ):
931)             monkeypatch.setattr(
932)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
933)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

936)                 ['--config', *command_line],
937)                 catch_exceptions=False,
938)                 input=input,
939)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

940)         result = tests.ReadableResult.parse(_result)
941)         assert result.error_exit(
942)             error=err_text
943)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

944) 
945)     def test_225a_store_config_fail_manual_no_ssh_key_selection(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

951)             monkeypatch=monkeypatch,
952)             runner=runner,
953)             config={'global': {'phrase': 'abc'}, 'services': {}},
954)         ):
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

963)                 ['--key', '--config'],
964)                 catch_exceptions=False,
965)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

966)         result = tests.ReadableResult.parse(_result)
967)         assert result.error_exit(
968)             error=custom_error
969)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

971)     def test_225b_store_config_fail_manual_no_ssh_agent(
972)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

979)             monkeypatch=monkeypatch,
980)             runner=runner,
981)             config={'global': {'phrase': 'abc'}, 'services': {}},
982)         ):
983)             monkeypatch.delenv('SSH_AUTH_SOCK', raising=False)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

986)                 ['--key', '--config'],
987)                 catch_exceptions=False,
988)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

989)         result = tests.ReadableResult.parse(_result)
990)         assert result.error_exit(
991)             error='Cannot find running SSH agent'
992)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

993) 
994)     def test_225c_store_config_fail_manual_bad_ssh_agent_connection(
995)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1000)             monkeypatch=monkeypatch,
1001)             runner=runner,
1002)             config={'global': {'phrase': 'abc'}, 'services': {}},
1003)         ):
1004)             monkeypatch.setenv('SSH_AUTH_SOCK', os.getcwd())
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1007)                 ['--key', '--config'],
1008)                 catch_exceptions=False,
1009)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1010)         result = tests.ReadableResult.parse(_result)
1011)         assert result.error_exit(
1012)             error='Cannot connect to SSH agent'
1013)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

1014) 
1015)     @pytest.mark.parametrize('try_race_free_implementation', [True, False])
1016)     def test_225d_store_config_fail_manual_read_only_file(
1017)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1019)         try_race_free_implementation: bool,
1020)     ) -> None:
1021)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1023)             monkeypatch=monkeypatch,
1024)             runner=runner,
1025)             config={'global': {'phrase': 'abc'}, 'services': {}},
1026)         ):
1027)             tests.make_file_readonly(
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1029)                 try_race_free_implementation=try_race_free_implementation,
1030)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1033)                 ['--config', '--length=15', DUMMY_SERVICE],
1034)                 catch_exceptions=False,
1035)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1036)         result = tests.ReadableResult.parse(_result)
1037)         assert result.error_exit(
1038)             error='Cannot store config'
1039)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

1040) 
1041)     def test_225e_store_config_fail_manual_custom_error(
1042)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1047)             monkeypatch=monkeypatch,
1048)             runner=runner,
1049)             config={'global': {'phrase': 'abc'}, 'services': {}},
1050)         ):
1051)             custom_error = 'custom error message'
1052) 
1053)             def raiser(config: Any) -> None:
1054)                 del config
1055)                 raise RuntimeError(custom_error)
1056) 
1057)             monkeypatch.setattr(cli, '_save_config', raiser)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1060)                 ['--config', '--length=15', DUMMY_SERVICE],
1061)                 catch_exceptions=False,
1062)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1063)         result = tests.ReadableResult.parse(_result)
1064)         assert result.error_exit(
1065)             error=custom_error
1066)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

1067) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1070)         with tests.isolated_config(
1071)             monkeypatch=monkeypatch,
1072)             runner=runner,
1073)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1077)         result = tests.ReadableResult.parse(_result)
1078)         assert result.error_exit(
1079)             error='SERVICE is required'
1080)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

1081) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1082)     def test_226a_no_passphrase_or_key(
1083)         self, monkeypatch: pytest.MonkeyPatch
1084)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1086)         with tests.isolated_config(
1087)             monkeypatch=monkeypatch,
1088)             runner=runner,
1089)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1091)                 cli.derivepassphrase_vault,
1092)                 [DUMMY_SERVICE],
1093)                 catch_exceptions=False,
Marco Ricci Isolate tests properly and...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1099) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1100)     def test_230_config_directory_nonexistant(
1101)         self, monkeypatch: pytest.MonkeyPatch
1102)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1104)         runner = click.testing.CliRunner(mix_stderr=False)
1105)         with tests.isolated_config(
1106)             monkeypatch=monkeypatch,
1107)             runner=runner,
1108)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1110)             os_makedirs_called = False
1111)             real_os_makedirs = os.makedirs
1112) 
1113)             def makedirs(*args: Any, **kwargs: Any) -> Any:
1114)                 nonlocal os_makedirs_called
1115)                 os_makedirs_called = True
1116)                 return real_os_makedirs(*args, **kwargs)
1117) 
1118)             monkeypatch.setattr(os, 'makedirs', makedirs)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1121)                 ['--config', '-p'],
1122)                 catch_exceptions=False,
1123)                 input='abc\n',
1124)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1134)                 config_readback = json.load(infile)
1135)             assert config_readback == {
1136)                 'global': {'phrase': 'abc'},
1137)                 'services': {},
1138)             }, 'config mismatch'
1139) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1140)     def test_230a_config_directory_not_a_file(
1141)         self, monkeypatch: pytest.MonkeyPatch
1142)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1144)         runner = click.testing.CliRunner(mix_stderr=False)
1145)         with tests.isolated_config(
1146)             monkeypatch=monkeypatch,
1147)             runner=runner,
1148)         ):
1149)             _save_config = cli._save_config
1150) 
1151)             def obstruct_config_saving(*args: Any, **kwargs: Any) -> Any:
1152)                 with contextlib.suppress(FileNotFoundError):
1153)                     shutil.rmtree('.derivepassphrase')
1154)                 with open(
1155)                     '.derivepassphrase', 'w', encoding='UTF-8'
1156)                 ) as outfile:
1157)                     print('Obstruction!!', file=outfile)
1158)                 monkeypatch.setattr(cli, '_save_config', _save_config)
1159)                 return _save_config(*args, **kwargs)
1160) 
1161)             monkeypatch.setattr(cli, '_save_config', obstruct_config_saving)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1164)                 ['--config', '-p'],
1165)                 catch_exceptions=False,
1166)                 input='abc\n',
1167)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1168)             result = tests.ReadableResult.parse(_result)
1169)             assert result.error_exit(
1170)                 error='Cannot store config'
1171)             ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

1172) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1173)     def test_230b_store_config_custom_error(
1174)         self, monkeypatch: pytest.MonkeyPatch
1175)     ) -> None:
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

1176)         runner = click.testing.CliRunner(mix_stderr=False)
1177)         with tests.isolated_config(
1178)             monkeypatch=monkeypatch,
1179)             runner=runner,
1180)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1183)             def raiser(config: Any) -> None:
1184)                 del config
1185)                 raise RuntimeError(custom_error)
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1190)                 ['--config', '-p'],
1191)                 catch_exceptions=False,
1192)                 input='abc\n',
1193)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1201)         [
1202)             pytest.param(
1203)                 ['--import', '-'],
1204)                 json.dumps({
1205)                     'global': {'phrase': 'Du\u0308sseldorf'},
1206)                     'services': {},
1207)                 }),
1208)                 'the global passphrase is not NFC-normalized',
1209)                 id='global-NFC',
1210)             ),
1211)             pytest.param(
1212)                 ['--import', '-'],
1213)                 json.dumps({
1214)                     'services': {
1215)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1216)                         'weird entry name': {'phrase': 'Du\u0308sseldorf'},
1217)                     }
1218)                 }),
1219)                 (
1220)                     "the services.'weird entry name' passphrase "
1221)                     'is not NFC-normalized'
1222)                 ),
1223)                 id='service-weird-name-NFC',
1224)             ),
1225)             pytest.param(
1226)                 ['--config', '-p', DUMMY_SERVICE],
1227)                 'Du\u0308sseldorf',
1228)                 (
1229)                     f'the services.{DUMMY_SERVICE} passphrase '
1230)                     f'is not NFC-normalized'
1231)                 ),
1232)                 id='config-NFC',
1233)             ),
1234)             pytest.param(
1235)                 ['-p', DUMMY_SERVICE],
1236)                 'Du\u0308sseldorf',
1237)                 'the interactive passphrase is not NFC-normalized',
1238)                 id='direct-input-NFC',
1239)             ),
1240)             pytest.param(
1241)                 ['--import', '-'],
1242)                 json.dumps({
1243)                     'global': {
1244)                         'unicode_normalization_form': 'NFD',
1245)                         'phrase': 'D\u00fcsseldorf',
1246)                     },
1247)                     'services': {},
1248)                 }),
1249)                 'the global passphrase is not NFD-normalized',
1250)                 id='global-NFD',
1251)             ),
1252)             pytest.param(
1253)                 ['--import', '-'],
1254)                 json.dumps({
1255)                     'global': {
1256)                         'unicode_normalization_form': 'NFD',
1257)                     },
1258)                     'services': {
1259)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1260)                         'weird entry name': {'phrase': 'D\u00fcsseldorf'},
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1262)                 }),
1263)                 (
1264)                     "the services.'weird entry name' passphrase "
1265)                     'is not NFD-normalized'
1266)                 ),
1267)                 id='service-weird-name-NFD',
1268)             ),
1269)         ],
1270)     )
1271)     def test_300_unicode_normalization_form_warning(
1272)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1280)             monkeypatch=monkeypatch,
1281)             runner=runner,
1282)             config={'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}},
1283)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1286)                 command_line,
1287)                 catch_exceptions=False,
1288)                 input=input,
1289)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1290)         result = tests.ReadableResult.parse(_result)
1291)         assert result.clean_exit(), 'expected clean exit'
1292)         assert (
1293)             warning_message in result.stderr
1294)         ), 'expected known warning message in stderr'
Marco Ricci Allow all textual strings,...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

1296)     def test_400_missing_af_unix_support(
1297)         self,
1298)         monkeypatch: pytest.MonkeyPatch,
1299)     ) -> None:
1300)         runner = click.testing.CliRunner(mix_stderr=False)
1301)         with tests.isolated_vault_config(
1302)             monkeypatch=monkeypatch,
1303)             runner=runner,
1304)             config={'global': {'phrase': 'abc'}, 'services': {}},
1305)         ):
1306)             monkeypatch.setenv(
1307)                 'SSH_AUTH_SOCK', "the value doesn't even matter"
1308)             )
1309)             monkeypatch.delattr(socket, 'AF_UNIX', raising=False)
1310)             _result = runner.invoke(
1311)                 cli.derivepassphrase_vault,
1312)                 ['--key', '--config'],
1313)                 catch_exceptions=False,
1314)             )
1315)         result = tests.ReadableResult.parse(_result)
1316)         assert result.error_exit(
1317)             error='does not support UNIX domain sockets'
1318)         ), 'expected error exit and known error message'
1319) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

1322)     @pytest.mark.parametrize(
1323)         'config',
1324)         [
1325)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1326)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1327)             {
1328)                 'global': {'phrase': 'abc'},
1329)                 'services': {'sv': {'phrase': 'my passphrase'}},
1330)             },
1331)             {
1332)                 'global': {'phrase': 'abc'},
1333)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1334)             },
1335)             {
1336)                 'global': {'phrase': 'abc'},
1337)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1338)             },
1339)         ],
1340)     )
1341)     def test_100_load_config(
1342)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1343)     ) -> None:
1344)         runner = click.testing.CliRunner()
1345)         with tests.isolated_vault_config(
1346)             monkeypatch=monkeypatch, runner=runner, config=config
1347)         ):
1348)             config_filename = cli._config_filename(subsystem='vault')
1349)             with open(config_filename, encoding='UTF-8') as fileobj:
1350)                 assert json.load(fileobj) == config
1351)             assert cli._load_config() == config
1352) 
1353)     def test_110_save_bad_config(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1364) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1370)             # from https://montypython.fandom.com/wiki/Spam#The_menu
1371)             items = items or [
1372)                 'Egg and bacon',
1373)                 'Egg, sausage and bacon',
1374)                 'Egg and spam',
1375)                 'Egg, bacon and spam',
1376)                 'Egg, bacon, sausage and spam',
1377)                 'Spam, bacon, sausage and spam',
1378)                 'Spam, egg, spam, spam, bacon and spam',
1379)                 'Spam, spam, spam, egg and spam',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1380)                 (
1381)                     'Spam, spam, spam, spam, spam, spam, baked beans, '
1382)                     'spam, spam, spam and spam'
1383)                 ),
1384)                 (
1385)                     'Lobster thermidor aux crevettes with a mornay sauce '
1386)                     'garnished with truffle paté, brandy '
1387)                     'and a fried egg on top and spam'
1388)                 ),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1389)             ]
1390)             index = cli._prompt_for_selection(items, heading=heading)
1391)             click.echo('A fine choice: ', nl=False)
1392)             click.echo(items[index])
1393)             click.echo('(Note: Vikings strictly optional.)')
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

1396)         _result = runner.invoke(driver, [], input='9')
1397)         result = tests.ReadableResult.parse(_result)
1398)         assert result.clean_exit(
1399)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1400) Our menu:
1401) [1] Egg and bacon
1402) [2] Egg, sausage and bacon
1403) [3] Egg and spam
1404) [4] Egg, bacon and spam
1405) [5] Egg, bacon, sausage and spam
1406) [6] Spam, bacon, sausage and spam
1407) [7] Spam, egg, spam, spam, bacon and spam
1408) [8] Spam, spam, spam, egg and spam
1409) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1410) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
1411) Your selection? (1-10, leave empty to abort): 9
1412) A fine choice: Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1413) (Note: Vikings strictly optional.)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1419)         result = tests.ReadableResult.parse(_result)
1420)         assert result.error_exit(
1421)             error=IndexError
1422)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1424)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1426) [1] Egg and bacon
1427) [2] Egg, sausage and bacon
1428) [3] Egg and spam
1429) [4] Egg, bacon and spam
1430) [5] Egg, bacon, sausage and spam
1431) [6] Spam, bacon, sausage and spam
1432) [7] Spam, egg, spam, spam, bacon and spam
1433) [8] Spam, spam, spam, egg and spam
1434) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1435) [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

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1439) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1445)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1446)                 cli._prompt_for_selection(
1447)                     [item], heading='', single_choice_prompt=prompt
1448)                 )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1459)         result = tests.ReadableResult.parse(_result)
1460)         assert result.clean_exit(
1461)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1468)             driver,
1469)             ['Will replace with spam, okay? ' '(Please say "y" or "n".)'],
1470)             input='',
1471)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1472)         result = tests.ReadableResult.parse(_result)
1473)         assert result.error_exit(
1474)             error=IndexError
1475)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1477)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1481) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1484) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1488)         monkeypatch.setattr(
1489)             click,
1490)             'prompt',
1491)             lambda *a, **kw: json.dumps({'args': a, 'kwargs': kw}),
1492)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1494)         err_msg = 'missing arguments to passphrase prompt'
1495)         assert 'args' in res, err_msg
1496)         assert 'kwargs' in res, err_msg
1497)         assert res['args'][:1] == ['Passphrase'], err_msg
1498)         assert res['kwargs'].get('default') == '', err_msg
1499)         assert not res['kwargs'].get('show_default', True), err_msg
1500)         assert res['kwargs'].get('err'), err_msg
1501)         assert res['kwargs'].get('hide_input'), err_msg
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1502) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1503)     @pytest.mark.parametrize(
1504)         ['command_line', 'config', 'result_config'],
1505)         [
1506)             (
1507)                 ['--delete-globals'],
1508)                 {'global': {'phrase': 'abc'}, 'services': {}},
1509)                 {'services': {}},
1510)             ),
1511)             (
1512)                 ['--delete', DUMMY_SERVICE],
1513)                 {
1514)                     'global': {'phrase': 'abc'},
1515)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
1516)                 },
1517)                 {'global': {'phrase': 'abc'}, 'services': {}},
1518)             ),
1519)             (
1520)                 ['--clear'],
1521)                 {
1522)                     'global': {'phrase': 'abc'},
1523)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
1524)                 },
1525)                 {'services': {}},
1526)             ),
1527)         ],
1528)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1529)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1533)         config: _types.VaultConfig,
1534)         result_config: _types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1539)                 monkeypatch=monkeypatch, runner=runner, config=start_config
1540)             ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1542)                     cli.derivepassphrase_vault,
1543)                     command_line,
1544)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1553)                     config_readback = json.load(infile)
1554)                 assert config_readback == result_config
1555) 
1556)     def test_204_phrase_from_key_manually(self) -> None:
1557)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

1559)                 phrase=DUMMY_PHRASE_FROM_KEY1, **DUMMY_CONFIG_SETTINGS
1560)             ).generate(DUMMY_SERVICE)
1561)             == DUMMY_RESULT_KEY1
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1562)         )
1563) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1564)     @pytest.mark.parametrize(
1565)         ['vfunc', 'input'],
1566)         [
1567)             (cli._validate_occurrence_constraint, 20),
1568)             (cli._validate_length, 20),
1569)         ],
1570)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1571)     def test_210a_validate_constraints_manually(
1572)         self,
1573)         vfunc: Callable[[click.Context, click.Parameter, Any], int | None],
1574)         input: int,
1575)     ) -> None:
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1581)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

1587)         with monkeypatch.context():
1588)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent)
1589)             monkeypatch.setattr(
1590)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
1591)             )
1592)             hint: ssh_agent.SSHAgentClient | socket.socket | None
Marco Ricci Add support for Python 3.9

Marco Ricci authored 1 month ago

1593)             # Use match/case here once Python 3.9 becomes unsupported.
1594)             if conn_hint == 'client':
1595)                 hint = ssh_agent.SSHAgentClient()
1596)             elif conn_hint == 'socket':
1597)                 hint = socket.socket(family=socket.AF_UNIX)
1598)                 hint.connect(running_ssh_agent)
1599)             else:
1600)                 assert conn_hint == 'none'
1601)                 hint = None
Marco Ricci Add test fixture for manual...

Marco Ricci authored 1 month ago

1602)             exception: Exception | None = None
1603)             try:
1604)                 list(cli._get_suitable_ssh_keys(hint))
1605)             except RuntimeError:  # pragma: no cover
1606)                 pass
1607)             except Exception as e:  # noqa: BLE001 # pragma: no cover
1608)                 exception = e
1609)             finally:
1610)                 assert (
1611)                     exception is None
1612)                 ), 'exception querying suitable SSH keys'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

1613) 
1614) 
1615) class TestCLITransition:
1616)     def test_100_help_output(self, monkeypatch: pytest.MonkeyPatch) -> None:
1617)         runner = click.testing.CliRunner(mix_stderr=False)
1618)         with tests.isolated_config(
1619)             monkeypatch=monkeypatch,
1620)             runner=runner,
1621)         ):
1622)             _result = runner.invoke(
1623)                 cli.derivepassphrase, ['--help'], catch_exceptions=False
1624)             )
1625)             result = tests.ReadableResult.parse(_result)
1626)         assert result.clean_exit(
1627)             empty_stderr=True, output='currently implemented subcommands'
1628)         ), 'expected clean exit, and known help text'
1629) 
1630)     def test_101_help_output_export(
1631)         self, monkeypatch: pytest.MonkeyPatch
1632)     ) -> None:
1633)         runner = click.testing.CliRunner(mix_stderr=False)
1634)         with tests.isolated_config(
1635)             monkeypatch=monkeypatch,
1636)             runner=runner,
1637)         ):
1638)             _result = runner.invoke(
1639)                 cli.derivepassphrase,
1640)                 ['export', '--help'],
1641)                 catch_exceptions=False,
1642)             )
1643)             result = tests.ReadableResult.parse(_result)
1644)         assert result.clean_exit(
1645)             empty_stderr=True, output='only available subcommand'
1646)         ), 'expected clean exit, and known help text'
1647) 
1648)     def test_102_help_output_export_vault(
1649)         self, monkeypatch: pytest.MonkeyPatch
1650)     ) -> None:
1651)         runner = click.testing.CliRunner(mix_stderr=False)
1652)         with tests.isolated_config(
1653)             monkeypatch=monkeypatch,
1654)             runner=runner,
1655)         ):
1656)             _result = runner.invoke(
1657)                 cli.derivepassphrase,
1658)                 ['export', 'vault', '--help'],
1659)                 catch_exceptions=False,
1660)             )
1661)             result = tests.ReadableResult.parse(_result)
1662)         assert result.clean_exit(
1663)             empty_stderr=True, output='Read the vault-native configuration'
1664)         ), 'expected clean exit, and known help text'
1665) 
1666)     def test_103_help_output_vault(
1667)         self, monkeypatch: pytest.MonkeyPatch
1668)     ) -> None:
1669)         runner = click.testing.CliRunner(mix_stderr=False)
1670)         with tests.isolated_config(
1671)             monkeypatch=monkeypatch,
1672)             runner=runner,
1673)         ):
1674)             _result = runner.invoke(
1675)                 cli.derivepassphrase,
1676)                 ['vault', '--help'],
1677)                 catch_exceptions=False,
1678)             )
1679)             result = tests.ReadableResult.parse(_result)
1680)         assert result.clean_exit(
1681)             empty_stderr=True, output='Password generation:\n'
1682)         ), 'expected clean exit, and option groups in help text'
1683)         assert result.clean_exit(
1684)             empty_stderr=True, output='Use NUMBER=0, e.g. "--symbol 0"'
1685)         ), 'expected clean exit, and option group epilog in help text'
1686) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

1687)     @pytest.mark.parametrize(
1688)         'config',
1689)         [
1690)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1691)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1692)             {
1693)                 'global': {'phrase': 'abc'},
1694)                 'services': {'sv': {'phrase': 'my passphrase'}},
1695)             },
1696)             {
1697)                 'global': {'phrase': 'abc'},
1698)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1699)             },
1700)             {
1701)                 'global': {'phrase': 'abc'},
1702)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1703)             },
1704)         ],
1705)     )
1706)     def test_110_load_config_backup(
1707)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1708)     ) -> None:
1709)         runner = click.testing.CliRunner()
1710)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
1711)             config_filename = cli._config_filename()
1712)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
1713)                 print(json.dumps(config, indent=2), file=fileobj)
1714)             assert cli._migrate_and_load_old_config()[0] == config
1715) 
1716)     @pytest.mark.parametrize(
1717)         'config',
1718)         [
1719)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1720)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1721)             {
1722)                 'global': {'phrase': 'abc'},
1723)                 'services': {'sv': {'phrase': 'my passphrase'}},
1724)             },
1725)             {
1726)                 'global': {'phrase': 'abc'},
1727)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1728)             },
1729)             {
1730)                 'global': {'phrase': 'abc'},
1731)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1732)             },
1733)         ],
1734)     )
1735)     def test_111_migrate_config(
1736)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1737)     ) -> None:
1738)         runner = click.testing.CliRunner()
1739)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
1740)             config_filename = cli._config_filename()
1741)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
1742)                 print(json.dumps(config, indent=2), file=fileobj)
1743)             assert cli._migrate_and_load_old_config() == (config, None)
1744) 
1745)     @pytest.mark.parametrize(
1746)         'config',
1747)         [
1748)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1749)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1750)             {
1751)                 'global': {'phrase': 'abc'},
1752)                 'services': {'sv': {'phrase': 'my passphrase'}},
1753)             },
1754)             {
1755)                 'global': {'phrase': 'abc'},
1756)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1757)             },
1758)             {
1759)                 'global': {'phrase': 'abc'},
1760)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1761)             },
1762)         ],
1763)     )
1764)     def test_112_migrate_config_error(
1765)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1766)     ) -> None:
1767)         runner = click.testing.CliRunner()
1768)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
1769)             config_filename = cli._config_filename()
1770)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
1771)                 print(json.dumps(config, indent=2), file=fileobj)
1772)             os.mkdir(cli._config_filename(subsystem='vault'))
1773)             config2, err = cli._migrate_and_load_old_config()
1774)             assert config2 == config
1775)             assert isinstance(err, OSError)
1776)             assert err.errno == errno.EISDIR
1777) 
1778)     @pytest.mark.parametrize(
1779)         'config',
1780)         [
1781)             {'global': '', 'services': {}},
1782)             {'global': 0, 'services': {}},
1783)             {
1784)                 'global': {'phrase': 'abc'},
1785)                 'services': False,
1786)             },
1787)             {
1788)                 'global': {'phrase': 'abc'},
1789)                 'services': True,
1790)             },
1791)             {
1792)                 'global': {'phrase': 'abc'},
1793)                 'services': None,
1794)             },
1795)         ],
1796)     )
1797)     def test_113_migrate_config_error_bad_config_value(
1798)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1799)     ) -> None:
1800)         runner = click.testing.CliRunner()
1801)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
1802)             config_filename = cli._config_filename()
1803)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
1804)                 print(json.dumps(config, indent=2), file=fileobj)
1805)             with pytest.raises(ValueError, match=cli._INVALID_VAULT_CONFIG):
1806)                 cli._migrate_and_load_old_config()
1807) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

1808)     def test_200_forward_export_vault_path_parameter(
1809)         self, monkeypatch: pytest.MonkeyPatch
1810)     ) -> None:
1811)         pytest.importorskip('cryptography', minversion='38.0')
1812)         runner = click.testing.CliRunner(mix_stderr=False)
1813)         with tests.isolated_vault_exporter_config(
1814)             monkeypatch=monkeypatch,
1815)             runner=runner,
1816)             vault_config=tests.VAULT_V03_CONFIG,
1817)             vault_key=tests.VAULT_MASTER_KEY,
1818)         ):
1819)             monkeypatch.setenv('VAULT_KEY', tests.VAULT_MASTER_KEY)
1820)             _result = runner.invoke(
1821)                 cli.derivepassphrase,
1822)                 ['export', 'VAULT_PATH'],
1823)             )
1824)         result = tests.ReadableResult.parse(_result)
1825)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

1826)         assert (
1827)             result.stderr
1828)             == f"""\
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1832)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

1833)         assert json.loads(result.output) == tests.VAULT_V03_CONFIG_DATA
1834) 
1835)     @pytest.mark.parametrize(
1836)         'charset_name', ['lower', 'upper', 'number', 'space', 'dash', 'symbol']
1837)     )
1838)     def test_210_forward_vault_disable_character_set(
1839)         self, monkeypatch: pytest.MonkeyPatch, charset_name: str
1840)     ) -> None:
1841)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
1842)         option = f'--{charset_name}'
Marco Ricci Align behavior with vault c...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

1844)         runner = click.testing.CliRunner(mix_stderr=False)
1845)         with tests.isolated_config(
1846)             monkeypatch=monkeypatch,
1847)             runner=runner,
1848)         ):
1849)             _result = runner.invoke(
1850)                 cli.derivepassphrase,
1851)                 [option, '0', '-p', DUMMY_SERVICE],
1852)                 input=DUMMY_PASSPHRASE,
1853)                 catch_exceptions=False,
1854)             )
1855)             result = tests.ReadableResult.parse(_result)
1856)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

1857)         assert (
1858)             result.stderr
1859)             == f"""\
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1863)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

1864)         for c in charset:
1865)             assert (
1866)                 c not in result.output
1867)             ), f'derived password contains forbidden character {c!r}'