Skip to content

fix(no_NO): use Luhn check digit for Postgiro (0000) BBANs - #2468

Open
DYNOSuprovo wants to merge 2 commits into
joke2k:masterfrom
DYNOSuprovo:fix/no-no-iban-postgiro-2464
Open

DYNOSuprovo wants to merge 2 commits into
joke2k:masterfrom
DYNOSuprovo:fix/no-no-iban-postgiro-2464

Conversation

@DYNOSuprovo

Copy link
Copy Markdown

What does this change

Updates faker.providers.bank.no_NO.Provider.bban to compute a Luhn (modulus 10) check digit when the 4-digit bank register prefix is 0000 (Postgiro), and adds a deterministic regression test in TestNoNo.

What was wrong

Norwegian 11-digit account numbers (BBANs) normally use a MOD11 check digit over all 10 preceding digits. However, when the 4-digit bank register number is 0000 (the Postgiro code), the remaining 7 digits form a Postgiro account number whose check digit uses Luhn (modulus 10), as validated by stdnum.no.kontonr / stdnum.iban.validate. Because no_NO's bban() always applied MOD11, any generated BBAN starting with 0000 (~1 in 10,000 draws) had an invalid Postgiro check digit ~90% of the time, causing TestNoNo.test_iban_stdnum (iban_validator.validate(faker.iban())) to fail whenever 0000 was drawn.

How this fixes it

When first_10.startswith("0000"), bban() computes the check digit over the 6-digit Postgiro account body (first_10[4:]) using calculate_luhn.

Fixes #2464

Checklist

  • I have read the documentation about CONTRIBUTING
  • I have read the documentation about Coding style
  • I have run make lint

Signed-off-by: DYNOSuprovo <DYNOSuprovo@users.noreply.github.com>
Signed-off-by: DYNOSuprovo <DYNOSuprovo@users.noreply.github.com>

@fcurella fcurella left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no_NO.iban() is invalid when the account starts 0000: Postgiro uses Luhn

2 participants