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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

7) import contextlib
Marco Ricci Remove `click` handling of...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

17) from typing_extensions import NamedTuple
18) 
19) import derivepassphrase as dpp
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 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 6 months ago

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

Marco Ricci authored 5 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 4 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 6 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 3 months ago

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

Marco Ricci authored 6 months ago

48) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 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 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 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 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

88) ]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 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 6 months ago

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

Marco Ricci authored 5 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 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 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 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 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 5 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 6 months ago

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

Marco Ricci authored 5 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 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 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 5 months ago

219) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 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 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 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 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 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 3 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 5 months ago

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

Marco Ricci authored 3 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 6 months ago

246) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 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 5 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 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 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 3 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 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

272) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 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 3 months ago

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

Marco Ricci authored 5 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 5 months ago

297)     def test_204a_key_from_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 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 6 months ago

325) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 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 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 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 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 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 6 months ago

357) 
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 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 3 months ago

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

Marco Ricci authored 4 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) 
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

399)         with monkeypatch.context():
400)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent)
401)             monkeypatch.setattr(
402)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 4 months ago

403)             )
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

404)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', sign)
405)             runner = click.testing.CliRunner(mix_stderr=False)
406)             with tests.isolated_vault_config(
407)                 monkeypatch=monkeypatch, runner=runner, config=config
408)             ):
409)                 _result = runner.invoke(
410)                     cli.derivepassphrase_vault,
411)                     ['-k', DUMMY_SERVICE],
412)                     input=f'{key_index}\n',
413)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

422)     def test_205_service_phrase_if_key_in_global_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

428)             monkeypatch=monkeypatch,
429)             runner=runner,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

435)                         **DUMMY_CONFIG_SETTINGS,
436)                     }
437)                 },
438)             },
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

455) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

496)     )
497)     def test_211_service_needed(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

558)     def test_212_incompatible_options(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

580)     def test_213_import_bad_config_not_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

597)     def test_213a_import_bad_config_not_json_data(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

614)     def test_213b_import_bad_config_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

638) 
639)     def test_214_export_settings_no_stored_settings(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

655)     def test_214a_export_settings_bad_stored_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

674)     def test_214b_export_settings_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

694)     def test_214c_export_settings_target_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

711) 
Marco Ricci Create the configuration di...

Marco Ricci authored 4 months ago

712)     def test_214d_export_settings_settings_directory_not_a_directory(
713)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

726)                 catch_exceptions=False,
727)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

732) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

737) 
738) # - - - - - >8 - - - - - >8 - - - - - >8 - - - - - >8 - - - - -
739) contents go here
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

763) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

812) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

877)     def test_224_store_config_good(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

908) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

913)             (
914)                 ['sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

915)                 '',
916)                 'Cannot update service settings without actual settings',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

920)         ],
921)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

922)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

926)         input: str,
927)         err_text: str,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

948) 
949)     def test_225a_store_config_fail_manual_no_ssh_key_selection(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

975)     def test_225b_store_config_fail_manual_no_ssh_agent(
976)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

995) 
996)     def test_225c_store_config_fail_manual_bad_ssh_agent_connection(
997)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1031)                 try_race_free_implementation=try_race_free_implementation,
1032)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1042) 
1043)     def test_225e_store_config_fail_manual_custom_error(
1044)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1069) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

1083) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

1101) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1174) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1342) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1402)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1404) [1] Egg and bacon
1405) [2] Egg, sausage and bacon
1406) [3] Egg and spam
1407) [4] Egg, bacon and spam
1408) [5] Egg, bacon, sausage and spam
1409) [6] Spam, bacon, sausage and spam
1410) [7] Spam, egg, spam, spam, bacon and spam
1411) [8] Spam, spam, spam, egg and spam
1412) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1413) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1417) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1423)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1455)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1459) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1462) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1480) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1507)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1511)         config: _types.VaultConfig,
1512)         result_config: _types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1517)                 monkeypatch=monkeypatch, runner=runner, config=start_config
1518)             ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1540)         )
1541) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1559)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1565)         with monkeypatch.context():
1566)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent)
1567)             monkeypatch.setattr(
1568)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
1569)             )
1570)             hint: ssh_agent.SSHAgentClient | socket.socket | None
Marco Ricci Add support for Python 3.9

Marco Ricci authored 2 months ago

1571)             # Use match/case here once Python 3.9 becomes unsupported.
1572)             if conn_hint == 'client':
1573)                 hint = ssh_agent.SSHAgentClient()
1574)             elif conn_hint == 'socket':
1575)                 hint = socket.socket(family=socket.AF_UNIX)
1576)                 hint.connect(running_ssh_agent)
1577)             else:
1578)                 assert conn_hint == 'none'
1579)                 hint = None
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

1580)             exception: Exception | None = None
1581)             try:
1582)                 list(cli._get_suitable_ssh_keys(hint))
1583)             except RuntimeError:  # pragma: no cover
1584)                 pass
1585)             except Exception as e:  # noqa: BLE001 # pragma: no cover
1586)                 exception = e
1587)             finally:
1588)                 assert (
1589)                     exception is None
1590)                 ), 'exception querying suitable SSH keys'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1804)         assert (
1805)             result.stderr
1806)             == f"""\
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1810)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1835)         assert (
1836)             result.stderr
1837)             == f"""\
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1841)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1842)         for c in charset:
1843)             assert (
1844)                 c not in result.output
1845)             ), f'derived password contains forbidden character {c!r}'