-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes iban checksum calculation #2591
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments, but I have not manually tested it. Will make some time to manually test it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for working on this, @srcoley !
It looks good to me, but let's add an extra test for iban_checksum
if possible.
private | ||
|
||
# https://en.wikipedia.org/wiki/International_Bank_Account_Number#Validating_the_IBAN | ||
def valid_iban_checksum?(iban) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
To answer your question, I think your fixes should be merged so we can improve the current generator, even though it's currently limited. Then, we can evaluate how much effort it would take to add support to national check digit support and make it more accurate. |
Thanks for the review @thdaraujo! I've pushed up a new test for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks!
Summary
Fixes Issue #2588
IBAN check digit can be incorrectly calculated to fall outside the proper range of
2-98
. This would cause some IBAN validator libraries(ex: https://github.com/gocardless/ibandit) to mark the IBANs as invalid.This change calculates the check digit correctly and adds checksum asserts to each country's IBAN test.
Other Information
While this change resolves the IBAN check digit issue, there is another issue lurking in Faker's IBAN generation code. Some countries implement a national check digit in addition to the standard IBAN check digit. This can cause Faker generated IBANs to fail full validations where the national check digit is taken into account. This means that while an IBAN might be considered valid with a library such as
ibandit
, it could be flagged as invalid with more strict validators such as https://www.iban.com/iban-checker.Valid according to
ibandit
:Invalid according to https://www.iban.com:
To complicate matters, the algorithm for calculating a national check digit varies country to country. France, for instance, make use of the standard
ISO 7064 MOD-97-10
, but has their own variation for encoding account letters to numbers. Some countries don't use theISO 7064 MOD-97-10
standard at all, but instead opt for Luhn, "conversion + sum", or"weighted sum" algorithms.
When I started working on this issue, I overlooked the IBAN check digit calculation bug that this pull request aims to solve, and instead thought the invalid IBANs were a result of Faker not calculating a valid national check digit. It took me a while to discover there were two separate issues, and I spent some time attempting to properly calculate national check digits focusing firstly on the
ISO 7064 MOD-97-10
algorithm and France's variant.You can see the progress I was making here: main...srcoley:faker:iban_national_check_digit_support
I'd be happy to continue adding national check digit support(at least for
ISO 7064 MOD-97-10
and variants), but I figure the maintainers have some decisions to make first:ibandit
(and no other lib I could find) properly validates national check digits, what should the testing strategy look like?For more information on national check digits, see: https://en.wikipedia.org/wiki/International_Bank_Account_Number#National_check_digits