33b76f6b4d547cc056753aa3b73294683b68946e
Marco Ricci Change the author e-mail ad...

Marco Ricci authored 2 months ago

tests/test_derivepassphrase_vault.py   1) # SPDX-FileCopyrightText: 2024 Marco Ricci <software@the13thletter.info>
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py         2) #
tests/test_derivepassphrase.py         3) # SPDX-License-Identifier: MIT
tests/test_derivepassphrase.py         4) 
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py         5) """Test passphrase generation via derivepassphrase.vault.Vault."""
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py         6) 
tests/test_derivepassphrase.py         7) from __future__ import annotations
tests/test_derivepassphrase.py         8) 
tests/test_derivepassphrase.py         9) import math
Marco Ricci Add support for Python 3.9

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py  10) from typing import TYPE_CHECKING
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        11) 
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py  12) import hypothesis
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        13) import pytest
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py  14) from hypothesis import strategies
Marco Ricci Add support for Python 3.9

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py  15) from typing_extensions import TypeAlias, TypeVar
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        16) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        17) import derivepassphrase
Marco Ricci Centralize settings for hyp...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py  18) import tests
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        19) 
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py  20) if TYPE_CHECKING:
tests/test_derivepassphrase_vault.py  21)     from collections.abc import Iterator
tests/test_derivepassphrase_vault.py  22) 
tests/test_derivepassphrase_vault.py  23) Vault: TypeAlias = derivepassphrase.vault.Vault
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        24) 
tests/test_derivepassphrase.py        25) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        26) class TestVault:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        27)     phrase = b'She cells C shells bye the sea shoars'
tests/test_derivepassphrase.py        28)     google_phrase = rb': 4TVH#5:aZl8LueOT\{'
tests/test_derivepassphrase.py        29)     twitter_phrase = rb"[ (HN_N:lI&<ro=)3'g9"
tests/test_derivepassphrase.py        30) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        31)     @pytest.mark.parametrize(
tests/test_derivepassphrase.py        32)         ['service', 'expected'],
tests/test_derivepassphrase.py        33)         [
tests/test_derivepassphrase.py        34)             (b'google', google_phrase),
tests/test_derivepassphrase.py        35)             ('twitter', twitter_phrase),
tests/test_derivepassphrase.py        36)         ],
tests/test_derivepassphrase.py        37)     )
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        38)     def test_200_basic_configuration(
tests/test_derivepassphrase.py        39)         self, service: bytes | str, expected: bytes
tests/test_derivepassphrase.py        40)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        41)         assert Vault(phrase=self.phrase).generate(service) == expected
tests/test_derivepassphrase.py        42) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        43)     def test_201_phrase_dependence(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        44)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        45)             Vault(phrase=(self.phrase + b'X')).generate('google')
tests/test_derivepassphrase.py        46)             == b'n+oIz6sL>K*lTEWYRO%7'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        47)         )
tests/test_derivepassphrase.py        48) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        49)     def test_202_reproducibility_and_bytes_service_name(self) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        50)         assert Vault(phrase=self.phrase).generate(b'google') == Vault(
tests/test_derivepassphrase.py        51)             phrase=self.phrase
tests/test_derivepassphrase.py        52)         ).generate('google')
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        53) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        54)     def test_203_reproducibility_and_bytearray_service_name(self) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        55)         assert Vault(phrase=self.phrase).generate(b'google') == Vault(
tests/test_derivepassphrase.py        56)             phrase=self.phrase
tests/test_derivepassphrase.py        57)         ).generate(bytearray(b'google'))
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        58) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        59)     def test_210_nonstandard_length(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        60)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        61)             Vault(phrase=self.phrase, length=4).generate('google') == b'xDFu'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        62)         )
tests/test_derivepassphrase.py        63) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        64)     def test_211_repetition_limit(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        65)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        66)             Vault(
tests/test_derivepassphrase.py        67)                 phrase=b'', length=24, symbol=0, number=0, repeat=1
tests/test_derivepassphrase.py        68)             ).generate('asd')
tests/test_derivepassphrase.py        69)             == b'IVTDzACftqopUXqDHPkuCIhV'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        70)         )
tests/test_derivepassphrase.py        71) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        72)     def test_212_without_symbols(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        73)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        74)             Vault(phrase=self.phrase, symbol=0).generate('google')
tests/test_derivepassphrase.py        75)             == b'XZ4wRe0bZCazbljCaMqR'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        76)         )
tests/test_derivepassphrase.py        77) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        78)     def test_213_no_numbers(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        79)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        80)             Vault(phrase=self.phrase, number=0).generate('google')
tests/test_derivepassphrase.py        81)             == b'_*$TVH.%^aZl(LUeOT?>'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        82)         )
tests/test_derivepassphrase.py        83) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        84)     def test_214_no_lowercase_letters(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        85)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        86)             Vault(phrase=self.phrase, lower=0).generate('google')
tests/test_derivepassphrase.py        87)             == b':{?)+7~@OA:L]!0E$)(+'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        88)         )
tests/test_derivepassphrase.py        89) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        90)     def test_215_at_least_5_digits(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        91)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        92)             Vault(phrase=self.phrase, length=8, number=5).generate('songkick')
tests/test_derivepassphrase.py        93)             == b'i0908.7['
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        94)         )
tests/test_derivepassphrase.py        95) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        96)     def test_216_lots_of_spaces(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py        97)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py        98)             Vault(phrase=self.phrase, space=12).generate('songkick')
tests/test_derivepassphrase.py        99)             == b' c   6 Bq  % 5fR    '
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       100)         )
tests/test_derivepassphrase.py       101) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       102)     def test_217_all_character_classes(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       103)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       104)             Vault(
tests/test_derivepassphrase.py       105)                 phrase=self.phrase,
tests/test_derivepassphrase.py       106)                 lower=2,
tests/test_derivepassphrase.py       107)                 upper=2,
tests/test_derivepassphrase.py       108)                 number=1,
tests/test_derivepassphrase.py       109)                 space=3,
tests/test_derivepassphrase.py       110)                 dash=2,
tests/test_derivepassphrase.py       111)                 symbol=1,
tests/test_derivepassphrase.py       112)             ).generate('google')
tests/test_derivepassphrase.py       113)             == b': : fv_wqt>a-4w1S  R'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       114)         )
tests/test_derivepassphrase.py       115) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       116)     def test_218_only_numbers_and_very_high_repetition_limit(self) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       117)         generated = Vault(
tests/test_derivepassphrase.py       118)             phrase=b'',
tests/test_derivepassphrase.py       119)             length=40,
tests/test_derivepassphrase.py       120)             lower=0,
tests/test_derivepassphrase.py       121)             upper=0,
tests/test_derivepassphrase.py       122)             space=0,
tests/test_derivepassphrase.py       123)             dash=0,
tests/test_derivepassphrase.py       124)             symbol=0,
tests/test_derivepassphrase.py       125)             repeat=4,
tests/test_derivepassphrase.py       126)         ).generate('abcdef')
tests/test_derivepassphrase.py       127)         forbidden_substrings = {
tests/test_derivepassphrase.py       128)             b'0000',
tests/test_derivepassphrase.py       129)             b'1111',
tests/test_derivepassphrase.py       130)             b'2222',
tests/test_derivepassphrase.py       131)             b'3333',
tests/test_derivepassphrase.py       132)             b'4444',
tests/test_derivepassphrase.py       133)             b'5555',
tests/test_derivepassphrase.py       134)             b'6666',
tests/test_derivepassphrase.py       135)             b'7777',
tests/test_derivepassphrase.py       136)             b'8888',
tests/test_derivepassphrase.py       137)             b'9999',
tests/test_derivepassphrase.py       138)         }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       139)         for substring in forbidden_substrings:
tests/test_derivepassphrase.py       140)             assert substring not in generated
tests/test_derivepassphrase.py       141) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       142)     def test_219_very_limited_character_set(self) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       143)         generated = Vault(
tests/test_derivepassphrase.py       144)             phrase=b'', length=24, lower=0, upper=0, space=0, symbol=0
tests/test_derivepassphrase.py       145)         ).generate('testing')
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       146)         assert generated == b'763252593304946694588866'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       147) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       148)     def test_220_character_set_subtraction(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       149)         assert Vault._subtract(b'be', b'abcdef') == bytearray(b'acdf')
tests/test_derivepassphrase.py       150) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       151)     @pytest.mark.parametrize(
tests/test_derivepassphrase.py       152)         ['length', 'settings', 'entropy'],
tests/test_derivepassphrase.py       153)         [
tests/test_derivepassphrase.py       154)             (20, {}, math.log2(math.factorial(20)) + 20 * math.log2(94)),
tests/test_derivepassphrase.py       155)             (
tests/test_derivepassphrase.py       156)                 20,
tests/test_derivepassphrase.py       157)                 {'upper': 0, 'number': 0, 'space': 0, 'symbol': 0},
tests/test_derivepassphrase.py       158)                 math.log2(math.factorial(20)) + 20 * math.log2(26),
tests/test_derivepassphrase.py       159)             ),
tests/test_derivepassphrase.py       160)             (0, {}, float('-inf')),
tests/test_derivepassphrase.py       161)             (
tests/test_derivepassphrase.py       162)                 0,
tests/test_derivepassphrase.py       163)                 {'lower': 0, 'number': 0, 'space': 0, 'symbol': 0},
tests/test_derivepassphrase.py       164)                 float('-inf'),
tests/test_derivepassphrase.py       165)             ),
tests/test_derivepassphrase.py       166)             (1, {}, math.log2(94)),
tests/test_derivepassphrase.py       167)             (1, {'upper': 0, 'lower': 0, 'number': 0, 'symbol': 0}, 0.0),
tests/test_derivepassphrase.py       168)         ],
tests/test_derivepassphrase.py       169)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       170)     def test_221_entropy(
tests/test_derivepassphrase.py       171)         self, length: int, settings: dict[str, int], entropy: int
tests/test_derivepassphrase.py       172)     ) -> None:
tests/test_derivepassphrase.py       173)         v = Vault(length=length, **settings)  # type: ignore[arg-type]
tests/test_derivepassphrase.py       174)         assert math.isclose(v._entropy(), entropy)
tests/test_derivepassphrase.py       175)         assert v._estimate_sufficient_hash_length() > 0
tests/test_derivepassphrase.py       176)         if math.isfinite(entropy) and entropy:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       177)             assert v._estimate_sufficient_hash_length(1.0) == math.ceil(
tests/test_derivepassphrase.py       178)                 entropy / 8
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       179)             )
tests/test_derivepassphrase.py       180)         assert v._estimate_sufficient_hash_length(8.0) >= entropy
tests/test_derivepassphrase.py       181) 
tests/test_derivepassphrase.py       182)     def test_222_hash_length_estimation(self) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       183)         v = Vault(
tests/test_derivepassphrase.py       184)             phrase=self.phrase,
tests/test_derivepassphrase.py       185)             lower=0,
tests/test_derivepassphrase.py       186)             upper=0,
tests/test_derivepassphrase.py       187)             number=0,
tests/test_derivepassphrase.py       188)             symbol=0,
tests/test_derivepassphrase.py       189)             space=1,
tests/test_derivepassphrase.py       190)             length=1,
tests/test_derivepassphrase.py       191)         )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       192)         assert v._entropy() == 0.0
tests/test_derivepassphrase.py       193)         assert v._estimate_sufficient_hash_length() > 0
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       194) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       195)     @pytest.mark.parametrize(
tests/test_derivepassphrase.py       196)         ['service', 'expected'],
tests/test_derivepassphrase.py       197)         [
tests/test_derivepassphrase.py       198)             (b'google', google_phrase),
tests/test_derivepassphrase.py       199)             ('twitter', twitter_phrase),
tests/test_derivepassphrase.py       200)         ],
tests/test_derivepassphrase.py       201)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       202)     def test_223_hash_length_expansion(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 2 months ago

tests/test_derivepassphrase_vault.py 203)         self,
tests/test_derivepassphrase_vault.py 204)         monkeypatch: pytest.MonkeyPatch,
tests/test_derivepassphrase_vault.py 205)         service: str | bytes,
tests/test_derivepassphrase_vault.py 206)         expected: bytes,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       207)     ) -> None:
tests/test_derivepassphrase.py       208)         v = Vault(phrase=self.phrase)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       209)         monkeypatch.setattr(
tests/test_derivepassphrase.py       210)             v,
tests/test_derivepassphrase.py       211)             '_estimate_sufficient_hash_length',
tests/test_derivepassphrase.py       212)             lambda *args, **kwargs: 1,  # noqa: ARG005
tests/test_derivepassphrase.py       213)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       214)         assert v._estimate_sufficient_hash_length() < len(self.phrase)
tests/test_derivepassphrase.py       215)         assert v.generate(service) == expected
tests/test_derivepassphrase.py       216) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       217)     @pytest.mark.parametrize(
Marco Ricci Allow all textual strings,...

Marco Ricci authored 2 months ago

tests/test_derivepassphrase.py       218)         's',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       219)         [
Marco Ricci Allow all textual strings,...

Marco Ricci authored 2 months ago

tests/test_derivepassphrase.py       220)             'ñ',
tests/test_derivepassphrase.py       221)             'Düsseldorf',
tests/test_derivepassphrase.py       222)             'liberté, egalité, fraternité',
tests/test_derivepassphrase.py       223)             'ASCII',
tests/test_derivepassphrase.py       224)             b'D\xc3\xbcsseldorf',
tests/test_derivepassphrase.py       225)             bytearray([2, 3, 5, 7, 11, 13]),
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       226)         ],
tests/test_derivepassphrase.py       227)     )
Marco Ricci Allow all textual strings,...

Marco Ricci authored 2 months ago

tests/test_derivepassphrase.py       228)     def test_224_binary_strings(self, s: str | bytes | bytearray) -> None:
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       229)         binstr = Vault._get_binary_string
Marco Ricci Allow all textual strings,...

Marco Ricci authored 2 months ago

tests/test_derivepassphrase.py       230)         if isinstance(s, str):
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       231)             assert binstr(s) == s.encode('UTF-8')
tests/test_derivepassphrase.py       232)             assert binstr(binstr(s)) == s.encode('UTF-8')
tests/test_derivepassphrase.py       233)         else:
tests/test_derivepassphrase.py       234)             assert binstr(s) == bytes(s)
tests/test_derivepassphrase.py       235)             assert binstr(binstr(s)) == bytes(s)
tests/test_derivepassphrase.py       236) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       237)     def test_310_too_many_symbols(self) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       238)         with pytest.raises(
tests/test_derivepassphrase.py       239)             ValueError, match='requested passphrase length too short'
tests/test_derivepassphrase.py       240)         ):
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       241)             Vault(phrase=self.phrase, symbol=100)
tests/test_derivepassphrase.py       242) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       243)     def test_311_no_viable_characters(self) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       244)         with pytest.raises(ValueError, match='no allowed characters left'):
tests/test_derivepassphrase.py       245)             Vault(
tests/test_derivepassphrase.py       246)                 phrase=self.phrase,
tests/test_derivepassphrase.py       247)                 lower=0,
tests/test_derivepassphrase.py       248)                 upper=0,
tests/test_derivepassphrase.py       249)                 number=0,
tests/test_derivepassphrase.py       250)                 space=0,
tests/test_derivepassphrase.py       251)                 dash=0,
tests/test_derivepassphrase.py       252)                 symbol=0,
tests/test_derivepassphrase.py       253)             )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       254) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       255)     def test_320_character_set_subtraction_duplicate(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       256)         with pytest.raises(ValueError, match='duplicate characters'):
tests/test_derivepassphrase.py       257)             Vault._subtract(b'abcdef', b'aabbccddeeff')
tests/test_derivepassphrase.py       258)         with pytest.raises(ValueError, match='duplicate characters'):
tests/test_derivepassphrase.py       259)             Vault._subtract(b'aabbccddeeff', b'abcdef')
tests/test_derivepassphrase.py       260) 
tests/test_derivepassphrase.py       261)     def test_322_hash_length_estimation(self) -> None:
tests/test_derivepassphrase.py       262)         v = Vault(phrase=self.phrase)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       263)         with pytest.raises(ValueError, match='invalid safety factor'):
Marco Ricci Rename and regroup all test...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       264)             assert v._estimate_sufficient_hash_length(-1.0)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       265)         with pytest.raises(
tests/test_derivepassphrase.py       266)             TypeError, match='invalid safety factor: not a float'
tests/test_derivepassphrase.py       267)         ):
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 2 months ago

tests/test_derivepassphrase.py       268)             assert v._estimate_sufficient_hash_length(None)  # type: ignore[arg-type]
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 269) 
tests/test_derivepassphrase_vault.py 270) 
tests/test_derivepassphrase_vault.py 271) class TestHypotheses:
Marco Ricci Centralize settings for hyp...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 272)     @tests.hypothesis_settings_coverage_compatible
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 273)     @hypothesis.given(
tests/test_derivepassphrase_vault.py 274)         phrase=strategies.one_of(
tests/test_derivepassphrase_vault.py 275)             strategies.binary(min_size=1), strategies.text(min_size=1)
tests/test_derivepassphrase_vault.py 276)         ),
Marco Ricci Move vault service config g...

Marco Ricci authored 4 weeks ago

tests/test_derivepassphrase_vault.py 277)         config=tests.vault_full_service_config(),
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 278)         service=strategies.text(min_size=1),
tests/test_derivepassphrase_vault.py 279)     )
tests/test_derivepassphrase_vault.py 280)     # regression test
tests/test_derivepassphrase_vault.py 281)     @hypothesis.example(
tests/test_derivepassphrase_vault.py 282)         phrase=b'\x00',
tests/test_derivepassphrase_vault.py 283)         config={
tests/test_derivepassphrase_vault.py 284)             'lower': 0,
tests/test_derivepassphrase_vault.py 285)             'upper': 0,
tests/test_derivepassphrase_vault.py 286)             'number': 0,
tests/test_derivepassphrase_vault.py 287)             'space': 2,
tests/test_derivepassphrase_vault.py 288)             'dash': 0,
tests/test_derivepassphrase_vault.py 289)             'symbol': 1,
tests/test_derivepassphrase_vault.py 290)             'repeat': 2,
tests/test_derivepassphrase_vault.py 291)             'length': 3,
tests/test_derivepassphrase_vault.py 292)         },
tests/test_derivepassphrase_vault.py 293)         service='0',
tests/test_derivepassphrase_vault.py 294)     )
tests/test_derivepassphrase_vault.py 295)     # regression test
tests/test_derivepassphrase_vault.py 296)     @hypothesis.example(
tests/test_derivepassphrase_vault.py 297)         phrase=b'\x00',
tests/test_derivepassphrase_vault.py 298)         config={
tests/test_derivepassphrase_vault.py 299)             'lower': 0,
tests/test_derivepassphrase_vault.py 300)             'upper': 0,
tests/test_derivepassphrase_vault.py 301)             'number': 0,
tests/test_derivepassphrase_vault.py 302)             'space': 1,
tests/test_derivepassphrase_vault.py 303)             'dash': 0,
tests/test_derivepassphrase_vault.py 304)             'symbol': 0,
tests/test_derivepassphrase_vault.py 305)             'repeat': 9,
tests/test_derivepassphrase_vault.py 306)             'length': 5,
tests/test_derivepassphrase_vault.py 307)         },
tests/test_derivepassphrase_vault.py 308)         service='0',
tests/test_derivepassphrase_vault.py 309)     )
Marco Ricci Add explicit example in hyp...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 310)     # branch coverage: case `repeat = 0` in `if config[repeat]` below
tests/test_derivepassphrase_vault.py 311)     @hypothesis.example(
tests/test_derivepassphrase_vault.py 312)         phrase=b'\x00',
tests/test_derivepassphrase_vault.py 313)         config={
tests/test_derivepassphrase_vault.py 314)             'lower': 0,
tests/test_derivepassphrase_vault.py 315)             'upper': 0,
tests/test_derivepassphrase_vault.py 316)             'number': 0,
tests/test_derivepassphrase_vault.py 317)             'space': 1,
tests/test_derivepassphrase_vault.py 318)             'dash': 0,
tests/test_derivepassphrase_vault.py 319)             'symbol': 0,
tests/test_derivepassphrase_vault.py 320)             'repeat': 0,
tests/test_derivepassphrase_vault.py 321)             'length': 5,
tests/test_derivepassphrase_vault.py 322)         },
tests/test_derivepassphrase_vault.py 323)         service='0',
tests/test_derivepassphrase_vault.py 324)     )
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 325)     def test_100_all_length_character_and_occurrence_constraints_satisfied(
tests/test_derivepassphrase_vault.py 326)         self,
tests/test_derivepassphrase_vault.py 327)         phrase: str | bytes,
tests/test_derivepassphrase_vault.py 328)         config: dict[str, int],
tests/test_derivepassphrase_vault.py 329)         service: str,
tests/test_derivepassphrase_vault.py 330)     ) -> None:
tests/test_derivepassphrase_vault.py 331)         try:
tests/test_derivepassphrase_vault.py 332)             password = Vault(phrase=phrase, **config).generate(service)
tests/test_derivepassphrase_vault.py 333)         except ValueError as exc:
tests/test_derivepassphrase_vault.py 334)             if 'no allowed characters left' in exc.args:
tests/test_derivepassphrase_vault.py 335)                 return
tests/test_derivepassphrase_vault.py 336)             raise  # pragma: no cover
tests/test_derivepassphrase_vault.py 337)         n = len(password)
tests/test_derivepassphrase_vault.py 338)         assert n == config['length'], 'Password has wrong length.'
tests/test_derivepassphrase_vault.py 339)         for key in ('lower', 'upper', 'number', 'space', 'dash', 'symbol'):
tests/test_derivepassphrase_vault.py 340)             if config[key] > 0:
tests/test_derivepassphrase_vault.py 341)                 assert (
tests/test_derivepassphrase_vault.py 342)                     sum(c in Vault._CHARSETS[key] for c in password)
tests/test_derivepassphrase_vault.py 343)                     >= config[key]
tests/test_derivepassphrase_vault.py 344)                 ), (
tests/test_derivepassphrase_vault.py 345)                     'Password does not satisfy '
tests/test_derivepassphrase_vault.py 346)                     'character occurrence constraints.'
tests/test_derivepassphrase_vault.py 347)                 )
tests/test_derivepassphrase_vault.py 348)             elif key in {'dash', 'symbol'}:
tests/test_derivepassphrase_vault.py 349)                 # Character classes overlap, so "forbidden" characters may
tests/test_derivepassphrase_vault.py 350)                 # appear via the other character class.
tests/test_derivepassphrase_vault.py 351)                 assert True
tests/test_derivepassphrase_vault.py 352)             else:
tests/test_derivepassphrase_vault.py 353)                 assert (
tests/test_derivepassphrase_vault.py 354)                     sum(c in Vault._CHARSETS[key] for c in password) == 0
tests/test_derivepassphrase_vault.py 355)                 ), 'Password does not satisfy character ban constraints.'
tests/test_derivepassphrase_vault.py 356) 
tests/test_derivepassphrase_vault.py 357)         T = TypeVar('T', str, bytes)
tests/test_derivepassphrase_vault.py 358) 
tests/test_derivepassphrase_vault.py 359)         def length_r_substrings(string: T, *, r: int) -> Iterator[T]:
tests/test_derivepassphrase_vault.py 360)             for i in range(len(string) - (r - 1)):
tests/test_derivepassphrase_vault.py 361)                 yield string[i : i + r]
tests/test_derivepassphrase_vault.py 362) 
tests/test_derivepassphrase_vault.py 363)         repeat = config['repeat']
tests/test_derivepassphrase_vault.py 364)         if repeat:
tests/test_derivepassphrase_vault.py 365)             for snippet in length_r_substrings(password, r=(repeat + 1)):
tests/test_derivepassphrase_vault.py 366)                 assert (
tests/test_derivepassphrase_vault.py 367)                     len(set(snippet)) > 1
tests/test_derivepassphrase_vault.py 368)                 ), 'Password does not satisfy character repeat constraints.'
tests/test_derivepassphrase_vault.py 369) 
Marco Ricci Centralize settings for hyp...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 370)     @tests.hypothesis_settings_coverage_compatible
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 371)     @hypothesis.given(
tests/test_derivepassphrase_vault.py 372)         phrase=strategies.one_of(
Marco Ricci Centralize settings for hyp...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 373)             strategies.binary(min_size=1, max_size=100),
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 374)             strategies.text(
tests/test_derivepassphrase_vault.py 375)                 min_size=1,
Marco Ricci Centralize settings for hyp...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 376)                 max_size=100,
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 377)                 alphabet=strategies.characters(max_codepoint=255),
tests/test_derivepassphrase_vault.py 378)             ),
tests/test_derivepassphrase_vault.py 379)         ),
Marco Ricci Centralize settings for hyp...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 380)         length=strategies.integers(min_value=1, max_value=200),
tests/test_derivepassphrase_vault.py 381)         service=strategies.text(min_size=1, max_size=100),
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 382)     )
tests/test_derivepassphrase_vault.py 383)     def test_101_password_with_length(
tests/test_derivepassphrase_vault.py 384)         self,
tests/test_derivepassphrase_vault.py 385)         phrase: str | bytes,
tests/test_derivepassphrase_vault.py 386)         length: int,
tests/test_derivepassphrase_vault.py 387)         service: str,
tests/test_derivepassphrase_vault.py 388)     ) -> None:
tests/test_derivepassphrase_vault.py 389)         password = Vault(phrase=phrase, length=length).generate(service)
tests/test_derivepassphrase_vault.py 390)         assert len(password) == length
tests/test_derivepassphrase_vault.py 391) 
tests/test_derivepassphrase_vault.py 392)     # This test has time complexity `O(length * repeat)`, both of which
Marco Ricci Centralize settings for hyp...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 393)     # are chosen by hypothesis and thus outside our control.
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 394)     @hypothesis.settings(deadline=None)
tests/test_derivepassphrase_vault.py 395)     @hypothesis.given(
tests/test_derivepassphrase_vault.py 396)         phrase=strategies.one_of(
Marco Ricci Centralize settings for hyp...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 397)             strategies.binary(min_size=1, max_size=100),
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 398)             strategies.text(
tests/test_derivepassphrase_vault.py 399)                 min_size=1,
Marco Ricci Centralize settings for hyp...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 400)                 max_size=100,
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 401)                 alphabet=strategies.characters(max_codepoint=255),
tests/test_derivepassphrase_vault.py 402)             ),
tests/test_derivepassphrase_vault.py 403)         ),
Marco Ricci Centralize settings for hyp...

Marco Ricci authored 1 month ago

tests/test_derivepassphrase_vault.py 404)         length=strategies.integers(min_value=2, max_value=200),
tests/test_derivepassphrase_vault.py 405)         repeat=strategies.integers(min_value=1, max_value=200),
tests/test_derivepassphrase_vault.py 406)         service=strategies.text(min_size=1, max_size=1000),