c24003e853bd053cf88b2b9c3d940170dbc332ec
Marco Ricci Change the author e-mail ad...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

7) import contextlib
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

10) import json
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

11) import logging
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

12) import os
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

14) import socket
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

15) import textwrap
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

16) import warnings
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

21) import pytest
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

22) from hypothesis import stateful, strategies
23) from typing_extensions import Any, NamedTuple
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

27) 
28) if TYPE_CHECKING:
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

29)     from collections.abc import Callable, Iterable
Marco Ricci Add prototype command-line...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

53) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

93) ]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

205) 
206) 
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

207) def is_warning_line(line: str) -> bool:
208)     """Return true if the line is a warning line."""
209)     return ' Warning: ' in line or ' Deprecation warning: ' in line
210) 
211) 
212) def is_harmless_config_import_warning(record: tuple[str, int, str]) -> bool:
213)     """Return true if the warning is harmless, during config import."""
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

214)     possible_warnings = [
215)         'Replacing invalid value ',
216)         'Removing ineffective setting ',
217)         (
218)             'Setting a global passphrase is ineffective '
219)             'because a key is also set.'
220)         ),
221)         (
222)             'Setting a service passphrase is ineffective '
223)             'because a key is also set.'
224)         ),
225)     ]
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

226)     return any(tests.warning_emitted(w, [record]) for w in possible_warnings)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

227) 
228) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

239)             result = tests.ReadableResult.parse(_result)
240)         assert result.clean_exit(
241)             empty_stderr=True, output='Password generation:\n'
242)         ), 'expected clean exit, and option groups in help text'
243)         assert result.clean_exit(
244)             empty_stderr=True, output='Use NUMBER=0, e.g. "--symbol 0"'
245)         ), 'expected clean exit, and option group epilog in help text'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

246) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

262)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

263)                 [option, '0', '-p', '--', DUMMY_SERVICE],
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

264)                 input=DUMMY_PASSPHRASE,
265)                 catch_exceptions=False,
266)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

273) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

274)     def test_202_disable_repetition(
275)         self, monkeypatch: pytest.MonkeyPatch
276)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

279)         with tests.isolated_config(
280)             monkeypatch=monkeypatch,
281)             runner=runner,
282)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

284)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

285)                 ['--repeat', '0', '-p', '--', DUMMY_SERVICE],
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

286)                 input=DUMMY_PASSPHRASE,
287)                 catch_exceptions=False,
288)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

289)             result = tests.ReadableResult.parse(_result)
290)         assert result.clean_exit(
291)             empty_stderr=True
292)         ), 'expected clean exit and empty stderr'
293)         passphrase = result.output.rstrip('\r\n')
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

299) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

300)     @pytest.mark.parametrize(
301)         'config',
302)         [
303)             pytest.param(
304)                 {
305)                     'global': {'key': DUMMY_KEY1_B64},
306)                     'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS},
307)                 },
308)                 id='global',
309)             ),
310)             pytest.param(
311)                 {
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

313)                     'services': {
314)                         DUMMY_SERVICE: {
315)                             'key': DUMMY_KEY1_B64,
316)                             **DUMMY_CONFIG_SETTINGS,
317)                         }
318)                     },
319)                 },
320)                 id='service',
321)             ),
322)         ],
323)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

324)     def test_204a_key_from_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

330)         with tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

331)             monkeypatch=monkeypatch, runner=runner, vault_config=config
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

332)         ):
333)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

337)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

338)                 ['--', DUMMY_SERVICE],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

339)                 catch_exceptions=False,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

341)         result = tests.ReadableResult.parse(_result)
342)         assert result.clean_exit(
343)             empty_stderr=True
344)         ), 'expected clean exit and empty stderr'
345)         assert _result.stdout_bytes
346)         assert (
347)             _result.stdout_bytes.rstrip(b'\n') != DUMMY_RESULT_PASSPHRASE
348)         ), 'known false output: phrase-based instead of key-based'
349)         assert (
350)             _result.stdout_bytes.rstrip(b'\n') == DUMMY_RESULT_KEY1
351)         ), 'expected known output'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

352) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

353)     def test_204b_key_from_command_line(
354)         self, monkeypatch: pytest.MonkeyPatch
355)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

358)             monkeypatch=monkeypatch,
359)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

360)             vault_config={'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

361)         ):
362)             monkeypatch.setattr(
363)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
364)             )
365)             monkeypatch.setattr(
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

369)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

372)                 catch_exceptions=False,
373)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

374)         result = tests.ReadableResult.parse(_result)
375)         assert result.clean_exit(), 'expected clean exit'
376)         assert _result.stdout_bytes, 'expected program output'
377)         last_line = _result.stdout_bytes.splitlines(True)[-1]
378)         assert (
379)             last_line.rstrip(b'\n') != DUMMY_RESULT_PASSPHRASE
380)         ), 'known false output: phrase-based instead of key-based'
381)         assert (
382)             last_line.rstrip(b'\n') == DUMMY_RESULT_KEY1
383)         ), 'expected known output'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

384) 
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 5 months ago

385)     @pytest.mark.parametrize(
386)         'config',
387)         [
388)             pytest.param(
389)                 {
390)                     'global': {'key': DUMMY_KEY1_B64},
391)                     'services': {DUMMY_SERVICE: {}},
392)                 },
393)                 id='global_config',
394)             ),
395)             pytest.param(
396)                 {'services': {DUMMY_SERVICE: {'key': DUMMY_KEY2_B64}}},
397)                 id='service_config',
398)             ),
399)             pytest.param(
400)                 {
401)                     'global': {'key': DUMMY_KEY1_B64},
402)                     'services': {DUMMY_SERVICE: {'key': DUMMY_KEY2_B64}},
403)                 },
404)                 id='full_config',
405)             ),
406)         ],
407)     )
408)     @pytest.mark.parametrize('key_index', [1, 2, 3], ids=lambda i: f'index{i}')
409)     def test_204c_key_override_on_command_line(
410)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

411)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

412)         running_ssh_agent: tests.RunningSSHAgentInfo,
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 5 months ago

413)         config: dict[str, Any],
414)         key_index: int,
415)     ) -> None:
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

416)         with monkeypatch.context():
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

417)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent.socket)
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

418)             monkeypatch.setattr(
419)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

422)             runner = click.testing.CliRunner(mix_stderr=False)
423)             with tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

424)                 monkeypatch=monkeypatch, runner=runner, vault_config=config
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

425)             ):
426)                 _result = runner.invoke(
427)                     cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

428)                     ['-k', '--', DUMMY_SERVICE],
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

429)                     input=f'{key_index}\n',
430)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

431)         result = tests.ReadableResult.parse(_result)
432)         assert result.clean_exit(), 'expected clean exit'
433)         assert result.output, 'expected program output'
434)         assert result.stderr, 'expected stderr'
435)         assert (
436)             'Error:' not in result.stderr
437)         ), 'expected no error messages on stderr'
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

439)     def test_205_service_phrase_if_key_in_global_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

441)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

442)         running_ssh_agent: tests.RunningSSHAgentInfo,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

444)         with monkeypatch.context():
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

445)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent.socket)
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

446)             monkeypatch.setattr(
447)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

449)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', tests.sign)
450)             runner = click.testing.CliRunner(mix_stderr=False)
451)             with tests.isolated_vault_config(
452)                 monkeypatch=monkeypatch,
453)                 runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

454)                 vault_config={
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

455)                     'global': {'key': DUMMY_KEY1_B64},
456)                     'services': {
457)                         DUMMY_SERVICE: {
458)                             'phrase': DUMMY_PASSPHRASE.rstrip('\n'),
459)                             **DUMMY_CONFIG_SETTINGS,
460)                         }
461)                     },
462)                 },
463)             ):
464)                 _result = runner.invoke(
465)                     cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

466)                     ['--', DUMMY_SERVICE],
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

467)                     catch_exceptions=False,
468)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

469)         result = tests.ReadableResult.parse(_result)
470)         assert result.clean_exit(), 'expected clean exit'
471)         assert _result.stdout_bytes, 'expected program output'
472)         last_line = _result.stdout_bytes.splitlines(True)[-1]
473)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

479) 
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

480)     @pytest.mark.parametrize(
481)         'config',
482)         [
483)             {
484)                 'services': {
485)                     DUMMY_SERVICE: {
486)                         'key': DUMMY_KEY1_B64,
487)                         **DUMMY_CONFIG_SETTINGS,
488)                     },
489)                 },
490)             },
491)             {
492)                 'global': {'key': DUMMY_KEY1_B64},
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

493)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()},
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

494)             },
495)         ],
496)     )
497)     def test_206_setting_service_phrase_thus_overriding_key_in_config(
498)         self,
499)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

500)         running_ssh_agent: tests.RunningSSHAgentInfo,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

501)         caplog: pytest.LogCaptureFixture,
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

502)         config: _types.VaultConfig,
503)     ) -> None:
504)         with monkeypatch.context():
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

505)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent.socket)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

506)             monkeypatch.setattr(
507)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
508)             )
509)             monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', tests.sign)
510)             runner = click.testing.CliRunner(mix_stderr=False)
511)             with tests.isolated_vault_config(
512)                 monkeypatch=monkeypatch,
513)                 runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

514)                 vault_config=config,
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

515)             ):
516)                 _result = runner.invoke(
517)                     cli.derivepassphrase_vault,
518)                     ['--config', '-p', '--', DUMMY_SERVICE],
519)                     input=DUMMY_PASSPHRASE,
520)                     catch_exceptions=False,
521)                 )
522)         result = tests.ReadableResult.parse(_result)
523)         assert result.clean_exit(), 'expected clean exit'
524)         assert not result.output.strip(), 'expected no program output'
525)         assert result.stderr, 'expected known error output'
526)         err_lines = result.stderr.splitlines(False)
527)         assert err_lines[0].startswith('Passphrase:')
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

528)         assert tests.warning_emitted(
529)             'Setting a service passphrase is ineffective ',
530)             caplog.record_tuples,
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

531)         ), 'expected known warning message'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

532)         assert all(map(is_warning_line, result.stderr.splitlines(True)))
533)         assert all(
534)             map(is_harmless_config_import_warning, caplog.record_tuples)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

535)         ), 'unexpected error output'
536) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

537)     @pytest.mark.parametrize(
538)         'option',
539)         [
540)             '--lower',
541)             '--upper',
542)             '--number',
543)             '--space',
544)             '--dash',
545)             '--symbol',
546)             '--repeat',
547)             '--length',
548)         ],
549)     )
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

554)         with tests.isolated_config(
555)             monkeypatch=monkeypatch,
556)             runner=runner,
557)         ):
558)             for value in '-42', 'invalid':
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

560)                     cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

561)                     [option, value, '-p', '--', DUMMY_SERVICE],
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

562)                     input=DUMMY_PASSPHRASE,
563)                     catch_exceptions=False,
564)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

565)                 result = tests.ReadableResult.parse(_result)
566)                 assert result.error_exit(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

567)                     error='Invalid value'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

568)                 ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

569) 
570)     @pytest.mark.parametrize(
571)         ['options', 'service', 'input', 'check_success'],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

572)         [
573)             (o.options, o.needs_service, o.input, o.check_success)
574)             for o in INTERESTING_OPTION_COMBINATIONS
575)             if not o.incompatible
576)         ],
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

577)     )
578)     def test_211_service_needed(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

589)             monkeypatch=monkeypatch,
590)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

591)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

594)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

595)                 options if service else [*options, '--', DUMMY_SERVICE],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

596)                 input=input,
597)                 catch_exceptions=False,
598)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

606)                 assert result.error_exit(
607)                     error=err_msg
608)                 ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

610)                 assert result.clean_exit(
611)                     empty_stderr=True
612)                 ), 'expected clean exit'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

615)                 monkeypatch=monkeypatch,
616)                 runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

617)                 vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

618)             ):
619)                 monkeypatch.setattr(
620)                     cli, '_prompt_for_passphrase', tests.auto_prompt
621)                 )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

623)                     cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

624)                     [*options, '--', DUMMY_SERVICE] if service else options,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

625)                     input=input,
626)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

630) 
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

631)     def test_211a_empty_service_name_causes_warning(
632)         self,
633)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

634)         caplog: pytest.LogCaptureFixture,
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

635)     ) -> None:
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

636)         def is_expected_warning(record: tuple[str, int, str]) -> bool:
637)             return is_harmless_config_import_warning(
638)                 record
639)             ) or tests.warning_emitted(
640)                 'An empty SERVICE is not supported by vault(1)', [record]
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

641)             )
642) 
643)         monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt)
644)         runner = click.testing.CliRunner(mix_stderr=False)
645)         with tests.isolated_vault_config(
646)             monkeypatch=monkeypatch,
647)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

648)             vault_config={'services': {}},
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

649)         ):
650)             _result = runner.invoke(
651)                 cli.derivepassphrase_vault,
652)                 ['--config', '--length=30', '--', ''],
653)                 catch_exceptions=False,
654)             )
655)             result = tests.ReadableResult.parse(_result)
656)             assert result.clean_exit(empty_stderr=False), 'expected clean exit'
657)             assert result.stderr is not None, 'expected known error output'
658)             assert all(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

659)                 map(is_expected_warning, caplog.record_tuples)
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

660)             ), 'expected known error output'
661)             assert cli._load_config() == {
662)                 'global': {'length': 30},
663)                 'services': {},
664)             }, 'requested configuration change was not applied'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

665)             caplog.clear()
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

666)             _result = runner.invoke(
667)                 cli.derivepassphrase_vault,
668)                 ['--import', '-'],
669)                 input=json.dumps({'services': {'': {'length': 40}}}),
670)                 catch_exceptions=False,
671)             )
672)             result = tests.ReadableResult.parse(_result)
673)             assert result.clean_exit(empty_stderr=False), 'expected clean exit'
674)             assert result.stderr is not None, 'expected known error output'
675)             assert all(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

676)                 map(is_expected_warning, caplog.record_tuples)
Marco Ricci Warn the user upon supplyin...

Marco Ricci authored 2 months ago

677)             ), 'expected known error output'
678)             assert cli._load_config() == {
679)                 'global': {'length': 30},
680)                 'services': {'': {'length': 40}},
681)             }, 'requested configuration change was not applied'
682) 
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

685)         [
686)             (o.options, o.needs_service)
687)             for o in INTERESTING_OPTION_COMBINATIONS
688)             if o.incompatible
689)         ],
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

691)     def test_212_incompatible_options(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

698)         with tests.isolated_config(
699)             monkeypatch=monkeypatch,
700)             runner=runner,
701)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

703)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

704)                 [*options, '--', DUMMY_SERVICE] if service else options,
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

705)                 input=DUMMY_PASSPHRASE,
706)                 catch_exceptions=False,
707)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

708)         result = tests.ReadableResult.parse(_result)
709)         assert result.error_exit(
710)             error='mutually exclusive with '
711)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

713)     @pytest.mark.parametrize(
714)         'config',
715)         [
716)             conf.config
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

717)             for conf in TEST_CONFIGS
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

718)             if tests.is_valid_test_config(conf)
719)         ],
720)     )
721)     def test_213_import_config_success(
722)         self,
723)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

724)         caplog: pytest.LogCaptureFixture,
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

725)         config: Any,
726)     ) -> None:
727)         runner = click.testing.CliRunner(mix_stderr=False)
728)         with tests.isolated_vault_config(
729)             monkeypatch=monkeypatch,
730)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

731)             vault_config={'services': {}},
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

732)         ):
733)             _result = runner.invoke(
734)                 cli.derivepassphrase_vault,
735)                 ['--import', '-'],
736)                 input=json.dumps(config),
737)                 catch_exceptions=False,
738)             )
739)             with open(
740)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
741)             ) as infile:
742)                 config2 = json.load(infile)
743)         result = tests.ReadableResult.parse(_result)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

744)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

745)         assert config2 == config, 'config not imported correctly'
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

746)         assert not result.stderr or all(  # pragma: no branch
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

747)             map(is_harmless_config_import_warning, caplog.record_tuples)
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

748)         ), 'unexpected error output'
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

749) 
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

750)     @tests.hypothesis_settings_coverage_compatible_with_caplog
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

751)     @hypothesis.given(
752)         conf=tests.smudged_vault_test_config(
753)             strategies.sampled_from(TEST_CONFIGS).filter(
754)                 tests.is_valid_test_config
755)             )
756)         )
757)     )
758)     def test_213a_import_config_success(
759)         self,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

760)         caplog: pytest.LogCaptureFixture,
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

761)         conf: tests.VaultTestConfig,
762)     ) -> None:
763)         config = conf.config
764)         config2 = copy.deepcopy(config)
765)         _types.clean_up_falsy_vault_config_values(config2)
766)         runner = click.testing.CliRunner(mix_stderr=False)
767)         with tests.isolated_vault_config(
768)             monkeypatch=pytest.MonkeyPatch(),
769)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

770)             vault_config={'services': {}},
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

771)         ):
772)             _result = runner.invoke(
773)                 cli.derivepassphrase_vault,
774)                 ['--import', '-'],
775)                 input=json.dumps(config),
776)                 catch_exceptions=False,
777)             )
778)             with open(
779)                 cli._config_filename(subsystem='vault'), encoding='UTF-8'
780)             ) as infile:
781)                 config3 = json.load(infile)
782)         result = tests.ReadableResult.parse(_result)
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

783)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

784)         assert config3 == config2, 'config not imported correctly'
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

785)         assert not result.stderr or all(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

786)             map(is_harmless_config_import_warning, caplog.record_tuples)
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

787)         ), 'unexpected error output'
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

788) 
789)     def test_213b_import_bad_config_not_vault_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

801)         result = tests.ReadableResult.parse(_result)
802)         assert result.error_exit(
803)             error='Invalid vault config'
804)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

806)     def test_213c_import_bad_config_not_json_data(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

818)         result = tests.ReadableResult.parse(_result)
819)         assert result.error_exit(
820)             error='cannot decode JSON'
821)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

823)     def test_213d_import_bad_config_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

843)         result = tests.ReadableResult.parse(_result)
844)         assert result.error_exit(
845)             error=os.strerror(errno.EISDIR)
846)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

847) 
848)     def test_214_export_settings_no_stored_settings(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

857)                 cli.derivepassphrase_vault,
858)                 ['--export', '-'],
859)                 catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

864)     def test_214a_export_settings_bad_stored_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

869)         with tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

870)             monkeypatch=monkeypatch, runner=runner, vault_config={}
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

878)         result = tests.ReadableResult.parse(_result)
879)         assert result.error_exit(
880)             error='Cannot load config'
881)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

883)     def test_214b_export_settings_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

898)         result = tests.ReadableResult.parse(_result)
899)         assert result.error_exit(
900)             error='Cannot load config'
901)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

903)     def test_214c_export_settings_target_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

916)         result = tests.ReadableResult.parse(_result)
917)         assert result.error_exit(
918)             error='Cannot store config'
919)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

920) 
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

921)     def test_214d_export_settings_settings_directory_not_a_directory(
922)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

935)                 catch_exceptions=False,
936)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

937)         result = tests.ReadableResult.parse(_result)
938)         assert result.error_exit(
939)             error='Cannot load config'
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

940)         ) or result.error_exit(
941)             error='Cannot load user config'
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

943) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

944)     def test_220_edit_notes_successfully(
945)         self, monkeypatch: pytest.MonkeyPatch
946)     ) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

948) 
949) # - - - - - >8 - - - - - >8 - - - - - >8 - - - - - >8 - - - - -
950) contents go here
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

954)             monkeypatch=monkeypatch,
955)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

956)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

957)         ):
958)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: edit_result)  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

960)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

961)                 ['--notes', '--', 'sv'],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

970)             assert config == {
971)                 'global': {'phrase': 'abc'},
972)                 'services': {'sv': {'notes': 'contents go here'}},
973)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

974) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

975)     def test_221_edit_notes_noop(
976)         self, monkeypatch: pytest.MonkeyPatch
977)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

980)             monkeypatch=monkeypatch,
981)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

982)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

983)         ):
984)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: None)  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

986)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

987)                 ['--notes', '--', 'sv'],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

998)     def test_222_edit_notes_marker_removed(
999)         self, monkeypatch: pytest.MonkeyPatch
1000)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1003)             monkeypatch=monkeypatch,
1004)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1005)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1006)         ):
1007)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: 'long\ntext')  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1009)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1010)                 ['--notes', '--', 'sv'],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1019)             assert config == {
1020)                 'global': {'phrase': 'abc'},
1021)                 'services': {'sv': {'notes': 'long\ntext'}},
1022)             }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1023) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1024)     def test_223_edit_notes_abort(
1025)         self, monkeypatch: pytest.MonkeyPatch
1026)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1029)             monkeypatch=monkeypatch,
1030)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1031)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1032)         ):
1033)             monkeypatch.setattr(click, 'edit', lambda *a, **kw: '\n\n')  # noqa: ARG005
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1035)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1036)                 ['--notes', '--', 'sv'],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1037)                 catch_exceptions=False,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1039)             result = tests.ReadableResult.parse(_result)
1040)             assert result.error_exit(
1041)                 error='user aborted request'
1042)             ), 'expected known error message'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1049)     @pytest.mark.parametrize(
1050)         ['command_line', 'input', 'result_config'],
1051)         [
1052)             (
1053)                 ['--phrase'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1055)                 {'global': {'phrase': 'my passphrase'}, 'services': {}},
1056)             ),
1057)             (
1058)                 ['--key'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1059)                 '1\n',
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

1060)                 {
1061)                     'global': {'key': DUMMY_KEY1_B64, 'phrase': 'abc'},
1062)                     'services': {},
1063)                 },
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1064)             ),
1065)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1066)                 ['--phrase', '--', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1068)                 {
1069)                     'global': {'phrase': 'abc'},
1070)                     'services': {'sv': {'phrase': 'my passphrase'}},
1071)                 },
1072)             ),
1073)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1074)                 ['--key', '--', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1076)                 {
1077)                     'global': {'phrase': 'abc'},
1078)                     'services': {'sv': {'key': DUMMY_KEY1_B64}},
1079)                 },
1080)             ),
1081)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1082)                 ['--key', '--length', '15', '--', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1084)                 {
1085)                     'global': {'phrase': 'abc'},
1086)                     'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1087)                 },
1088)             ),
1089)         ],
1090)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1091)     def test_224_store_config_good(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1096)         result_config: Any,
1097)     ) -> None:
1098)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1100)             monkeypatch=monkeypatch,
1101)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1102)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1103)         ):
1104)             monkeypatch.setattr(
1105)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1106)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1109)                 ['--config', *command_line],
1110)                 catch_exceptions=False,
1111)                 input=input,
1112)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1119)             assert (
1120)                 config == result_config
1121)             ), 'stored config does not match expectation'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1122) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1123)     @pytest.mark.parametrize(
1124)         ['command_line', 'input', 'err_text'],
1125)         [
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1127)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1128)                 ['--', 'sv'],
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1129)                 '',
1130)                 'Cannot update service settings without actual settings',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1131)             ),
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1132)             (['--phrase', '--', 'sv'], '', 'No passphrase given'),
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1133)             (['--key'], '', 'No valid SSH key selected'),
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1134)         ],
1135)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1136)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1140)         input: str,
1141)         err_text: str,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1145)             monkeypatch=monkeypatch,
1146)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1147)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1148)         ):
1149)             monkeypatch.setattr(
1150)                 cli, '_get_suitable_ssh_keys', tests.suitable_ssh_keys
1151)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1154)                 ['--config', *command_line],
1155)                 catch_exceptions=False,
1156)                 input=input,
1157)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1158)         result = tests.ReadableResult.parse(_result)
1159)         assert result.error_exit(
1160)             error=err_text
1161)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1162) 
1163)     def test_225a_store_config_fail_manual_no_ssh_key_selection(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1169)             monkeypatch=monkeypatch,
1170)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1171)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1172)         ):
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1181)                 ['--key', '--config'],
1182)                 catch_exceptions=False,
1183)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1184)         result = tests.ReadableResult.parse(_result)
1185)         assert result.error_exit(
1186)             error=custom_error
1187)         ), 'expected error exit and known error message'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

1189)     def test_225b_store_config_fail_manual_no_ssh_agent(
1190)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1197)             monkeypatch=monkeypatch,
1198)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1199)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1200)         ):
1201)             monkeypatch.delenv('SSH_AUTH_SOCK', raising=False)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1204)                 ['--key', '--config'],
1205)                 catch_exceptions=False,
1206)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1207)         result = tests.ReadableResult.parse(_result)
1208)         assert result.error_exit(
1209)             error='Cannot find running SSH agent'
1210)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1211) 
1212)     def test_225c_store_config_fail_manual_bad_ssh_agent_connection(
1213)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1218)             monkeypatch=monkeypatch,
1219)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1220)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1221)         ):
1222)             monkeypatch.setenv('SSH_AUTH_SOCK', os.getcwd())
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1225)                 ['--key', '--config'],
1226)                 catch_exceptions=False,
1227)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1228)         result = tests.ReadableResult.parse(_result)
1229)         assert result.error_exit(
1230)             error='Cannot connect to SSH agent'
1231)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1232) 
1233)     @pytest.mark.parametrize('try_race_free_implementation', [True, False])
1234)     def test_225d_store_config_fail_manual_read_only_file(
1235)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1237)         try_race_free_implementation: bool,
1238)     ) -> None:
1239)         runner = click.testing.CliRunner(mix_stderr=False)
Marco Ricci Modularize test helpers to...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1241)             monkeypatch=monkeypatch,
1242)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1243)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1244)         ):
1245)             tests.make_file_readonly(
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1247)                 try_race_free_implementation=try_race_free_implementation,
1248)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1250)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1251)                 ['--config', '--length=15', '--', DUMMY_SERVICE],
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1252)                 catch_exceptions=False,
1253)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1254)         result = tests.ReadableResult.parse(_result)
1255)         assert result.error_exit(
1256)             error='Cannot store config'
1257)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1258) 
1259)     def test_225e_store_config_fail_manual_custom_error(
1260)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1265)             monkeypatch=monkeypatch,
1266)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1267)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1268)         ):
1269)             custom_error = 'custom error message'
1270) 
1271)             def raiser(config: Any) -> None:
1272)                 del config
1273)                 raise RuntimeError(custom_error)
1274) 
1275)             monkeypatch.setattr(cli, '_save_config', raiser)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1277)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1278)                 ['--config', '--length=15', '--', DUMMY_SERVICE],
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1279)                 catch_exceptions=False,
1280)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1281)         result = tests.ReadableResult.parse(_result)
1282)         assert result.error_exit(
1283)             error=custom_error
1284)         ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1285) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1288)         with tests.isolated_config(
1289)             monkeypatch=monkeypatch,
1290)             runner=runner,
1291)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1295)         result = tests.ReadableResult.parse(_result)
1296)         assert result.error_exit(
1297)             error='SERVICE is required'
1298)         ), 'expected error exit and known error message'
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

1299) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1300)     def test_226a_no_passphrase_or_key(
1301)         self, monkeypatch: pytest.MonkeyPatch
1302)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1304)         with tests.isolated_config(
1305)             monkeypatch=monkeypatch,
1306)             runner=runner,
1307)         ):
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1309)                 cli.derivepassphrase_vault,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1310)                 ['--', DUMMY_SERVICE],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

1311)                 catch_exceptions=False,
Marco Ricci Isolate tests properly and...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1317) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1318)     def test_230_config_directory_nonexistant(
1319)         self, monkeypatch: pytest.MonkeyPatch
1320)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1322)         runner = click.testing.CliRunner(mix_stderr=False)
1323)         with tests.isolated_config(
1324)             monkeypatch=monkeypatch,
1325)             runner=runner,
1326)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1328)             os_makedirs_called = False
1329)             real_os_makedirs = os.makedirs
1330) 
1331)             def makedirs(*args: Any, **kwargs: Any) -> Any:
1332)                 nonlocal os_makedirs_called
1333)                 os_makedirs_called = True
1334)                 return real_os_makedirs(*args, **kwargs)
1335) 
1336)             monkeypatch.setattr(os, 'makedirs', makedirs)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1339)                 ['--config', '-p'],
1340)                 catch_exceptions=False,
1341)                 input='abc\n',
1342)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1352)                 config_readback = json.load(infile)
1353)             assert config_readback == {
1354)                 'global': {'phrase': 'abc'},
1355)                 'services': {},
1356)             }, 'config mismatch'
1357) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1358)     def test_230a_config_directory_not_a_file(
1359)         self, monkeypatch: pytest.MonkeyPatch
1360)     ) -> None:
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

1362)         runner = click.testing.CliRunner(mix_stderr=False)
1363)         with tests.isolated_config(
1364)             monkeypatch=monkeypatch,
1365)             runner=runner,
1366)         ):
1367)             _save_config = cli._save_config
1368) 
1369)             def obstruct_config_saving(*args: Any, **kwargs: Any) -> Any:
1370)                 with contextlib.suppress(FileNotFoundError):
1371)                     shutil.rmtree('.derivepassphrase')
1372)                 with open(
1373)                     '.derivepassphrase', 'w', encoding='UTF-8'
1374)                 ) as outfile:
1375)                     print('Obstruction!!', file=outfile)
1376)                 monkeypatch.setattr(cli, '_save_config', _save_config)
1377)                 return _save_config(*args, **kwargs)
1378) 
1379)             monkeypatch.setattr(cli, '_save_config', obstruct_config_saving)
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1382)                 ['--config', '-p'],
1383)                 catch_exceptions=False,
1384)                 input='abc\n',
1385)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1386)             result = tests.ReadableResult.parse(_result)
1387)             assert result.error_exit(
1388)                 error='Cannot store config'
1389)             ), 'expected error exit and known error message'
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1390) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1391)     def test_230b_store_config_custom_error(
1392)         self, monkeypatch: pytest.MonkeyPatch
1393)     ) -> None:
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

1394)         runner = click.testing.CliRunner(mix_stderr=False)
1395)         with tests.isolated_config(
1396)             monkeypatch=monkeypatch,
1397)             runner=runner,
1398)         ):
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1401)             def raiser(config: Any) -> None:
1402)                 del config
1403)                 raise RuntimeError(custom_error)
Marco Ricci Add missing tests for rewor...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1408)                 ['--config', '-p'],
1409)                 catch_exceptions=False,
1410)                 input='abc\n',
1411)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1417)     @pytest.mark.parametrize(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

1419)         [
1420)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1421)                 '',
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1422)                 ['--import', '-'],
1423)                 json.dumps({
1424)                     'global': {'phrase': 'Du\u0308sseldorf'},
1425)                     'services': {},
1426)                 }),
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

1427)                 'the $.global passphrase is not NFC-normalized',
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1428)                 id='global-NFC',
1429)             ),
1430)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1431)                 '',
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1432)                 ['--import', '-'],
1433)                 json.dumps({
1434)                     'services': {
1435)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1436)                         'weird entry name': {'phrase': 'Du\u0308sseldorf'},
1437)                     }
1438)                 }),
1439)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

1440)                     'the $.services["weird entry name"] passphrase '
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1441)                     'is not NFC-normalized'
1442)                 ),
1443)                 id='service-weird-name-NFC',
1444)             ),
1445)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1446)                 '',
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1447)                 ['--config', '-p', '--', DUMMY_SERVICE],
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1448)                 'Du\u0308sseldorf',
1449)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

1450)                     f'the $.services.{DUMMY_SERVICE} passphrase '
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1451)                     f'is not NFC-normalized'
1452)                 ),
1453)                 id='config-NFC',
1454)             ),
1455)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1456)                 '',
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1457)                 ['-p', '--', DUMMY_SERVICE],
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1458)                 'Du\u0308sseldorf',
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1459)                 'the interactive input passphrase is not NFC-normalized',
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1460)                 id='direct-input-NFC',
1461)             ),
1462)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1463)                 textwrap.dedent(r"""
1464)                 [vault]
1465)                 default-unicode-normalization-form = 'NFD'
1466)                 """),
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1467)                 ['--import', '-'],
1468)                 json.dumps({
1469)                     'global': {
1470)                         'phrase': 'D\u00fcsseldorf',
1471)                     },
1472)                     'services': {},
1473)                 }),
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

1474)                 'the $.global passphrase is not NFD-normalized',
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1475)                 id='global-NFD',
1476)             ),
1477)             pytest.param(
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1478)                 textwrap.dedent(r"""
1479)                 [vault]
1480)                 default-unicode-normalization-form = 'NFD'
1481)                 """),
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1482)                 ['--import', '-'],
1483)                 json.dumps({
1484)                     'services': {
1485)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1486)                         'weird entry name': {'phrase': 'D\u00fcsseldorf'},
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1488)                 }),
1489)                 (
Marco Ricci Signal and list falsy value...

Marco Ricci authored 3 months ago

1490)                     'the $.services["weird entry name"] passphrase '
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1491)                     'is not NFD-normalized'
1492)                 ),
1493)                 id='service-weird-name-NFD',
1494)             ),
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1495)             pytest.param(
1496)                 textwrap.dedent(r"""
1497)                 [vault.unicode-normalization-form]
1498)                 'weird entry name 2' = 'NFKD'
1499)                 """),
1500)                 ['--import', '-'],
1501)                 json.dumps({
1502)                     'services': {
1503)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1504)                         'weird entry name 1': {'phrase': 'D\u00fcsseldorf'},
1505)                         'weird entry name 2': {'phrase': 'D\u00fcsseldorf'},
1506)                     },
1507)                 }),
1508)                 (
1509)                     'the $.services["weird entry name 2"] passphrase '
1510)                     'is not NFKD-normalized'
1511)                 ),
1512)                 id='service-weird-name-2-NFKD',
1513)             ),
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1514)         ],
1515)     )
1516)     def test_300_unicode_normalization_form_warning(
1517)         self,
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1518)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

1519)         caplog: pytest.LogCaptureFixture,
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1520)         main_config: str,
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

1527)             monkeypatch=monkeypatch,
1528)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1529)             vault_config={
1530)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1531)             },
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1532)             main_config_str=main_config,
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

1535)                 cli.derivepassphrase_vault,
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1536)                 ['--debug', *command_line],
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1537)                 catch_exceptions=False,
1538)                 input=input,
1539)             )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1540)         result = tests.ReadableResult.parse(_result)
1541)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

1542)         assert tests.warning_emitted(
1543)             warning_message, caplog.record_tuples
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1544)         ), 'expected known warning message in stderr'
Marco Ricci Allow all textual strings,...

Marco Ricci authored 4 months ago

1545) 
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

1546)     @pytest.mark.parametrize(
1547)         ['main_config', 'command_line', 'input', 'error_message'],
1548)         [
1549)             pytest.param(
1550)                 textwrap.dedent(r"""
1551)                 [vault]
1552)                 default-unicode-normalization-form = 'XXX'
1553)                 """),
1554)                 ['--import', '-'],
1555)                 json.dumps({
1556)                     'services': {
1557)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1558)                         'with_normalization': {'phrase': 'D\u00fcsseldorf'},
1559)                     },
1560)                 }),
1561)                 (
1562)                     "Invalid value 'XXX' for config key "
1563)                     "vault.default-unicode-normalization-form"
1564)                 ),
1565)                 id='global',
1566)             ),
1567)             pytest.param(
1568)                 textwrap.dedent(r"""
1569)                 [vault.unicode-normalization-form]
1570)                 with_normalization = 'XXX'
1571)                 """),
1572)                 ['--import', '-'],
1573)                 json.dumps({
1574)                     'services': {
1575)                         DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy(),
1576)                         'with_normalization': {'phrase': 'D\u00fcsseldorf'},
1577)                     },
1578)                 }),
1579)                 (
1580)                     "Invalid value 'XXX' for config key "
1581)                     "vault.with_normalization.unicode-normalization-form"
1582)                 ),
1583)                 id='service',
1584)             ),
1585)         ],
1586)     )
1587)     def test_301_unicode_normalization_form_error(
1588)         self,
1589)         monkeypatch: pytest.MonkeyPatch,
1590)         main_config: str,
1591)         command_line: list[str],
1592)         input: str | None,
1593)         error_message: str,
1594)     ) -> None:
1595)         runner = click.testing.CliRunner(mix_stderr=False)
1596)         with tests.isolated_vault_config(
1597)             monkeypatch=monkeypatch,
1598)             runner=runner,
1599)             vault_config={
1600)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1601)             },
1602)             main_config_str=main_config,
1603)         ):
1604)             _result = runner.invoke(
1605)                 cli.derivepassphrase_vault,
1606)                 command_line,
1607)                 catch_exceptions=False,
1608)                 input=input,
1609)             )
1610)         result = tests.ReadableResult.parse(_result)
1611)         assert result.error_exit(
1612)             error='The configuration file is invalid.'
1613)         ), 'expected error exit and known error message'
1614)         assert result.error_exit(
1615)             error=error_message
1616)         ), 'expected error exit and known error message'
1617) 
1618)     @pytest.mark.parametrize(
1619)         'command_line',
1620)         [
1621)             pytest.param(
1622)                 ['--config', '--phrase'],
1623)                 id='configure global passphrase',
1624)             ),
1625)             pytest.param(
1626)                 ['--phrase', '--', DUMMY_SERVICE],
1627)                 id='interactive passphrase',
1628)             ),
1629)         ],
1630)     )
1631)     def test_301a_unicode_normalization_form_error_from_stored_config(
1632)         self,
1633)         monkeypatch: pytest.MonkeyPatch,
1634)         command_line: list[str],
1635)     ) -> None:
1636)         runner = click.testing.CliRunner(mix_stderr=False)
1637)         with tests.isolated_vault_config(
1638)             monkeypatch=monkeypatch,
1639)             runner=runner,
1640)             vault_config={
1641)                 'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS.copy()}
1642)             },
1643)             main_config_str=textwrap.dedent("""
1644)             [vault]
1645)             default-unicode-normalization-form = 'XXX'
1646)             """),
1647)         ):
1648)             _result = runner.invoke(
1649)                 cli.derivepassphrase_vault,
1650)                 command_line,
1651)                 input=DUMMY_PASSPHRASE,
1652)                 catch_exceptions=False,
1653)             )
1654)             result = tests.ReadableResult.parse(_result)
1655)             assert result.error_exit(
1656)                 error='The configuration file is invalid.'
1657)             ), 'expected error exit and known error message'
1658)             assert result.error_exit(
1659)                 error=(
1660)                     "Invalid value 'XXX' for config key "
1661)                     "vault.default-unicode-normalization-form"
1662)                 ),
1663)             ), 'expected error exit and known error message'
1664) 
1665)     def test_310_bad_user_config_file(
1666)         self,
1667)         monkeypatch: pytest.MonkeyPatch,
1668)     ) -> None:
1669)         runner = click.testing.CliRunner(mix_stderr=False)
1670)         with tests.isolated_vault_config(
1671)             monkeypatch=monkeypatch,
1672)             runner=runner,
1673)             vault_config={'services': {}},
1674)             main_config_str=textwrap.dedent("""
1675)             This file is not valid TOML.
1676)             """),
1677)         ):
1678)             _result = runner.invoke(
1679)                 cli.derivepassphrase_vault,
1680)                 ['--phrase', '--', DUMMY_SERVICE],
1681)                 input=DUMMY_PASSPHRASE,
1682)                 catch_exceptions=False,
1683)             )
1684)             result = tests.ReadableResult.parse(_result)
1685)             assert result.error_exit(
1686)                 error='Cannot load user config:'
1687)             ), 'expected error exit and known error message'
1688) 
Marco Ricci Fail gracefully if UNIX dom...

Marco Ricci authored 3 months ago

1689)     def test_400_missing_af_unix_support(
1690)         self,
1691)         monkeypatch: pytest.MonkeyPatch,
1692)     ) -> None:
1693)         runner = click.testing.CliRunner(mix_stderr=False)
1694)         with tests.isolated_vault_config(
1695)             monkeypatch=monkeypatch,
1696)             runner=runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1697)             vault_config={'global': {'phrase': 'abc'}, 'services': {}},
Marco Ricci Fail gracefully if UNIX dom...

Marco Ricci authored 3 months ago

1698)         ):
1699)             monkeypatch.setenv(
1700)                 'SSH_AUTH_SOCK', "the value doesn't even matter"
1701)             )
1702)             monkeypatch.delattr(socket, 'AF_UNIX', raising=False)
1703)             _result = runner.invoke(
1704)                 cli.derivepassphrase_vault,
1705)                 ['--key', '--config'],
1706)                 catch_exceptions=False,
1707)             )
1708)         result = tests.ReadableResult.parse(_result)
1709)         assert result.error_exit(
1710)             error='does not support UNIX domain sockets'
1711)         ), 'expected error exit and known error message'
1712) 
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

1715)     @pytest.mark.parametrize(
1716)         'config',
1717)         [
1718)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
1719)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
1720)             {
1721)                 'global': {'phrase': 'abc'},
1722)                 'services': {'sv': {'phrase': 'my passphrase'}},
1723)             },
1724)             {
1725)                 'global': {'phrase': 'abc'},
1726)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
1727)             },
1728)             {
1729)                 'global': {'phrase': 'abc'},
1730)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
1731)             },
1732)         ],
1733)     )
1734)     def test_100_load_config(
1735)         self, monkeypatch: pytest.MonkeyPatch, config: Any
1736)     ) -> None:
1737)         runner = click.testing.CliRunner()
1738)         with tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1739)             monkeypatch=monkeypatch, runner=runner, vault_config=config
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

1740)         ):
1741)             config_filename = cli._config_filename(subsystem='vault')
1742)             with open(config_filename, encoding='UTF-8') as fileobj:
1743)                 assert json.load(fileobj) == config
1744)             assert cli._load_config() == config
1745) 
1746)     def test_110_save_bad_config(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1749)         runner = click.testing.CliRunner()
Marco Ricci Refactor code to run under...

Marco Ricci authored 1 month ago

1750)         # Use parenthesized context manager expressions here once Python
1751)         # 3.9 becomes unsupported.
1752)         with contextlib.ExitStack() as stack:
1753)             stack.enter_context(
1754)                 tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

1755)                     monkeypatch=monkeypatch, runner=runner, vault_config={}
Marco Ricci Refactor code to run under...

Marco Ricci authored 1 month ago

1756)                 )
1757)             )
1758)             stack.enter_context(
1759)                 pytest.raises(ValueError, match='Invalid vault config')
1760)             )
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1762) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1768)             # from https://montypython.fandom.com/wiki/Spam#The_menu
1769)             items = items or [
1770)                 'Egg and bacon',
1771)                 'Egg, sausage and bacon',
1772)                 'Egg and spam',
1773)                 'Egg, bacon and spam',
1774)                 'Egg, bacon, sausage and spam',
1775)                 'Spam, bacon, sausage and spam',
1776)                 'Spam, egg, spam, spam, bacon and spam',
1777)                 'Spam, spam, spam, egg and spam',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1778)                 (
1779)                     'Spam, spam, spam, spam, spam, spam, baked beans, '
1780)                     'spam, spam, spam and spam'
1781)                 ),
1782)                 (
1783)                     'Lobster thermidor aux crevettes with a mornay sauce '
1784)                     'garnished with truffle paté, brandy '
1785)                     'and a fried egg on top and spam'
1786)                 ),
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1787)             ]
1788)             index = cli._prompt_for_selection(items, heading=heading)
1789)             click.echo('A fine choice: ', nl=False)
1790)             click.echo(items[index])
1791)             click.echo('(Note: Vikings strictly optional.)')
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

1794)         _result = runner.invoke(driver, [], input='9')
1795)         result = tests.ReadableResult.parse(_result)
1796)         assert result.clean_exit(
1797)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1798) Our menu:
1799) [1] Egg and bacon
1800) [2] Egg, sausage and bacon
1801) [3] Egg and spam
1802) [4] Egg, bacon and spam
1803) [5] Egg, bacon, sausage and spam
1804) [6] Spam, bacon, sausage and spam
1805) [7] Spam, egg, spam, spam, bacon and spam
1806) [8] Spam, spam, spam, egg and spam
1807) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1808) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
1809) Your selection? (1-10, leave empty to abort): 9
1810) A fine choice: Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1811) (Note: Vikings strictly optional.)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1817)         result = tests.ReadableResult.parse(_result)
1818)         assert result.error_exit(
1819)             error=IndexError
1820)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1822)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1824) [1] Egg and bacon
1825) [2] Egg, sausage and bacon
1826) [3] Egg and spam
1827) [4] Egg, bacon and spam
1828) [5] Egg, bacon, sausage and spam
1829) [6] Spam, bacon, sausage and spam
1830) [7] Spam, egg, spam, spam, bacon and spam
1831) [8] Spam, spam, spam, egg and spam
1832) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1833) [10] Lobster thermidor aux crevettes with a mornay sauce garnished with truffle paté, brandy and a fried egg on top and spam
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1837) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1843)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1844)                 cli._prompt_for_selection(
1845)                     [item], heading='', single_choice_prompt=prompt
1846)                 )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1857)         result = tests.ReadableResult.parse(_result)
1858)         assert result.clean_exit(
1859)             output="""\
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1866)             driver,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

1867)             ['Will replace with spam, okay? (Please say "y" or "n".)'],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

1868)             input='',
1869)         )
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

1870)         result = tests.ReadableResult.parse(_result)
1871)         assert result.error_exit(
1872)             error=IndexError
1873)         ), 'expected error exit and known error type'
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1875)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1879) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1882) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

1886)         monkeypatch.setattr(
1887)             click,
1888)             'prompt',
1889)             lambda *a, **kw: json.dumps({'args': a, 'kwargs': kw}),
1890)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

1892)         err_msg = 'missing arguments to passphrase prompt'
1893)         assert 'args' in res, err_msg
1894)         assert 'kwargs' in res, err_msg
1895)         assert res['args'][:1] == ['Passphrase'], err_msg
1896)         assert res['kwargs'].get('default') == '', err_msg
1897)         assert not res['kwargs'].get('show_default', True), err_msg
1898)         assert res['kwargs'].get('err'), err_msg
1899)         assert res['kwargs'].get('hide_input'), err_msg
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

1900) 
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

1901)     def test_120_standard_logging_context_manager(
1902)         self,
1903)         caplog: pytest.LogCaptureFixture,
1904)         capsys: pytest.CaptureFixture[str],
1905)     ) -> None:
1906)         prog_name = cli.StandardCLILogging.prog_name
1907)         package_name = cli.StandardCLILogging.package_name
1908)         logger = logging.getLogger(package_name)
1909)         deprecation_logger = logging.getLogger(f'{package_name}.deprecation')
1910)         logging_cm = cli.StandardCLILogging.ensure_standard_logging()
1911)         with logging_cm:
1912)             assert (
1913)                 sum(
1914)                     1
1915)                     for h in logger.handlers
1916)                     if h is cli.StandardCLILogging.cli_handler
1917)                 )
1918)                 == 1
1919)             )
1920)             logger.warning('message 1')
1921)             with logging_cm:
1922)                 deprecation_logger.warning('message 2')
1923)                 assert (
1924)                     sum(
1925)                         1
1926)                         for h in logger.handlers
1927)                         if h is cli.StandardCLILogging.cli_handler
1928)                     )
1929)                     == 1
1930)                 )
1931)                 assert capsys.readouterr() == (
1932)                     '',
1933)                     (
1934)                         f'{prog_name}: Warning: message 1\n'
1935)                         f'{prog_name}: Deprecation warning: message 2\n'
1936)                     ),
1937)                 )
1938)             logger.warning('message 3')
1939)             assert (
1940)                 sum(
1941)                     1
1942)                     for h in logger.handlers
1943)                     if h is cli.StandardCLILogging.cli_handler
1944)                 )
1945)                 == 1
1946)             )
1947)             assert capsys.readouterr() == (
1948)                 '',
1949)                 f'{prog_name}: Warning: message 3\n',
1950)             )
1951)             assert caplog.record_tuples == [
1952)                 (package_name, logging.WARNING, 'message 1'),
1953)                 (f'{package_name}.deprecation', logging.WARNING, 'message 2'),
1954)                 (package_name, logging.WARNING, 'message 3'),
1955)             ]
1956) 
1957)     def test_121_standard_logging_warnings_context_manager(
1958)         self,
1959)         caplog: pytest.LogCaptureFixture,
1960)         capsys: pytest.CaptureFixture[str],
1961)     ) -> None:
1962)         warnings_cm = cli.StandardCLILogging.ensure_standard_warnings_logging()
1963)         THE_FUTURE = 'the future will be here sooner than you think'  # noqa: N806
1964)         JUST_TESTING = 'just testing whether warnings work'  # noqa: N806
1965)         with warnings_cm:
1966)             assert (
1967)                 sum(
1968)                     1
1969)                     for h in logging.getLogger('py.warnings').handlers
1970)                     if h is cli.StandardCLILogging.warnings_handler
1971)                 )
1972)                 == 1
1973)             )
1974)             warnings.warn(UserWarning(JUST_TESTING), stacklevel=1)
1975)             with warnings_cm:
1976)                 warnings.warn(FutureWarning(THE_FUTURE), stacklevel=1)
1977)                 _out, err = capsys.readouterr()
1978)                 err_lines = err.splitlines(True)
1979)                 assert any(
1980)                     f'UserWarning: {JUST_TESTING}' in line
1981)                     for line in err_lines
1982)                 )
1983)                 assert any(
1984)                     f'FutureWarning: {THE_FUTURE}' in line
1985)                     for line in err_lines
1986)                 )
1987)             warnings.warn(UserWarning(JUST_TESTING), stacklevel=1)
1988)             _out, err = capsys.readouterr()
1989)             err_lines = err.splitlines(True)
1990)             assert any(
1991)                 f'UserWarning: {JUST_TESTING}' in line for line in err_lines
1992)             )
1993)             assert not any(
1994)                 f'FutureWarning: {THE_FUTURE}' in line for line in err_lines
1995)             )
1996)             record_tuples = caplog.record_tuples
1997)             assert [tup[:2] for tup in record_tuples] == [
1998)                 ('py.warnings', logging.WARNING),
1999)                 ('py.warnings', logging.WARNING),
2000)                 ('py.warnings', logging.WARNING),
2001)             ]
2002)             assert f'UserWarning: {JUST_TESTING}' in record_tuples[0][2]
2003)             assert f'FutureWarning: {THE_FUTURE}' in record_tuples[1][2]
2004)             assert f'UserWarning: {JUST_TESTING}' in record_tuples[2][2]
2005) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2006)     @pytest.mark.parametrize(
2007)         ['command_line', 'config', 'result_config'],
2008)         [
2009)             (
2010)                 ['--delete-globals'],
2011)                 {'global': {'phrase': 'abc'}, 'services': {}},
2012)                 {'services': {}},
2013)             ),
2014)             (
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

2015)                 ['--delete', '--', DUMMY_SERVICE],
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2016)                 {
2017)                     'global': {'phrase': 'abc'},
2018)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
2019)                 },
2020)                 {'global': {'phrase': 'abc'}, 'services': {}},
2021)             ),
2022)             (
2023)                 ['--clear'],
2024)                 {
2025)                     'global': {'phrase': 'abc'},
2026)                     'services': {DUMMY_SERVICE: {'notes': '...'}},
2027)                 },
2028)                 {'services': {}},
2029)             ),
2030)         ],
2031)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2032)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

2036)         config: _types.VaultConfig,
2037)         result_config: _types.VaultConfig,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

2041)             with tests.isolated_vault_config(
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

2042)                 monkeypatch=monkeypatch,
2043)                 runner=runner,
2044)                 vault_config=start_config,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

2047)                     cli.derivepassphrase_vault,
2048)                     command_line,
2049)                     catch_exceptions=False,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

2058)                     config_readback = json.load(infile)
2059)                 assert config_readback == result_config
2060) 
2061)     def test_204_phrase_from_key_manually(self) -> None:
2062)         assert (
Marco Ricci Align behavior with vault c...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

2064)                 phrase=DUMMY_PHRASE_FROM_KEY1, **DUMMY_CONFIG_SETTINGS
2065)             ).generate(DUMMY_SERVICE)
2066)             == DUMMY_RESULT_KEY1
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2067)         )
2068) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

2069)     @pytest.mark.parametrize(
2070)         ['vfunc', 'input'],
2071)         [
2072)             (cli._validate_occurrence_constraint, 20),
2073)             (cli._validate_length, 20),
2074)         ],
2075)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 6 months ago

2076)     def test_210a_validate_constraints_manually(
2077)         self,
2078)         vfunc: Callable[[click.Context, click.Parameter, Any], int | None],
2079)         input: int,
2080)     ) -> None:
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

2086)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

2088)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

2089)         running_ssh_agent: tests.RunningSSHAgentInfo,
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

2092)         with monkeypatch.context():
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

2093)             monkeypatch.setenv('SSH_AUTH_SOCK', running_ssh_agent.socket)
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

2094)             monkeypatch.setattr(
2095)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
2096)             )
2097)             hint: ssh_agent.SSHAgentClient | socket.socket | None
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

2098)             # Use match/case here once Python 3.9 becomes unsupported.
2099)             if conn_hint == 'client':
2100)                 hint = ssh_agent.SSHAgentClient()
2101)             elif conn_hint == 'socket':
2102)                 hint = socket.socket(family=socket.AF_UNIX)
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

2103)                 hint.connect(running_ssh_agent.socket)
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

2104)             else:
2105)                 assert conn_hint == 'none'
2106)                 hint = None
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

2107)             exception: Exception | None = None
2108)             try:
2109)                 list(cli._get_suitable_ssh_keys(hint))
2110)             except RuntimeError:  # pragma: no cover
2111)                 pass
2112)             except Exception as e:  # noqa: BLE001 # pragma: no cover
2113)                 exception = e
2114)             finally:
2115)                 assert (
2116)                     exception is None
2117)                 ), 'exception querying suitable SSH keys'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2118) 
2119) 
2120) class TestCLITransition:
2121)     def test_100_help_output(self, monkeypatch: pytest.MonkeyPatch) -> None:
2122)         runner = click.testing.CliRunner(mix_stderr=False)
2123)         with tests.isolated_config(
2124)             monkeypatch=monkeypatch,
2125)             runner=runner,
2126)         ):
2127)             _result = runner.invoke(
2128)                 cli.derivepassphrase, ['--help'], catch_exceptions=False
2129)             )
2130)             result = tests.ReadableResult.parse(_result)
2131)         assert result.clean_exit(
2132)             empty_stderr=True, output='currently implemented subcommands'
2133)         ), 'expected clean exit, and known help text'
2134) 
2135)     def test_101_help_output_export(
2136)         self, monkeypatch: pytest.MonkeyPatch
2137)     ) -> None:
2138)         runner = click.testing.CliRunner(mix_stderr=False)
2139)         with tests.isolated_config(
2140)             monkeypatch=monkeypatch,
2141)             runner=runner,
2142)         ):
2143)             _result = runner.invoke(
2144)                 cli.derivepassphrase,
2145)                 ['export', '--help'],
2146)                 catch_exceptions=False,
2147)             )
2148)             result = tests.ReadableResult.parse(_result)
2149)         assert result.clean_exit(
2150)             empty_stderr=True, output='only available subcommand'
2151)         ), 'expected clean exit, and known help text'
2152) 
2153)     def test_102_help_output_export_vault(
2154)         self, monkeypatch: pytest.MonkeyPatch
2155)     ) -> None:
2156)         runner = click.testing.CliRunner(mix_stderr=False)
2157)         with tests.isolated_config(
2158)             monkeypatch=monkeypatch,
2159)             runner=runner,
2160)         ):
2161)             _result = runner.invoke(
2162)                 cli.derivepassphrase,
2163)                 ['export', 'vault', '--help'],
2164)                 catch_exceptions=False,
2165)             )
2166)             result = tests.ReadableResult.parse(_result)
2167)         assert result.clean_exit(
2168)             empty_stderr=True, output='Read the vault-native configuration'
2169)         ), 'expected clean exit, and known help text'
2170) 
2171)     def test_103_help_output_vault(
2172)         self, monkeypatch: pytest.MonkeyPatch
2173)     ) -> None:
2174)         runner = click.testing.CliRunner(mix_stderr=False)
2175)         with tests.isolated_config(
2176)             monkeypatch=monkeypatch,
2177)             runner=runner,
2178)         ):
2179)             _result = runner.invoke(
2180)                 cli.derivepassphrase,
2181)                 ['vault', '--help'],
2182)                 catch_exceptions=False,
2183)             )
2184)             result = tests.ReadableResult.parse(_result)
2185)         assert result.clean_exit(
2186)             empty_stderr=True, output='Password generation:\n'
2187)         ), 'expected clean exit, and option groups in help text'
2188)         assert result.clean_exit(
2189)             empty_stderr=True, output='Use NUMBER=0, e.g. "--symbol 0"'
2190)         ), 'expected clean exit, and option group epilog in help text'
2191) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2192)     @pytest.mark.parametrize(
2193)         'config',
2194)         [
2195)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2196)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2197)             {
2198)                 'global': {'phrase': 'abc'},
2199)                 'services': {'sv': {'phrase': 'my passphrase'}},
2200)             },
2201)             {
2202)                 'global': {'phrase': 'abc'},
2203)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2204)             },
2205)             {
2206)                 'global': {'phrase': 'abc'},
2207)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2208)             },
2209)         ],
2210)     )
2211)     def test_110_load_config_backup(
2212)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2213)     ) -> None:
2214)         runner = click.testing.CliRunner()
2215)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2216)             config_filename = cli._config_filename(
2217)                 subsystem='old settings.json'
2218)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2219)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2220)                 print(json.dumps(config, indent=2), file=fileobj)
2221)             assert cli._migrate_and_load_old_config()[0] == config
2222) 
2223)     @pytest.mark.parametrize(
2224)         'config',
2225)         [
2226)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2227)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2228)             {
2229)                 'global': {'phrase': 'abc'},
2230)                 'services': {'sv': {'phrase': 'my passphrase'}},
2231)             },
2232)             {
2233)                 'global': {'phrase': 'abc'},
2234)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2235)             },
2236)             {
2237)                 'global': {'phrase': 'abc'},
2238)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2239)             },
2240)         ],
2241)     )
2242)     def test_111_migrate_config(
2243)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2244)     ) -> None:
2245)         runner = click.testing.CliRunner()
2246)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2247)             config_filename = cli._config_filename(
2248)                 subsystem='old settings.json'
2249)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2250)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2251)                 print(json.dumps(config, indent=2), file=fileobj)
2252)             assert cli._migrate_and_load_old_config() == (config, None)
2253) 
2254)     @pytest.mark.parametrize(
2255)         'config',
2256)         [
2257)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2258)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2259)             {
2260)                 'global': {'phrase': 'abc'},
2261)                 'services': {'sv': {'phrase': 'my passphrase'}},
2262)             },
2263)             {
2264)                 'global': {'phrase': 'abc'},
2265)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2266)             },
2267)             {
2268)                 'global': {'phrase': 'abc'},
2269)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2270)             },
2271)         ],
2272)     )
2273)     def test_112_migrate_config_error(
2274)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2275)     ) -> None:
2276)         runner = click.testing.CliRunner()
2277)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2278)             config_filename = cli._config_filename(
2279)                 subsystem='old settings.json'
2280)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2281)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2282)                 print(json.dumps(config, indent=2), file=fileobj)
2283)             os.mkdir(cli._config_filename(subsystem='vault'))
2284)             config2, err = cli._migrate_and_load_old_config()
2285)             assert config2 == config
2286)             assert isinstance(err, OSError)
2287)             assert err.errno == errno.EISDIR
2288) 
2289)     @pytest.mark.parametrize(
2290)         'config',
2291)         [
2292)             {'global': '', 'services': {}},
2293)             {'global': 0, 'services': {}},
2294)             {
2295)                 'global': {'phrase': 'abc'},
2296)                 'services': False,
2297)             },
2298)             {
2299)                 'global': {'phrase': 'abc'},
2300)                 'services': True,
2301)             },
2302)             {
2303)                 'global': {'phrase': 'abc'},
2304)                 'services': None,
2305)             },
2306)         ],
2307)     )
2308)     def test_113_migrate_config_error_bad_config_value(
2309)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2310)     ) -> None:
2311)         runner = click.testing.CliRunner()
2312)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2313)             config_filename = cli._config_filename(
2314)                 subsystem='old settings.json'
2315)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2316)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2317)                 print(json.dumps(config, indent=2), file=fileobj)
2318)             with pytest.raises(ValueError, match=cli._INVALID_VAULT_CONFIG):
2319)                 cli._migrate_and_load_old_config()
2320) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2321)     def test_200_forward_export_vault_path_parameter(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2322)         self,
2323)         monkeypatch: pytest.MonkeyPatch,
2324)         caplog: pytest.LogCaptureFixture,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2325)     ) -> None:
2326)         pytest.importorskip('cryptography', minversion='38.0')
2327)         runner = click.testing.CliRunner(mix_stderr=False)
2328)         with tests.isolated_vault_exporter_config(
2329)             monkeypatch=monkeypatch,
2330)             runner=runner,
2331)             vault_config=tests.VAULT_V03_CONFIG,
2332)             vault_key=tests.VAULT_MASTER_KEY,
2333)         ):
2334)             monkeypatch.setenv('VAULT_KEY', tests.VAULT_MASTER_KEY)
2335)             _result = runner.invoke(
2336)                 cli.derivepassphrase,
2337)                 ['export', 'VAULT_PATH'],
2338)             )
2339)         result = tests.ReadableResult.parse(_result)
2340)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2341)         assert tests.deprecation_warning_emitted(
2342)             'A subcommand will be required in v1.0', caplog.record_tuples
2343)         )
2344)         assert tests.warning_emitted(
2345)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

2346)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2347)         assert json.loads(result.output) == tests.VAULT_V03_CONFIG_DATA
2348) 
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2349)     def test_201_forward_export_vault_empty_commandline(
2350)         self,
2351)         monkeypatch: pytest.MonkeyPatch,
2352)         caplog: pytest.LogCaptureFixture,
2353)     ) -> None:
2354)         pytest.importorskip('cryptography', minversion='38.0')
2355)         runner = click.testing.CliRunner(mix_stderr=False)
2356)         with tests.isolated_config(
2357)             monkeypatch=monkeypatch,
2358)             runner=runner,
2359)         ):
2360)             _result = runner.invoke(
2361)                 cli.derivepassphrase,
2362)                 ['export'],
2363)             )
2364)         result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2365)         assert tests.deprecation_warning_emitted(
2366)             'A subcommand will be required in v1.0', caplog.record_tuples
2367)         )
2368)         assert tests.warning_emitted(
2369)             'Defaulting to subcommand "vault"', caplog.record_tuples
2370)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2371)         assert result.error_exit(
2372)             error="Missing argument 'PATH'"
2373)         ), 'expected error exit and known error type'
2374) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2375)     @pytest.mark.parametrize(
2376)         'charset_name', ['lower', 'upper', 'number', 'space', 'dash', 'symbol']
2377)     )
2378)     def test_210_forward_vault_disable_character_set(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2379)         self,
2380)         monkeypatch: pytest.MonkeyPatch,
2381)         caplog: pytest.LogCaptureFixture,
2382)         charset_name: str,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

2387)         runner = click.testing.CliRunner(mix_stderr=False)
2388)         with tests.isolated_config(
2389)             monkeypatch=monkeypatch,
2390)             runner=runner,
2391)         ):
2392)             _result = runner.invoke(
2393)                 cli.derivepassphrase,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

2394)                 [option, '0', '-p', '--', DUMMY_SERVICE],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2395)                 input=DUMMY_PASSPHRASE,
2396)                 catch_exceptions=False,
2397)             )
2398)             result = tests.ReadableResult.parse(_result)
2399)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2400)         assert tests.deprecation_warning_emitted(
2401)             'A subcommand will be required in v1.0', caplog.record_tuples
2402)         )
2403)         assert tests.warning_emitted(
2404)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

2405)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2406)         for c in charset:
2407)             assert (
2408)                 c not in result.output
2409)             ), f'derived password contains forbidden character {c!r}'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2410) 
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2411)     def test_211_forward_vault_empty_command_line(
2412)         self,
2413)         monkeypatch: pytest.MonkeyPatch,
2414)         caplog: pytest.LogCaptureFixture,
2415)     ) -> None:
2416)         runner = click.testing.CliRunner(mix_stderr=False)
2417)         with tests.isolated_config(
2418)             monkeypatch=monkeypatch,
2419)             runner=runner,
2420)         ):
2421)             _result = runner.invoke(
2422)                 cli.derivepassphrase,
2423)                 [],
2424)                 input=DUMMY_PASSPHRASE,
2425)                 catch_exceptions=False,
2426)             )
2427)             result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2428)         assert tests.deprecation_warning_emitted(
2429)             'A subcommand will be required in v1.0', caplog.record_tuples
2430)         )
2431)         assert tests.warning_emitted(
2432)             'Defaulting to subcommand "vault"', caplog.record_tuples
2433)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2434)         assert result.error_exit(
2435)             error='SERVICE is required'
2436)         ), 'expected error exit and known error type'
2437) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2438)     def test_300_export_using_old_config_file(
2439)         self,
2440)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2441)         caplog: pytest.LogCaptureFixture,
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2442)     ) -> None:
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2443)         caplog.set_level(logging.INFO)
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2444)         runner = click.testing.CliRunner(mix_stderr=False)
2445)         with tests.isolated_config(
2446)             monkeypatch=monkeypatch,
2447)             runner=runner,
2448)         ):
2449)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2450)                 cli._config_filename(subsystem='old settings.json'),
2451)                 'w',
2452)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2453)             ) as fileobj:
2454)                 print(
2455)                     json.dumps(
2456)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
2457)                         indent=2,
2458)                     ),
2459)                     file=fileobj,
2460)                 )
2461)             _result = runner.invoke(
2462)                 cli.derivepassphrase_vault,
2463)                 ['--export', '-'],
2464)                 catch_exceptions=False,
2465)             )
2466)         result = tests.ReadableResult.parse(_result)
2467)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2468)         assert tests.deprecation_warning_emitted(
2469)             'v0.1-style config file', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2470)         ), 'expected known warning message in stderr'
Marco Ricci Fix usage of `--debug`, `--...

Marco Ricci authored 3 weeks ago

2471)         assert tests.deprecation_info_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2472)             'Successfully migrated to ', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2473)         ), 'expected known warning message in stderr'
2474) 
2475)     def test_300a_export_using_old_config_file_migration_error(
2476)         self,
2477)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2478)         caplog: pytest.LogCaptureFixture,
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2479)     ) -> None:
2480)         runner = click.testing.CliRunner(mix_stderr=False)
2481)         with tests.isolated_config(
2482)             monkeypatch=monkeypatch,
2483)             runner=runner,
2484)         ):
2485)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2486)                 cli._config_filename(subsystem='old settings.json'),
2487)                 'w',
2488)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2489)             ) as fileobj:
2490)                 print(
2491)                     json.dumps(
2492)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
2493)                         indent=2,
2494)                     ),
2495)                     file=fileobj,
2496)                 )
2497) 
2498)             def raiser(*_args: Any, **_kwargs: Any) -> None:
2499)                 raise OSError(
2500)                     errno.EACCES,
2501)                     os.strerror(errno.EACCES),
2502)                     cli._config_filename(subsystem='vault'),
2503)                 )
2504) 
2505)             monkeypatch.setattr(os, 'replace', raiser)
2506)             _result = runner.invoke(
2507)                 cli.derivepassphrase_vault,
2508)                 ['--export', '-'],
2509)                 catch_exceptions=False,
2510)             )
2511)         result = tests.ReadableResult.parse(_result)
2512)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2513)         assert tests.deprecation_warning_emitted(
2514)             'v0.1-style config file', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2515)         ), 'expected known warning message in stderr'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2516)         assert tests.warning_emitted(
2517)             'Failed to migrate to ', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2518)         ), 'expected known warning message in stderr'
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2519) 
2520) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2521) _known_services = (DUMMY_SERVICE, 'email', 'bank', 'work')
2522) _valid_properties = (
2523)     'length',
2524)     'repeat',
2525)     'upper',
2526)     'lower',
2527)     'number',
2528)     'space',
2529)     'dash',
2530)     'symbol',
2531) )
2532) 
2533) 
2534) def _build_reduced_vault_config_settings(
2535)     config: _types.VaultConfigServicesSettings,
2536)     keys_to_purge: frozenset[str],
2537) ) -> _types.VaultConfigServicesSettings:
2538)     config2 = copy.deepcopy(config)
2539)     for key in keys_to_purge:
2540)         config2.pop(key, None)  # type: ignore[misc]
2541)     return config2
2542) 
2543) 
2544) _services_strategy = strategies.builds(
2545)     _build_reduced_vault_config_settings,
2546)     tests.vault_full_service_config(),
2547)     strategies.sets(
2548)         strategies.sampled_from(_valid_properties),
2549)         max_size=7,
2550)     ),
2551) )
2552) 
2553) 
2554) def _assemble_config(
2555)     global_data: _types.VaultConfigGlobalSettings,
2556)     service_data: list[tuple[str, _types.VaultConfigServicesSettings]],
2557) ) -> _types.VaultConfig:
2558)     services_dict = dict(service_data)
2559)     return (
2560)         {'global': global_data, 'services': services_dict}
2561)         if global_data
2562)         else {'services': services_dict}
2563)     )
2564) 
2565) 
2566) @strategies.composite
2567) def _draw_service_name_and_data(
2568)     draw: hypothesis.strategies.DrawFn,
2569)     num_entries: int,
2570) ) -> tuple[tuple[str, _types.VaultConfigServicesSettings], ...]:
2571)     possible_services = list(_known_services)
2572)     selected_services: list[str] = []
2573)     for _ in range(num_entries):
2574)         selected_services.append(
2575)             draw(strategies.sampled_from(possible_services))
2576)         )
2577)         possible_services.remove(selected_services[-1])
2578)     return tuple(
2579)         (service, draw(_services_strategy)) for service in selected_services
2580)     )
2581) 
2582) 
2583) _vault_full_config = strategies.builds(
2584)     _assemble_config,
2585)     _services_strategy,
2586)     strategies.integers(
2587)         min_value=2,
2588)         max_value=4,
2589)     ).flatmap(_draw_service_name_and_data),
2590) )
2591) 
2592) 
Marco Ricci Actually correctly implemen...

Marco Ricci authored 4 weeks ago

2593) @tests.hypothesis_settings_coverage_compatible
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2594) class ConfigManagementStateMachine(stateful.RuleBasedStateMachine):
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2595)     def __init__(self) -> None:
2596)         super().__init__()
2597)         self.runner = click.testing.CliRunner(mix_stderr=False)
2598)         self.exit_stack = contextlib.ExitStack().__enter__()
2599)         self.monkeypatch = self.exit_stack.enter_context(
2600)             pytest.MonkeyPatch().context()
2601)         )
2602)         self.isolated_config = self.exit_stack.enter_context(
2603)             tests.isolated_vault_config(
2604)                 monkeypatch=self.monkeypatch,
2605)                 runner=self.runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

2606)                 vault_config={'services': {}},
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2607)             )
2608)         )
2609) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2610)     setting = stateful.Bundle('setting')
2611)     configuration = stateful.Bundle('configuration')
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2612) 
2613)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2614)         target=configuration,
2615)         configs=strategies.lists(
2616)             _vault_full_config,
2617)             min_size=4,
2618)             max_size=4,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2619)         ),
2620)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2621)     def declare_initial_configs(
2622)         self,
2623)         configs: Iterable[_types.VaultConfig],
2624)     ) -> Iterable[_types.VaultConfig]:
2625)         return stateful.multiple(*configs)
Marco Ricci Test config merging with pa...

Marco Ricci authored 4 weeks ago

2626) 
2627)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2628)         target=setting,
2629)         config=_vault_full_config,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2630)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2631)     def extract_initial_settings(
2632)         self,
2633)         config: _types.VaultConfig,
2634)     ) -> Iterable[_types.VaultConfigServicesSettings]:
2635)         return stateful.multiple(
2636)             *map(copy.deepcopy, config['services'].values())
2637)         )
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2638) 
2639)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2640)         target=configuration,
2641)         config=_vault_full_config,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2642)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2643)     def declare_config(
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2644)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2645)         config: _types.VaultConfig,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2646)     ) -> _types.VaultConfig:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2647)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2648) 
2649)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2650)         target=setting,
2651)         config=_vault_full_config,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2652)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2653)     def extract_settings(
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2654)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2655)         config: _types.VaultConfig,
2656)     ) -> Iterable[_types.VaultConfigServicesSettings]:
2657)         return stateful.multiple(
2658)             *map(copy.deepcopy, config['services'].values())
2659)         )
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2660) 
2661)     @staticmethod
2662)     def fold_configs(
2663)         c1: _types.VaultConfig, c2: _types.VaultConfig
2664)     ) -> _types.VaultConfig:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2665)         """Fold `c1` into `c2`, overriding the latter."""
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2666)         new_global_dict = c1.get('global', c2.get('global'))
2667)         if new_global_dict is not None:
2668)             return {
2669)                 'global': new_global_dict,
2670)                 'services': {**c2['services'], **c1['services']},
2671)             }
2672)         return {
2673)             'services': {**c2['services'], **c1['services']},
2674)         }
2675) 
2676)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2677)         target=configuration,
2678)         config=configuration,
2679)         setting=setting.filter(bool),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2680)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2681)     )
2682)     def set_globals(
2683)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2684)         config: _types.VaultConfig,
2685)         setting: _types.VaultConfigGlobalSettings,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2686)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2687)     ) -> _types.VaultConfig:
2688)         cli._save_config(config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2689)         if overwrite:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2690)             config['global'] = {}
2691)         config.setdefault('global', {}).update(setting)
2692)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2693)         # NOTE: This relies on settings_obj containing only the keys
2694)         # "length", "repeat", "upper", "lower", "number", "space",
2695)         # "dash" and "symbol".
2696)         _result = self.runner.invoke(
2697)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2698)             [
2699)                 '--config',
2700)                 '--overwrite-existing' if overwrite else '--merge-existing',
2701)             ]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2702)             + [
2703)                 f'--{key}={value}'
2704)                 for key, value in setting.items()
2705)                 if key in _valid_properties
2706)             ],
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2707)             catch_exceptions=False,
2708)         )
2709)         result = tests.ReadableResult.parse(_result)
2710)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2711)         assert cli._load_config() == config
2712)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2713) 
2714)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2715)         target=configuration,
2716)         config=configuration,
2717)         service=strategies.sampled_from(_known_services),
2718)         setting=setting.filter(bool),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2719)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2720)     )
2721)     def set_service(
2722)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2723)         config: _types.VaultConfig,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2724)         service: str,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2725)         setting: _types.VaultConfigServicesSettings,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2726)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2727)     ) -> _types.VaultConfig:
2728)         cli._save_config(config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2729)         if overwrite:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2730)             config['services'][service] = {}
2731)         config['services'].setdefault(service, {}).update(setting)
2732)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2733)         # NOTE: This relies on settings_obj containing only the keys
2734)         # "length", "repeat", "upper", "lower", "number", "space",
2735)         # "dash" and "symbol".
2736)         _result = self.runner.invoke(
2737)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2738)             [
2739)                 '--config',
2740)                 '--overwrite-existing' if overwrite else '--merge-existing',
2741)             ]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2742)             + [
2743)                 f'--{key}={value}'
2744)                 for key, value in setting.items()
2745)                 if key in _valid_properties
2746)             ]
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2747)             + ['--', service],
2748)             catch_exceptions=False,
2749)         )
2750)         result = tests.ReadableResult.parse(_result)
2751)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2752)         assert cli._load_config() == config
2753)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2754) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2755)     @stateful.rule(
2756)         target=configuration,
2757)         config=configuration.filter(lambda c: 'global' in c),
2758)     )
2759)     def purge_global(
2760)         self,
2761)         config: _types.VaultConfig,
2762)     ) -> _types.VaultConfig:
2763)         cli._save_config(config)
2764)         config.pop('global')
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2765)         _result = self.runner.invoke(
2766)             cli.derivepassphrase_vault,
2767)             ['--delete-globals'],
2768)             input='y',
2769)             catch_exceptions=False,
2770)         )
2771)         result = tests.ReadableResult.parse(_result)
2772)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2773)         assert cli._load_config() == config
2774)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2775) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2776)     @stateful.rule(
2777)         target=configuration,
2778)         config_and_service=configuration.filter(
2779)             lambda c: len(c['services']) > 1
2780)         ).flatmap(
2781)             lambda c: strategies.tuples(
2782)                 strategies.just(c),
2783)                 strategies.sampled_from(tuple(c['services'].keys())),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2784)             )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2785)         ),
2786)     )
2787)     def purge_service(
2788)         self,
2789)         config_and_service: tuple[_types.VaultConfig, str],
2790)     ) -> _types.VaultConfig:
2791)         config, service = config_and_service
2792)         cli._save_config(config)
2793)         config['services'].pop(service, None)
2794)         _result = self.runner.invoke(
2795)             cli.derivepassphrase_vault,
2796)             ['--delete', '--', service],
2797)             input='y',
2798)             catch_exceptions=False,
2799)         )
2800)         result = tests.ReadableResult.parse(_result)
2801)         assert result.clean_exit(empty_stderr=False)
2802)         assert cli._load_config() == config
2803)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2804) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2805)     @stateful.rule(
2806)         target=configuration,
2807)         config=configuration.filter(lambda c: 0 < len(c['services']) < 5),
2808)     )
2809)     def purge_all(
2810)         self,
2811)         config: _types.VaultConfig,
2812)     ) -> _types.VaultConfig:
2813)         cli._save_config(config)
2814)         config = {'services': {}}
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2815)         _result = self.runner.invoke(
2816)             cli.derivepassphrase_vault,
2817)             ['--clear'],
2818)             input='y',
2819)             catch_exceptions=False,
2820)         )
2821)         result = tests.ReadableResult.parse(_result)
2822)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2823)         assert cli._load_config() == config
2824)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2825) 
2826)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2827)         target=configuration,
2828)         base_config=configuration,
2829)         config_to_import=configuration,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2830)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2831)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2832)     def import_configuration(
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2833)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2834)         base_config: _types.VaultConfig,
2835)         config_to_import: _types.VaultConfig,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2836)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2837)     ) -> _types.VaultConfig:
2838)         cli._save_config(base_config)
2839)         config = (
2840)             self.fold_configs(config_to_import, base_config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2841)             if not overwrite
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2842)             else config_to_import
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2843)         )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2844)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2845)         _result = self.runner.invoke(
2846)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2847)             ['--import', '-']
2848)             + (['--overwrite-existing'] if overwrite else []),
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2849)             input=json.dumps(config_to_import),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2850)             catch_exceptions=False,
2851)         )
2852)         assert tests.ReadableResult.parse(_result).clean_exit(
2853)             empty_stderr=False
2854)         )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2855)         assert cli._load_config() == config
2856)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2857) 
2858)     def teardown(self) -> None:
2859)         self.exit_stack.close()
2860) 
2861)