Coverage for tests/test_derivepassphrase_typing.py: 100.000%

1# SPDX-FileCopyrightText: 2024 Marco Ricci <m@the13thletter.info>

2#

3# SPDX-License-Identifier: MIT

4

5 from __future__ import annotations

6

7 from typing_extensions import Any

8

9 import derivepassphrase.types

10 import pytest

11

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 ({'global': {'key': '...'},

47 'services': {'sv1': {'phrase': 'abc', 'length': 10, 'upper': 1},

48 'sv2': {'length': 10, 'repeat': 1, 'lower': 1}}}, ''),

49])

50 def test_200_is_vault_config(obj: Any, comment: str) -> None:

51 is_vault_config = derivepassphrase.types.is_vault_config

52 assert is_vault_config(obj) == (not comment), (

53 'failed to complain about: ' + comment if comment

54 else 'failed on valid example'

55 )