7d2f2b1bda31ead428d3c009772aaf3d2261d60c
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 Align behavior with vault c...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 6 months ago

18) import pytest
Marco Ricci Align behavior with vault c...

Marco Ricci authored 2 months ago

19) from hypothesis import strategies
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

20) from typing_extensions import NamedTuple
21) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 months ago

45) TEST_CONFIGS = tests.TEST_CONFIGS
46) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

52) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

57)     check_success: bool
58) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

65)     check_success: bool
66) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

92) ]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

97)         True,
98)         DUMMY_PASSPHRASE,
99)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

204) 
205) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

209)         with tests.isolated_config(
210)             monkeypatch=monkeypatch,
211)             runner=runner,
212)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

223) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

234)         with tests.isolated_config(
235)             monkeypatch=monkeypatch,
236)             runner=runner,
237)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

240)                 [option, '0', '-p', DUMMY_SERVICE],
241)                 input=DUMMY_PASSPHRASE,
242)                 catch_exceptions=False,
243)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

250) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

251)     def test_202_disable_repetition(
252)         self, monkeypatch: pytest.MonkeyPatch
253)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

256)         with tests.isolated_config(
257)             monkeypatch=monkeypatch,
258)             runner=runner,
259)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

262)                 ['--repeat', '0', '-p', DUMMY_SERVICE],
263)                 input=DUMMY_PASSPHRASE,
264)                 catch_exceptions=False,
265)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

276) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

290)                     'services': {
291)                         DUMMY_SERVICE: {
292)                             'key': DUMMY_KEY1_B64,
293)                             **DUMMY_CONFIG_SETTINGS,
294)                         }
295)                     },
296)                 },
297)                 id='service',
298)             ),
299)         ],
300)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

301)     def test_204a_key_from_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

308)             monkeypatch=monkeypatch, runner=runner, config=config
309)         ):
310)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

314)                 cli.derivepassphrase_vault,
315)                 [DUMMY_SERVICE],
316)                 catch_exceptions=False,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

329) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

330)     def test_204b_key_from_command_line(
331)         self, monkeypatch: pytest.MonkeyPatch
332)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

335)             monkeypatch=monkeypatch,
336)             runner=runner,
337)             config={'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
338)         ):
339)             monkeypatch.setattr(
340)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
341)             )
342)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

349)                 catch_exceptions=False,
350)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

361) 
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

390)         config: dict[str, Any],
391)         key_index: int,
392)     ) -> None:
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

393)         with monkeypatch.context():
394)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent)
395)             monkeypatch.setattr(
396)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

416)     def test_205_service_phrase_if_key_in_global_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 2 months ago

421)         with monkeypatch.context():
422)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent)
423)             monkeypatch.setattr(
424)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

446)         result = tests.ReadableResult.parse(_result)
447)         assert result.clean_exit(), 'expected clean exit'
448)         assert _result.stdout_bytes, 'expected program output'
449)         last_line = _result.stdout_bytes.splitlines(True)[-1]
450)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

456) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

559)     def test_212_incompatible_options(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 months ago

581)     @pytest.mark.parametrize(
582)         'config',
583)         [
584)             conf.config
585)             for conf in tests.TEST_CONFIGS
586)             if tests.is_valid_test_config(conf)
587)         ],
588)     )
589)     def test_213_import_config_success(
590)         self,
591)         monkeypatch: pytest.MonkeyPatch,
592)         config: Any,
593)     ) -> None:
594)         runner = click.testing.CliRunner(mix_stderr=False)
595)         with tests.isolated_vault_config(
596)             monkeypatch=monkeypatch,
597)             runner=runner,
598)             config={'services': {}},
599)         ):
600)             _result = runner.invoke(
601)                 cli.derivepassphrase_vault,
602)                 ['--import', '-'],
603)                 input=json.dumps(config),
604)                 catch_exceptions=False,
605)             )
606)             with open(
607)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
608)             ) as infile:
609)                 config2 = json.load(infile)
610)         result = tests.ReadableResult.parse(_result)
611)         assert result.clean_exit(empty_stderr=True), 'expected clean exit'
612)         assert config2 == config, 'config not imported correctly'
613) 
614)     @hypothesis.given(
615)         conf=tests.smudged_vault_test_config(
616)             strategies.sampled_from(TEST_CONFIGS).filter(
617)                 tests.is_valid_test_config
618)             )
619)         )
620)     )
621)     def test_213a_import_config_success(
622)         self,
623)         conf: tests.VaultTestConfig,
624)     ) -> None:
625)         config = conf.config
626)         config2 = copy.deepcopy(config)
627)         _types.clean_up_falsy_vault_config_values(config2)
628)         runner = click.testing.CliRunner(mix_stderr=False)
629)         with tests.isolated_vault_config(
630)             monkeypatch=pytest.MonkeyPatch(),
631)             runner=runner,
632)             config={'services': {}},
633)         ):
634)             _result = runner.invoke(
635)                 cli.derivepassphrase_vault,
636)                 ['--import', '-'],
637)                 input=json.dumps(config),
638)                 catch_exceptions=False,
639)             )
640)             with open(
641)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
642)             ) as infile:
643)                 config3 = json.load(infile)
644)         result = tests.ReadableResult.parse(_result)
645)         assert result.clean_exit(empty_stderr=True), 'expected clean exit'
646)         assert config3 == config2, 'config not imported correctly'
647) 
648)     def test_213b_import_bad_config_not_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

660)         result = tests.ReadableResult.parse(_result)
661)         assert result.error_exit(
662)             error='Invalid vault config'
663)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 months ago

665)     def test_213c_import_bad_config_not_json_data(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

677)         result = tests.ReadableResult.parse(_result)
678)         assert result.error_exit(
679)             error='cannot decode JSON'
680)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 months ago

682)     def test_213d_import_bad_config_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

702)         result = tests.ReadableResult.parse(_result)
703)         assert result.error_exit(
704)             error=os.strerror(errno.EISDIR)
705)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

706) 
707)     def test_214_export_settings_no_stored_settings(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

716)                 cli.derivepassphrase_vault,
717)                 ['--export', '-'],
718)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

723)     def test_214a_export_settings_bad_stored_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

737)         result = tests.ReadableResult.parse(_result)
738)         assert result.error_exit(
739)             error='Cannot load config'
740)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

742)     def test_214b_export_settings_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

757)         result = tests.ReadableResult.parse(_result)
758)         assert result.error_exit(
759)             error='Cannot load config'
760)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

762)     def test_214c_export_settings_target_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

775)         result = tests.ReadableResult.parse(_result)
776)         assert result.error_exit(
777)             error='Cannot store config'
778)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

779) 
Marco Ricci Create the configuration di...

Marco Ricci authored 4 months ago

780)     def test_214d_export_settings_settings_directory_not_a_directory(
781)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

794)                 catch_exceptions=False,
795)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

796)         result = tests.ReadableResult.parse(_result)
797)         assert result.error_exit(
798)             error='Cannot load config'
799)         ), 'expected error exit and known error message'
Marco Ricci Create the configuration di...

Marco Ricci authored 4 months ago

800) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

801)     def test_220_edit_notes_successfully(
802)         self, monkeypatch: pytest.MonkeyPatch
803)     ) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

805) 
806) # - - - - - >8 - - - - - >8 - - - - - >8 - - - - - >8 - - - - -
807) contents go here
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

811)             monkeypatch=monkeypatch,
812)             runner=runner,
813)             config={'global': {'phrase': 'abc'}, 'services': {}},
814)         ):
815)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: edit_result)  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

817)                 cli.derivepassphrase_vault,
818)                 ['--notes', 'sv'],
819)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

827)             assert config == {
828)                 'global': {'phrase': 'abc'},
829)                 'services': {'sv': {'notes': 'contents go here'}},
830)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

831) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

832)     def test_221_edit_notes_noop(
833)         self, monkeypatch: pytest.MonkeyPatch
834)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

837)             monkeypatch=monkeypatch,
838)             runner=runner,
839)             config={'global': {'phrase': 'abc'}, 'services': {}},
840)         ):
841)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: None)  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

843)                 cli.derivepassphrase_vault,
844)                 ['--notes', 'sv'],
845)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

855)     def test_222_edit_notes_marker_removed(
856)         self, monkeypatch: pytest.MonkeyPatch
857)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

860)             monkeypatch=monkeypatch,
861)             runner=runner,
862)             config={'global': {'phrase': 'abc'}, 'services': {}},
863)         ):
864)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: 'long\ntext')  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

866)                 cli.derivepassphrase_vault,
867)                 ['--notes', 'sv'],
868)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

876)             assert config == {
877)                 'global': {'phrase': 'abc'},
878)                 'services': {'sv': {'notes': 'long\ntext'}},
879)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

880) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

881)     def test_223_edit_notes_abort(
882)         self, monkeypatch: pytest.MonkeyPatch
883)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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(click, 'edit', lambda *a, **kw: '\n\n')  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

892)                 cli.derivepassphrase_vault,
893)                 ['--notes', 'sv'],
894)                 catch_exceptions=False,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

896)             result = tests.ReadableResult.parse(_result)
897)             assert result.error_exit(
898)                 error='user aborted request'
899)             ), 'expected known error message'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

906)     @pytest.mark.parametrize(
907)         ['command_line', 'input', 'result_config'],
908)         [
909)             (
910)                 ['--phrase'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

912)                 {'global': {'phrase': 'my passphrase'}, 'services': {}},
913)             ),
914)             (
915)                 ['--key'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

917)                 {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
918)             ),
919)             (
920)                 ['--phrase', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

922)                 {
923)                     'global': {'phrase': 'abc'},
924)                     'services': {'sv': {'phrase': 'my passphrase'}},
925)                 },
926)             ),
927)             (
928)                 ['--key', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

930)                 {
931)                     'global': {'phrase': 'abc'},
932)                     'services': {'sv': {'key': DUMMY_KEY1_B64}},
933)                 },
934)             ),
935)             (
936)                 ['--key', '--length', '15', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

938)                 {
939)                     'global': {'phrase': 'abc'},
940)                     'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
941)                 },
942)             ),
943)         ],
944)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

945)     def test_224_store_config_good(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

954)             monkeypatch=monkeypatch,
955)             runner=runner,
956)             config={'global': {'phrase': 'abc'}, 'services': {}},
957)         ):
958)             monkeypatch.setattr(
959)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
960)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

973)             assert (
974)                 config == result_config
975)             ), 'stored config does not match expectation'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

976) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

977)     @pytest.mark.parametrize(
978)         ['command_line', 'input', 'err_text'],
979)         [
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

981)             (
982)                 ['sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

983)                 '',
984)                 'Cannot update service settings without actual settings',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

988)         ],
989)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

990)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

994)         input: str,
995)         err_text: str,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

999)             monkeypatch=monkeypatch,
1000)             runner=runner,
1001)             config={'global': {'phrase': 'abc'}, 'services': {}},
1002)         ):
1003)             monkeypatch.setattr(
1004)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1005)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1012)         result = tests.ReadableResult.parse(_result)
1013)         assert result.error_exit(
1014)             error=err_text
1015)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

1016) 
1017)     def test_225a_store_config_fail_manual_no_ssh_key_selection(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1023)             monkeypatch=monkeypatch,
1024)             runner=runner,
1025)             config={'global': {'phrase': 'abc'}, 'services': {}},
1026)         ):
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1038)         result = tests.ReadableResult.parse(_result)
1039)         assert result.error_exit(
1040)             error=custom_error
1041)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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)             monkeypatch.delenv('SSH_AUTH_SOCK', raising=False)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1058)                 ['--key', '--config'],
1059)                 catch_exceptions=False,
1060)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

1061)         result = tests.ReadableResult.parse(_result)
1062)         assert result.error_exit(
1063)             error='Cannot find running SSH agent'
1064)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1065) 
1066)     def test_225c_store_config_fail_manual_bad_ssh_agent_connection(
1067)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1072)             monkeypatch=monkeypatch,
1073)             runner=runner,
1074)             config={'global': {'phrase': 'abc'}, 'services': {}},
1075)         ):
1076)             monkeypatch.setenv('SSH_AUTH_SOCK', os.getcwd())
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1079)                 ['--key', '--config'],
1080)                 catch_exceptions=False,
1081)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

1082)         result = tests.ReadableResult.parse(_result)
1083)         assert result.error_exit(
1084)             error='Cannot connect to SSH agent'
1085)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1086) 
1087)     @pytest.mark.parametrize('try_race_free_implementation', [True, False])
1088)     def test_225d_store_config_fail_manual_read_only_file(
1089)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1091)         try_race_free_implementation: bool,
1092)     ) -> None:
1093)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1095)             monkeypatch=monkeypatch,
1096)             runner=runner,
1097)             config={'global': {'phrase': 'abc'}, 'services': {}},
1098)         ):
1099)             tests.make_file_readonly(
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1101)                 try_race_free_implementation=try_race_free_implementation,
1102)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1105)                 ['--config', '--length=15', DUMMY_SERVICE],
1106)                 catch_exceptions=False,
1107)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

1108)         result = tests.ReadableResult.parse(_result)
1109)         assert result.error_exit(
1110)             error='Cannot store config'
1111)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1112) 
1113)     def test_225e_store_config_fail_manual_custom_error(
1114)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1119)             monkeypatch=monkeypatch,
1120)             runner=runner,
1121)             config={'global': {'phrase': 'abc'}, 'services': {}},
1122)         ):
1123)             custom_error = 'custom error message'
1124) 
1125)             def raiser(config: Any) -> None:
1126)                 del config
1127)                 raise RuntimeError(custom_error)
1128) 
1129)             monkeypatch.setattr(cli, '_save_config', raiser)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1132)                 ['--config', '--length=15', DUMMY_SERVICE],
1133)                 catch_exceptions=False,
1134)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

1135)         result = tests.ReadableResult.parse(_result)
1136)         assert result.error_exit(
1137)             error=custom_error
1138)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1139) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1142)         with tests.isolated_config(
1143)             monkeypatch=monkeypatch,
1144)             runner=runner,
1145)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1149)         result = tests.ReadableResult.parse(_result)
1150)         assert result.error_exit(
1151)             error='SERVICE is required'
1152)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

1153) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

1154)     def test_226a_no_passphrase_or_key(
1155)         self, monkeypatch: pytest.MonkeyPatch
1156)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1158)         with tests.isolated_config(
1159)             monkeypatch=monkeypatch,
1160)             runner=runner,
1161)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1163)                 cli.derivepassphrase_vault,
1164)                 [DUMMY_SERVICE],
1165)                 catch_exceptions=False,
Marco Ricci Isolate tests properly and...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

1171) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

1172)     def test_230_config_directory_nonexistant(
1173)         self, monkeypatch: pytest.MonkeyPatch
1174)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1182)             os_makedirs_called = False
1183)             real_os_makedirs = os.makedirs
1184) 
1185)             def makedirs(*args: Any, **kwargs: Any) -> Any:
1186)                 nonlocal os_makedirs_called
1187)                 os_makedirs_called = True
1188)                 return real_os_makedirs(*args, **kwargs)
1189) 
1190)             monkeypatch.setattr(os, 'makedirs', makedirs)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1206)                 config_readback = json.load(infile)
1207)             assert config_readback == {
1208)                 'global': {'phrase': 'abc'},
1209)                 'services': {},
1210)             }, 'config mismatch'
1211) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

1212)     def test_230a_config_directory_not_a_file(
1213)         self, monkeypatch: pytest.MonkeyPatch
1214)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1216)         runner = click.testing.CliRunner(mix_stderr=False)
1217)         with tests.isolated_config(
1218)             monkeypatch=monkeypatch,
1219)             runner=runner,
1220)         ):
1221)             _save_config = cli._save_config
1222) 
1223)             def obstruct_config_saving(*args: Any, **kwargs: Any) -> Any:
1224)                 with contextlib.suppress(FileNotFoundError):
1225)                     shutil.rmtree('.derivepassphrase')
1226)                 with open(
1227)                     '.derivepassphrase', 'w', encoding='UTF-8'
1228)                 ) as outfile:
1229)                     print('Obstruction!!', file=outfile)
1230)                 monkeypatch.setattr(cli, '_save_config', _save_config)
1231)                 return _save_config(*args, **kwargs)
1232) 
1233)             monkeypatch.setattr(cli, '_save_config', obstruct_config_saving)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1236)                 ['--config', '-p'],
1237)                 catch_exceptions=False,
1238)                 input='abc\n',
1239)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1244) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

1245)     def test_230b_store_config_custom_error(
1246)         self, monkeypatch: pytest.MonkeyPatch
1247)     ) -> None:
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1248)         runner = click.testing.CliRunner(mix_stderr=False)
1249)         with tests.isolated_config(
1250)             monkeypatch=monkeypatch,
1251)             runner=runner,
1252)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1255)             def raiser(config: Any) -> None:
1256)                 del config
1257)                 raise RuntimeError(custom_error)
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1262)                 ['--config', '-p'],
1263)                 catch_exceptions=False,
1264)                 input='abc\n',
1265)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1273)         [
1274)             pytest.param(
1275)                 ['--import', '-'],
1276)                 json.dumps({
1277)                     'global': {'phrase': 'Du\u0308sseldorf'},
1278)                     'services': {},
1279)                 }),
1280)                 'the global passphrase is not NFC-normalized',
1281)                 id='global-NFC',
1282)             ),
1283)             pytest.param(
1284)                 ['--import', '-'],
1285)                 json.dumps({
1286)                     'services': {
1287)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1288)                         'weird entry name': {'phrase': 'Du\u0308sseldorf'},
1289)                     }
1290)                 }),
1291)                 (
1292)                     "the services.'weird entry name' passphrase "
1293)                     'is not NFC-normalized'
1294)                 ),
1295)                 id='service-weird-name-NFC',
1296)             ),
1297)             pytest.param(
1298)                 ['--config', '-p', DUMMY_SERVICE],
1299)                 'Du\u0308sseldorf',
1300)                 (
1301)                     f'the services.{DUMMY_SERVICE} passphrase '
1302)                     f'is not NFC-normalized'
1303)                 ),
1304)                 id='config-NFC',
1305)             ),
1306)             pytest.param(
1307)                 ['-p', DUMMY_SERVICE],
1308)                 'Du\u0308sseldorf',
1309)                 'the interactive passphrase is not NFC-normalized',
1310)                 id='direct-input-NFC',
1311)             ),
1312)             pytest.param(
1313)                 ['--import', '-'],
1314)                 json.dumps({
1315)                     'global': {
1316)                         'unicode_normalization_form': 'NFD',
1317)                         'phrase': 'D\u00fcsseldorf',
1318)                     },
1319)                     'services': {},
1320)                 }),
1321)                 'the global passphrase is not NFD-normalized',
1322)                 id='global-NFD',
1323)             ),
1324)             pytest.param(
1325)                 ['--import', '-'],
1326)                 json.dumps({
1327)                     'global': {
1328)                         'unicode_normalization_form': 'NFD',
1329)                     },
1330)                     'services': {
1331)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1332)                         'weird entry name': {'phrase': 'D\u00fcsseldorf'},
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1334)                 }),
1335)                 (
1336)                     "the services.'weird entry name' passphrase "
1337)                     'is not NFD-normalized'
1338)                 ),
1339)                 id='service-weird-name-NFD',
1340)             ),
1341)         ],
1342)     )
1343)     def test_300_unicode_normalization_form_warning(
1344)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1352)             monkeypatch=monkeypatch,
1353)             runner=runner,
1354)             config={'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}},
1355)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1358)                 command_line,
1359)                 catch_exceptions=False,
1360)                 input=input,
1361)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

1362)         result = tests.ReadableResult.parse(_result)
1363)         assert result.clean_exit(), 'expected clean exit'
1364)         assert (
1365)             warning_message in result.stderr
1366)         ), 'expected known warning message in stderr'
Marco Ricci Allow all textual strings,...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1368)     def test_400_missing_af_unix_support(
1369)         self,
1370)         monkeypatch: pytest.MonkeyPatch,
1371)     ) -> None:
1372)         runner = click.testing.CliRunner(mix_stderr=False)
1373)         with tests.isolated_vault_config(
1374)             monkeypatch=monkeypatch,
1375)             runner=runner,
1376)             config={'global': {'phrase': 'abc'}, 'services': {}},
1377)         ):
1378)             monkeypatch.setenv(
1379)                 'SSH_AUTH_SOCK', "the value doesn't even matter"
1380)             )
1381)             monkeypatch.delattr(socket, 'AF_UNIX', raising=False)
1382)             _result = runner.invoke(
1383)                 cli.derivepassphrase_vault,
1384)                 ['--key', '--config'],
1385)                 catch_exceptions=False,
1386)             )
1387)         result = tests.ReadableResult.parse(_result)
1388)         assert result.error_exit(
1389)             error='does not support UNIX domain sockets'
1390)         ), 'expected error exit and known error message'
1391) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1394)     @pytest.mark.parametrize(
1395)         'config',
1396)         [
1397)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1398)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1399)             {
1400)                 'global': {'phrase': 'abc'},
1401)                 'services': {'sv': {'phrase': 'my passphrase'}},
1402)             },
1403)             {
1404)                 'global': {'phrase': 'abc'},
1405)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1406)             },
1407)             {
1408)                 'global': {'phrase': 'abc'},
1409)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1410)             },
1411)         ],
1412)     )
1413)     def test_100_load_config(
1414)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1415)     ) -> None:
1416)         runner = click.testing.CliRunner()
1417)         with tests.isolated_vault_config(
1418)             monkeypatch=monkeypatch, runner=runner, config=config
1419)         ):
1420)             config_filename = cli._config_filename(subsystem='vault')
1421)             with open(config_filename, encoding='UTF-8') as fileobj:
1422)                 assert json.load(fileobj) == config
1423)             assert cli._load_config() == config
1424) 
1425)     def test_110_save_bad_config(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1436) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1442)             # from https://montypython.fandom.com/wiki/Spam#The_menu
1443)             items = items or [
1444)                 'Egg and bacon',
1445)                 'Egg, sausage and bacon',
1446)                 'Egg and spam',
1447)                 'Egg, bacon and spam',
1448)                 'Egg, bacon, sausage and spam',
1449)                 'Spam, bacon, sausage and spam',
1450)                 'Spam, egg, spam, spam, bacon and spam',
1451)                 'Spam, spam, spam, egg and spam',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1452)                 (
1453)                     'Spam, spam, spam, spam, spam, spam, baked beans, '
1454)                     'spam, spam, spam and spam'
1455)                 ),
1456)                 (
1457)                     'Lobster thermidor aux crevettes with a mornay sauce '
1458)                     'garnished with truffle paté, brandy '
1459)                     'and a fried egg on top and spam'
1460)                 ),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

1461)             ]
1462)             index = cli._prompt_for_selection(items, heading=heading)
1463)             click.echo('A fine choice: ', nl=False)
1464)             click.echo(items[index])
1465)             click.echo('(Note: Vikings strictly optional.)')
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1468)         _result = runner.invoke(driver, [], input='9')
1469)         result = tests.ReadableResult.parse(_result)
1470)         assert result.clean_exit(
1471)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

1472) Our menu:
1473) [1] Egg and bacon
1474) [2] Egg, sausage and bacon
1475) [3] Egg and spam
1476) [4] Egg, bacon and spam
1477) [5] Egg, bacon, sausage and spam
1478) [6] Spam, bacon, sausage and spam
1479) [7] Spam, egg, spam, spam, bacon and spam
1480) [8] Spam, spam, spam, egg and spam
1481) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1482) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
1483) Your selection? (1-10, leave empty to abort): 9
1484) A fine choice: Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1485) (Note: Vikings strictly optional.)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1491)         result = tests.ReadableResult.parse(_result)
1492)         assert result.error_exit(
1493)             error=IndexError
1494)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1496)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1498) [1] Egg and bacon
1499) [2] Egg, sausage and bacon
1500) [3] Egg and spam
1501) [4] Egg, bacon and spam
1502) [5] Egg, bacon, sausage and spam
1503) [6] Spam, bacon, sausage and spam
1504) [7] Spam, egg, spam, spam, bacon and spam
1505) [8] Spam, spam, spam, egg and spam
1506) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1507) [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

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1511) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1517)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1518)                 cli._prompt_for_selection(
1519)                     [item], heading='', single_choice_prompt=prompt
1520)                 )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1531)         result = tests.ReadableResult.parse(_result)
1532)         assert result.clean_exit(
1533)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1540)             driver,
1541)             ['Will replace with spam, okay? ' '(Please say "y" or "n".)'],
1542)             input='',
1543)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

1544)         result = tests.ReadableResult.parse(_result)
1545)         assert result.error_exit(
1546)             error=IndexError
1547)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1549)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1553) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1556) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1560)         monkeypatch.setattr(
1561)             click,
1562)             'prompt',
1563)             lambda *a, **kw: json.dumps({'args': a, 'kwargs': kw}),
1564)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1566)         err_msg = 'missing arguments to passphrase prompt'
1567)         assert 'args' in res, err_msg
1568)         assert 'kwargs' in res, err_msg
1569)         assert res['args'][:1] == ['Passphrase'], err_msg
1570)         assert res['kwargs'].get('default') == '', err_msg
1571)         assert not res['kwargs'].get('show_default', True), err_msg
1572)         assert res['kwargs'].get('err'), err_msg
1573)         assert res['kwargs'].get('hide_input'), err_msg
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

1574) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1575)     @pytest.mark.parametrize(
1576)         ['command_line', 'config', 'result_config'],
1577)         [
1578)             (
1579)                 ['--delete-globals'],
1580)                 {'global': {'phrase': 'abc'}, 'services': {}},
1581)                 {'services': {}},
1582)             ),
1583)             (
1584)                 ['--delete', DUMMY_SERVICE],
1585)                 {
1586)                     'global': {'phrase': 'abc'},
1587)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
1588)                 },
1589)                 {'global': {'phrase': 'abc'}, 'services': {}},
1590)             ),
1591)             (
1592)                 ['--clear'],
1593)                 {
1594)                     'global': {'phrase': 'abc'},
1595)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
1596)                 },
1597)                 {'services': {}},
1598)             ),
1599)         ],
1600)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

1601)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1605)         config: _types.VaultConfig,
1606)         result_config: _types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1611)                 monkeypatch=monkeypatch, runner=runner, config=start_config
1612)             ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1614)                     cli.derivepassphrase_vault,
1615)                     command_line,
1616)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1625)                     config_readback = json.load(infile)
1626)                 assert config_readback == result_config
1627) 
1628)     def test_204_phrase_from_key_manually(self) -> None:
1629)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 5 months ago

1631)                 phrase=DUMMY_PHRASE_FROM_KEY1, **DUMMY_CONFIG_SETTINGS
1632)             ).generate(DUMMY_SERVICE)
1633)             == DUMMY_RESULT_KEY1
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

1634)         )
1635) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1636)     @pytest.mark.parametrize(
1637)         ['vfunc', 'input'],
1638)         [
1639)             (cli._validate_occurrence_constraint, 20),
1640)             (cli._validate_length, 20),
1641)         ],
1642)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

1643)     def test_210a_validate_constraints_manually(
1644)         self,
1645)         vfunc: Callable[[click.Context, click.Parameter, Any], int | None],
1646)         input: int,
1647)     ) -> None:
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

1653)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

1659)         with monkeypatch.context():
1660)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent)
1661)             monkeypatch.setattr(
1662)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
1663)             )
1664)             hint: ssh_agent.SSHAgentClient | socket.socket | None
Marco Ricci Add support for Python 3.9

Marco Ricci authored 2 months ago

1665)             # Use match/case here once Python 3.9 becomes unsupported.
1666)             if conn_hint == 'client':
1667)                 hint = ssh_agent.SSHAgentClient()
1668)             elif conn_hint == 'socket':
1669)                 hint = socket.socket(family=socket.AF_UNIX)
1670)                 hint.connect(running_ssh_agent)
1671)             else:
1672)                 assert conn_hint == 'none'
1673)                 hint = None
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

1674)             exception: Exception | None = None
1675)             try:
1676)                 list(cli._get_suitable_ssh_keys(hint))
1677)             except RuntimeError:  # pragma: no cover
1678)                 pass
1679)             except Exception as e:  # noqa: BLE001 # pragma: no cover
1680)                 exception = e
1681)             finally:
1682)                 assert (
1683)                     exception is None
1684)                 ), 'exception querying suitable SSH keys'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1685) 
1686) 
1687) class TestCLITransition:
1688)     def test_100_help_output(self, monkeypatch: pytest.MonkeyPatch) -> None:
1689)         runner = click.testing.CliRunner(mix_stderr=False)
1690)         with tests.isolated_config(
1691)             monkeypatch=monkeypatch,
1692)             runner=runner,
1693)         ):
1694)             _result = runner.invoke(
1695)                 cli.derivepassphrase, ['--help'], catch_exceptions=False
1696)             )
1697)             result = tests.ReadableResult.parse(_result)
1698)         assert result.clean_exit(
1699)             empty_stderr=True, output='currently implemented subcommands'
1700)         ), 'expected clean exit, and known help text'
1701) 
1702)     def test_101_help_output_export(
1703)         self, monkeypatch: pytest.MonkeyPatch
1704)     ) -> None:
1705)         runner = click.testing.CliRunner(mix_stderr=False)
1706)         with tests.isolated_config(
1707)             monkeypatch=monkeypatch,
1708)             runner=runner,
1709)         ):
1710)             _result = runner.invoke(
1711)                 cli.derivepassphrase,
1712)                 ['export', '--help'],
1713)                 catch_exceptions=False,
1714)             )
1715)             result = tests.ReadableResult.parse(_result)
1716)         assert result.clean_exit(
1717)             empty_stderr=True, output='only available subcommand'
1718)         ), 'expected clean exit, and known help text'
1719) 
1720)     def test_102_help_output_export_vault(
1721)         self, monkeypatch: pytest.MonkeyPatch
1722)     ) -> None:
1723)         runner = click.testing.CliRunner(mix_stderr=False)
1724)         with tests.isolated_config(
1725)             monkeypatch=monkeypatch,
1726)             runner=runner,
1727)         ):
1728)             _result = runner.invoke(
1729)                 cli.derivepassphrase,
1730)                 ['export', 'vault', '--help'],
1731)                 catch_exceptions=False,
1732)             )
1733)             result = tests.ReadableResult.parse(_result)
1734)         assert result.clean_exit(
1735)             empty_stderr=True, output='Read the vault-native configuration'
1736)         ), 'expected clean exit, and known help text'
1737) 
1738)     def test_103_help_output_vault(
1739)         self, monkeypatch: pytest.MonkeyPatch
1740)     ) -> None:
1741)         runner = click.testing.CliRunner(mix_stderr=False)
1742)         with tests.isolated_config(
1743)             monkeypatch=monkeypatch,
1744)             runner=runner,
1745)         ):
1746)             _result = runner.invoke(
1747)                 cli.derivepassphrase,
1748)                 ['vault', '--help'],
1749)                 catch_exceptions=False,
1750)             )
1751)             result = tests.ReadableResult.parse(_result)
1752)         assert result.clean_exit(
1753)             empty_stderr=True, output='Password generation:\n'
1754)         ), 'expected clean exit, and option groups in help text'
1755)         assert result.clean_exit(
1756)             empty_stderr=True, output='Use NUMBER=0, e.g. "--symbol 0"'
1757)         ), 'expected clean exit, and option group epilog in help text'
1758) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

1759)     @pytest.mark.parametrize(
1760)         'config',
1761)         [
1762)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1763)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1764)             {
1765)                 'global': {'phrase': 'abc'},
1766)                 'services': {'sv': {'phrase': 'my passphrase'}},
1767)             },
1768)             {
1769)                 'global': {'phrase': 'abc'},
1770)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1771)             },
1772)             {
1773)                 'global': {'phrase': 'abc'},
1774)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1775)             },
1776)         ],
1777)     )
1778)     def test_110_load_config_backup(
1779)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1780)     ) -> None:
1781)         runner = click.testing.CliRunner()
1782)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
1783)             config_filename = cli._config_filename()
1784)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
1785)                 print(json.dumps(config, indent=2), file=fileobj)
1786)             assert cli._migrate_and_load_old_config()[0] == config
1787) 
1788)     @pytest.mark.parametrize(
1789)         'config',
1790)         [
1791)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1792)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1793)             {
1794)                 'global': {'phrase': 'abc'},
1795)                 'services': {'sv': {'phrase': 'my passphrase'}},
1796)             },
1797)             {
1798)                 'global': {'phrase': 'abc'},
1799)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1800)             },
1801)             {
1802)                 'global': {'phrase': 'abc'},
1803)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1804)             },
1805)         ],
1806)     )
1807)     def test_111_migrate_config(
1808)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1809)     ) -> None:
1810)         runner = click.testing.CliRunner()
1811)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
1812)             config_filename = cli._config_filename()
1813)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
1814)                 print(json.dumps(config, indent=2), file=fileobj)
1815)             assert cli._migrate_and_load_old_config() == (config, None)
1816) 
1817)     @pytest.mark.parametrize(
1818)         'config',
1819)         [
1820)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1821)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1822)             {
1823)                 'global': {'phrase': 'abc'},
1824)                 'services': {'sv': {'phrase': 'my passphrase'}},
1825)             },
1826)             {
1827)                 'global': {'phrase': 'abc'},
1828)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1829)             },
1830)             {
1831)                 'global': {'phrase': 'abc'},
1832)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1833)             },
1834)         ],
1835)     )
1836)     def test_112_migrate_config_error(
1837)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1838)     ) -> None:
1839)         runner = click.testing.CliRunner()
1840)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
1841)             config_filename = cli._config_filename()
1842)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
1843)                 print(json.dumps(config, indent=2), file=fileobj)
1844)             os.mkdir(cli._config_filename(subsystem='vault'))
1845)             config2, err = cli._migrate_and_load_old_config()
1846)             assert config2 == config
1847)             assert isinstance(err, OSError)
1848)             assert err.errno == errno.EISDIR
1849) 
1850)     @pytest.mark.parametrize(
1851)         'config',
1852)         [
1853)             {'global': '', 'services': {}},
1854)             {'global': 0, 'services': {}},
1855)             {
1856)                 'global': {'phrase': 'abc'},
1857)                 'services': False,
1858)             },
1859)             {
1860)                 'global': {'phrase': 'abc'},
1861)                 'services': True,
1862)             },
1863)             {
1864)                 'global': {'phrase': 'abc'},
1865)                 'services': None,
1866)             },
1867)         ],
1868)     )
1869)     def test_113_migrate_config_error_bad_config_value(
1870)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1871)     ) -> None:
1872)         runner = click.testing.CliRunner()
1873)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
1874)             config_filename = cli._config_filename()
1875)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
1876)                 print(json.dumps(config, indent=2), file=fileobj)
1877)             with pytest.raises(ValueError, match=cli._INVALID_VAULT_CONFIG):
1878)                 cli._migrate_and_load_old_config()
1879) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1880)     def test_200_forward_export_vault_path_parameter(
1881)         self, monkeypatch: pytest.MonkeyPatch
1882)     ) -> None:
1883)         pytest.importorskip('cryptography', minversion='38.0')
1884)         runner = click.testing.CliRunner(mix_stderr=False)
1885)         with tests.isolated_vault_exporter_config(
1886)             monkeypatch=monkeypatch,
1887)             runner=runner,
1888)             vault_config=tests.VAULT_V03_CONFIG,
1889)             vault_key=tests.VAULT_MASTER_KEY,
1890)         ):
1891)             monkeypatch.setenv('VAULT_KEY', tests.VAULT_MASTER_KEY)
1892)             _result = runner.invoke(
1893)                 cli.derivepassphrase,
1894)                 ['export', 'VAULT_PATH'],
1895)             )
1896)         result = tests.ReadableResult.parse(_result)
1897)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

1898)         assert (
1899)             result.stderr
1900)             == f"""\
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1904)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1905)         assert json.loads(result.output) == tests.VAULT_V03_CONFIG_DATA
1906) 
1907)     @pytest.mark.parametrize(
1908)         'charset_name', ['lower', 'upper', 'number', 'space', 'dash', 'symbol']
1909)     )
1910)     def test_210_forward_vault_disable_character_set(
1911)         self, monkeypatch: pytest.MonkeyPatch, charset_name: str
1912)     ) -> None:
1913)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
1914)         option = f'--{charset_name}'
Marco Ricci Align behavior with vault c...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1916)         runner = click.testing.CliRunner(mix_stderr=False)
1917)         with tests.isolated_config(
1918)             monkeypatch=monkeypatch,
1919)             runner=runner,
1920)         ):
1921)             _result = runner.invoke(
1922)                 cli.derivepassphrase,
1923)                 [option, '0', '-p', DUMMY_SERVICE],
1924)                 input=DUMMY_PASSPHRASE,
1925)                 catch_exceptions=False,
1926)             )
1927)             result = tests.ReadableResult.parse(_result)
1928)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

1929)         assert (
1930)             result.stderr
1931)             == f"""\
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1935)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1936)         for c in charset:
1937)             assert (
1938)                 c not in result.output
1939)             ), f'derived password contains forbidden character {c!r}'