Skip to content

Commit

Permalink
only validate FI IdentificationCode when present or required
Browse files Browse the repository at this point in the history
  • Loading branch information
atonks2 committed Feb 1, 2024
1 parent ebf16d9 commit 3421101
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 33 deletions.
16 changes: 1 addition & 15 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,18 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
github.com/moov-io/base v0.48.2 h1:BPSNgmwokOVaVzAMJg71L48LCrDYelMfVXJEiZb2zOY=
github.com/moov-io/base v0.48.2/go.mod h1:u1/WC3quR6otC9NrM1TtXSwNti1A/m7MR49RIXY1ee4=
github.com/moov-io/base v0.48.3 h1:0VH5+a1yH+6CCwnMVa8+XUbu7Rth7l0LzHMq3xnE6/I=
github.com/moov-io/base v0.48.3/go.mod h1:5/LTQ3Sy+c39yTCs9vgsHEhjEQHmDinhwIxBkBLNL20=
github.com/moov-io/base v0.48.5 h1:QaTyTo6eFFFV35R9l/GdePQN40IJti9knD5hqdWPnnM=
github.com/moov-io/base v0.48.5/go.mod h1:D5ZV9COV/qtCjTQuYpq7gGInCk64AhOQI6UY4kt4Rq8=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q=
github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY=
github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk=
github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
Expand All @@ -58,10 +52,6 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0=
golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM=
golang.org/x/oauth2 v0.15.0 h1:s8pnnxNVzjWyrvYdFUQq5llS1PX2zhPXmccZv99h7uQ=
golang.org/x/oauth2 v0.15.0/go.mod h1:q48ptWNTY5XWf+JNten23lcvHpLJ0ZSxF5ttTHKVCAM=
golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ=
golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -71,8 +61,6 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand All @@ -92,8 +80,6 @@ google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAs
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
20 changes: 11 additions & 9 deletions instructingFI.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,18 @@ func (ifi *InstructingFI) Validate() error {
if ifi.tag != TagInstructingFI {
return fieldError("tag", ErrValidTagForType, ifi.tag)
}
if err := ifi.isIdentificationCode(ifi.FinancialInstitution.IdentificationCode); err != nil {
return fieldError("IdentificationCode", err, ifi.FinancialInstitution.IdentificationCode)
}
// Can only be these Identification Codes
switch ifi.FinancialInstitution.IdentificationCode {
case
"B", "C", "D", "F", "U":
default:
return fieldError("IdentificationCode", ErrIdentificationCode, ifi.FinancialInstitution.IdentificationCode)

// only validate IdentificationCode if a value was provided, or if it's required due to the presence of an Identifier
if ifi.FinancialInstitution.Identifier != "" || ifi.FinancialInstitution.IdentificationCode != "" {
// Can only be these Identification Codes
switch ifi.FinancialInstitution.IdentificationCode {
case
"B", "C", "D", "F", "U":
default:
return fieldError("IdentificationCode", ErrIdentificationCode, ifi.FinancialInstitution.IdentificationCode)
}
}

if err := ifi.isAlphanumeric(ifi.FinancialInstitution.Identifier); err != nil {
return fieldError("Identifier", err, ifi.FinancialInstitution.Identifier)
}
Expand Down
9 changes: 9 additions & 0 deletions instructingFI_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ func TestInstructingFIIdentifierRequired(t *testing.T) {
require.EqualError(t, err, fieldError("Identifier", ErrFieldRequired).Error())
}

func TestInstructingFI_IDCodeAndIDValidation(t *testing.T) {
// ID Code must be empty if no identifier is present
line := "{5200} *FI Name*Address One*Address Two*Address Three*"
ifi := new(InstructingFI)
require.NoError(t, ifi.Parse(line))
require.NoError(t, ifi.Validate())
require.Equal(t, ifi.Format(FormatOptions{VariableLengthFields: true}), line)
}

// TestParseInstructingFIWrongLength parses a wrong InstructingFI record length
func TestParseInstructingFIWrongLength(t *testing.T) {
var line = "{5200}D123456789 FI Name Address One Address Two Address Three "
Expand Down
20 changes: 11 additions & 9 deletions originatorFI.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,18 @@ func (ofi *OriginatorFI) Validate() error {
if ofi.tag != TagOriginatorFI {
return fieldError("tag", ErrValidTagForType, ofi.tag)
}
if err := ofi.isIdentificationCode(ofi.FinancialInstitution.IdentificationCode); err != nil {
return fieldError("IdentificationCode", err, ofi.FinancialInstitution.IdentificationCode)
}
// Can only be these Identification Codes
switch ofi.FinancialInstitution.IdentificationCode {
case
"B", "C", "D", "F", "U":
default:
return fieldError("IdentificationCode", ErrIdentificationCode, ofi.FinancialInstitution.IdentificationCode)

// only validate IdentificationCode if a value was provided, or if it's required due to the presence of an Identifier
if ofi.FinancialInstitution.Identifier != "" || ofi.FinancialInstitution.IdentificationCode != "" {
// Can only be these Identification Codes
switch ofi.FinancialInstitution.IdentificationCode {
case
"B", "C", "D", "F", "U":
default:
return fieldError("IdentificationCode", ErrIdentificationCode, ofi.FinancialInstitution.IdentificationCode)
}
}

if err := ofi.isAlphanumeric(ofi.FinancialInstitution.Identifier); err != nil {
return fieldError("Identifier", err, ofi.FinancialInstitution.Identifier)
}
Expand Down
9 changes: 9 additions & 0 deletions originatorFI_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ func TestOriginatorFIIdentifierRequired(t *testing.T) {
require.EqualError(t, err, fieldError("Identifier", ErrFieldRequired).Error())
}

func TestOriginatorFI_IDCodeAndIDValidation(t *testing.T) {
// ID Code must be empty if no identifier is present
line := "{5100} *FI Name*Address One*Address Two*Address Three*"
ofi := new(OriginatorFI)
require.NoError(t, ofi.Parse(line))
require.NoError(t, ofi.Validate())
require.Equal(t, ofi.Format(FormatOptions{VariableLengthFields: true}), line)
}

// TestParseOriginatorFIWrongLength parses a wrong OriginatorFI record length
func TestParseOriginatorFIWrongLength(t *testing.T) {
var line = "{5100}D123456789 FI Name Address One Address Two Address Three "
Expand Down

0 comments on commit 3421101

Please sign in to comment.