wazuh-dashboard-plugins
wazuh-dashboard-plugins copied to clipboard
Add validation to the plugin settings
Description
This PR:
- Add:
- Plugin setting validations:
- Frontend
Settings/Configurationform:- Display the validation error
- Highlight the setting with invalid input
- Display the count of settings with an invalid value
- Disable the save button when there is some invalid value in some setting changed
- Backend:
PUT /utils/configuration
- Frontend
- Plugin setting validations:
Closes #4446
Screenshots
-
Input's validation, invalid settings highlight, error count display and disabled of the save button.

-
Warning icon added to the invalid settings, reason displayed on mouse over.

Tests
Scenario: Set an invalid value for the setting in Settings/Configuration form
When the user changes the input value to something invalid. This depends on each setting validation.
Then an error should appear below the input form.
And the setting should be red colored and highlighted as invalid.
And the bottom bar should display the count settings with invalid values.
And the save button should be disabled.
Scenario: Set 2 or more invalid values for the settings in Settings/Configuration form
When the user changes the input value of 2 or more settings to invalid values. This depends on each setting validation.
Then an error should appear below the input form for each setting.
And the settings should be red colored and highlighted as invalid.
And the bottom bar should display the count settings with invalid values.
And the save button should be disabled.
Scenario: Set a valid value for the setting in Settings/Configuration form
When the user changes the input value to valid value. This depends on each setting validation.
Then it should not appear a validation error below the input.
Scenario: Send invalid values to update the plugin configuration through the plugin backend endpoint
When the user send a request to PUT /utils/configuration with one or more settings, where at least one of them has an invalid value.
Then it should reply with a bad request displaying the validation error.
- Fixed some settings validation errors
- Updated the development branch with the last changes of the base branch
- Updated the development branch with the last changes of the base branch.
- Updated the development branch with the last changes of the base branch.
- Added tests to validate each setting in the endpoint to update the plugin configuration on the backend.
- Added tests related to validation for
useFormhook andInputFormcomponent
Enhancement suggestion
- The names of indices don't support any characters. For Kibana 7.10.2, they could be: https://github.com/elastic/elasticsearch/blob/v7.10.2/docs/reference/indices/create-index.asciidoc
affected settings:
alerts.sample.prefix,cron.prefix,cron.statistics.index.name
- Index patterns name. Review if there are unsupported characters. They could be the same as the indices.
affected settings:
pattern,wazuh.monitoring.pattern,ip.ignore
- Enhanced the validation of some plugin settings related to indices and index patterns.
- Added tests for these validations.
- Added tests for the input validation.
- Updated the development branch with the base branch
Update
- Fix a bug in the
useFormhook - Refactor the definition of the setting validation functions to a class with static methods
Update
- Enhance the validation of the settings of type
numberchecking if these are integers. Related to https://github.com/wazuh/wazuh-kibana-app/pull/4501#issuecomment-1286687890.
TR: :heavy_check_mark:
| Code coverage (Jest) | % | values |
|---|---|---|
| Statements | 7.93% | ( 2897 / 36516 ) |
| Branches | 3.57% | ( 1005 / 28112 ) |
| Functions | 6.8% | ( 615 / 9038 ) |
| Lines | 7.99% | ( 2792 / 34947 ) |
The backport to 4.4-2.3-wzd failed:
The process '/usr/bin/git' failed with exit code 1
To backport manually, run these commands in your terminal:
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-4.4-2.3-wzd 4.4-2.3-wzd
# Navigate to the new working tree
cd .worktrees/backport-4.4-2.3-wzd
# Create a new branch
git switch --create backport-4503-to-4.4-2.3-wzd
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 5c0c413f7357afe7388af748007fec62c25dd9a0
# Push it to GitHub
git push --set-upstream origin backport-4503-to-4.4-2.3-wzd
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-4.4-2.3-wzd
Then, create a pull request where the base branch is 4.4-2.3-wzd and the compare/head branch is backport-4503-to-4.4-2.3-wzd.