Skip to content

Commit

Permalink
Merge pull request #128 from gocardless/jay-prevent-all-0-account-num…
Browse files Browse the repository at this point in the history
…bers-australia

Prevent all-zero account numbers in Australia
  • Loading branch information
jaysh authored Jan 10, 2019
2 parents 036739b + a613938 commit 17b1ff3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/ibandit/iban.rb
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def valid_ca_details?
def valid_australian_details?
return true unless country_code == "AU"

bsb_check?
bsb_check? && account_number_not_all_zeros?
end

def bsb_check?
Expand Down Expand Up @@ -512,5 +512,12 @@ def pseudo_iban?(input)
return false if input.nil?
input.slice(2, 2) == Constants::PSEUDO_IBAN_CHECK_DIGITS
end

def account_number_not_all_zeros?
return true if @swift_account_number.to_s.chars.uniq != ["0"]

@errors[:account_number] = Ibandit.translate(:is_invalid)
false
end
end
end
17 changes: 17 additions & 0 deletions spec/ibandit/iban_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,23 @@
its(:valid?) { is_expected.to eq(true) }
its(:to_s) { is_expected.to eq("") }
end

context "and an account number that is all zero" do
let(:account_number) { "000000" }

its(:country_code) { is_expected.to eq("AU") }
its(:bank_code) { is_expected.to be_nil }
its(:branch_code) { is_expected.to eq("123456") }
its(:account_number) { is_expected.to eq("0000000000") }
its(:swift_bank_code) { is_expected.to be_nil }
its(:swift_branch_code) { is_expected.to eq("123456") }
its(:swift_account_number) { is_expected.to eq("0000000000") }
its(:swift_national_id) { is_expected.to eq("123456") }
its(:iban) { is_expected.to be_nil }
its(:pseudo_iban) { is_expected.to eq("AUZZ1234560000000000") }
its(:valid?) { is_expected.to eq(false) }
its(:to_s) { is_expected.to eq("") }
end
end

context "when the IBAN was created from an Australian pseudo-IBAN" do
Expand Down

0 comments on commit 17b1ff3

Please sign in to comment.