From cc4af04dd85eab02ad7d571f7d9426465d331b55 Mon Sep 17 00:00:00 2001 From: Benjamin Bengfort Date: Tue, 31 Oct 2023 12:40:42 -0500 Subject: [PATCH] Refactor Beneficiary Account Numbers Validation (#156) --- pkg/rvasp/transfer.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/rvasp/transfer.go b/pkg/rvasp/transfer.go index c464898..24db3eb 100644 --- a/pkg/rvasp/transfer.go +++ b/pkg/rvasp/transfer.go @@ -240,9 +240,23 @@ func ValidateIdentityPayload(identity *ivms101.IdentityPayload, requireBeneficia } // Check that the account number is present - if len(identity.Beneficiary.AccountNumbers) == 0 || identity.Beneficiary.AccountNumbers[0] == "" { - log.Warn().Msg("identity payload missing account number") + if len(identity.Beneficiary.AccountNumbers) == 0 { + log.Warn().Msg("identity payload missing beneficiary account number") return protocol.Errorf(protocol.IncompleteIdentity, "missing beneficiary account number") + } else { + // Verify that there is at least one valid account number + foundValid := false + for _, accountNumber := range identity.Beneficiary.AccountNumbers { + if accountNumber != "" { + foundValid = true + break + } + } + + if !foundValid { + log.Warn().Strs("account_numbers", identity.Beneficiary.AccountNumbers).Msg("no valid beneficiary account numbers") + return protocol.Errorf(protocol.IncompleteIdentity, "no valid beneficiary account number(s) found") + } } // Check that the beneficiary vasp is present