27f9bd183d7b124ddf137b536d1063dd64db3c66
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 Fail gracefully if UNIX dom...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

997) 
998)     def test_225c_store_config_fail_manual_bad_ssh_agent_connection(
999)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1033)                 try_race_free_implementation=try_race_free_implementation,
1034)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1044) 
1045)     def test_225e_store_config_fail_manual_custom_error(
1046)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1071) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

1085) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

1103) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1176) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1368) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1400)         _result = runner.invoke(driver, [], input='9')
1401)         result = tests.ReadableResult.parse(_result)
1402)         assert result.clean_exit(
1403)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1423)         result = tests.ReadableResult.parse(_result)
1424)         assert result.error_exit(
1425)             error=IndexError
1426)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1428)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1443) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1449)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1450)                 cli._prompt_for_selection(
1451)                     [item], heading='', single_choice_prompt=prompt
1452)                 )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1463)         result = tests.ReadableResult.parse(_result)
1464)         assert result.clean_exit(
1465)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1472)             driver,
1473)             ['Will replace with spam, okay? ' '(Please say "y" or "n".)'],
1474)             input='',
1475)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

1476)         result = tests.ReadableResult.parse(_result)
1477)         assert result.error_exit(
1478)             error=IndexError
1479)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1481)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1485) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1488) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1492)         monkeypatch.setattr(
1493)             click,
1494)             'prompt',
1495)             lambda *a, **kw: json.dumps({'args': a, 'kwargs': kw}),
1496)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1506) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1533)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1537)         config: _types.VaultConfig,
1538)         result_config: _types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1543)                 monkeypatch=monkeypatch, runner=runner, config=start_config
1544)             ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1546)                     cli.derivepassphrase_vault,
1547)                     command_line,
1548)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1557)                     config_readback = json.load(infile)
1558)                 assert config_readback == result_config
1559) 
1560)     def test_204_phrase_from_key_manually(self) -> None:
1561)         assert (
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1563)                 phrase=DUMMY_PHRASE_FROM_KEY1, **DUMMY_CONFIG_SETTINGS
1564)             ).generate(DUMMY_SERVICE)
1565)             == DUMMY_RESULT_KEY1
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

1566)         )
1567) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1568)     @pytest.mark.parametrize(
1569)         ['vfunc', 'input'],
1570)         [
1571)             (cli._validate_occurrence_constraint, 20),
1572)             (cli._validate_length, 20),
1573)         ],
1574)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

1575)     def test_210a_validate_constraints_manually(
1576)         self,
1577)         vfunc: Callable[[click.Context, click.Parameter, Any], int | None],
1578)         input: int,
1579)     ) -> None:
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1585)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1591)         with monkeypatch.context():
1592)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent)
1593)             monkeypatch.setattr(
1594)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
1595)             )
1596)             hint: ssh_agent.SSHAgentClient | socket.socket | None
Marco Ricci Add support for Python 3.9

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1836)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1837)         assert json.loads(result.output) == tests.VAULT_V03_CONFIG_DATA
1838) 
1839)     @pytest.mark.parametrize(
1840)         'charset_name', ['lower', 'upper', 'number', 'space', 'dash', 'symbol']
1841)     )
1842)     def test_210_forward_vault_disable_character_set(
1843)         self, monkeypatch: pytest.MonkeyPatch, charset_name: str
1844)     ) -> None:
1845)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
1846)         option = f'--{charset_name}'
1847)         charset = dpp.vault.Vault._CHARSETS[charset_name].decode('ascii')
1848)         runner = click.testing.CliRunner(mix_stderr=False)
1849)         with tests.isolated_config(
1850)             monkeypatch=monkeypatch,
1851)             runner=runner,
1852)         ):
1853)             _result = runner.invoke(
1854)                 cli.derivepassphrase,
1855)                 [option, '0', '-p', DUMMY_SERVICE],
1856)                 input=DUMMY_PASSPHRASE,
1857)                 catch_exceptions=False,
1858)             )
1859)             result = tests.ReadableResult.parse(_result)
1860)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

1861)         assert (
1862)             result.stderr
1863)             == f"""\
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1867)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1868)         for c in charset:
1869)             assert (
1870)                 c not in result.output
1871)             ), f'derived password contains forbidden character {c!r}'