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

[DUOS-2720] Fix date and uri validation #2354

Merged
merged 2 commits into from
Oct 17, 2023
Merged

Conversation

rushtong
Copy link
Contributor

Addresses

https://broadworkbench.atlassian.net/browse/DUOS-2720

Summary

There are some issues with trying to pass custom validator functions into the Ajv-generated validator code. In our case, we have custom functions in JsonSchemaUtils.js but it doesn't look like we're actually passing them into the script that does code generation (in a separate script). Therefore, they're never actually used.

As a workaround, this PR fixes the date validation and re-implements the URI validation that was previously commented out due to this same problem. These were being pulled from ajv-formats but seem to be intermittently undefined, i.e., the validation function would exist for one field, but not for another later on in the validation process.


Have you read Terra's Contributing Guide lately? If not, do that first.

  • Label PR with a Jira ticket number and include a link to the ticket
  • Label PR with a security risk modifier [no, low, medium, high]
  • PR describes scope of changes
  • Get a minimum of one thumbs worth of review, preferably two if enough team members are available
  • Get PO sign-off for all non-trivial UI or workflow changes
  • Verify all tests go green
  • Test this change deployed correctly and works on dev environment after deployment

regenerate validation;
re-implement uri validation;
@rushtong rushtong requested a review from a team as a code owner October 13, 2023 18:09
Comment on lines -8 to +537
const formats0 = { "_items": ["require(\"ajv-formats/dist/formats\").", { "str": "fullFormats" }, ""] }.date;
const dateRegex = /^\d{4}-(02-(0[1-9]|[12][0-9])|(0[469]|11)-(0[1-9]|[12][0-9]|30)|(0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))$/;
const dateValid = (value) => dateRegex.test(value);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the meat of the fix - this date regex comes from /src/components/forms/formValidation.js

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this validation file is automatically generated from ajv, if this change is implemented manually will it be overwritten the next time we run ajv?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there is a script that we have to run that re-writes this file. Most of the changes here are from that process. This is not a sustainable process and we need to move away from it which is what I'm looking into now.

Copy link
Contributor

@fboulnois fboulnois left a comment

Choose a reason for hiding this comment

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

One question:

Comment on lines -8 to +537
const formats0 = { "_items": ["require(\"ajv-formats/dist/formats\").", { "str": "fullFormats" }, ""] }.date;
const dateRegex = /^\d{4}-(02-(0[1-9]|[12][0-9])|(0[469]|11)-(0[1-9]|[12][0-9]|30)|(0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))$/;
const dateValid = (value) => dateRegex.test(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this validation file is automatically generated from ajv, if this change is implemented manually will it be overwritten the next time we run ajv?

Copy link
Contributor

@hams7504 hams7504 left a comment

Choose a reason for hiding this comment

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

lgtm! 👍

Copy link
Contributor

@fboulnois fboulnois left a comment

Choose a reason for hiding this comment

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

lgtm 👍

@rushtong rushtong merged commit a4aff5e into develop Oct 17, 2023
10 checks passed
@rushtong rushtong deleted the gr-DUOS-2720-date-validation branch October 17, 2023 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants