5e5c12b78d541fd09e37595f1ba63deb22c82847
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 Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

7) import base64
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

17) import warnings
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

18) from typing import TYPE_CHECKING, NoReturn
Marco Ricci Add finished command-line i...

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

54) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

94) ]
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

247) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

274) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

300) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

325)     def test_204a_key_from_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

353) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

385) 
Marco Ricci Avoid crashing when overrid...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

440)     def test_205_service_phrase_if_key_in_global_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

480) 
Marco Ricci Fix missing consideration o...

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

692)     def test_212_incompatible_options(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

807)     def test_213c_import_bad_config_not_json_data(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

824)     def test_213d_import_bad_config_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

865)     def test_214a_export_settings_bad_stored_config(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

884)     def test_214b_export_settings_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

904)     def test_214c_export_settings_target_not_a_file(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

921) 
Marco Ricci Create the configuration di...

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

944) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

975) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1024) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 2 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1092)     def test_224_store_config_good(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1123) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1137)     def test_225_store_config_fail(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1286) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1300) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1318) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1391) 
Marco Ricci Clean up testing machinery...

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 4 months ago

1546) 
Marco Ricci Turn Unicode normalization...

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1763) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1823)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1825) [1] Egg and bacon
1826) [2] Egg, sausage and bacon
1827) [3] Egg and spam
1828) [4] Egg, bacon and spam
1829) [5] Egg, bacon, sausage and spam
1830) [6] Spam, bacon, sausage and spam
1831) [7] Spam, egg, spam, spam, bacon and spam
1832) [8] Spam, spam, spam, egg and spam
1833) [9] Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam
1834) [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

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1838) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1844)             try:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

1876)             result.output
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

1880) Boo.
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 6 months ago

1883) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

2033)     def test_203_repeated_config_deletion(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 weeks ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

2068)         )
2069) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

2087)     def test_227_get_suitable_ssh_keys(
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

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

Marco Ricci authored 4 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 5 months ago

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

Marco Ricci authored 6 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

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

Marco Ricci authored 3 months ago

2095)             monkeypatch.setattr(
2096)                 ssh_agent.SSHAgentClient, 'list_keys', tests.list_keys
2097)             )
2098)             hint: ssh_agent.SSHAgentClient | socket.socket | None
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

2099)             # Use match/case here once Python 3.9 becomes unsupported.
2100)             if conn_hint == 'client':
2101)                 hint = ssh_agent.SSHAgentClient()
2102)             elif conn_hint == 'socket':
2103)                 hint = socket.socket(family=socket.AF_UNIX)
Marco Ricci Let the `running_ssh_agent`...

Marco Ricci authored 1 month ago

2104)                 hint.connect(running_ssh_agent.socket)
Marco Ricci Add support for Python 3.9

Marco Ricci authored 3 months ago

2105)             else:
2106)                 assert conn_hint == 'none'
2107)                 hint = None
Marco Ricci Add test fixture for manual...

Marco Ricci authored 3 months ago

2108)             exception: Exception | None = None
2109)             try:
2110)                 list(cli._get_suitable_ssh_keys(hint))
2111)             except RuntimeError:  # pragma: no cover
2112)                 pass
2113)             except Exception as e:  # noqa: BLE001 # pragma: no cover
2114)                 exception = e
2115)             finally:
2116)                 assert (
2117)                     exception is None
2118)                 ), 'exception querying suitable SSH keys'
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2119) 
Marco Ricci Hoist and add tests for int...

Marco Ricci authored 3 weeks ago

2120)     def test_400_key_to_phrase(
2121)         self,
2122)         monkeypatch: pytest.MonkeyPatch,
2123)         skip_if_no_af_unix_support: None,
2124)         ssh_agent_client_with_test_keys_loaded: ssh_agent.SSHAgentClient,
2125)     ) -> None:
2126) 
2127)         class CustomError(RuntimeError):
2128)             pass
2129) 
2130)         def err(*args: Any, **_kwargs: Any) -> NoReturn:
2131)             args = args or ('custom error message',)
2132)             raise CustomError(*args)
2133) 
2134)         def fail(*_args: Any, **_kwargs: Any) -> Any:
2135)             raise ssh_agent.SSHAgentFailedError(
2136)                 _types.SSH_AGENT.FAILURE.value,
2137)                 b'',
2138)             )
2139) 
2140)         del skip_if_no_af_unix_support
2141)         monkeypatch.setattr(ssh_agent.SSHAgentClient, 'sign', fail)
2142)         loaded_keys = list(ssh_agent_client_with_test_keys_loaded.list_keys())
2143)         loaded_key = base64.standard_b64encode(loaded_keys[0][0])
2144)         with monkeypatch.context() as mp:
2145)             mp.setattr(
2146)                 ssh_agent.SSHAgentClient,
2147)                 'list_keys',
2148)                 lambda *_a, **_kw: [],
2149)             )
2150)             with pytest.raises(CustomError, match='not loaded into the agent'):
2151)                 cli._key_to_phrase(loaded_key, error_callback=err)
2152)         with monkeypatch.context() as mp:
2153)             mp.setattr(ssh_agent.SSHAgentClient, 'list_keys', fail)
2154)             with pytest.raises(
2155)                 CustomError, match='SSH agent failed to complete'
2156)             ):
2157)                 cli._key_to_phrase(loaded_key, error_callback=err)
2158)         with monkeypatch.context() as mp:
2159)             mp.setattr(ssh_agent.SSHAgentClient, 'list_keys', err)
2160)             with pytest.raises(
2161)                 CustomError, match='SSH agent failed to complete'
2162)             ) as excinfo:
2163)                 cli._key_to_phrase(loaded_key, error_callback=err)
2164)             assert excinfo.value.args
2165)             assert isinstance(
2166)                 excinfo.value.args[0], ssh_agent.SSHAgentFailedError
2167)             )
2168)             assert excinfo.value.args[0].__context__ is not None
2169)             assert isinstance(excinfo.value.args[0].__context__, CustomError)
2170)         with monkeypatch.context() as mp:
2171)             mp.delenv('SSH_AUTH_SOCK', raising=True)
2172)             with pytest.raises(
2173)                 CustomError, match='Cannot find running SSH agent'
2174)             ):
2175)                 cli._key_to_phrase(loaded_key, error_callback=err)
2176)         with monkeypatch.context() as mp:
2177)             mp.setenv(
2178)                 'SSH_AUTH_SOCK', os.environ['SSH_AUTH_SOCK'] + '~'
2179)             )
2180)             with pytest.raises(
2181)                 CustomError, match='Cannot connect to SSH agent'
2182)             ):
2183)                 cli._key_to_phrase(loaded_key, error_callback=err)
2184)         with monkeypatch.context() as mp:
2185)             mp.delattr(socket, 'AF_UNIX', raising=True)
2186)             with pytest.raises(
2187)                 CustomError, match='does not support UNIX domain sockets'
2188)             ):
2189)                 cli._key_to_phrase(loaded_key, error_callback=err)
2190) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2191) 
2192) class TestCLITransition:
2193)     def test_100_help_output(self, monkeypatch: pytest.MonkeyPatch) -> None:
2194)         runner = click.testing.CliRunner(mix_stderr=False)
2195)         with tests.isolated_config(
2196)             monkeypatch=monkeypatch,
2197)             runner=runner,
2198)         ):
2199)             _result = runner.invoke(
2200)                 cli.derivepassphrase, ['--help'], catch_exceptions=False
2201)             )
2202)             result = tests.ReadableResult.parse(_result)
2203)         assert result.clean_exit(
2204)             empty_stderr=True, output='currently implemented subcommands'
2205)         ), 'expected clean exit, and known help text'
2206) 
2207)     def test_101_help_output_export(
2208)         self, monkeypatch: pytest.MonkeyPatch
2209)     ) -> None:
2210)         runner = click.testing.CliRunner(mix_stderr=False)
2211)         with tests.isolated_config(
2212)             monkeypatch=monkeypatch,
2213)             runner=runner,
2214)         ):
2215)             _result = runner.invoke(
2216)                 cli.derivepassphrase,
2217)                 ['export', '--help'],
2218)                 catch_exceptions=False,
2219)             )
2220)             result = tests.ReadableResult.parse(_result)
2221)         assert result.clean_exit(
2222)             empty_stderr=True, output='only available subcommand'
2223)         ), 'expected clean exit, and known help text'
2224) 
2225)     def test_102_help_output_export_vault(
2226)         self, monkeypatch: pytest.MonkeyPatch
2227)     ) -> None:
2228)         runner = click.testing.CliRunner(mix_stderr=False)
2229)         with tests.isolated_config(
2230)             monkeypatch=monkeypatch,
2231)             runner=runner,
2232)         ):
2233)             _result = runner.invoke(
2234)                 cli.derivepassphrase,
2235)                 ['export', 'vault', '--help'],
2236)                 catch_exceptions=False,
2237)             )
2238)             result = tests.ReadableResult.parse(_result)
2239)         assert result.clean_exit(
2240)             empty_stderr=True, output='Read the vault-native configuration'
2241)         ), 'expected clean exit, and known help text'
2242) 
2243)     def test_103_help_output_vault(
2244)         self, monkeypatch: pytest.MonkeyPatch
2245)     ) -> None:
2246)         runner = click.testing.CliRunner(mix_stderr=False)
2247)         with tests.isolated_config(
2248)             monkeypatch=monkeypatch,
2249)             runner=runner,
2250)         ):
2251)             _result = runner.invoke(
2252)                 cli.derivepassphrase,
2253)                 ['vault', '--help'],
2254)                 catch_exceptions=False,
2255)             )
2256)             result = tests.ReadableResult.parse(_result)
2257)         assert result.clean_exit(
2258)             empty_stderr=True, output='Password generation:\n'
2259)         ), 'expected clean exit, and option groups in help text'
2260)         assert result.clean_exit(
2261)             empty_stderr=True, output='Use NUMBER=0, e.g. "--symbol 0"'
2262)         ), 'expected clean exit, and option group epilog in help text'
2263) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2264)     @pytest.mark.parametrize(
2265)         'config',
2266)         [
2267)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2268)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2269)             {
2270)                 'global': {'phrase': 'abc'},
2271)                 'services': {'sv': {'phrase': 'my passphrase'}},
2272)             },
2273)             {
2274)                 'global': {'phrase': 'abc'},
2275)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2276)             },
2277)             {
2278)                 'global': {'phrase': 'abc'},
2279)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2280)             },
2281)         ],
2282)     )
2283)     def test_110_load_config_backup(
2284)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2285)     ) -> None:
2286)         runner = click.testing.CliRunner()
2287)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2288)             config_filename = cli._config_filename(
2289)                 subsystem='old settings.json'
2290)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2291)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2292)                 print(json.dumps(config, indent=2), file=fileobj)
2293)             assert cli._migrate_and_load_old_config()[0] == config
2294) 
2295)     @pytest.mark.parametrize(
2296)         'config',
2297)         [
2298)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2299)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2300)             {
2301)                 'global': {'phrase': 'abc'},
2302)                 'services': {'sv': {'phrase': 'my passphrase'}},
2303)             },
2304)             {
2305)                 'global': {'phrase': 'abc'},
2306)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2307)             },
2308)             {
2309)                 'global': {'phrase': 'abc'},
2310)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2311)             },
2312)         ],
2313)     )
2314)     def test_111_migrate_config(
2315)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2316)     ) -> None:
2317)         runner = click.testing.CliRunner()
2318)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2319)             config_filename = cli._config_filename(
2320)                 subsystem='old settings.json'
2321)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2322)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2323)                 print(json.dumps(config, indent=2), file=fileobj)
2324)             assert cli._migrate_and_load_old_config() == (config, None)
2325) 
2326)     @pytest.mark.parametrize(
2327)         'config',
2328)         [
2329)             {'global': {'phrase': 'my passphrase'}, 'services': {}},
2330)             {'global': {'key': DUMMY_KEY1_B64}, 'services': {}},
2331)             {
2332)                 'global': {'phrase': 'abc'},
2333)                 'services': {'sv': {'phrase': 'my passphrase'}},
2334)             },
2335)             {
2336)                 'global': {'phrase': 'abc'},
2337)                 'services': {'sv': {'key': DUMMY_KEY1_B64}},
2338)             },
2339)             {
2340)                 'global': {'phrase': 'abc'},
2341)                 'services': {'sv': {'key': DUMMY_KEY1_B64, 'length': 15}},
2342)             },
2343)         ],
2344)     )
2345)     def test_112_migrate_config_error(
2346)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2347)     ) -> None:
2348)         runner = click.testing.CliRunner()
2349)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2350)             config_filename = cli._config_filename(
2351)                 subsystem='old settings.json'
2352)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2353)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2354)                 print(json.dumps(config, indent=2), file=fileobj)
2355)             os.mkdir(cli._config_filename(subsystem='vault'))
2356)             config2, err = cli._migrate_and_load_old_config()
2357)             assert config2 == config
2358)             assert isinstance(err, OSError)
2359)             assert err.errno == errno.EISDIR
2360) 
2361)     @pytest.mark.parametrize(
2362)         'config',
2363)         [
2364)             {'global': '', 'services': {}},
2365)             {'global': 0, 'services': {}},
2366)             {
2367)                 'global': {'phrase': 'abc'},
2368)                 'services': False,
2369)             },
2370)             {
2371)                 'global': {'phrase': 'abc'},
2372)                 'services': True,
2373)             },
2374)             {
2375)                 'global': {'phrase': 'abc'},
2376)                 'services': None,
2377)             },
2378)         ],
2379)     )
2380)     def test_113_migrate_config_error_bad_config_value(
2381)         self, monkeypatch: pytest.MonkeyPatch, config: Any
2382)     ) -> None:
2383)         runner = click.testing.CliRunner()
2384)         with tests.isolated_config(monkeypatch=monkeypatch, runner=runner):
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2385)             config_filename = cli._config_filename(
2386)                 subsystem='old settings.json'
2387)             )
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2388)             with open(config_filename, 'w', encoding='UTF-8') as fileobj:
2389)                 print(json.dumps(config, indent=2), file=fileobj)
2390)             with pytest.raises(ValueError, match=cli._INVALID_VAULT_CONFIG):
2391)                 cli._migrate_and_load_old_config()
2392) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2393)     def test_200_forward_export_vault_path_parameter(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2394)         self,
2395)         monkeypatch: pytest.MonkeyPatch,
2396)         caplog: pytest.LogCaptureFixture,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2397)     ) -> None:
2398)         pytest.importorskip('cryptography', minversion='38.0')
2399)         runner = click.testing.CliRunner(mix_stderr=False)
2400)         with tests.isolated_vault_exporter_config(
2401)             monkeypatch=monkeypatch,
2402)             runner=runner,
2403)             vault_config=tests.VAULT_V03_CONFIG,
2404)             vault_key=tests.VAULT_MASTER_KEY,
2405)         ):
2406)             monkeypatch.setenv('VAULT_KEY', tests.VAULT_MASTER_KEY)
2407)             _result = runner.invoke(
2408)                 cli.derivepassphrase,
2409)                 ['export', 'VAULT_PATH'],
2410)             )
2411)         result = tests.ReadableResult.parse(_result)
2412)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2413)         assert tests.deprecation_warning_emitted(
2414)             'A subcommand will be required in v1.0', caplog.record_tuples
2415)         )
2416)         assert tests.warning_emitted(
2417)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

2418)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2419)         assert json.loads(result.output) == tests.VAULT_V03_CONFIG_DATA
2420) 
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2421)     def test_201_forward_export_vault_empty_commandline(
2422)         self,
2423)         monkeypatch: pytest.MonkeyPatch,
2424)         caplog: pytest.LogCaptureFixture,
2425)     ) -> None:
2426)         pytest.importorskip('cryptography', minversion='38.0')
2427)         runner = click.testing.CliRunner(mix_stderr=False)
2428)         with tests.isolated_config(
2429)             monkeypatch=monkeypatch,
2430)             runner=runner,
2431)         ):
2432)             _result = runner.invoke(
2433)                 cli.derivepassphrase,
2434)                 ['export'],
2435)             )
2436)         result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2437)         assert tests.deprecation_warning_emitted(
2438)             'A subcommand will be required in v1.0', caplog.record_tuples
2439)         )
2440)         assert tests.warning_emitted(
2441)             'Defaulting to subcommand "vault"', caplog.record_tuples
2442)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2443)         assert result.error_exit(
2444)             error="Missing argument 'PATH'"
2445)         ), 'expected error exit and known error type'
2446) 
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2447)     @pytest.mark.parametrize(
2448)         'charset_name', ['lower', 'upper', 'number', 'space', 'dash', 'symbol']
2449)     )
2450)     def test_210_forward_vault_disable_character_set(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2451)         self,
2452)         monkeypatch: pytest.MonkeyPatch,
2453)         caplog: pytest.LogCaptureFixture,
2454)         charset_name: str,
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

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

Marco Ricci authored 3 months ago

2459)         runner = click.testing.CliRunner(mix_stderr=False)
2460)         with tests.isolated_config(
2461)             monkeypatch=monkeypatch,
2462)             runner=runner,
2463)         ):
2464)             _result = runner.invoke(
2465)                 cli.derivepassphrase,
Marco Ricci Fix missing escaping in tes...

Marco Ricci authored 1 month ago

2466)                 [option, '0', '-p', '--', DUMMY_SERVICE],
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2467)                 input=DUMMY_PASSPHRASE,
2468)                 catch_exceptions=False,
2469)             )
2470)             result = tests.ReadableResult.parse(_result)
2471)         assert result.clean_exit(empty_stderr=False), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2472)         assert tests.deprecation_warning_emitted(
2473)             'A subcommand will be required in v1.0', caplog.record_tuples
2474)         )
2475)         assert tests.warning_emitted(
2476)             'Defaulting to subcommand "vault"', caplog.record_tuples
Marco Ricci Fix minor typo, formatting...

Marco Ricci authored 3 months ago

2477)         )
Marco Ricci Reintegrate all functionali...

Marco Ricci authored 3 months ago

2478)         for c in charset:
2479)             assert (
2480)                 c not in result.output
2481)             ), f'derived password contains forbidden character {c!r}'
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2482) 
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2483)     def test_211_forward_vault_empty_command_line(
2484)         self,
2485)         monkeypatch: pytest.MonkeyPatch,
2486)         caplog: pytest.LogCaptureFixture,
2487)     ) -> None:
2488)         runner = click.testing.CliRunner(mix_stderr=False)
2489)         with tests.isolated_config(
2490)             monkeypatch=monkeypatch,
2491)             runner=runner,
2492)         ):
2493)             _result = runner.invoke(
2494)                 cli.derivepassphrase,
2495)                 [],
2496)                 input=DUMMY_PASSPHRASE,
2497)                 catch_exceptions=False,
2498)             )
2499)             result = tests.ReadableResult.parse(_result)
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2500)         assert tests.deprecation_warning_emitted(
2501)             'A subcommand will be required in v1.0', caplog.record_tuples
2502)         )
2503)         assert tests.warning_emitted(
2504)             'Defaulting to subcommand "vault"', caplog.record_tuples
2505)         )
Marco Ricci Reimplement deprecated subc...

Marco Ricci authored 1 month ago

2506)         assert result.error_exit(
2507)             error='SERVICE is required'
2508)         ), 'expected error exit and known error type'
2509) 
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2510)     def test_300_export_using_old_config_file(
2511)         self,
2512)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2513)         caplog: pytest.LogCaptureFixture,
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

2515)         caplog.set_level(logging.INFO)
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2516)         runner = click.testing.CliRunner(mix_stderr=False)
2517)         with tests.isolated_config(
2518)             monkeypatch=monkeypatch,
2519)             runner=runner,
2520)         ):
2521)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2522)                 cli._config_filename(subsystem='old settings.json'),
2523)                 'w',
2524)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2525)             ) as fileobj:
2526)                 print(
2527)                     json.dumps(
2528)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
2529)                         indent=2,
2530)                     ),
2531)                     file=fileobj,
2532)                 )
2533)             _result = runner.invoke(
2534)                 cli.derivepassphrase_vault,
2535)                 ['--export', '-'],
2536)                 catch_exceptions=False,
2537)             )
2538)         result = tests.ReadableResult.parse(_result)
2539)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2540)         assert tests.deprecation_warning_emitted(
2541)             'v0.1-style config file', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2542)         ), 'expected known warning message in stderr'
Marco Ricci Fix usage of `--debug`, `--...

Marco Ricci authored 3 weeks ago

2543)         assert tests.deprecation_info_emitted(
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2544)             'Successfully migrated to ', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2545)         ), 'expected known warning message in stderr'
2546) 
2547)     def test_300a_export_using_old_config_file_migration_error(
2548)         self,
2549)         monkeypatch: pytest.MonkeyPatch,
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2550)         caplog: pytest.LogCaptureFixture,
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2551)     ) -> None:
2552)         runner = click.testing.CliRunner(mix_stderr=False)
2553)         with tests.isolated_config(
2554)             monkeypatch=monkeypatch,
2555)             runner=runner,
2556)         ):
2557)             with open(
Marco Ricci Make obtaining the compatib...

Marco Ricci authored 3 weeks ago

2558)                 cli._config_filename(subsystem='old settings.json'),
2559)                 'w',
2560)                 encoding='UTF-8',
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2561)             ) as fileobj:
2562)                 print(
2563)                     json.dumps(
2564)                         {'services': {DUMMY_SERVICE: DUMMY_CONFIG_SETTINGS}},
2565)                         indent=2,
2566)                     ),
2567)                     file=fileobj,
2568)                 )
2569) 
2570)             def raiser(*_args: Any, **_kwargs: Any) -> None:
2571)                 raise OSError(
2572)                     errno.EACCES,
2573)                     os.strerror(errno.EACCES),
2574)                     cli._config_filename(subsystem='vault'),
2575)                 )
2576) 
2577)             monkeypatch.setattr(os, 'replace', raiser)
2578)             _result = runner.invoke(
2579)                 cli.derivepassphrase_vault,
2580)                 ['--export', '-'],
2581)                 catch_exceptions=False,
2582)             )
2583)         result = tests.ReadableResult.parse(_result)
2584)         assert result.clean_exit(), 'expected clean exit'
Marco Ricci Adapt the test suite to use...

Marco Ricci authored 1 month ago

2585)         assert tests.deprecation_warning_emitted(
2586)             'v0.1-style config file', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

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

Marco Ricci authored 1 month ago

2588)         assert tests.warning_emitted(
2589)             'Failed to migrate to ', caplog.record_tuples
Marco Ricci Rename the configuration fi...

Marco Ricci authored 3 months ago

2590)         ), 'expected known warning message in stderr'
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2591) 
2592) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2593) _known_services = (DUMMY_SERVICE, 'email', 'bank', 'work')
2594) _valid_properties = (
2595)     'length',
2596)     'repeat',
2597)     'upper',
2598)     'lower',
2599)     'number',
2600)     'space',
2601)     'dash',
2602)     'symbol',
2603) )
2604) 
2605) 
2606) def _build_reduced_vault_config_settings(
2607)     config: _types.VaultConfigServicesSettings,
2608)     keys_to_purge: frozenset[str],
2609) ) -> _types.VaultConfigServicesSettings:
2610)     config2 = copy.deepcopy(config)
2611)     for key in keys_to_purge:
2612)         config2.pop(key, None)  # type: ignore[misc]
2613)     return config2
2614) 
2615) 
2616) _services_strategy = strategies.builds(
2617)     _build_reduced_vault_config_settings,
2618)     tests.vault_full_service_config(),
2619)     strategies.sets(
2620)         strategies.sampled_from(_valid_properties),
2621)         max_size=7,
2622)     ),
2623) )
2624) 
2625) 
2626) def _assemble_config(
2627)     global_data: _types.VaultConfigGlobalSettings,
2628)     service_data: list[tuple[str, _types.VaultConfigServicesSettings]],
2629) ) -> _types.VaultConfig:
2630)     services_dict = dict(service_data)
2631)     return (
2632)         {'global': global_data, 'services': services_dict}
2633)         if global_data
2634)         else {'services': services_dict}
2635)     )
2636) 
2637) 
2638) @strategies.composite
2639) def _draw_service_name_and_data(
2640)     draw: hypothesis.strategies.DrawFn,
2641)     num_entries: int,
2642) ) -> tuple[tuple[str, _types.VaultConfigServicesSettings], ...]:
2643)     possible_services = list(_known_services)
2644)     selected_services: list[str] = []
2645)     for _ in range(num_entries):
2646)         selected_services.append(
2647)             draw(strategies.sampled_from(possible_services))
2648)         )
2649)         possible_services.remove(selected_services[-1])
2650)     return tuple(
2651)         (service, draw(_services_strategy)) for service in selected_services
2652)     )
2653) 
2654) 
2655) _vault_full_config = strategies.builds(
2656)     _assemble_config,
2657)     _services_strategy,
2658)     strategies.integers(
2659)         min_value=2,
2660)         max_value=4,
2661)     ).flatmap(_draw_service_name_and_data),
2662) )
2663) 
2664) 
Marco Ricci Actually correctly implemen...

Marco Ricci authored 4 weeks ago

2665) @tests.hypothesis_settings_coverage_compatible
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2666) class ConfigManagementStateMachine(stateful.RuleBasedStateMachine):
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2667)     def __init__(self) -> None:
2668)         super().__init__()
2669)         self.runner = click.testing.CliRunner(mix_stderr=False)
2670)         self.exit_stack = contextlib.ExitStack().__enter__()
2671)         self.monkeypatch = self.exit_stack.enter_context(
2672)             pytest.MonkeyPatch().context()
2673)         )
2674)         self.isolated_config = self.exit_stack.enter_context(
2675)             tests.isolated_vault_config(
2676)                 monkeypatch=self.monkeypatch,
2677)                 runner=self.runner,
Marco Ricci Introduce a central user co...

Marco Ricci authored 3 weeks ago

2678)                 vault_config={'services': {}},
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2679)             )
2680)         )
2681) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2682)     setting = stateful.Bundle('setting')
2683)     configuration = stateful.Bundle('configuration')
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2684) 
2685)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2686)         target=configuration,
2687)         configs=strategies.lists(
2688)             _vault_full_config,
2689)             min_size=4,
2690)             max_size=4,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2691)         ),
2692)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2693)     def declare_initial_configs(
2694)         self,
2695)         configs: Iterable[_types.VaultConfig],
2696)     ) -> Iterable[_types.VaultConfig]:
2697)         return stateful.multiple(*configs)
Marco Ricci Test config merging with pa...

Marco Ricci authored 4 weeks ago

2698) 
2699)     @stateful.initialize(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2700)         target=setting,
2701)         config=_vault_full_config,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2702)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2703)     def extract_initial_settings(
2704)         self,
2705)         config: _types.VaultConfig,
2706)     ) -> Iterable[_types.VaultConfigServicesSettings]:
2707)         return stateful.multiple(
2708)             *map(copy.deepcopy, config['services'].values())
2709)         )
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2710) 
2711)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2712)         target=configuration,
2713)         config=_vault_full_config,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2714)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2715)     def declare_config(
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2716)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2717)         config: _types.VaultConfig,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2718)     ) -> _types.VaultConfig:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2719)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2720) 
2721)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2722)         target=setting,
2723)         config=_vault_full_config,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2724)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2725)     def extract_settings(
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2726)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2727)         config: _types.VaultConfig,
2728)     ) -> Iterable[_types.VaultConfigServicesSettings]:
2729)         return stateful.multiple(
2730)             *map(copy.deepcopy, config['services'].values())
2731)         )
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2732) 
2733)     @staticmethod
2734)     def fold_configs(
2735)         c1: _types.VaultConfig, c2: _types.VaultConfig
2736)     ) -> _types.VaultConfig:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2737)         """Fold `c1` into `c2`, overriding the latter."""
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2738)         new_global_dict = c1.get('global', c2.get('global'))
2739)         if new_global_dict is not None:
2740)             return {
2741)                 'global': new_global_dict,
2742)                 'services': {**c2['services'], **c1['services']},
2743)             }
2744)         return {
2745)             'services': {**c2['services'], **c1['services']},
2746)         }
2747) 
2748)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2749)         target=configuration,
2750)         config=configuration,
2751)         setting=setting.filter(bool),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2752)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2753)     )
2754)     def set_globals(
2755)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2756)         config: _types.VaultConfig,
2757)         setting: _types.VaultConfigGlobalSettings,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2758)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2759)     ) -> _types.VaultConfig:
2760)         cli._save_config(config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2761)         if overwrite:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2762)             config['global'] = {}
2763)         config.setdefault('global', {}).update(setting)
2764)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2765)         # NOTE: This relies on settings_obj containing only the keys
2766)         # "length", "repeat", "upper", "lower", "number", "space",
2767)         # "dash" and "symbol".
2768)         _result = self.runner.invoke(
2769)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2770)             [
2771)                 '--config',
2772)                 '--overwrite-existing' if overwrite else '--merge-existing',
2773)             ]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2774)             + [
2775)                 f'--{key}={value}'
2776)                 for key, value in setting.items()
2777)                 if key in _valid_properties
2778)             ],
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2779)             catch_exceptions=False,
2780)         )
2781)         result = tests.ReadableResult.parse(_result)
2782)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2783)         assert cli._load_config() == config
2784)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2785) 
2786)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2787)         target=configuration,
2788)         config=configuration,
2789)         service=strategies.sampled_from(_known_services),
2790)         setting=setting.filter(bool),
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2791)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2792)     )
2793)     def set_service(
2794)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2795)         config: _types.VaultConfig,
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2796)         service: str,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2797)         setting: _types.VaultConfigServicesSettings,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2798)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2799)     ) -> _types.VaultConfig:
2800)         cli._save_config(config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2801)         if overwrite:
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2802)             config['services'][service] = {}
2803)         config['services'].setdefault(service, {}).update(setting)
2804)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2805)         # NOTE: This relies on settings_obj containing only the keys
2806)         # "length", "repeat", "upper", "lower", "number", "space",
2807)         # "dash" and "symbol".
2808)         _result = self.runner.invoke(
2809)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2810)             [
2811)                 '--config',
2812)                 '--overwrite-existing' if overwrite else '--merge-existing',
2813)             ]
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2814)             + [
2815)                 f'--{key}={value}'
2816)                 for key, value in setting.items()
2817)                 if key in _valid_properties
2818)             ]
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2819)             + ['--', service],
2820)             catch_exceptions=False,
2821)         )
2822)         result = tests.ReadableResult.parse(_result)
2823)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2824)         assert cli._load_config() == config
2825)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2826) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2827)     @stateful.rule(
2828)         target=configuration,
2829)         config=configuration.filter(lambda c: 'global' in c),
2830)     )
2831)     def purge_global(
2832)         self,
2833)         config: _types.VaultConfig,
2834)     ) -> _types.VaultConfig:
2835)         cli._save_config(config)
2836)         config.pop('global')
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2837)         _result = self.runner.invoke(
2838)             cli.derivepassphrase_vault,
2839)             ['--delete-globals'],
2840)             input='y',
2841)             catch_exceptions=False,
2842)         )
2843)         result = tests.ReadableResult.parse(_result)
2844)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2845)         assert cli._load_config() == config
2846)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2847) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2848)     @stateful.rule(
2849)         target=configuration,
2850)         config_and_service=configuration.filter(
2851)             lambda c: len(c['services']) > 1
2852)         ).flatmap(
2853)             lambda c: strategies.tuples(
2854)                 strategies.just(c),
2855)                 strategies.sampled_from(tuple(c['services'].keys())),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2856)             )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2857)         ),
2858)     )
2859)     def purge_service(
2860)         self,
2861)         config_and_service: tuple[_types.VaultConfig, str],
2862)     ) -> _types.VaultConfig:
2863)         config, service = config_and_service
2864)         cli._save_config(config)
2865)         config['services'].pop(service, None)
2866)         _result = self.runner.invoke(
2867)             cli.derivepassphrase_vault,
2868)             ['--delete', '--', service],
2869)             input='y',
2870)             catch_exceptions=False,
2871)         )
2872)         result = tests.ReadableResult.parse(_result)
2873)         assert result.clean_exit(empty_stderr=False)
2874)         assert cli._load_config() == config
2875)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2876) 
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2877)     @stateful.rule(
2878)         target=configuration,
2879)         config=configuration.filter(lambda c: 0 < len(c['services']) < 5),
2880)     )
2881)     def purge_all(
2882)         self,
2883)         config: _types.VaultConfig,
2884)     ) -> _types.VaultConfig:
2885)         cli._save_config(config)
2886)         config = {'services': {}}
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2887)         _result = self.runner.invoke(
2888)             cli.derivepassphrase_vault,
2889)             ['--clear'],
2890)             input='y',
2891)             catch_exceptions=False,
2892)         )
2893)         result = tests.ReadableResult.parse(_result)
2894)         assert result.clean_exit(empty_stderr=False)
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2895)         assert cli._load_config() == config
2896)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2897) 
2898)     @stateful.rule(
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2899)         target=configuration,
2900)         base_config=configuration,
2901)         config_to_import=configuration,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2902)         overwrite=strategies.booleans(),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2903)     )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2904)     def import_configuration(
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2905)         self,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2906)         base_config: _types.VaultConfig,
2907)         config_to_import: _types.VaultConfig,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2908)         overwrite: bool,
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2909)     ) -> _types.VaultConfig:
2910)         cli._save_config(base_config)
2911)         config = (
2912)             self.fold_configs(config_to_import, base_config)
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2913)             if not overwrite
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2914)             else config_to_import
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2915)         )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2916)         assert _types.is_vault_config(config)
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2917)         _result = self.runner.invoke(
2918)             cli.derivepassphrase_vault,
Marco Ricci Allow the user to overwrite...

Marco Ricci authored 4 weeks ago

2919)             ['--import', '-']
2920)             + (['--overwrite-existing'] if overwrite else []),
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2921)             input=json.dumps(config_to_import),
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2922)             catch_exceptions=False,
2923)         )
2924)         assert tests.ReadableResult.parse(_result).clean_exit(
2925)             empty_stderr=False
2926)         )
Marco Ricci Overhaul the state machine...

Marco Ricci authored 4 weeks ago

2927)         assert cli._load_config() == config
2928)         return config
Marco Ricci Add a stateful hypothesis t...

Marco Ricci authored 2 months ago

2929) 
2930)     def teardown(self) -> None:
2931)         self.exit_stack.close()
2932) 
2933)