4ea247a8c0739e114d44fae84f6baa09ad4ebb5c
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) 
19) import derivepassphrase as dpp
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

20) import tests
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

48) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

88) ]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

219) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

225)     ) -> None:
226)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
227)         option = f'--{charset_name}'
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

246) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

262)             result = tests.ReadableResult.parse(_result)
263)         assert result.clean_exit(
264)             empty_stderr=True
265)         ), 'expected clean exit and empty stderr'
266)         passphrase = result.output.rstrip('\r\n')
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

272) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

297)     def test_204a_key_from_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

304)             monkeypatch=monkeypatch, runner=runner, config=config
305)         ):
306)             monkeypatch.setattr(
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

325) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

331)             monkeypatch=monkeypatch,
332)             runner=runner,
333)             config={'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
334)         ):
335)             monkeypatch.setattr(
336)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
337)             )
338)             monkeypatch.setattr(
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

357) 
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

385)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

386)         config: dict[str, Any],
387)         key_index: int,
388)     ) -> None:
389)         def sign(
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 2 months ago

390)             _: Any, key: bytes | bytearray, message: bytes | bytearray
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

391)         ) -> bytes:
392)             del message  # Unused.
393)             for value in tests.SUPPORTED_KEYS.values():
394)                 if value['public_key_data'] == key:
395)                     assert value['expected_signature'] is not None
396)                     return value['expected_signature']
397)             raise AssertionError
398) 
399)         monkeypatch.setattr(
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 3 months ago

400)             ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

401)         )
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 3 months ago

402)         monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', sign)
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

404)         with tests.isolated_vault_config(
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

405)             monkeypatch=monkeypatch, runner=runner, config=config
406)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

408)                 cli.derivepassphrase_vault,
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

410)                 input=f'{key_index}\n',
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

412)         result = tests.ReadableResult.parse(_result)
413)         assert result.clean_exit(), 'expected clean exit'
414)         assert result.output, 'expected program output'
415)         assert result.stderr, 'expected stderr'
416)         assert (
417)             'Error:' not in result.stderr
418)         ), 'expected no error messages on stderr'
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

420)     def test_205_service_phrase_if_key_in_global_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

426)             monkeypatch=monkeypatch,
427)             runner=runner,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

428)             config={
429)                 'global': {'key': DUMMY_KEY1_B64},
430)                 'services': {
431)                     DUMMY_SERVICE: {
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

432)                         'phrase': DUMMY_PASSPHRASE.rstrip('\n'),
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

433)                         **DUMMY_CONFIG_SETTINGS,
434)                     }
435)                 },
436)             },
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

439)                 cli.derivepassphrase_vault,
440)                 [DUMMY_SERVICE],
441)                 catch_exceptions=False,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

443)         result = tests.ReadableResult.parse(_result)
444)         assert result.clean_exit(), 'expected clean exit'
445)         assert _result.stdout_bytes, 'expected program output'
446)         last_line = _result.stdout_bytes.splitlines(True)[-1]
447)         assert (
448)             last_line.rstrip(b'\n') != DUMMY_RESULT_KEY1
449)         ), 'known false output: key-based instead of phrase-based'
450)         assert (
451)             last_line.rstrip(b'\n') == DUMMY_RESULT_PASSPHRASE
452)         ), 'expected known output'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

453) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

494)     )
495)     def test_211_service_needed(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

556)     def test_212_incompatible_options(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

578)     def test_213_import_bad_config_not_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

595)     def test_213a_import_bad_config_not_json_data(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

612)     def test_213b_import_bad_config_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

636) 
637)     def test_214_export_settings_no_stored_settings(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

653)     def test_214a_export_settings_bad_stored_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

672)     def test_214b_export_settings_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

692)     def test_214c_export_settings_target_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

709) 
Marco Ricci Create the configuration di...

Marco Ricci authored 3 months ago

710)     def test_214d_export_settings_settings_directory_not_a_directory(
711)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

724)                 catch_exceptions=False,
725)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

730) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

735) 
736) # - - - - - >8 - - - - - >8 - - - - - >8 - - - - - >8 - - - - -
737) contents go here
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

761) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

806)             assert config == {
807)                 'global': {'phrase': 'abc'},
808)                 'services': {'sv': {'notes': 'long\ntext'}},
809)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

810) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

811)     def test_223_edit_notes_abort(
812)         self, monkeypatch: pytest.MonkeyPatch
813)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

875)     def test_224_store_config_good(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

906) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

911)             (
912)                 ['sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

913)                 '',
914)                 'Cannot update service settings without actual settings',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

918)         ],
919)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

920)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

924)         input: str,
925)         err_text: str,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

946) 
947)     def test_225a_store_config_fail_manual_no_ssh_key_selection(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

973)     def test_225b_store_config_fail_manual_no_ssh_agent(
974)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

976)     ) -> None:
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 Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

1298)     @pytest.mark.parametrize(
1299)         'config',
1300)         [
1301)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1302)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1303)             {
1304)                 'global': {'phrase': 'abc'},
1305)                 'services': {'sv': {'phrase': 'my passphrase'}},
1306)             },
1307)             {
1308)                 'global': {'phrase': 'abc'},
1309)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1310)             },
1311)             {
1312)                 'global': {'phrase': 'abc'},
1313)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1314)             },
1315)         ],
1316)     )
1317)     def test_100_load_config(
1318)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1319)     ) -> None:
1320)         runner = click.testing.CliRunner()
1321)         with tests.isolated_vault_config(
1322)             monkeypatch=monkeypatch, runner=runner, config=config
1323)         ):
1324)             config_filename = cli._config_filename(subsystem='vault')
1325)             with open(config_filename, encoding='UTF-8') as fileobj:
1326)                 assert json.load(fileobj) == config
1327)             assert cli._load_config() == config
1328) 
1329)     def test_110_save_bad_config(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1340) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1346)             # from https://montypython.fandom.com/wiki/Spam#The_menu
1347)             items = items or [
1348)                 'Egg and bacon',
1349)                 'Egg, sausage and bacon',
1350)                 'Egg and spam',
1351)                 'Egg, bacon and spam',
1352)                 'Egg, bacon, sausage and spam',
1353)                 'Spam, bacon, sausage and spam',
1354)                 'Spam, egg, spam, spam, bacon and spam',
1355)                 'Spam, spam, spam, egg and spam',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1356)                 (
1357)                     'Spam, spam, spam, spam, spam, spam, baked beans, '
1358)                     'spam, spam, spam and spam'
1359)                 ),
1360)                 (
1361)                     'Lobster thermidor aux crevettes with a mornay sauce '
1362)                     'garnished with truffle paté, brandy '
1363)                     'and a fried egg on top and spam'
1364)                 ),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1365)             ]
1366)             index = cli._prompt_for_selection(items, heading=heading)
1367)             click.echo('A fine choice: ', nl=False)
1368)             click.echo(items[index])
1369)             click.echo('(Note: Vikings strictly optional.)')
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

1372)         _result = runner.invoke(driver, [], input='9')
1373)         result = tests.ReadableResult.parse(_result)
1374)         assert result.clean_exit(
1375)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1376) Our menu:
1377) [1] Egg and bacon
1378) [2] Egg, sausage and bacon
1379) [3] Egg and spam
1380) [4] Egg, bacon and spam
1381) [5] Egg, bacon, sausage and spam
1382) [6] Spam, bacon, sausage and spam
1383) [7] Spam, egg, spam, spam, bacon and spam
1384) [8] Spam, spam, spam, egg and spam
1385) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1386) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
1387) Your selection? (1-10, leave empty to abort): 9
1388) A fine choice: Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1389) (Note: Vikings strictly optional.)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1395)         result = tests.ReadableResult.parse(_result)
1396)         assert result.error_exit(
1397)             error=IndexError
1398)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1400)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1402) [1] Egg and bacon
1403) [2] Egg, sausage and bacon
1404) [3] Egg and spam
1405) [4] Egg, bacon and spam
1406) [5] Egg, bacon, sausage and spam
1407) [6] Spam, bacon, sausage and spam
1408) [7] Spam, egg, spam, spam, bacon and spam
1409) [8] Spam, spam, spam, egg and spam
1410) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1411) [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

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1415) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1421)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1422)                 cli._prompt_for_selection(
1423)                     [item], heading='', single_choice_prompt=prompt
1424)                 )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1435)         result = tests.ReadableResult.parse(_result)
1436)         assert result.clean_exit(
1437)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1444)             driver,
1445)             ['Will replace with spam, okay? ' '(Please say "y" or "n".)'],
1446)             input='',
1447)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1448)         result = tests.ReadableResult.parse(_result)
1449)         assert result.error_exit(
1450)             error=IndexError
1451)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1453)             result.output
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) [1] baked beans
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1457) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1460) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1464)         monkeypatch.setattr(
1465)             click,
1466)             'prompt',
1467)             lambda *a, **kw: json.dumps({'args': a, 'kwargs': kw}),
1468)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1470)         err_msg = 'missing arguments to passphrase prompt'
1471)         assert 'args' in res, err_msg
1472)         assert 'kwargs' in res, err_msg
1473)         assert res['args'][:1] == ['Passphrase'], err_msg
1474)         assert res['kwargs'].get('default') == '', err_msg
1475)         assert not res['kwargs'].get('show_default', True), err_msg
1476)         assert res['kwargs'].get('err'), err_msg
1477)         assert res['kwargs'].get('hide_input'), err_msg
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1478) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1479)     @pytest.mark.parametrize(
1480)         ['command_line', 'config', 'result_config'],
1481)         [
1482)             (
1483)                 ['--delete-globals'],
1484)                 {'global': {'phrase': 'abc'}, 'services': {}},
1485)                 {'services': {}},
1486)             ),
1487)             (
1488)                 ['--delete', DUMMY_SERVICE],
1489)                 {
1490)                     'global': {'phrase': 'abc'},
1491)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
1492)                 },
1493)                 {'global': {'phrase': 'abc'}, 'services': {}},
1494)             ),
1495)             (
1496)                 ['--clear'],
1497)                 {
1498)                     'global': {'phrase': 'abc'},
1499)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
1500)                 },
1501)                 {'services': {}},
1502)             ),
1503)         ],
1504)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1505)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1509)         config: _types.VaultConfig,
1510)         result_config: _types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1515)                 monkeypatch=monkeypatch, runner=runner, config=start_config
1516)             ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1518)                     cli.derivepassphrase_vault,
1519)                     command_line,
1520)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1529)                     config_readback = json.load(infile)
1530)                 assert config_readback == result_config
1531) 
1532)     def test_204_phrase_from_key_manually(self) -> None:
1533)         assert (
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 3 months ago

1534)             dpp.vault.Vault(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1535)                 phrase=DUMMY_PHRASE_FROM_KEY1, **DUMMY_CONFIG_SETTINGS
1536)             ).generate(DUMMY_SERVICE)
1537)             == DUMMY_RESULT_KEY1
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1538)         )
1539) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1540)     @pytest.mark.parametrize(
1541)         ['vfunc', 'input'],
1542)         [
1543)             (cli._validate_occurrence_constraint, 20),
1544)             (cli._validate_length, 20),
1545)         ],
1546)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1547)     def test_210a_validate_constraints_manually(
1548)         self,
1549)         vfunc: Callable[[click.Context, click.Parameter, Any], int | None],
1550)         input: int,
1551)     ) -> None:
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1554)         assert vfunc(ctx, param, input) == input
1555) 
1556)     @tests.skip_if_no_agent
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1558)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1562)     ) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1563)         monkeypatch.setattr(
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 3 months ago

1564)             ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1565)         )
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 3 months ago

1566)         hint: ssh_agent.SSHAgentClient | socket.socket | None
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1567)         match conn_hint:
1568)             case 'client':
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 3 months ago

1569)                 hint = ssh_agent.SSHAgentClient()
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1570)             case 'socket':
1571)                 hint = socket.socket(family=socket.AF_UNIX)
1572)                 hint.connect(os.environ['SSH_AUTH_SOCK'])
1573)             case _:
1574)                 assert conn_hint == 'none'
1575)                 hint = None
1576)         exception: Exception | None = None
1577)         try:
1578)             list(cli._get_suitable_ssh_keys(hint))
1579)         except RuntimeError:  # pragma: no cover
1580)             pass
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

1581)         except Exception as e:  # noqa: BLE001 # pragma: no cover
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1582)             exception = e
1583)         finally:
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

1584)             assert exception is None, 'exception querying suitable SSH keys'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

1585) 
1586) 
1587) class TestCLITransition:
1588)     def test_100_help_output(self, monkeypatch: pytest.MonkeyPatch) -> None:
1589)         runner = click.testing.CliRunner(mix_stderr=False)
1590)         with tests.isolated_config(
1591)             monkeypatch=monkeypatch,
1592)             runner=runner,
1593)         ):
1594)             _result = runner.invoke(
1595)                 cli.derivepassphrase, ['--help'], catch_exceptions=False
1596)             )
1597)             result = tests.ReadableResult.parse(_result)
1598)         assert result.clean_exit(
1599)             empty_stderr=True, output='currently implemented subcommands'
1600)         ), 'expected clean exit, and known help text'
1601) 
1602)     def test_101_help_output_export(
1603)         self, monkeypatch: pytest.MonkeyPatch
1604)     ) -> None:
1605)         runner = click.testing.CliRunner(mix_stderr=False)
1606)         with tests.isolated_config(
1607)             monkeypatch=monkeypatch,
1608)             runner=runner,
1609)         ):
1610)             _result = runner.invoke(
1611)                 cli.derivepassphrase,
1612)                 ['export', '--help'],
1613)                 catch_exceptions=False,
1614)             )
1615)             result = tests.ReadableResult.parse(_result)
1616)         assert result.clean_exit(
1617)             empty_stderr=True, output='only available subcommand'
1618)         ), 'expected clean exit, and known help text'
1619) 
1620)     def test_102_help_output_export_vault(
1621)         self, monkeypatch: pytest.MonkeyPatch
1622)     ) -> None:
1623)         runner = click.testing.CliRunner(mix_stderr=False)
1624)         with tests.isolated_config(
1625)             monkeypatch=monkeypatch,
1626)             runner=runner,
1627)         ):
1628)             _result = runner.invoke(
1629)                 cli.derivepassphrase,
1630)                 ['export', 'vault', '--help'],
1631)                 catch_exceptions=False,
1632)             )
1633)             result = tests.ReadableResult.parse(_result)
1634)         assert result.clean_exit(
1635)             empty_stderr=True, output='Read the vault-native configuration'
1636)         ), 'expected clean exit, and known help text'
1637) 
1638)     def test_103_help_output_vault(
1639)         self, monkeypatch: pytest.MonkeyPatch
1640)     ) -> None:
1641)         runner = click.testing.CliRunner(mix_stderr=False)
1642)         with tests.isolated_config(
1643)             monkeypatch=monkeypatch,
1644)             runner=runner,
1645)         ):
1646)             _result = runner.invoke(
1647)                 cli.derivepassphrase,
1648)                 ['vault', '--help'],
1649)                 catch_exceptions=False,
1650)             )
1651)             result = tests.ReadableResult.parse(_result)
1652)         assert result.clean_exit(
1653)             empty_stderr=True, output='Password generation:\n'
1654)         ), 'expected clean exit, and option groups in help text'
1655)         assert result.clean_exit(
1656)             empty_stderr=True, output='Use NUMBER=0, e.g. "--symbol 0"'
1657)         ), 'expected clean exit, and option group epilog in help text'
1658) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 2 months ago

1659)     @pytest.mark.parametrize(
1660)         'config',
1661)         [
1662)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1663)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1664)             {
1665)                 'global': {'phrase': 'abc'},
1666)                 'services': {'sv': {'phrase': 'my passphrase'}},
1667)             },
1668)             {
1669)                 'global': {'phrase': 'abc'},
1670)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1671)             },
1672)             {
1673)                 'global': {'phrase': 'abc'},
1674)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1675)             },
1676)         ],
1677)     )
1678)     def test_110_load_config_backup(
1679)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1680)     ) -> None:
1681)         runner = click.testing.CliRunner()
1682)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
1683)             config_filename = cli._config_filename()
1684)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
1685)                 print(json.dumps(config, indent=2), file=fileobj)
1686)             assert cli._migrate_and_load_old_config()[0] == config
1687) 
1688)     @pytest.mark.parametrize(
1689)         'config',
1690)         [
1691)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1692)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1693)             {
1694)                 'global': {'phrase': 'abc'},
1695)                 'services': {'sv': {'phrase': 'my passphrase'}},
1696)             },
1697)             {
1698)                 'global': {'phrase': 'abc'},
1699)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1700)             },
1701)             {
1702)                 'global': {'phrase': 'abc'},
1703)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1704)             },
1705)         ],
1706)     )
1707)     def test_111_migrate_config(
1708)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1709)     ) -> None:
1710)         runner = click.testing.CliRunner()
1711)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
1712)             config_filename = cli._config_filename()
1713)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
1714)                 print(json.dumps(config, indent=2), file=fileobj)
1715)             assert cli._migrate_and_load_old_config() == (config, None)
1716) 
1717)     @pytest.mark.parametrize(
1718)         'config',
1719)         [
1720)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1721)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1722)             {
1723)                 'global': {'phrase': 'abc'},
1724)                 'services': {'sv': {'phrase': 'my passphrase'}},
1725)             },
1726)             {
1727)                 'global': {'phrase': 'abc'},
1728)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1729)             },
1730)             {
1731)                 'global': {'phrase': 'abc'},
1732)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1733)             },
1734)         ],
1735)     )
1736)     def test_112_migrate_config_error(
1737)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1738)     ) -> None:
1739)         runner = click.testing.CliRunner()
1740)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
1741)             config_filename = cli._config_filename()
1742)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
1743)                 print(json.dumps(config, indent=2), file=fileobj)
1744)             os.mkdir(cli._config_filename(subsystem='vault'))
1745)             config2, err = cli._migrate_and_load_old_config()
1746)             assert config2 == config
1747)             assert isinstance(err, OSError)
1748)             assert err.errno == errno.EISDIR
1749) 
1750)     @pytest.mark.parametrize(
1751)         'config',
1752)         [
1753)             {'global': '', 'services': {}},
1754)             {'global': 0, 'services': {}},
1755)             {
1756)                 'global': {'phrase': 'abc'},
1757)                 'services': False,
1758)             },
1759)             {
1760)                 'global': {'phrase': 'abc'},
1761)                 'services': True,
1762)             },
1763)             {
1764)                 'global': {'phrase': 'abc'},
1765)                 'services': None,
1766)             },
1767)         ],
1768)     )
1769)     def test_113_migrate_config_error_bad_config_value(
1770)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1771)     ) -> None:
1772)         runner = click.testing.CliRunner()
1773)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
1774)             config_filename = cli._config_filename()
1775)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
1776)                 print(json.dumps(config, indent=2), file=fileobj)
1777)             with pytest.raises(ValueError, match=cli._INVALID_VAULT_CONFIG):
1778)                 cli._migrate_and_load_old_config()
1779) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

1780)     def test_200_forward_export_vault_path_parameter(
1781)         self, monkeypatch: pytest.MonkeyPatch
1782)     ) -> None:
1783)         pytest.importorskip('cryptography', minversion='38.0')
1784)         runner = click.testing.CliRunner(mix_stderr=False)
1785)         with tests.isolated_vault_exporter_config(
1786)             monkeypatch=monkeypatch,
1787)             runner=runner,
1788)             vault_config=tests.VAULT_V03_CONFIG,
1789)             vault_key=tests.VAULT_MASTER_KEY,
1790)         ):
1791)             monkeypatch.setenv('VAULT_KEY', tests.VAULT_MASTER_KEY)
1792)             _result = runner.invoke(
1793)                 cli.derivepassphrase,
1794)                 ['export', 'VAULT_PATH'],
1795)             )
1796)         result = tests.ReadableResult.parse(_result)
1797)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

1798)         assert (
1799)             result.stderr
1800)             == f"""\
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1804)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

1805)         assert json.loads(result.output) == tests.VAULT_V03_CONFIG_DATA
1806) 
1807)     @pytest.mark.parametrize(
1808)         'charset_name', ['lower', 'upper', 'number', 'space', 'dash', 'symbol']
1809)     )
1810)     def test_210_forward_vault_disable_character_set(
1811)         self, monkeypatch: pytest.MonkeyPatch, charset_name: str
1812)     ) -> None:
1813)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
1814)         option = f'--{charset_name}'
1815)         charset = dpp.vault.Vault._CHARSETS[charset_name].decode('ascii')
1816)         runner = click.testing.CliRunner(mix_stderr=False)
1817)         with tests.isolated_config(
1818)             monkeypatch=monkeypatch,
1819)             runner=runner,
1820)         ):
1821)             _result = runner.invoke(
1822)                 cli.derivepassphrase,
1823)                 [option, '0', '-p', DUMMY_SERVICE],
1824)                 input=DUMMY_PASSPHRASE,
1825)                 catch_exceptions=False,
1826)             )
1827)             result = tests.ReadableResult.parse(_result)
1828)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

1829)         assert (
1830)             result.stderr
1831)             == f"""\
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1835)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

1836)         for c in charset:
1837)             assert (
1838)                 c not in result.output
1839)             ), f'derived password contains forbidden character {c!r}'