From a6533fea7a64f9676dfc3dab8816be43f28bbbd9 Mon Sep 17 00:00:00 2001 From: Yuki Morikawa <193417531+Doyoubelieveinfate@users.noreply.github.com> Date: Tue, 20 Oct 2026 22:59:28 +0900 Subject: [PATCH] Require both check digits for individual INNs --- src/validators/i18n/ru.py | 8 +------- tests/i18n/test_ru.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/validators/i18n/ru.py b/src/validators/i18n/ru.py index 0df5fce0..2b6da7f2 100644 --- a/src/validators/i18n/ru.py +++ b/src/validators/i18n/ru.py @@ -50,13 +50,7 @@ def ru_inn(value: str): control_number1 = sum([d * w for d, w in zip(digits, weight_coefs1)]) % 11 weight_coefs2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0] control_number2 = sum([d * w for d, w in zip(digits, weight_coefs2)]) % 11 - return ( - (control_number1 % 10) == digits[-2] - if control_number1 > 9 - else control_number1 == digits[-2] and (control_number2 % 10) == digits[-1] - if control_number2 > 9 - else control_number2 == digits[-1] - ) + return (control_number1 % 10) == digits[-2] and (control_number2 % 10) == digits[-1] else: return False except ValueError: diff --git a/tests/i18n/test_ru.py b/tests/i18n/test_ru.py index 1f111087..5c7017e4 100644 --- a/tests/i18n/test_ru.py +++ b/tests/i18n/test_ru.py @@ -46,3 +46,22 @@ def test_returns_true_on_valid_ru_inn(value: str): def test_returns_false_on_valid_ru_inn(value: str): """Test returns true on valid russian individual tax number.""" assert isinstance(ru_inn(value), ValidationError) + + +@pytest.mark.parametrize( + "value", + [ + "500100732266", # First check digit is wrong; the second matches. + "100000001103", # First remainder is 10; the second check digit is wrong. + "100000000781", # Second remainder is 10; its check digit must be zero. + ], +) +def test_individual_inn_requires_both_check_digits(value: str): + """Reject an individual INN when either check digit is wrong.""" + assert isinstance(ru_inn(value), ValidationError) + + +@pytest.mark.parametrize("value", ["500100732259", "100000001102", "100000000780"]) +def test_individual_inn_check_digit_remainders(value: str): + """Accept both ordinary remainders and remainder 10 mapped to zero.""" + assert ru_inn(value) is True