8fdf780f166e815f08cdcd3c27b034501794b8c0
Marco Ricci Add prototype command-line...

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

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

Marco Ricci authored 1 month ago

7) import contextlib
Marco Ricci Add finished command-line i...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month 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 2 months ago

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

Marco Ricci authored 1 month 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 2 months ago

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

Marco Ricci authored 2 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 2 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 1 month ago

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

Marco Ricci authored 2 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 1 month ago

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

Marco Ricci authored 2 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 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month 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 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

84) ]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month 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 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

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

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

Marco Ricci authored 2 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 1 month 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 2 months ago

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

Marco Ricci authored 1 month 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 2 months ago

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

Marco Ricci authored 2 months ago

198) class TestCLI:
Marco Ricci Isolate tests properly and...

Marco Ricci authored 1 month ago

199)     def test_200_help_output(self, monkeypatch: Any) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

201)         with tests.isolated_config(
202)             monkeypatch=monkeypatch,
203)             runner=runner,
204)             config={'services': {}},
205)         ):
206)             result = runner.invoke(
207)                 cli.derivepassphrase, ['--help'], catch_exceptions=False
208)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

216) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

220)     def test_201_disable_character_set(
221)         self, monkeypatch: Any, charset_name: str
222)     ) -> None:
223)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
224)         option = f'--{charset_name}'
225)         charset = dpp.Vault._CHARSETS[charset_name].decode('ascii')
226)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Isolate tests properly and...

Marco Ricci authored 1 month ago

227)         with tests.isolated_config(
228)             monkeypatch=monkeypatch,
229)             runner=runner,
230)             config={'services': {}},
231)         ):
232)             result = runner.invoke(
233)                 cli.derivepassphrase,
234)                 [option, '0', '-p', DUMMY_SERVICE],
235)                 input=DUMMY_PASSPHRASE,
236)                 catch_exceptions=False,
237)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

238)         assert (
239)             result.exit_code == 0
240)         ), f'program died unexpectedly with exit code {result.exit_code}'
241)         assert (
242)             not result.stderr_bytes
243)         ), f'program barfed on stderr: {result.stderr_bytes!r}'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

244)         for c in charset:
245)             assert c not in result.stdout, (
246)                 f'derived password contains forbidden character {c!r}: '
247)                 f'{result.stdout!r}'
248)             )
Marco Ricci Add prototype command-line...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

250)     def test_202_disable_repetition(self, monkeypatch: Any) -> None:
251)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
252)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Isolate tests properly and...

Marco Ricci authored 1 month ago

253)         with tests.isolated_config(
254)             monkeypatch=monkeypatch,
255)             runner=runner,
256)             config={'services': {}},
257)         ):
258)             result = runner.invoke(
259)                 cli.derivepassphrase,
260)                 ['--repeat', '0', '-p', DUMMY_SERVICE],
261)                 input=DUMMY_PASSPHRASE,
262)                 catch_exceptions=False,
263)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

264)         assert (
265)             result.exit_code == 0
266)         ), f'program died unexpectedly with exit code {result.exit_code}'
267)         assert (
268)             not result.stderr_bytes
269)         ), f'program barfed on stderr: {result.stderr_bytes!r}'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

276) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

277)     @pytest.mark.parametrize(
278)         'config',
279)         [
280)             pytest.param(
281)                 {
282)                     'global': {'key': DUMMY_KEY1_B64},
283)                     'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS},
284)                 },
285)                 id='global',
286)             ),
287)             pytest.param(
288)                 {
289)                     'global': {
290)                         'phrase': DUMMY_PASSPHRASE.rstrip(b'\n').decode(
291)                             'ASCII'
292)                         )
293)                     },
294)                     'services': {
295)                         DUMMY_SERVICE: {
296)                             'key': DUMMY_KEY1_B64,
297)                             **DUMMY_CONFIG_SETTINGS,
298)                         }
299)                     },
300)                 },
301)                 id='service',
302)             ),
303)         ],
304)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

305)     def test_204a_key_from_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

306)         self,
307)         monkeypatch: Any,
308)         config: dpp.types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

311)         with tests.isolated_config(
312)             monkeypatch=monkeypatch, runner=runner, config=config
313)         ):
314)             monkeypatch.setattr(
315)                 dpp.Vault, 'phrase_from_key', tests.phrase_from_key
Marco Ricci Add finished command-line i...

Marco Ricci authored 2 months ago

316)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

317)             result = runner.invoke(
318)                 cli.derivepassphrase, [DUMMY_SERVICE], catch_exceptions=False
319)             )
320)             assert (result.exit_code, result.stderr_bytes) == (
321)                 0,
322)                 b'',
323)             ), 'program exited with failure'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

333)         with tests.isolated_config(
334)             monkeypatch=monkeypatch,
335)             runner=runner,
336)             config={'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
337)         ):
338)             monkeypatch.setattr(
339)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
340)             )
341)             monkeypatch.setattr(
342)                 dpp.Vault, 'phrase_from_key', tests.phrase_from_key
343)             )
344)             result = runner.invoke(
345)                 cli.derivepassphrase,
346)                 ['-k', DUMMY_SERVICE],
347)                 input=b'1\n',
348)                 catch_exceptions=False,
349)             )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

353)             assert (
354)                 last_line.rstrip(b'\n') != DUMMY_RESULT_PASSPHRASE
355)             ), 'program generated unexpected result (phrase instead of key)'
356)             assert (
357)                 last_line.rstrip(b'\n') == DUMMY_RESULT_KEY1
358)             ), 'program generated unexpected result (wrong settings?)'
Marco Ricci Add finished command-line i...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

360)     def test_205_service_phrase_if_key_in_global_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

361)         self,
362)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

363)     ) -> None:
364)         runner = click.testing.CliRunner(mix_stderr=False)
365)         with tests.isolated_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

366)             monkeypatch=monkeypatch,
367)             runner=runner,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

368)             config={
369)                 'global': {'key': DUMMY_KEY1_B64},
370)                 'services': {
371)                     DUMMY_SERVICE: {
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

372)                         'phrase': DUMMY_PASSPHRASE.rstrip(b'\n').decode(
373)                             'ASCII'
374)                         ),
375)                         **DUMMY_CONFIG_SETTINGS,
376)                     }
377)                 },
378)             },
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

379)         ):
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

380)             result = runner.invoke(
381)                 cli.derivepassphrase, [DUMMY_SERVICE], catch_exceptions=False
382)             )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

386)             assert (
387)                 last_line.rstrip(b'\n') != DUMMY_RESULT_KEY1
388)             ), 'program generated unexpected result (key instead of phrase)'
389)             assert (
390)                 last_line.rstrip(b'\n') == DUMMY_RESULT_PASSPHRASE
391)             ), 'program generated unexpected result (wrong settings?)'
Marco Ricci Add finished command-line i...

Marco Ricci authored 2 months ago

392) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

393)     @pytest.mark.parametrize(
394)         'option',
395)         [
396)             '--lower',
397)             '--upper',
398)             '--number',
399)             '--space',
400)             '--dash',
401)             '--symbol',
402)             '--repeat',
403)             '--length',
404)         ],
405)     )
Marco Ricci Isolate tests properly and...

Marco Ricci authored 1 month ago

406)     def test_210_invalid_argument_range(
407)         self, monkeypatch: Any, option: str
408)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

410)         with tests.isolated_config(
411)             monkeypatch=monkeypatch,
412)             runner=runner,
413)             config={'services': {}},
414)         ):
415)             for value in '-42', 'invalid':
416)                 result = runner.invoke(
417)                     cli.derivepassphrase,
418)                     [option, value, '-p', DUMMY_SERVICE],
419)                     input=DUMMY_PASSPHRASE,
420)                     catch_exceptions=False,
421)                 )
422)                 assert result.exit_code > 0, 'program unexpectedly succeeded'
423)                 assert (
424)                     result.stderr_bytes
425)                 ), 'program did not print any error message'
426)                 assert (
427)                     b'Error: Invalid value' in result.stderr_bytes
428)                 ), 'program did not print the expected error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

429) 
430)     @pytest.mark.parametrize(
431)         ['options', 'service', 'input', 'check_success'],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

432)         [
433)             (o.options, o.needs_service, o.input, o.check_success)
434)             for o in INTERESTING_OPTION_COMBINATIONS
435)             if not o.incompatible
436)         ],
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

437)     )
438)     def test_211_service_needed(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

439)         self,
440)         monkeypatch: Any,
441)         options: list[str],
442)         service: bool | None,
443)         input: bytes | None,
444)         check_success: bool,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

448)         with tests.isolated_config(
449)             monkeypatch=monkeypatch,
450)             runner=runner,
451)             config={'global': {'phrase': 'abc'}, 'services': {}},
452)         ):
453)             result = runner.invoke(
454)                 cli.derivepassphrase,
455)                 options if service else [*options, DUMMY_SERVICE],
456)                 input=input,
457)                 catch_exceptions=False,
458)             )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

460)                 assert result.exit_code > 0, 'program unexpectedly succeeded'
461)                 assert (
462)                     result.stderr_bytes
463)                 ), 'program did not print any error message'
464)                 err_msg = (
465)                     b' requires a SERVICE'
466)                     if service
467)                     else b' does not take a SERVICE argument'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

468)                 )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

472)             else:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

477)         if check_success:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

478)             with tests.isolated_config(
479)                 monkeypatch=monkeypatch,
480)                 runner=runner,
481)                 config={'global': {'phrase': 'abc'}, 'services': {}},
482)             ):
483)                 monkeypatch.setattr(
484)                     cli, '_prompt_for_passphrase', tests.auto_prompt
485)                 )
486)                 result = runner.invoke(
487)                     cli.derivepassphrase,
488)                     [*options, DUMMY_SERVICE] if service else options,
489)                     input=input,
490)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

491)                 )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

492)                 assert (result.exit_code, result.stderr_bytes) == (
493)                     0,
494)                     b'',
495)                 ), 'program unexpectedly failed'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

496) 
497)     @pytest.mark.parametrize(
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

499)         [
500)             (o.options, o.needs_service)
501)             for o in INTERESTING_OPTION_COMBINATIONS
502)             if o.incompatible
503)         ],
Marco Ricci Add finished command-line i...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

505)     def test_212_incompatible_options(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

506)         self,
Marco Ricci Isolate tests properly and...

Marco Ricci authored 1 month ago

507)         monkeypatch: Any,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

512)         with tests.isolated_config(
513)             monkeypatch=monkeypatch,
514)             runner=runner,
515)             config={'services': {}},
516)         ):
517)             result = runner.invoke(
518)                 cli.derivepassphrase,
519)                 [*options, DUMMY_SERVICE] if service else options,
520)                 input=DUMMY_PASSPHRASE,
521)                 catch_exceptions=False,
522)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

523)         assert result.exit_code > 0, 'program unexpectedly succeeded'
524)         assert result.stderr_bytes, 'program did not print any error message'
525)         assert (
526)             b'mutually exclusive with ' in result.stderr_bytes
527)         ), 'program did not print the expected error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

529)     def test_213_import_bad_config_not_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

530)         self,
531)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

534)         with tests.isolated_config(
535)             monkeypatch=monkeypatch, runner=runner, config={'services': {}}
536)         ):
537)             result = runner.invoke(
538)                 cli.derivepassphrase,
539)                 ['--import', '-'],
540)                 input=b'null',
541)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

542)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

543)             assert result.exit_code > 0, 'program unexpectedly succeeded'
544)             assert (
545)                 result.stderr_bytes
546)             ), 'program did not print any error message'
547)             assert (
548)                 b'not a valid config' in result.stderr_bytes
549)             ), 'program did not print the expected error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

551)     def test_213a_import_bad_config_not_json_data(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

552)         self,
553)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

556)         with tests.isolated_config(
557)             monkeypatch=monkeypatch, runner=runner, config={'services': {}}
558)         ):
559)             result = runner.invoke(
560)                 cli.derivepassphrase,
561)                 ['--import', '-'],
562)                 input=b'This string is not valid JSON.',
563)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

564)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

565)             assert result.exit_code > 0, 'program unexpectedly succeeded'
566)             assert (
567)                 result.stderr_bytes
568)             ), 'program did not print any error message'
569)             assert (
570)                 b'cannot decode JSON' in result.stderr_bytes
571)             ), 'program did not print the expected error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

573)     def test_213b_import_bad_config_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

581)         with tests.isolated_config(
582)             monkeypatch=monkeypatch, runner=runner, config={'services': {}}
583)         ):
584)             with open(
585)                 cli._config_filename(), 'w', encoding='UTF-8'
586)             ) as outfile:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

593)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

594)             assert result.exit_code > 0, 'program unexpectedly succeeded'
595)             assert (
596)                 result.stderr_bytes
597)             ), 'program did not print any error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

602)         self,
603)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

606)         with tests.isolated_config(
607)             monkeypatch=monkeypatch, runner=runner, config={'services': {}}
608)         ):
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

613)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

614)             assert (result.exit_code, result.stderr_bytes) == (
615)                 0,
616)                 b'',
617)             ), 'program exited with failure'
Marco Ricci Add finished command-line i...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

619)     def test_214a_export_settings_bad_stored_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

620)         self,
621)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

624)         with tests.isolated_config(
625)             monkeypatch=monkeypatch, runner=runner, config={}
626)         ):
627)             result = runner.invoke(
628)                 cli.derivepassphrase,
629)                 ['--export', '-'],
630)                 input=b'null',
631)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

632)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

641)     def test_214b_export_settings_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

642)         self,
643)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

646)         with tests.isolated_config(
647)             monkeypatch=monkeypatch, runner=runner, config={'services': {}}
648)         ):
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

650)                 os.remove(cli._config_filename())
651)             os.makedirs(cli._config_filename())
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

652)             result = runner.invoke(
653)                 cli.derivepassphrase,
654)                 ['--export', '-'],
655)                 input=b'null',
656)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

657)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

658)             assert result.exit_code > 0, 'program unexpectedly succeeded'
659)             assert (
660)                 result.stderr_bytes
661)             ), 'program did not print any error message'
662)             assert (
663)                 b'cannot load config' in result.stderr_bytes
664)             ), 'program did not print the expected error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

666)     def test_214c_export_settings_target_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

667)         self,
668)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

671)         with tests.isolated_config(
672)             monkeypatch=monkeypatch, runner=runner, config={'services': {}}
673)         ):
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

675)             result = runner.invoke(
676)                 cli.derivepassphrase,
677)                 ['--export', os.fsdecode(dname)],
678)                 input=b'null',
679)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

680)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

681)             assert result.exit_code > 0, 'program unexpectedly succeeded'
682)             assert (
683)                 result.stderr_bytes
684)             ), 'program did not print any error message'
685)             assert (
686)                 b'cannot write config' in result.stderr_bytes
687)             ), 'program did not print the expected error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

691) 
692) # - - - - - >8 - - - - - >8 - - - - - >8 - - - - - >8 - - - - -
693) contents go here
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

704)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

705)             assert (result.exit_code, result.stderr_bytes) == (
706)                 0,
707)                 b'',
708)             ), 'program exited with failure'
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

711)             assert config == {
712)                 'global': {'phrase': 'abc'},
713)                 'services': {'sv': {'notes': 'contents go here'}},
714)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

718)         with tests.isolated_config(
719)             monkeypatch=monkeypatch,
720)             runner=runner,
721)             config={'global': {'phrase': 'abc'}, 'services': {}},
722)         ):
723)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: None)  # noqa: ARG005
724)             result = runner.invoke(
725)                 cli.derivepassphrase, ['--notes', 'sv'], catch_exceptions=False
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

726)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

727)             assert (result.exit_code, result.stderr_bytes) == (
728)                 0,
729)                 b'',
730)             ), 'program exited with failure'
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

732)                 config = json.load(infile)
733)             assert config == {'global': {'phrase': 'abc'}, 'services': {}}
734) 
735)     def test_222_edit_notes_marker_removed(self, monkeypatch: Any) -> None:
736)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

745)             )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

746)             assert (result.exit_code, result.stderr_bytes) == (
747)                 0,
748)                 b'',
749)             ), 'program exited with failure'
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

752)             assert config == {
753)                 'global': {'phrase': 'abc'},
754)                 'services': {'sv': {'notes': 'long\ntext'}},
755)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

759)         with tests.isolated_config(
760)             monkeypatch=monkeypatch,
761)             runner=runner,
762)             config={'global': {'phrase': 'abc'}, 'services': {}},
763)         ):
764)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: '\n\n')  # noqa: ARG005
765)             result = runner.invoke(
766)                 cli.derivepassphrase, ['--notes', 'sv'], catch_exceptions=False
767)             )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

777)     @pytest.mark.parametrize(
778)         ['command_line', 'input', 'result_config'],
779)         [
780)             (
781)                 ['--phrase'],
782)                 b'my passphrase\n',
783)                 {'global': {'phrase': 'my passphrase'}, 'services': {}},
784)             ),
785)             (
786)                 ['--key'],
787)                 b'1\n',
788)                 {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
789)             ),
790)             (
791)                 ['--phrase', 'sv'],
792)                 b'my passphrase\n',
793)                 {
794)                     'global': {'phrase': 'abc'},
795)                     'services': {'sv': {'phrase': 'my passphrase'}},
796)                 },
797)             ),
798)             (
799)                 ['--key', 'sv'],
800)                 b'1\n',
801)                 {
802)                     'global': {'phrase': 'abc'},
803)                     'services': {'sv': {'key': DUMMY_KEY1_B64}},
804)                 },
805)             ),
806)             (
807)                 ['--key', '--length', '15', 'sv'],
808)                 b'1\n',
809)                 {
810)                     'global': {'phrase': 'abc'},
811)                     'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
812)                 },
813)             ),
814)         ],
815)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

816)     def test_224_store_config_good(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

817)         self,
818)         monkeypatch: Any,
819)         command_line: list[str],
820)         input: bytes,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

821)         result_config: Any,
822)     ) -> None:
823)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

824)         with tests.isolated_config(
825)             monkeypatch=monkeypatch,
826)             runner=runner,
827)             config={'global': {'phrase': 'abc'}, 'services': {}},
828)         ):
829)             monkeypatch.setattr(
830)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
831)             )
832)             result = runner.invoke(
833)                 cli.derivepassphrase,
834)                 ['--config', *command_line],
835)                 catch_exceptions=False,
836)                 input=input,
837)             )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

841)             assert (
842)                 config == result_config
843)             ), 'stored config does not match expectation'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

844) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

845)     @pytest.mark.parametrize(
846)         ['command_line', 'input', 'err_text'],
847)         [
848)             (
849)                 [],
850)                 b'',
851)                 b'cannot update global settings without actual settings',
852)             ),
853)             (
854)                 ['sv'],
855)                 b'',
856)                 b'cannot update service settings without actual settings',
857)             ),
858)             (['--phrase', 'sv'], b'', b'no passphrase given'),
859)             (['--key'], b'', b'no valid SSH key selected'),
860)         ],
861)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

862)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

863)         self,
864)         monkeypatch: Any,
865)         command_line: list[str],
866)         input: bytes,
867)         err_text: bytes,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

870)         with tests.isolated_config(
871)             monkeypatch=monkeypatch,
872)             runner=runner,
873)             config={'global': {'phrase': 'abc'}, 'services': {}},
874)         ):
875)             monkeypatch.setattr(
876)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
877)             )
878)             result = runner.invoke(
879)                 cli.derivepassphrase,
880)                 ['--config', *command_line],
881)                 catch_exceptions=False,
882)                 input=input,
883)             )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

889) 
890)     def test_225a_store_config_fail_manual_no_ssh_key_selection(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

891)         self,
892)         monkeypatch: Any,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

895)         with tests.isolated_config(
896)             monkeypatch=monkeypatch,
897)             runner=runner,
898)             config={'global': {'phrase': 'abc'}, 'services': {}},
899)         ):
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

906)             result = runner.invoke(
907)                 cli.derivepassphrase,
908)                 ['--key', '--config'],
909)                 catch_exceptions=False,
910)             )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

913)             assert (
914)                 custom_error.encode() in result.stderr_bytes
915)             ), 'expected error message missing'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

916) 
Marco Ricci Isolate tests properly and...

Marco Ricci authored 1 month ago

917)     def test_226_no_arguments(self, monkeypatch: Any) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

919)         with tests.isolated_config(
920)             monkeypatch=monkeypatch,
921)             runner=runner,
922)             config={'services': {}},
923)         ):
924)             result = runner.invoke(
925)                 cli.derivepassphrase, [], catch_exceptions=False
926)             )
Marco Ricci Add finished command-line i...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

932) 
Marco Ricci Isolate tests properly and...

Marco Ricci authored 1 month ago

933)     def test_226a_no_passphrase_or_key(self, monkeypatch: Any) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

935)         with tests.isolated_config(
936)             monkeypatch=monkeypatch,
937)             runner=runner,
938)             config={'services': {}},
939)         ):
940)             result = runner.invoke(
941)                 cli.derivepassphrase, [DUMMY_SERVICE], catch_exceptions=False
942)             )
Marco Ricci Add finished command-line i...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

948) 
949) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

953)         with (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

954)             tests.isolated_config(
955)                 monkeypatch=monkeypatch, runner=runner, config={}
956)             ),
957)             pytest.raises(ValueError, match='Invalid vault config'),
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

966)             # from https://montypython.fandom.com/wiki/Spam#The_menu
967)             items = items or [
968)                 'Egg and bacon',
969)                 'Egg, sausage and bacon',
970)                 'Egg and spam',
971)                 'Egg, bacon and spam',
972)                 'Egg, bacon, sausage and spam',
973)                 'Spam, bacon, sausage and spam',
974)                 'Spam, egg, spam, spam, bacon and spam',
975)                 'Spam, spam, spam, egg and spam',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

976)                 (
977)                     'Spam, spam, spam, spam, spam, spam, baked beans, '
978)                     'spam, spam, spam and spam'
979)                 ),
980)                 (
981)                     'Lobster thermidor aux crevettes with a mornay sauce '
982)                     'garnished with truffle paté, brandy '
983)                     'and a fried egg on top and spam'
984)                 ),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

985)             ]
986)             index = cli._prompt_for_selection(items, heading=heading)
987)             click.echo('A fine choice: ', nl=False)
988)             click.echo(items[index])
989)             click.echo('(Note: Vikings strictly optional.)')
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

994)         assert (
995)             result.stdout
996)             == """\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

997) Our menu:
998) [1] Egg and bacon
999) [2] Egg, sausage and bacon
1000) [3] Egg and spam
1001) [4] Egg, bacon and spam
1002) [5] Egg, bacon, sausage and spam
1003) [6] Spam, bacon, sausage and spam
1004) [7] Spam, egg, spam, spam, bacon and spam
1005) [8] Spam, spam, spam, egg and spam
1006) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1007) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
1008) Your selection? (1-10, leave empty to abort): 9
1009) A fine choice: Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1010) (Note: Vikings strictly optional.)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

1011) """  # noqa: E501
1012)         ), 'driver program produced unexpected output'
1013)         result = runner.invoke(
1014)             driver, ['--heading='], input='', catch_exceptions=True
1015)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

1017)         assert (
1018)             result.stdout
1019)             == """\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

1020) [1] Egg and bacon
1021) [2] Egg, sausage and bacon
1022) [3] Egg and spam
1023) [4] Egg, bacon and spam
1024) [5] Egg, bacon, sausage and spam
1025) [6] Spam, bacon, sausage and spam
1026) [7] Spam, egg, spam, spam, bacon and spam
1027) [8] Spam, spam, spam, egg and spam
1028) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1029) [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 1 month ago

1030) Your selection? (1-10, leave empty to abort):\x20
1031) """  # noqa: E501
1032)         ), 'driver program produced unexpected output'
1033)         assert isinstance(
1034)             result.exception, IndexError
1035)         ), 'driver program did not raise IndexError?!'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

1042)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

1043)                 cli._prompt_for_selection(
1044)                     [item], heading='', single_choice_prompt=prompt
1045)                 )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

1057)         assert (
1058)             result.stdout
1059)             == """\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

1063) """
1064)         ), 'driver program produced unexpected output'
1065)         result = runner.invoke(
1066)             driver,
1067)             ['Will replace with spam, okay? ' '(Please say "y" or "n".)'],
1068)             input='',
1069)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

1071)         assert (
1072)             result.stdout
1073)             == """\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

1076) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

1077) """
1078)         ), 'driver program produced unexpected output'
1079)         assert isinstance(
1080)             result.exception, IndexError
1081)         ), 'driver program did not raise IndexError?!'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

1084)         monkeypatch.setattr(
1085)             click,
1086)             'prompt',
1087)             lambda *a, **kw: json.dumps({'args': a, 'kwargs': kw}),
1088)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

1090)         err_msg = 'missing arguments to passphrase prompt'
1091)         assert 'args' in res, err_msg
1092)         assert 'kwargs' in res, err_msg
1093)         assert res['args'][:1] == ['Passphrase'], err_msg
1094)         assert res['kwargs'].get('default') == '', err_msg
1095)         assert not res['kwargs'].get('show_default', True), err_msg
1096)         assert res['kwargs'].get('err'), err_msg
1097)         assert res['kwargs'].get('hide_input'), err_msg
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

1098) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

1099)     @pytest.mark.parametrize(
1100)         ['command_line', 'config', 'result_config'],
1101)         [
1102)             (
1103)                 ['--delete-globals'],
1104)                 {'global': {'phrase': 'abc'}, 'services': {}},
1105)                 {'services': {}},
1106)             ),
1107)             (
1108)                 ['--delete', DUMMY_SERVICE],
1109)                 {
1110)                     'global': {'phrase': 'abc'},
1111)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
1112)                 },
1113)                 {'global': {'phrase': 'abc'}, 'services': {}},
1114)             ),
1115)             (
1116)                 ['--clear'],
1117)                 {
1118)                     'global': {'phrase': 'abc'},
1119)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
1120)                 },
1121)                 {'services': {}},
1122)             ),
1123)         ],
1124)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

1125)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

1126)         self,
1127)         monkeypatch: Any,
1128)         command_line: list[str],
1129)         config: dpp.types.VaultConfig,
1130)         result_config: dpp.types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

1134)             with tests.isolated_config(
1135)                 monkeypatch=monkeypatch, runner=runner, config=start_config
1136)             ):
1137)                 result = runner.invoke(
1138)                     cli.derivepassphrase, command_line, catch_exceptions=False
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

1139)                 )
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

1140)                 assert (result.exit_code, result.stderr_bytes) == (
1141)                     0,
1142)                     b'',
1143)                 ), 'program exited with failure'
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

1145)                     config_readback = json.load(infile)
1146)                 assert config_readback == result_config
1147) 
1148)     def test_204_phrase_from_key_manually(self) -> None:
1149)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

1150)             dpp.Vault(
1151)                 phrase=DUMMY_PHRASE_FROM_KEY1, **DUMMY_CONFIG_SETTINGS
1152)             ).generate(DUMMY_SERVICE)
1153)             == DUMMY_RESULT_KEY1
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

1154)         )
1155) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

1156)     @pytest.mark.parametrize(
1157)         ['vfunc', 'input'],
1158)         [
1159)             (cli._validate_occurrence_constraint, 20),
1160)             (cli._validate_length, 20),
1161)         ],
1162)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

1163)     def test_210a_validate_constraints_manually(
1164)         self,
1165)         vfunc: Callable[[click.Context, click.Parameter, Any], int | None],
1166)         input: int,
1167)     ) -> None:
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

1169)         param = cli.derivepassphrase.params[0]
1170)         assert vfunc(ctx, param, input) == input
1171) 
1172)     @tests.skip_if_no_agent
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

1174)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 1 month ago

1175)         self,
1176)         monkeypatch: Any,
1177)         conn_hint: str,
Marco Ricci Fix miscellaneous type chec...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

1179)         monkeypatch.setattr(
1180)             ssh_agent_client.SSHAgentClient, 'list_keys', tests.list_keys
1181)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 2 months ago

1182)         hint: ssh_agent_client.SSHAgentClient | socket.socket | None
1183)         match conn_hint:
1184)             case 'client':
1185)                 hint = ssh_agent_client.SSHAgentClient()
1186)             case 'socket':
1187)                 hint = socket.socket(family=socket.AF_UNIX)
1188)                 hint.connect(os.environ['SSH_AUTH_SOCK'])
1189)             case _:
1190)                 assert conn_hint == 'none'
1191)                 hint = None
1192)         exception: Exception | None = None
1193)         try:
1194)             list(cli._get_suitable_ssh_keys(hint))
1195)         except RuntimeError:  # pragma: no cover
1196)             pass
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

1198)             exception = e
1199)         finally: