Skip to content
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

bug fix for natural person validation #117

Merged
merged 4 commits into from
Feb 16, 2023
Merged

bug fix for natural person validation #117

merged 4 commits into from
Feb 16, 2023

Conversation

DanielSollis
Copy link
Contributor

@DanielSollis DanielSollis commented Feb 15, 2023

Adds a nil check before validating the natural person to prevent panics when the beneficiary contains a legal person.
NOTE: I also needed to regenerate the test certs since they were expired as of December of last year.

@DanielSollis DanielSollis requested a review from pdeziel February 15, 2023 19:32
Copy link
Collaborator

@pdeziel pdeziel left a comment

Choose a reason for hiding this comment

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

Thank you for updating the certs to fix the test! I just had one follow up question.

if err = identity.Beneficiary.BeneficiaryPersons[0].GetNaturalPerson().Validate(); err != nil {
log.Warn().Err(err).Msg("beneficiary person validation error")
return protocol.Errorf(protocol.ValidationError, "beneficiary person validation error: %s", err)
if naturalPerson := identity.Beneficiary.BeneficiaryPersons[0].GetNaturalPerson(); naturalPerson != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If natural person is nil do we also want to consider that an error? In other words is the beneficiary person required for a valid beneficiary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue here is that Krupa's identity had a legal person under beneficiary_persons and not a natural person, which if I'm correct is entirely valid IVMS101

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, here's what I propose. Let's make it a switch statement and check for either NaturalPerson or LegalPerson. In both of those cases validate the entity, otherwise return a validation error. That should correspond better to IVMS101. We should probably do the same for BeneficiaryVASP on line 250 while we're at it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea, I implemented the changes, that should fix the issue

Copy link
Collaborator

@pdeziel pdeziel left a comment

Choose a reason for hiding this comment

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

Just one small change requested, basically I think we should throw a validation error if the beneficiary person or beneficiary vasp person does not match one of the expected types.

if err = person.LegalPerson.Validate(); err != nil {
log.Warn().Err(err).Msg("beneficiary legal person validation error")
return protocol.Errorf(protocol.ValidationError, "beneficiary legal person validation error: %s", err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need a default case to handle the case where the beneficiary person is nil (or something that happens to fit the isPerson_Person interface but is not a Person_NaturalPerson or Person_LegalPerson).

See this example, if a nil object is type checked then the default case is triggered: https://go.dev/play/p/aHIX6AOtfJz

if err = person.LegalPerson.Validate(); err != nil {
log.Warn().Err(err).Msg("beneficiary vasp legal person validation error")
return protocol.Errorf(protocol.ValidationError, "beneficiary vasp legal person validation error: %s", err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also add a default case here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you also create a follow up story to add a test for validateIdentityPayload? Specifically I want to make sure this fix avoids the panic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Default added and story created

Copy link
Collaborator

@pdeziel pdeziel left a comment

Choose a reason for hiding this comment

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

Awesome! I look forward to deploying it!

@DanielSollis DanielSollis merged commit b124712 into main Feb 16, 2023
@DanielSollis DanielSollis deleted the trv-815 branch February 16, 2023 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants