99863c4d7b2a3ee8f7b0d0d3e3f924afe7d40fb8
Marco Ricci Add prototype command-line...

Marco Ricci authored 4 months ago

1) # SPDX-FileCopyrightText: 2024 Marco Ricci <m@the13thletter.info>
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 Add finished command-line i...

Marco Ricci authored 4 months ago

8) import json
9) import os
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

10) import socket
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

11) from typing import TYPE_CHECKING, cast
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

13) import click.testing
14) import pytest
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

19) import tests
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

27) DUMMY_SERVICE = tests.DUMMY_SERVICE
28) DUMMY_PASSPHRASE = tests.DUMMY_PASSPHRASE
29) DUMMY_CONFIG_SETTINGS = tests.DUMMY_CONFIG_SETTINGS
30) DUMMY_RESULT_PASSPHRASE = tests.DUMMY_RESULT_PASSPHRASE
31) DUMMY_RESULT_KEY1 = tests.DUMMY_RESULT_KEY1
32) DUMMY_PHRASE_FROM_KEY1_RAW = tests.DUMMY_PHRASE_FROM_KEY1_RAW
33) DUMMY_PHRASE_FROM_KEY1 = tests.DUMMY_PHRASE_FROM_KEY1
34) 
35) DUMMY_KEY1 = tests.DUMMY_KEY1
36) DUMMY_KEY1_B64 = tests.DUMMY_KEY1_B64
37) DUMMY_KEY2 = tests.DUMMY_KEY2
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

38) 
39) 
40) class IncompatibleConfiguration(NamedTuple):
41)     other_options: list[tuple[str, ...]]
42)     needs_service: bool | None
43)     input: bytes | None
44) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

46) class SingleConfiguration(NamedTuple):
47)     needs_service: bool | None
48)     input: bytes | None
49)     check_success: bool
50) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

52) class OptionCombination(NamedTuple):
53)     options: list[str]
54)     incompatible: bool
55)     needs_service: bool | None
56)     input: bytes | None
57)     check_success: bool
58) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

61)     ('--phrase',),
62)     ('--key',),
63)     ('--length', '20'),
64)     ('--repeat', '20'),
65)     ('--lower', '1'),
66)     ('--upper', '1'),
67)     ('--number', '1'),
68)     ('--space', '1'),
69)     ('--dash', '1'),
70)     ('--symbol', '1'),
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

73)     ('--notes',),
74)     ('--config',),
75)     ('--delete',),
76)     ('--delete-globals',),
77)     ('--clear',),
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

84) ]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

89)         True,
90)         DUMMY_PASSPHRASE,
91)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

120)         [
121)             ('--config',),
122)             ('--delete',),
123)             ('--delete-globals',),
124)             ('--clear',),
125)             *STORAGE_OPTIONS,
126)         ],
127)         True,
128)         None,
129)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

131)         [('--delete',), ('--delete-globals',), ('--clear',), *STORAGE_OPTIONS],
132)         None,
133)         DUMMY_PASSPHRASE,
134)     ),
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

143)         [('--import', '-')], False, None
144)     ),
145)     ('--import', '-'): IncompatibleConfiguration([], False, None),
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

146) }
147) SINGLES: dict[tuple[str, ...], SingleConfiguration] = {
148)     ('--phrase',): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
149)     ('--key',): SingleConfiguration(True, None, False),
150)     ('--length', '20'): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
151)     ('--repeat', '20'): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
152)     ('--lower', '1'): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
153)     ('--upper', '1'): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
154)     ('--number', '1'): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
155)     ('--space', '1'): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
156)     ('--dash', '1'): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
157)     ('--symbol', '1'): SingleConfiguration(True, DUMMY_PASSPHRASE, True),
158)     ('--notes',): SingleConfiguration(True, None, False),
159)     ('--config', '-p'): SingleConfiguration(None, DUMMY_PASSPHRASE, False),
160)     ('--delete',): SingleConfiguration(True, None, False),
161)     ('--delete-globals',): SingleConfiguration(False, None, True),
162)     ('--clear',): SingleConfiguration(False, None, True),
163)     ('--export', '-'): SingleConfiguration(False, None, True),
164)     ('--import', '-'): SingleConfiguration(False, b'{"services": {}}', True),
165) }
166) INTERESTING_OPTION_COMBINATIONS: list[OptionCombination] = []
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

168) for opt, config in INCOMPATIBLE.items():
169)     for opt2 in config.other_options:
170)         INTERESTING_OPTION_COMBINATIONS.extend([
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

185)         ])
186) for opt, config in SINGLES.items():
187)     INTERESTING_OPTION_COMBINATIONS.append(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

188)         OptionCombination(
189)             options=list(opt),
190)             incompatible=False,
191)             needs_service=config.needs_service,
192)             input=config.input,
193)             check_success=config.check_success,
194)         )
195)     )
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

196) 
197) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

198) class TestCLI:
199)     def test_200_help_output(self):
200)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

201)         result = runner.invoke(
202)             cli.derivepassphrase, ['--help'], catch_exceptions=False
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

203)         )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

204)         assert result.exit_code == 0
205)         assert (
206)             'Password generation:\n' in result.output
207)         ), 'Option groups not respected in help text.'
208)         assert (
209)             'Use NUMBER=0, e.g. "--symbol 0"' in result.output
210)         ), 'Option group epilog not printed.'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

211) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

215)     def test_201_disable_character_set(
216)         self, monkeypatch: Any, charset_name: str
217)     ) -> None:
218)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
219)         option = f'--{charset_name}'
220)         charset = dpp.Vault._CHARSETS[charset_name].decode('ascii')
221)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

222)         result = runner.invoke(
223)             cli.derivepassphrase,
224)             [option, '0', '-p', DUMMY_SERVICE],
225)             input=DUMMY_PASSPHRASE,
226)             catch_exceptions=False,
Marco Ricci Add prototype command-line...

Marco Ricci authored 4 months ago

227)         )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

228)         assert (
229)             result.exit_code == 0
230)         ), f'program died unexpectedly with exit code {result.exit_code}'
231)         assert (
232)             not result.stderr_bytes
233)         ), f'program barfed on stderr: {result.stderr_bytes!r}'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

234)         for c in charset:
235)             assert c not in result.stdout, (
236)                 f'derived password contains forbidden character {c!r}: '
237)                 f'{result.stdout!r}'
238)             )
Marco Ricci Add prototype command-line...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

240)     def test_202_disable_repetition(self, monkeypatch: Any) -> None:
241)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
242)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

243)         result = runner.invoke(
244)             cli.derivepassphrase,
245)             ['--repeat', '0', '-p', DUMMY_SERVICE],
246)             input=DUMMY_PASSPHRASE,
247)             catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

248)         )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

249)         assert (
250)             result.exit_code == 0
251)         ), f'program died unexpectedly with exit code {result.exit_code}'
252)         assert (
253)             not result.stderr_bytes
254)         ), f'program barfed on stderr: {result.stderr_bytes!r}'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

255)         passphrase = result.stdout.rstrip('\r\n')
256)         for i in range(len(passphrase) - 1):
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

258)                 f'derived password contains repeated character '
259)                 f'at position {i}: {result.stdout!r}'
260)             )
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

261) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

262)     @pytest.mark.parametrize(
263)         'config',
264)         [
265)             pytest.param(
266)                 {
267)                     'global': {'key': DUMMY_KEY1_B64},
268)                     'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS},
269)                 },
270)                 id='global',
271)             ),
272)             pytest.param(
273)                 {
274)                     'global': {
275)                         'phrase': DUMMY_PASSPHRASE.rstrip(b'\n').decode(
276)                             'ASCII'
277)                         )
278)                     },
279)                     'services': {
280)                         DUMMY_SERVICE: {
281)                             'key': DUMMY_KEY1_B64,
282)                             **DUMMY_CONFIG_SETTINGS,
283)                         }
284)                     },
285)                 },
286)                 id='service',
287)             ),
288)         ],
289)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

290)     def test_204a_key_from_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

291)         self,
292)         monkeypatch: Any,
293)         config: dpp.types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

294)     ) -> None:
295)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

296)         with tests.isolated_config(
297)             monkeypatch=monkeypatch, runner=runner, config=config
298)         ):
299)             monkeypatch.setattr(
300)                 dpp.Vault, 'phrase_from_key', tests.phrase_from_key
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

301)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

302)             result = runner.invoke(
303)                 cli.derivepassphrase, [DUMMY_SERVICE], catch_exceptions=False
304)             )
305)             assert (result.exit_code, result.stderr_bytes) == (
306)                 0,
307)                 b'',
308)             ), 'program exited with failure'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

309)             assert (
310)                 result.stdout_bytes.rstrip(b'\n') != DUMMY_RESULT_PASSPHRASE
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

311)             ), 'program generated unexpected result (phrase instead of key)'
312)             assert (
313)                 result.stdout_bytes.rstrip(b'\n') == DUMMY_RESULT_KEY1
314)             ), 'program generated unexpected result (wrong settings?)'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

316)     def test_204b_key_from_command_line(self, monkeypatch: Any) -> None:
317)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

318)         with tests.isolated_config(
319)             monkeypatch=monkeypatch,
320)             runner=runner,
321)             config={'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
322)         ):
323)             monkeypatch.setattr(
324)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
325)             )
326)             monkeypatch.setattr(
327)                 dpp.Vault, 'phrase_from_key', tests.phrase_from_key
328)             )
329)             result = runner.invoke(
330)                 cli.derivepassphrase,
331)                 ['-k', DUMMY_SERVICE],
332)                 input=b'1\n',
333)                 catch_exceptions=False,
334)             )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

335)             assert result.exit_code == 0, 'program exited with failure'
336)             assert result.stdout_bytes, 'program output expected'
337)             last_line = result.stdout_bytes.splitlines(True)[-1]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

338)             assert (
339)                 last_line.rstrip(b'\n') != DUMMY_RESULT_PASSPHRASE
340)             ), 'program generated unexpected result (phrase instead of key)'
341)             assert (
342)                 last_line.rstrip(b'\n') == DUMMY_RESULT_KEY1
343)             ), 'program generated unexpected result (wrong settings?)'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

345)     def test_205_service_phrase_if_key_in_global_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

346)         self,
347)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

348)     ) -> None:
349)         runner = click.testing.CliRunner(mix_stderr=False)
350)         with tests.isolated_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

351)             monkeypatch=monkeypatch,
352)             runner=runner,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

353)             config={
354)                 'global': {'key': DUMMY_KEY1_B64},
355)                 'services': {
356)                     DUMMY_SERVICE: {
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

357)                         'phrase': DUMMY_PASSPHRASE.rstrip(b'\n').decode(
358)                             'ASCII'
359)                         ),
360)                         **DUMMY_CONFIG_SETTINGS,
361)                     }
362)                 },
363)             },
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

364)         ):
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

365)             result = runner.invoke(
366)                 cli.derivepassphrase, [DUMMY_SERVICE], catch_exceptions=False
367)             )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

368)             assert result.exit_code == 0, 'program exited with failure'
369)             assert result.stdout_bytes, 'program output expected'
370)             last_line = result.stdout_bytes.splitlines(True)[-1]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

371)             assert (
372)                 last_line.rstrip(b'\n') != DUMMY_RESULT_KEY1
373)             ), 'program generated unexpected result (key instead of phrase)'
374)             assert (
375)                 last_line.rstrip(b'\n') == DUMMY_RESULT_PASSPHRASE
376)             ), 'program generated unexpected result (wrong settings?)'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

377) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

378)     @pytest.mark.parametrize(
379)         'option',
380)         [
381)             '--lower',
382)             '--upper',
383)             '--number',
384)             '--space',
385)             '--dash',
386)             '--symbol',
387)             '--repeat',
388)             '--length',
389)         ],
390)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

391)     def test_210_invalid_argument_range(self, option: str) -> None:
392)         runner = click.testing.CliRunner(mix_stderr=False)
393)         value: str | int
394)         for value in '-42', 'invalid':
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

395)             result = runner.invoke(
396)                 cli.derivepassphrase,
397)                 [option, cast(str, value), '-p', DUMMY_SERVICE],
398)                 input=DUMMY_PASSPHRASE,
399)                 catch_exceptions=False,
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

400)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

401)             assert result.exit_code > 0, 'program unexpectedly succeeded'
402)             assert (
403)                 result.stderr_bytes
404)             ), 'program did not print any error message'
405)             assert (
406)                 b'Error: Invalid value' in result.stderr_bytes
407)             ), 'program did not print the expected error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

408) 
409)     @pytest.mark.parametrize(
410)         ['options', 'service', 'input', 'check_success'],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

411)         [
412)             (o.options, o.needs_service, o.input, o.check_success)
413)             for o in INTERESTING_OPTION_COMBINATIONS
414)             if not o.incompatible
415)         ],
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

416)     )
417)     def test_211_service_needed(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

418)         self,
419)         monkeypatch: Any,
420)         options: list[str],
421)         service: bool | None,
422)         input: bytes | None,
423)         check_success: bool,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

424)     ) -> None:
425)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
426)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

427)         with tests.isolated_config(
428)             monkeypatch=monkeypatch,
429)             runner=runner,
430)             config={'global': {'phrase': 'abc'}, 'services': {}},
431)         ):
432)             result = runner.invoke(
433)                 cli.derivepassphrase,
434)                 options if service else [*options, DUMMY_SERVICE],
435)                 input=input,
436)                 catch_exceptions=False,
437)             )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

439)                 assert result.exit_code > 0, 'program unexpectedly succeeded'
440)                 assert (
441)                     result.stderr_bytes
442)                 ), 'program did not print any error message'
443)                 err_msg = (
444)                     b' requires a SERVICE'
445)                     if service
446)                     else b' does not take a SERVICE argument'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

447)                 )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

448)                 assert (
449)                     err_msg in result.stderr_bytes
450)                 ), 'program did not print the expected error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

451)             else:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

452)                 assert (result.exit_code, result.stderr_bytes) == (
453)                     0,
454)                     b'',
455)                 ), 'program unexpectedly failed'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

456)         if check_success:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

457)             with tests.isolated_config(
458)                 monkeypatch=monkeypatch,
459)                 runner=runner,
460)                 config={'global': {'phrase': 'abc'}, 'services': {}},
461)             ):
462)                 monkeypatch.setattr(
463)                     cli, '_prompt_for_passphrase', tests.auto_prompt
464)                 )
465)                 result = runner.invoke(
466)                     cli.derivepassphrase,
467)                     [*options, DUMMY_SERVICE] if service else options,
468)                     input=input,
469)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

470)                 )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

471)                 assert (result.exit_code, result.stderr_bytes) == (
472)                     0,
473)                     b'',
474)                 ), 'program unexpectedly failed'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

475) 
476)     @pytest.mark.parametrize(
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

478)         [
479)             (o.options, o.needs_service)
480)             for o in INTERESTING_OPTION_COMBINATIONS
481)             if o.incompatible
482)         ],
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

484)     def test_212_incompatible_options(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

485)         self,
486)         options: list[str],
487)         service: bool | None,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

488)     ) -> None:
489)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

490)         result = runner.invoke(
491)             cli.derivepassphrase,
492)             [*options, DUMMY_SERVICE] if service else options,
493)             input=DUMMY_PASSPHRASE,
494)             catch_exceptions=False,
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

495)         )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

496)         assert result.exit_code > 0, 'program unexpectedly succeeded'
497)         assert result.stderr_bytes, 'program did not print any error message'
498)         assert (
499)             b'mutually exclusive with ' in result.stderr_bytes
500)         ), 'program did not print the expected error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

502)     def test_213_import_bad_config_not_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

503)         self,
504)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

505)     ) -> None:
506)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

507)         with tests.isolated_config(
508)             monkeypatch=monkeypatch, runner=runner, config={'services': {}}
509)         ):
510)             result = runner.invoke(
511)                 cli.derivepassphrase,
512)                 ['--import', '-'],
513)                 input=b'null',
514)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

515)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

516)             assert result.exit_code > 0, 'program unexpectedly succeeded'
517)             assert (
518)                 result.stderr_bytes
519)             ), 'program did not print any error message'
520)             assert (
521)                 b'not a valid config' in result.stderr_bytes
522)             ), 'program did not print the expected error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

524)     def test_213a_import_bad_config_not_json_data(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

525)         self,
526)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

527)     ) -> None:
528)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

529)         with tests.isolated_config(
530)             monkeypatch=monkeypatch, runner=runner, config={'services': {}}
531)         ):
532)             result = runner.invoke(
533)                 cli.derivepassphrase,
534)                 ['--import', '-'],
535)                 input=b'This string is not valid JSON.',
536)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

537)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

538)             assert result.exit_code > 0, 'program unexpectedly succeeded'
539)             assert (
540)                 result.stderr_bytes
541)             ), 'program did not print any error message'
542)             assert (
543)                 b'cannot decode JSON' in result.stderr_bytes
544)             ), 'program did not print the expected error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

546)     def test_213b_import_bad_config_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

547)         self,
548)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

549)     ) -> None:
550)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 4 months ago

551)         # `isolated_config` validates the configuration.  So, to pass an
552)         # actual broken configuration, we must open the configuration file
553)         # ourselves afterwards, inside the context.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

554)         with tests.isolated_config(
555)             monkeypatch=monkeypatch, runner=runner, config={'services': {}}
556)         ):
557)             with open(
558)                 cli._config_filename(), 'w', encoding='UTF-8'
559)             ) as outfile:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

561)             dname = os.path.dirname(cli._config_filename())
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

562)             result = runner.invoke(
563)                 cli.derivepassphrase,
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

566)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

567)             assert result.exit_code > 0, 'program unexpectedly succeeded'
568)             assert (
569)                 result.stderr_bytes
570)             ), 'program did not print any error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

571)             # Don't test the actual error message, because it is subject to
572)             # locale settings.  TODO: find a way anyway.
573) 
574)     def test_214_export_settings_no_stored_settings(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

575)         self,
576)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

577)     ) -> None:
578)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

579)         with tests.isolated_config(
580)             monkeypatch=monkeypatch, runner=runner, config={'services': {}}
581)         ):
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

583)                 os.remove(cli._config_filename())
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

584)             result = runner.invoke(
585)                 cli.derivepassphrase, ['--export', '-'], catch_exceptions=False
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

586)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

587)             assert (result.exit_code, result.stderr_bytes) == (
588)                 0,
589)                 b'',
590)             ), 'program exited with failure'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

592)     def test_214a_export_settings_bad_stored_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

593)         self,
594)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

595)     ) -> None:
596)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

597)         with tests.isolated_config(
598)             monkeypatch=monkeypatch, runner=runner, config={}
599)         ):
600)             result = runner.invoke(
601)                 cli.derivepassphrase,
602)                 ['--export', '-'],
603)                 input=b'null',
604)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

605)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

606)             assert result.exit_code > 0, 'program unexpectedly succeeded'
607)             assert (
608)                 result.stderr_bytes
609)             ), 'program did not print any error message'
610)             assert (
611)                 b'cannot load config' in result.stderr_bytes
612)             ), 'program did not print the expected error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

614)     def test_214b_export_settings_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

615)         self,
616)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

617)     ) -> None:
618)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

619)         with tests.isolated_config(
620)             monkeypatch=monkeypatch, runner=runner, config={'services': {}}
621)         ):
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

623)                 os.remove(cli._config_filename())
624)             os.makedirs(cli._config_filename())
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

625)             result = runner.invoke(
626)                 cli.derivepassphrase,
627)                 ['--export', '-'],
628)                 input=b'null',
629)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

630)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

631)             assert result.exit_code > 0, 'program unexpectedly succeeded'
632)             assert (
633)                 result.stderr_bytes
634)             ), 'program did not print any error message'
635)             assert (
636)                 b'cannot load config' in result.stderr_bytes
637)             ), 'program did not print the expected error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

639)     def test_214c_export_settings_target_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

640)         self,
641)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

642)     ) -> None:
643)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

644)         with tests.isolated_config(
645)             monkeypatch=monkeypatch, runner=runner, config={'services': {}}
646)         ):
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

647)             dname = os.path.dirname(cli._config_filename())
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

648)             result = runner.invoke(
649)                 cli.derivepassphrase,
650)                 ['--export', os.fsdecode(dname)],
651)                 input=b'null',
652)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

653)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

654)             assert result.exit_code > 0, 'program unexpectedly succeeded'
655)             assert (
656)                 result.stderr_bytes
657)             ), 'program did not print any error message'
658)             assert (
659)                 b'cannot write config' in result.stderr_bytes
660)             ), 'program did not print the expected error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

662)     def test_220_edit_notes_successfully(self, monkeypatch: Any) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

664) 
665) # - - - - - >8 - - - - - >8 - - - - - >8 - - - - - >8 - - - - -
666) contents go here
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

668)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

669)         with tests.isolated_config(
670)             monkeypatch=monkeypatch,
671)             runner=runner,
672)             config={'global': {'phrase': 'abc'}, 'services': {}},
673)         ):
674)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: edit_result)  # noqa: ARG005
675)             result = runner.invoke(
676)                 cli.derivepassphrase, ['--notes', 'sv'], catch_exceptions=False
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

677)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

678)             assert (result.exit_code, result.stderr_bytes) == (
679)                 0,
680)                 b'',
681)             ), 'program exited with failure'
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

684)             assert config == {
685)                 'global': {'phrase': 'abc'},
686)                 'services': {'sv': {'notes': 'contents go here'}},
687)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

688) 
689)     def test_221_edit_notes_noop(self, monkeypatch: Any) -> None:
690)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

691)         with tests.isolated_config(
692)             monkeypatch=monkeypatch,
693)             runner=runner,
694)             config={'global': {'phrase': 'abc'}, 'services': {}},
695)         ):
696)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: None)  # noqa: ARG005
697)             result = runner.invoke(
698)                 cli.derivepassphrase, ['--notes', 'sv'], catch_exceptions=False
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

699)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

700)             assert (result.exit_code, result.stderr_bytes) == (
701)                 0,
702)                 b'',
703)             ), 'program exited with failure'
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

705)                 config = json.load(infile)
706)             assert config == {'global': {'phrase': 'abc'}, 'services': {}}
707) 
708)     def test_222_edit_notes_marker_removed(self, monkeypatch: Any) -> None:
709)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

710)         with tests.isolated_config(
711)             monkeypatch=monkeypatch,
712)             runner=runner,
713)             config={'global': {'phrase': 'abc'}, 'services': {}},
714)         ):
715)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: 'long\ntext')  # noqa: ARG005
716)             result = runner.invoke(
717)                 cli.derivepassphrase, ['--notes', 'sv'], catch_exceptions=False
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

718)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

719)             assert (result.exit_code, result.stderr_bytes) == (
720)                 0,
721)                 b'',
722)             ), 'program exited with failure'
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

725)             assert config == {
726)                 'global': {'phrase': 'abc'},
727)                 'services': {'sv': {'notes': 'long\ntext'}},
728)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

729) 
730)     def test_223_edit_notes_abort(self, monkeypatch: Any) -> None:
731)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

732)         with tests.isolated_config(
733)             monkeypatch=monkeypatch,
734)             runner=runner,
735)             config={'global': {'phrase': 'abc'}, 'services': {}},
736)         ):
737)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: '\n\n')  # noqa: ARG005
738)             result = runner.invoke(
739)                 cli.derivepassphrase, ['--notes', 'sv'], catch_exceptions=False
740)             )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

741)             assert result.exit_code != 0, 'program unexpectedly succeeded'
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 4 months ago

742)             assert result.stderr_bytes is not None
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

743)             assert (
744)                 b'user aborted request' in result.stderr_bytes
745)             ), 'expected error message missing'
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

750)     @pytest.mark.parametrize(
751)         ['command_line', 'input', 'result_config'],
752)         [
753)             (
754)                 ['--phrase'],
755)                 b'my passphrase\n',
756)                 {'global': {'phrase': 'my passphrase'}, 'services': {}},
757)             ),
758)             (
759)                 ['--key'],
760)                 b'1\n',
761)                 {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
762)             ),
763)             (
764)                 ['--phrase', 'sv'],
765)                 b'my passphrase\n',
766)                 {
767)                     'global': {'phrase': 'abc'},
768)                     'services': {'sv': {'phrase': 'my passphrase'}},
769)                 },
770)             ),
771)             (
772)                 ['--key', 'sv'],
773)                 b'1\n',
774)                 {
775)                     'global': {'phrase': 'abc'},
776)                     'services': {'sv': {'key': DUMMY_KEY1_B64}},
777)                 },
778)             ),
779)             (
780)                 ['--key', '--length', '15', 'sv'],
781)                 b'1\n',
782)                 {
783)                     'global': {'phrase': 'abc'},
784)                     'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
785)                 },
786)             ),
787)         ],
788)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

789)     def test_224_store_config_good(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

790)         self,
791)         monkeypatch: Any,
792)         command_line: list[str],
793)         input: bytes,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

794)         result_config: Any,
795)     ) -> None:
796)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

797)         with tests.isolated_config(
798)             monkeypatch=monkeypatch,
799)             runner=runner,
800)             config={'global': {'phrase': 'abc'}, 'services': {}},
801)         ):
802)             monkeypatch.setattr(
803)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
804)             )
805)             result = runner.invoke(
806)                 cli.derivepassphrase,
807)                 ['--config', *command_line],
808)                 catch_exceptions=False,
809)                 input=input,
810)             )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

811)             assert result.exit_code == 0, 'program exited with failure'
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

814)             assert (
815)                 config == result_config
816)             ), 'stored config does not match expectation'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

817) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

818)     @pytest.mark.parametrize(
819)         ['command_line', 'input', 'err_text'],
820)         [
821)             (
822)                 [],
823)                 b'',
824)                 b'cannot update global settings without actual settings',
825)             ),
826)             (
827)                 ['sv'],
828)                 b'',
829)                 b'cannot update service settings without actual settings',
830)             ),
831)             (['--phrase', 'sv'], b'', b'no passphrase given'),
832)             (['--key'], b'', b'no valid SSH key selected'),
833)         ],
834)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

835)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

836)         self,
837)         monkeypatch: Any,
838)         command_line: list[str],
839)         input: bytes,
840)         err_text: bytes,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

841)     ) -> None:
842)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

843)         with tests.isolated_config(
844)             monkeypatch=monkeypatch,
845)             runner=runner,
846)             config={'global': {'phrase': 'abc'}, 'services': {}},
847)         ):
848)             monkeypatch.setattr(
849)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
850)             )
851)             result = runner.invoke(
852)                 cli.derivepassphrase,
853)                 ['--config', *command_line],
854)                 catch_exceptions=False,
855)                 input=input,
856)             )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

857)             assert result.exit_code != 0, 'program unexpectedly succeeded?!'
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 4 months ago

858)             assert result.stderr_bytes is not None
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

859)             assert (
860)                 err_text in result.stderr_bytes
861)             ), 'expected error message missing'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

862) 
863)     def test_225a_store_config_fail_manual_no_ssh_key_selection(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

864)         self,
865)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

866)     ) -> None:
867)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

868)         with tests.isolated_config(
869)             monkeypatch=monkeypatch,
870)             runner=runner,
871)             config={'global': {'phrase': 'abc'}, 'services': {}},
872)         ):
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

875)             def raiser():
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

878)             monkeypatch.setattr(cli, '_select_ssh_key', raiser)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

879)             result = runner.invoke(
880)                 cli.derivepassphrase,
881)                 ['--key', '--config'],
882)                 catch_exceptions=False,
883)             )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

884)             assert result.exit_code != 0, 'program unexpectedly succeeded'
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 4 months ago

885)             assert result.stderr_bytes is not None
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

886)             assert (
887)                 custom_error.encode() in result.stderr_bytes
888)             ), 'expected error message missing'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

889) 
890)     def test_226_no_arguments(self) -> None:
891)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

892)         result = runner.invoke(
893)             cli.derivepassphrase, [], catch_exceptions=False
894)         )
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

895)         assert result.exit_code != 0, 'program unexpectedly succeeded'
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 4 months ago

896)         assert result.stderr_bytes is not None
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

897)         assert (
898)             b'SERVICE is required' in result.stderr_bytes
899)         ), 'expected error message missing'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

901)     def test_226a_no_passphrase_or_key(self) -> None:
902)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

903)         result = runner.invoke(
904)             cli.derivepassphrase, [DUMMY_SERVICE], catch_exceptions=False
905)         )
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

906)         assert result.exit_code != 0, 'program unexpectedly succeeded'
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 4 months ago

907)         assert result.stderr_bytes is not None
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

908)         assert (
909)             b'no passphrase or key given' in result.stderr_bytes
910)         ), 'expected error message missing'
Marco Ricci Add finished command-line i...

Marco Ricci authored 4 months ago

911) 
912) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

913) class TestCLIUtils:
914)     def test_100_save_bad_config(self, monkeypatch: Any) -> None:
915)         runner = click.testing.CliRunner()
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

916)         with (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

917)             tests.isolated_config(
918)                 monkeypatch=monkeypatch, runner=runner, config={}
919)             ),
920)             pytest.raises(ValueError, match='Invalid vault config'),
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

921)         ):
922)             cli._save_config(None)  # type: ignore
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

925)         @click.command()
926)         @click.option('--heading', default='Our menu:')
927)         @click.argument('items', nargs=-1)
928)         def driver(heading, items):
929)             # from https://montypython.fandom.com/wiki/Spam#The_menu
930)             items = items or [
931)                 'Egg and bacon',
932)                 'Egg, sausage and bacon',
933)                 'Egg and spam',
934)                 'Egg, bacon and spam',
935)                 'Egg, bacon, sausage and spam',
936)                 'Spam, bacon, sausage and spam',
937)                 'Spam, egg, spam, spam, bacon and spam',
938)                 'Spam, spam, spam, egg and spam',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

939)                 (
940)                     'Spam, spam, spam, spam, spam, spam, baked beans, '
941)                     'spam, spam, spam and spam'
942)                 ),
943)                 (
944)                     'Lobster thermidor aux crevettes with a mornay sauce '
945)                     'garnished with truffle paté, brandy '
946)                     'and a fried egg on top and spam'
947)                 ),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

948)             ]
949)             index = cli._prompt_for_selection(items, heading=heading)
950)             click.echo('A fine choice: ', nl=False)
951)             click.echo(items[index])
952)             click.echo('(Note: Vikings strictly optional.)')
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

954)         runner = click.testing.CliRunner(mix_stderr=True)
955)         result = runner.invoke(driver, [], input='9')
956)         assert result.exit_code == 0, 'driver program failed'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

957)         assert (
958)             result.stdout
959)             == """\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

960) Our menu:
961) [1] Egg and bacon
962) [2] Egg, sausage and bacon
963) [3] Egg and spam
964) [4] Egg, bacon and spam
965) [5] Egg, bacon, sausage and spam
966) [6] Spam, bacon, sausage and spam
967) [7] Spam, egg, spam, spam, bacon and spam
968) [8] Spam, spam, spam, egg and spam
969) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
970) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
971) Your selection? (1-10, leave empty to abort): 9
972) A fine choice: Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
973) (Note: Vikings strictly optional.)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

974) """  # noqa: E501
975)         ), 'driver program produced unexpected output'
976)         result = runner.invoke(
977)             driver, ['--heading='], input='', catch_exceptions=True
978)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

979)         assert result.exit_code > 0, 'driver program succeeded?!'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

980)         assert (
981)             result.stdout
982)             == """\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

983) [1] Egg and bacon
984) [2] Egg, sausage and bacon
985) [3] Egg and spam
986) [4] Egg, bacon and spam
987) [5] Egg, bacon, sausage and spam
988) [6] Spam, bacon, sausage and spam
989) [7] Spam, egg, spam, spam, bacon and spam
990) [8] Spam, spam, spam, egg and spam
991) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
992) [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

993) Your selection? (1-10, leave empty to abort):\x20
994) """  # noqa: E501
995)         ), 'driver program produced unexpected output'
996)         assert isinstance(
997)             result.exception, IndexError
998)         ), 'driver program did not raise IndexError?!'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1001)         @click.command()
1002)         @click.option('--item', default='baked beans')
1003)         @click.argument('prompt')
1004)         def driver(item, prompt):
1005)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1006)                 cli._prompt_for_selection(
1007)                     [item], heading='', single_choice_prompt=prompt
1008)                 )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1015)         runner = click.testing.CliRunner(mix_stderr=True)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1016)         result = runner.invoke(
1017)             driver, ['Will replace with spam. Confirm, y/n?'], input='y'
1018)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1019)         assert result.exit_code == 0, 'driver program failed'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1020)         assert (
1021)             result.stdout
1022)             == """\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1026) """
1027)         ), 'driver program produced unexpected output'
1028)         result = runner.invoke(
1029)             driver,
1030)             ['Will replace with spam, okay? ' '(Please say "y" or "n".)'],
1031)             input='',
1032)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1033)         assert result.exit_code > 0, 'driver program succeeded?!'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1034)         assert (
1035)             result.stdout
1036)             == """\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1039) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1040) """
1041)         ), 'driver program produced unexpected output'
1042)         assert isinstance(
1043)             result.exception, IndexError
1044)         ), 'driver program did not raise IndexError?!'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1045) 
1046)     def test_103_prompt_for_passphrase(self, monkeypatch: Any) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1047)         monkeypatch.setattr(
1048)             click,
1049)             'prompt',
1050)             lambda *a, **kw: json.dumps({'args': a, 'kwargs': kw}),
1051)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1053)         err_msg = 'missing arguments to passphrase prompt'
1054)         assert 'args' in res, err_msg
1055)         assert 'kwargs' in res, err_msg
1056)         assert res['args'][:1] == ['Passphrase'], err_msg
1057)         assert res['kwargs'].get('default') == '', err_msg
1058)         assert not res['kwargs'].get('show_default', True), err_msg
1059)         assert res['kwargs'].get('err'), err_msg
1060)         assert res['kwargs'].get('hide_input'), err_msg
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1061) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1062)     @pytest.mark.parametrize(
1063)         ['command_line', 'config', 'result_config'],
1064)         [
1065)             (
1066)                 ['--delete-globals'],
1067)                 {'global': {'phrase': 'abc'}, 'services': {}},
1068)                 {'services': {}},
1069)             ),
1070)             (
1071)                 ['--delete', DUMMY_SERVICE],
1072)                 {
1073)                     'global': {'phrase': 'abc'},
1074)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
1075)                 },
1076)                 {'global': {'phrase': 'abc'}, 'services': {}},
1077)             ),
1078)             (
1079)                 ['--clear'],
1080)                 {
1081)                     'global': {'phrase': 'abc'},
1082)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
1083)                 },
1084)                 {'services': {}},
1085)             ),
1086)         ],
1087)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1088)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1089)         self,
1090)         monkeypatch: Any,
1091)         command_line: list[str],
1092)         config: dpp.types.VaultConfig,
1093)         result_config: dpp.types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1094)     ) -> None:
1095)         runner = click.testing.CliRunner(mix_stderr=False)
1096)         for start_config in [config, result_config]:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1097)             with tests.isolated_config(
1098)                 monkeypatch=monkeypatch, runner=runner, config=start_config
1099)             ):
1100)                 result = runner.invoke(
1101)                     cli.derivepassphrase, command_line, catch_exceptions=False
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1102)                 )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1103)                 assert (result.exit_code, result.stderr_bytes) == (
1104)                     0,
1105)                     b'',
1106)                 ), 'program exited with failure'
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1108)                     config_readback = json.load(infile)
1109)                 assert config_readback == result_config
1110) 
1111)     def test_204_phrase_from_key_manually(self) -> None:
1112)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1113)             dpp.Vault(
1114)                 phrase=DUMMY_PHRASE_FROM_KEY1, **DUMMY_CONFIG_SETTINGS
1115)             ).generate(DUMMY_SERVICE)
1116)             == DUMMY_RESULT_KEY1
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1117)         )
1118) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1119)     @pytest.mark.parametrize(
1120)         ['vfunc', 'input'],
1121)         [
1122)             (cli._validate_occurrence_constraint, 20),
1123)             (cli._validate_length, 20),
1124)         ],
1125)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1126)     def test_210a_validate_constraints_manually(
1127)         self,
1128)         vfunc: Callable[[click.Context, click.Parameter, Any], int | None],
1129)         input: int,
1130)     ) -> None:
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

1131)         ctx = cli.derivepassphrase.make_context(cli.PROG_NAME, [])
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1132)         param = cli.derivepassphrase.params[0]
1133)         assert vfunc(ctx, param, input) == input
1134) 
1135)     @tests.skip_if_no_agent
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1137)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

1138)         self,
1139)         monkeypatch: Any,
1140)         conn_hint: str,
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1142)         monkeypatch.setattr(
1143)             ssh_agent_client.SSHAgentClient, 'list_keys', tests.list_keys
1144)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

1145)         hint: ssh_agent_client.SSHAgentClient | socket.socket | None
1146)         match conn_hint:
1147)             case 'client':
1148)                 hint = ssh_agent_client.SSHAgentClient()
1149)             case 'socket':
1150)                 hint = socket.socket(family=socket.AF_UNIX)
1151)                 hint.connect(os.environ['SSH_AUTH_SOCK'])
1152)             case _:
1153)                 assert conn_hint == 'none'
1154)                 hint = None
1155)         exception: Exception | None = None
1156)         try:
1157)             list(cli._get_suitable_ssh_keys(hint))
1158)         except RuntimeError:  # pragma: no cover
1159)             pass
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1161)             exception = e
1162)         finally: