Coverage for tests/test_typing.py: 100.000%
7 statements
« prev ^ index » next coverage.py v7.5.3, created at 2024-06-24 13:13 +0200
« prev ^ index » next coverage.py v7.5.3, created at 2024-06-24 13:13 +0200
1# SPDX-FileCopyrightText: 2024 Marco Ricci <m@the13thletter.info>
2#
3# SPDX-License-Identifier: MIT
5from __future__ import annotations
7from typing import Any, cast, TYPE_CHECKING, NamedTuple
9import derivepassphrase as dpp
10import pytest
12@pytest.mark.parametrize(['obj', 'comment'], [
13 (None, 'not a dict'),
14 ({}, 'missing required keys'),
15 ({'global': None, 'services': {}}, 'bad config value: global'),
16 ({'global': {'key': 123}, 'services': {}},
17 'bad config value: global.key'),
18 ({'global': {'phrase': 'abc', 'key': '...'}, 'services': {}},
19 'incompatible config values: global.key and global.phrase'),
20 ({'services': None}, 'bad config value: services'),
21 ({'services': {2: {}}}, 'bad config value: services."2"'),
22 ({'services': {'2': 2}}, 'bad config value: services."2"'),
23 ({'services': {'sv': {'notes': False}}},
24 'bad config value: services.sv.notes'),
25 ({'services': {'sv': {'notes': 'blah blah blah'}}}, ''),
26 ({'services': {'sv': {'length': '200'}}},
27 'bad config value: services.sv.length'),
28 ({'services': {'sv': {'length': 0.5}}},
29 'bad config value: services.sv.length'),
30 ({'services': {'sv': {'length': -10}}},
31 'bad config value: services.sv.length'),
32 ({'services': {'sv': {'upper': -10}}},
33 'bad config value: services.sv.upper'),
34 ({'global': {'phrase': 'my secret phrase'},
35 'services': {'sv': {'length': 10}}},
36 ''),
37 ({'services': {'sv': {'length': 10, 'phrase': '...'}}}, ''),
38 ({'services': {'sv': {'length': 10, 'key': '...'}}}, ''),
39 ({'services': {'sv': {'upper': 10, 'key': '...'}}}, ''),
40 ({'services': {'sv': {'phrase': 'abc', 'key': '...'}}},
41 'incompatible config values: services.sv.key and services.sv.phrase'),
42 ({'global': {'phrase': 'abc'},
43 'services': {'sv': {'phrase': 'abc', 'length': 10}}}, ''),
44 ({'global': {'key': '...'},
45 'services': {'sv': {'phrase': 'abc', 'length': 10}}}, ''),
46])
47def test_200_is_vault_config(obj: Any, comment: str) -> None:
48 assert dpp.types.is_vault_config(obj) == (not comment), (
49 'failed to complain about: ' + comment if comment
50 else 'failed on valid example'
51 )