Move exporter command-line...
Marco Ricci authored 2 weeks ago
|
21)
22) class TestCLI:
23) def test_200_path_parameter(self, monkeypatch: pytest.MonkeyPatch) -> None:
24) runner = click.testing.CliRunner(mix_stderr=False)
25) with tests.isolated_vault_exporter_config(
26) monkeypatch=monkeypatch,
27) runner=runner,
28) vault_config=tests.VAULT_V03_CONFIG,
29) vault_key=tests.VAULT_MASTER_KEY,
30) ):
31) monkeypatch.setenv('VAULT_KEY', tests.VAULT_MASTER_KEY)
32) result = runner.invoke(
33) cli.derivepassphrase_export,
34) ['VAULT_PATH'],
35) )
36) assert not result.exception
37) assert (result.exit_code, result.stderr_bytes) == (0, b'')
38) assert json.loads(result.stdout) == tests.VAULT_V03_CONFIG_DATA
39)
40) def test_201_key_parameter(self, monkeypatch: pytest.MonkeyPatch) -> None:
41) runner = click.testing.CliRunner(mix_stderr=False)
42) with tests.isolated_vault_exporter_config(
43) monkeypatch=monkeypatch,
44) runner=runner,
45) vault_config=tests.VAULT_V03_CONFIG,
46) ):
47) result = runner.invoke(
48) cli.derivepassphrase_export,
49) ['-k', tests.VAULT_MASTER_KEY, '.vault'],
50) )
51) assert not result.exception
52) assert (result.exit_code, result.stderr_bytes) == (0, b'')
53) assert json.loads(result.stdout) == tests.VAULT_V03_CONFIG_DATA
54)
55) @pytest.mark.parametrize(
56) ['format', 'config', 'config_data'],
57) [
58) pytest.param(
59) 'v0.2',
60) tests.VAULT_V02_CONFIG,
61) tests.VAULT_V02_CONFIG_DATA,
62) id='0.2',
63) ),
64) pytest.param(
65) 'v0.3',
66) tests.VAULT_V03_CONFIG,
67) tests.VAULT_V03_CONFIG_DATA,
68) id='0.3',
69) ),
70) pytest.param(
71) 'storeroom',
72) tests.VAULT_STOREROOM_CONFIG_ZIPPED,
73) tests.VAULT_STOREROOM_CONFIG_DATA,
74) id='storeroom',
75) ),
76) ],
77) )
78) def test_210_load_vault_v02_v03_storeroom(
79) self,
80) monkeypatch: pytest.MonkeyPatch,
81) format: str,
82) config: str | bytes,
83) config_data: dict[str, Any],
84) ) -> None:
85) runner = click.testing.CliRunner(mix_stderr=False)
86) with tests.isolated_vault_exporter_config(
87) monkeypatch=monkeypatch,
88) runner=runner,
89) vault_config=config,
90) ):
91) result = runner.invoke(
92) cli.derivepassphrase_export,
93) ['-f', format, '-k', tests.VAULT_MASTER_KEY, 'VAULT_PATH'],
94) )
95) assert not result.exception
96) assert (result.exit_code, result.stderr_bytes) == (0, b'')
97) assert json.loads(result.stdout) == config_data
98)
99) # test_300_invalid_format is found in
100) # tests.test_derivepassphrase_export::Test002CLI
101)
102) def test_301_vault_config_not_found(
103) self,
104) monkeypatch: pytest.MonkeyPatch,
105) ) -> None:
106) runner = click.testing.CliRunner(mix_stderr=False)
107) with tests.isolated_vault_exporter_config(
108) monkeypatch=monkeypatch,
109) runner=runner,
110) vault_config=tests.VAULT_V03_CONFIG,
111) vault_key=tests.VAULT_MASTER_KEY,
112) ):
113) result = runner.invoke(
114) cli.derivepassphrase_export,
115) ['does-not-exist.txt'],
116) )
117) assert isinstance(result.exception, SystemExit)
118) assert result.exit_code
119) assert result.stderr_bytes
120) assert (
121) b"Cannot parse 'does-not-exist.txt' as a valid config"
122) in result.stderr_bytes
123) )
124) assert tests.CANNOT_LOAD_CRYPTOGRAPHY not in result.stderr_bytes
125)
126) def test_302_vault_config_invalid(
127) self,
128) monkeypatch: pytest.MonkeyPatch,
129) ) -> None:
130) runner = click.testing.CliRunner(mix_stderr=False)
131) with tests.isolated_vault_exporter_config(
132) monkeypatch=monkeypatch,
133) runner=runner,
134) vault_config='',
135) vault_key=tests.VAULT_MASTER_KEY,
136) ):
137) result = runner.invoke(
138) cli.derivepassphrase_export,
139) ['.vault'],
140) )
141) assert isinstance(result.exception, SystemExit)
142) assert result.exit_code
143) assert result.stderr_bytes
144) assert (
145) b"Cannot parse '.vault' as a valid config." in result.stderr_bytes
146) )
147) assert tests.CANNOT_LOAD_CRYPTOGRAPHY not in result.stderr_bytes
|
Test exporter data loading...
Marco Ricci authored 2 weeks ago
|
148)
149) def test_403_invalid_vault_config_bad_signature(
150) self,
151) monkeypatch: pytest.MonkeyPatch,
152) ) -> None:
153) runner = click.testing.CliRunner(mix_stderr=False)
154) with tests.isolated_vault_exporter_config(
155) monkeypatch=monkeypatch,
156) runner=runner,
157) vault_config=tests.VAULT_V02_CONFIG,
158) vault_key=tests.VAULT_MASTER_KEY,
159) ):
160) result = runner.invoke(
161) cli.derivepassphrase_export,
162) ['-f', 'v0.3', '.vault'],
163) )
164) assert isinstance(result.exception, SystemExit)
165) assert result.exit_code
166) assert result.stderr_bytes
167) assert (
168) b"Cannot parse '.vault' as a valid config." in result.stderr_bytes
169) )
170) assert tests.CANNOT_LOAD_CRYPTOGRAPHY not in result.stderr_bytes
171)
172) def test_500_vault_config_invalid_internal(
173) self,
174) monkeypatch: pytest.MonkeyPatch,
175) ) -> None:
176) runner = click.testing.CliRunner(mix_stderr=False)
177) with tests.isolated_vault_exporter_config(
178) monkeypatch=monkeypatch,
179) runner=runner,
180) vault_config=tests.VAULT_V03_CONFIG,
181) vault_key=tests.VAULT_MASTER_KEY,
182) ):
183)
184) def _load_data(*_args: Any, **_kwargs: Any) -> None:
185) return None
186)
187) monkeypatch.setattr(cli, '_load_data', _load_data)
188) result = runner.invoke(
189) cli.derivepassphrase_export,
190) ['.vault'],
191) )
192) assert isinstance(result.exception, SystemExit)
193) assert result.exit_code
194) assert result.stderr_bytes
195) assert b'Invalid vault config: ' in result.stderr_bytes
196) assert tests.CANNOT_LOAD_CRYPTOGRAPHY not in result.stderr_bytes
|