2bb00f7a81dad1210b60fb9a6d905ca8d5193655
Marco Ricci Change the author e-mail ad...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

48) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

88) ]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

219) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

246) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

272) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

297)     def test_204a_key_from_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

325) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

357) 
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

420)     def test_205_service_phrase_if_key_in_global_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

453) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

556)     def test_212_incompatible_options(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

578)     def test_213_import_bad_config_not_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

595)     def test_213a_import_bad_config_not_json_data(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

612)     def test_213b_import_bad_config_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

622)             with open(
623)                 cli._config_filename(), 'w', encoding='UTF-8'
624)             ) as outfile:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

625)                 print('This string is not valid JSON.', file=outfile)
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 4 months ago

626)             dname = os.path.dirname(cli._config_filename())
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

643)             with contextlib.suppress(FileNotFoundError):
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

644)                 os.remove(cli._config_filename())
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

653)     def test_214a_export_settings_bad_stored_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

672)     def test_214b_export_settings_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

678)             with contextlib.suppress(FileNotFoundError):
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

692)     def test_214c_export_settings_target_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

697)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

698)             dname = os.path.dirname(cli._config_filename())
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

709) 
Marco Ricci Create the configuration di...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

730) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

751)             result = tests.ReadableResult.parse(_result)
752)             assert result.clean_exit(empty_stderr=True), 'expected clean exit'
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

759) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

775)             result = tests.ReadableResult.parse(_result)
776)             assert result.clean_exit(empty_stderr=True), 'expected clean exit'
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

796)             result = tests.ReadableResult.parse(_result)
797)             assert result.clean_exit(empty_stderr=True), 'expected clean exit'
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

800)             assert config == {
801)                 'global': {'phrase': 'abc'},
802)                 'services': {'sv': {'notes': 'long\ntext'}},
803)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

804) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

805)     def test_223_edit_notes_abort(
806)         self, monkeypatch: pytest.MonkeyPatch
807)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

816)                 cli.derivepassphrase_vault,
817)                 ['--notes', 'sv'],
818)                 catch_exceptions=False,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

820)             result = tests.ReadableResult.parse(_result)
821)             assert result.error_exit(
822)                 error='user aborted request'
823)             ), 'expected known error message'
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

828)     @pytest.mark.parametrize(
829)         ['command_line', 'input', 'result_config'],
830)         [
831)             (
832)                 ['--phrase'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

834)                 {'global': {'phrase': 'my passphrase'}, 'services': {}},
835)             ),
836)             (
837)                 ['--key'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

860)                 {
861)                     'global': {'phrase': 'abc'},
862)                     'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
863)                 },
864)             ),
865)         ],
866)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

867)     def test_224_store_config_good(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

872)         result_config: Any,
873)     ) -> None:
874)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

876)             monkeypatch=monkeypatch,
877)             runner=runner,
878)             config={'global': {'phrase': 'abc'}, 'services': {}},
879)         ):
880)             monkeypatch.setattr(
881)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
882)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

885)                 ['--config', *command_line],
886)                 catch_exceptions=False,
887)                 input=input,
888)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

889)             result = tests.ReadableResult.parse(_result)
890)             assert result.clean_exit(), 'expected clean exit'
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

893)             assert (
894)                 config == result_config
895)             ), 'stored config does not match expectation'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

896) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

897)     @pytest.mark.parametrize(
898)         ['command_line', 'input', 'err_text'],
899)         [
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

901)             (
902)                 ['sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

903)                 '',
904)                 'Cannot update service settings without actual settings',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

908)         ],
909)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

910)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

914)         input: str,
915)         err_text: str,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

919)             monkeypatch=monkeypatch,
920)             runner=runner,
921)             config={'global': {'phrase': 'abc'}, 'services': {}},
922)         ):
923)             monkeypatch.setattr(
924)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
925)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

928)                 ['--config', *command_line],
929)                 catch_exceptions=False,
930)                 input=input,
931)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

932)         result = tests.ReadableResult.parse(_result)
933)         assert result.error_exit(
934)             error=err_text
935)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

936) 
937)     def test_225a_store_config_fail_manual_no_ssh_key_selection(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

943)             monkeypatch=monkeypatch,
944)             runner=runner,
945)             config={'global': {'phrase': 'abc'}, 'services': {}},
946)         ):
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

955)                 ['--key', '--config'],
956)                 catch_exceptions=False,
957)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

958)         result = tests.ReadableResult.parse(_result)
959)         assert result.error_exit(
960)             error=custom_error
961)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

963)     def test_225b_store_config_fail_manual_no_ssh_agent(
964)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

969)             monkeypatch=monkeypatch,
970)             runner=runner,
971)             config={'global': {'phrase': 'abc'}, 'services': {}},
972)         ):
973)             monkeypatch.delenv('SSH_AUTH_SOCK', raising=False)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

976)                 ['--key', '--config'],
977)                 catch_exceptions=False,
978)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

979)         result = tests.ReadableResult.parse(_result)
980)         assert result.error_exit(
981)             error='Cannot find running SSH agent'
982)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

983) 
984)     def test_225c_store_config_fail_manual_bad_ssh_agent_connection(
985)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

990)             monkeypatch=monkeypatch,
991)             runner=runner,
992)             config={'global': {'phrase': 'abc'}, 'services': {}},
993)         ):
994)             monkeypatch.setenv('SSH_AUTH_SOCK', os.getcwd())
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

997)                 ['--key', '--config'],
998)                 catch_exceptions=False,
999)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1000)         result = tests.ReadableResult.parse(_result)
1001)         assert result.error_exit(
1002)             error='Cannot connect to SSH agent'
1003)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

1004) 
1005)     @pytest.mark.parametrize('try_race_free_implementation', [True, False])
1006)     def test_225d_store_config_fail_manual_read_only_file(
1007)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1009)         try_race_free_implementation: bool,
1010)     ) -> None:
1011)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1013)             monkeypatch=monkeypatch,
1014)             runner=runner,
1015)             config={'global': {'phrase': 'abc'}, 'services': {}},
1016)         ):
1017)             tests.make_file_readonly(
1018)                 cli._config_filename(),
1019)                 try_race_free_implementation=try_race_free_implementation,
1020)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1023)                 ['--config', '--length=15', DUMMY_SERVICE],
1024)                 catch_exceptions=False,
1025)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1026)         result = tests.ReadableResult.parse(_result)
1027)         assert result.error_exit(
1028)             error='Cannot store config'
1029)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

1030) 
1031)     def test_225e_store_config_fail_manual_custom_error(
1032)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1037)             monkeypatch=monkeypatch,
1038)             runner=runner,
1039)             config={'global': {'phrase': 'abc'}, 'services': {}},
1040)         ):
1041)             custom_error = 'custom error message'
1042) 
1043)             def raiser(config: Any) -> None:
1044)                 del config
1045)                 raise RuntimeError(custom_error)
1046) 
1047)             monkeypatch.setattr(cli, '_save_config', raiser)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1050)                 ['--config', '--length=15', DUMMY_SERVICE],
1051)                 catch_exceptions=False,
1052)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1053)         result = tests.ReadableResult.parse(_result)
1054)         assert result.error_exit(
1055)             error=custom_error
1056)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

1057) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1060)         with tests.isolated_config(
1061)             monkeypatch=monkeypatch,
1062)             runner=runner,
1063)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1067)         result = tests.ReadableResult.parse(_result)
1068)         assert result.error_exit(
1069)             error='SERVICE is required'
1070)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

1071) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1081)                 cli.derivepassphrase_vault,
1082)                 [DUMMY_SERVICE],
1083)                 catch_exceptions=False,
Marco Ricci Isolate tests properly and...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1089) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1090)     def test_230_config_directory_nonexistant(
1091)         self, monkeypatch: pytest.MonkeyPatch
1092)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1094)         runner = click.testing.CliRunner(mix_stderr=False)
1095)         with tests.isolated_config(
1096)             monkeypatch=monkeypatch,
1097)             runner=runner,
1098)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1100)             os_makedirs_called = False
1101)             real_os_makedirs = os.makedirs
1102) 
1103)             def makedirs(*args: Any, **kwargs: Any) -> Any:
1104)                 nonlocal os_makedirs_called
1105)                 os_makedirs_called = True
1106)                 return real_os_makedirs(*args, **kwargs)
1107) 
1108)             monkeypatch.setattr(os, 'makedirs', makedirs)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1111)                 ['--config', '-p'],
1112)                 catch_exceptions=False,
1113)                 input='abc\n',
1114)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1119)             ), 'program unexpectedly failed?!'
1120)             assert os_makedirs_called, 'os.makedirs has not been called?!'
1121)             with open(cli._config_filename(), encoding='UTF-8') as infile:
1122)                 config_readback = json.load(infile)
1123)             assert config_readback == {
1124)                 'global': {'phrase': 'abc'},
1125)                 'services': {},
1126)             }, 'config mismatch'
1127) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1128)     def test_230a_config_directory_not_a_file(
1129)         self, monkeypatch: pytest.MonkeyPatch
1130)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1132)         runner = click.testing.CliRunner(mix_stderr=False)
1133)         with tests.isolated_config(
1134)             monkeypatch=monkeypatch,
1135)             runner=runner,
1136)         ):
1137)             _save_config = cli._save_config
1138) 
1139)             def obstruct_config_saving(*args: Any, **kwargs: Any) -> Any:
1140)                 with contextlib.suppress(FileNotFoundError):
1141)                     shutil.rmtree('.derivepassphrase')
1142)                 with open(
1143)                     '.derivepassphrase', 'w', encoding='UTF-8'
1144)                 ) as outfile:
1145)                     print('Obstruction!!', file=outfile)
1146)                 monkeypatch.setattr(cli, '_save_config', _save_config)
1147)                 return _save_config(*args, **kwargs)
1148) 
1149)             monkeypatch.setattr(cli, '_save_config', obstruct_config_saving)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1152)                 ['--config', '-p'],
1153)                 catch_exceptions=False,
1154)                 input='abc\n',
1155)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1156)             result = tests.ReadableResult.parse(_result)
1157)             assert result.error_exit(
1158)                 error='Cannot store config'
1159)             ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

1160) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1161)     def test_230b_store_config_custom_error(
1162)         self, monkeypatch: pytest.MonkeyPatch
1163)     ) -> None:
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

1164)         runner = click.testing.CliRunner(mix_stderr=False)
1165)         with tests.isolated_config(
1166)             monkeypatch=monkeypatch,
1167)             runner=runner,
1168)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1171)             def raiser(config: Any) -> None:
1172)                 del config
1173)                 raise RuntimeError(custom_error)
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1178)                 ['--config', '-p'],
1179)                 catch_exceptions=False,
1180)                 input='abc\n',
1181)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1250)                 }),
1251)                 (
1252)                     "the services.'weird entry name' passphrase "
1253)                     'is not NFD-normalized'
1254)                 ),
1255)                 id='service-weird-name-NFD',
1256)             ),
1257)         ],
1258)     )
1259)     def test_300_unicode_normalization_form_warning(
1260)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1268)             monkeypatch=monkeypatch,
1269)             runner=runner,
1270)             config={'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}},
1271)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1274)                 command_line,
1275)                 catch_exceptions=False,
1276)                 input=input,
1277)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1278)         result = tests.ReadableResult.parse(_result)
1279)         assert result.clean_exit(), 'expected clean exit'
1280)         assert (
1281)             warning_message in result.stderr
1282)         ), 'expected known warning message in stderr'
Marco Ricci Allow all textual strings,...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1285) class TestCLIUtils:
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1286)     def test_100_save_bad_config(
1287)         self, monkeypatch: pytest.MonkeyPatch
1288)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1297) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1303)             # from https://montypython.fandom.com/wiki/Spam#The_menu
1304)             items = items or [
1305)                 'Egg and bacon',
1306)                 'Egg, sausage and bacon',
1307)                 'Egg and spam',
1308)                 'Egg, bacon and spam',
1309)                 'Egg, bacon, sausage and spam',
1310)                 'Spam, bacon, sausage and spam',
1311)                 'Spam, egg, spam, spam, bacon and spam',
1312)                 'Spam, spam, spam, egg and spam',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1313)                 (
1314)                     'Spam, spam, spam, spam, spam, spam, baked beans, '
1315)                     'spam, spam, spam and spam'
1316)                 ),
1317)                 (
1318)                     'Lobster thermidor aux crevettes with a mornay sauce '
1319)                     'garnished with truffle paté, brandy '
1320)                     'and a fried egg on top and spam'
1321)                 ),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1322)             ]
1323)             index = cli._prompt_for_selection(items, heading=heading)
1324)             click.echo('A fine choice: ', nl=False)
1325)             click.echo(items[index])
1326)             click.echo('(Note: Vikings strictly optional.)')
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

1329)         _result = runner.invoke(driver, [], input='9')
1330)         result = tests.ReadableResult.parse(_result)
1331)         assert result.clean_exit(
1332)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1333) Our menu:
1334) [1] Egg and bacon
1335) [2] Egg, sausage and bacon
1336) [3] Egg and spam
1337) [4] Egg, bacon and spam
1338) [5] Egg, bacon, sausage and spam
1339) [6] Spam, bacon, sausage and spam
1340) [7] Spam, egg, spam, spam, bacon and spam
1341) [8] Spam, spam, spam, egg and spam
1342) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1343) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
1344) Your selection? (1-10, leave empty to abort): 9
1345) A fine choice: Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1346) (Note: Vikings strictly optional.)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1352)         result = tests.ReadableResult.parse(_result)
1353)         assert result.error_exit(
1354)             error=IndexError
1355)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1357)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1359) [1] Egg and bacon
1360) [2] Egg, sausage and bacon
1361) [3] Egg and spam
1362) [4] Egg, bacon and spam
1363) [5] Egg, bacon, sausage and spam
1364) [6] Spam, bacon, sausage and spam
1365) [7] Spam, egg, spam, spam, bacon and spam
1366) [8] Spam, spam, spam, egg and spam
1367) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1368) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1372) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1378)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1379)                 cli._prompt_for_selection(
1380)                     [item], heading='', single_choice_prompt=prompt
1381)                 )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1392)         result = tests.ReadableResult.parse(_result)
1393)         assert result.clean_exit(
1394)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1401)             driver,
1402)             ['Will replace with spam, okay? ' '(Please say "y" or "n".)'],
1403)             input='',
1404)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1405)         result = tests.ReadableResult.parse(_result)
1406)         assert result.error_exit(
1407)             error=IndexError
1408)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1410)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1414) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1417) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

1418)     def test_103_prompt_for_passphrase(
1419)         self, monkeypatch: pytest.MonkeyPatch
1420)     ) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1421)         monkeypatch.setattr(
1422)             click,
1423)             'prompt',
1424)             lambda *a, **kw: json.dumps({'args': a, 'kwargs': kw}),
1425)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1427)         err_msg = 'missing arguments to passphrase prompt'
1428)         assert 'args' in res, err_msg
1429)         assert 'kwargs' in res, err_msg
1430)         assert res['args'][:1] == ['Passphrase'], err_msg
1431)         assert res['kwargs'].get('default') == '', err_msg
1432)         assert not res['kwargs'].get('show_default', True), err_msg
1433)         assert res['kwargs'].get('err'), err_msg
1434)         assert res['kwargs'].get('hide_input'), err_msg
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1435) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1436)     @pytest.mark.parametrize(
1437)         ['command_line', 'config', 'result_config'],
1438)         [
1439)             (
1440)                 ['--delete-globals'],
1441)                 {'global': {'phrase': 'abc'}, 'services': {}},
1442)                 {'services': {}},
1443)             ),
1444)             (
1445)                 ['--delete', DUMMY_SERVICE],
1446)                 {
1447)                     'global': {'phrase': 'abc'},
1448)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
1449)                 },
1450)                 {'global': {'phrase': 'abc'}, 'services': {}},
1451)             ),
1452)             (
1453)                 ['--clear'],
1454)                 {
1455)                     'global': {'phrase': 'abc'},
1456)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
1457)                 },
1458)                 {'services': {}},
1459)             ),
1460)         ],
1461)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1462)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1466)         config: _types.VaultConfig,
1467)         result_config: _types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

1472)                 monkeypatch=monkeypatch, runner=runner, config=start_config
1473)             ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1475)                     cli.derivepassphrase_vault,
1476)                     command_line,
1477)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

1479)                 result = tests.ReadableResult.parse(_result)
1480)                 assert result.clean_exit(
1481)                     empty_stderr=True
1482)                 ), 'expected clean exit'
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1484)                     config_readback = json.load(infile)
1485)                 assert config_readback == result_config
1486) 
1487)     def test_204_phrase_from_key_manually(self) -> None:
1488)         assert (
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

1490)                 phrase=DUMMY_PHRASE_FROM_KEY1, **DUMMY_CONFIG_SETTINGS
1491)             ).generate(DUMMY_SERVICE)
1492)             == DUMMY_RESULT_KEY1
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1493)         )
1494) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1495)     @pytest.mark.parametrize(
1496)         ['vfunc', 'input'],
1497)         [
1498)             (cli._validate_occurrence_constraint, 20),
1499)             (cli._validate_length, 20),
1500)         ],
1501)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1502)     def test_210a_validate_constraints_manually(
1503)         self,
1504)         vfunc: Callable[[click.Context, click.Parameter, Any], int | None],
1505)         input: int,
1506)     ) -> None:
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 4 months ago

1509)         assert vfunc(ctx, param, input) == input
1510) 
1511)     @tests.skip_if_no_agent
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1513)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1522)         match conn_hint:
1523)             case 'client':
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1525)             case 'socket':
1526)                 hint = socket.socket(family=socket.AF_UNIX)
1527)                 hint.connect(os.environ['SSH_AUTH_SOCK'])
1528)             case _:
1529)                 assert conn_hint == 'none'
1530)                 hint = None
1531)         exception: Exception | None = None
1532)         try:
1533)             list(cli._get_suitable_ssh_keys(hint))
1534)         except RuntimeError:  # pragma: no cover
1535)             pass
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1537)             exception = e
1538)         finally:
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

1540) 
1541) 
1542) class TestCLITransition:
1543)     def test_100_help_output(self, monkeypatch: pytest.MonkeyPatch) -> None:
1544)         runner = click.testing.CliRunner(mix_stderr=False)
1545)         with tests.isolated_config(
1546)             monkeypatch=monkeypatch,
1547)             runner=runner,
1548)         ):
1549)             _result = runner.invoke(
1550)                 cli.derivepassphrase, ['--help'], catch_exceptions=False
1551)             )
1552)             result = tests.ReadableResult.parse(_result)
1553)         assert result.clean_exit(
1554)             empty_stderr=True, output='currently implemented subcommands'
1555)         ), 'expected clean exit, and known help text'
1556) 
1557)     def test_101_help_output_export(
1558)         self, monkeypatch: pytest.MonkeyPatch
1559)     ) -> None:
1560)         runner = click.testing.CliRunner(mix_stderr=False)
1561)         with tests.isolated_config(
1562)             monkeypatch=monkeypatch,
1563)             runner=runner,
1564)         ):
1565)             _result = runner.invoke(
1566)                 cli.derivepassphrase,
1567)                 ['export', '--help'],
1568)                 catch_exceptions=False,
1569)             )
1570)             result = tests.ReadableResult.parse(_result)
1571)         assert result.clean_exit(
1572)             empty_stderr=True, output='only available subcommand'
1573)         ), 'expected clean exit, and known help text'
1574) 
1575)     def test_102_help_output_export_vault(
1576)         self, monkeypatch: pytest.MonkeyPatch
1577)     ) -> None:
1578)         runner = click.testing.CliRunner(mix_stderr=False)
1579)         with tests.isolated_config(
1580)             monkeypatch=monkeypatch,
1581)             runner=runner,
1582)         ):
1583)             _result = runner.invoke(
1584)                 cli.derivepassphrase,
1585)                 ['export', 'vault', '--help'],
1586)                 catch_exceptions=False,
1587)             )
1588)             result = tests.ReadableResult.parse(_result)
1589)         assert result.clean_exit(
1590)             empty_stderr=True, output='Read the vault-native configuration'
1591)         ), 'expected clean exit, and known help text'
1592) 
1593)     def test_103_help_output_vault(
1594)         self, monkeypatch: pytest.MonkeyPatch
1595)     ) -> None:
1596)         runner = click.testing.CliRunner(mix_stderr=False)
1597)         with tests.isolated_config(
1598)             monkeypatch=monkeypatch,
1599)             runner=runner,
1600)         ):
1601)             _result = runner.invoke(
1602)                 cli.derivepassphrase,
1603)                 ['vault', '--help'],
1604)                 catch_exceptions=False,
1605)             )
1606)             result = tests.ReadableResult.parse(_result)
1607)         assert result.clean_exit(
1608)             empty_stderr=True, output='Password generation:\n'
1609)         ), 'expected clean exit, and option groups in help text'
1610)         assert result.clean_exit(
1611)             empty_stderr=True, output='Use NUMBER=0, e.g. "--symbol 0"'
1612)         ), 'expected clean exit, and option group epilog in help text'
1613) 
1614)     def test_200_forward_export_vault_path_parameter(
1615)         self, monkeypatch: pytest.MonkeyPatch
1616)     ) -> None:
1617)         pytest.importorskip('cryptography', minversion='38.0')
1618)         runner = click.testing.CliRunner(mix_stderr=False)
1619)         with tests.isolated_vault_exporter_config(
1620)             monkeypatch=monkeypatch,
1621)             runner=runner,
1622)             vault_config=tests.VAULT_V03_CONFIG,
1623)             vault_key=tests.VAULT_MASTER_KEY,
1624)         ):
1625)             monkeypatch.setenv('VAULT_KEY', tests.VAULT_MASTER_KEY)
1626)             _result = runner.invoke(
1627)                 cli.derivepassphrase,
1628)                 ['export', 'VAULT_PATH'],
1629)             )
1630)         result = tests.ReadableResult.parse(_result)
1631)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

1632)         assert (
1633)             result.stderr
1634)             == f"""\
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1638)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

1639)         assert json.loads(result.output) == tests.VAULT_V03_CONFIG_DATA
1640) 
1641)     @pytest.mark.parametrize(
1642)         'charset_name', ['lower', 'upper', 'number', 'space', 'dash', 'symbol']
1643)     )
1644)     def test_210_forward_vault_disable_character_set(
1645)         self, monkeypatch: pytest.MonkeyPatch, charset_name: str
1646)     ) -> None:
1647)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
1648)         option = f'--{charset_name}'
1649)         charset = dpp.vault.Vault._CHARSETS[charset_name].decode('ascii')
1650)         runner = click.testing.CliRunner(mix_stderr=False)
1651)         with tests.isolated_config(
1652)             monkeypatch=monkeypatch,
1653)             runner=runner,
1654)         ):
1655)             _result = runner.invoke(
1656)                 cli.derivepassphrase,
1657)                 [option, '0', '-p', DUMMY_SERVICE],
1658)                 input=DUMMY_PASSPHRASE,
1659)                 catch_exceptions=False,
1660)             )
1661)             result = tests.ReadableResult.parse(_result)
1662)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 2 months ago

1663)         assert (
1664)             result.stderr
1665)             == f"""\
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

1669)         )