wazuh-dashboard-plugins icon indicating copy to clipboard operation
wazuh-dashboard-plugins copied to clipboard

Add validation to the plugin settings

Open Desvelao opened this issue 3 years ago • 3 comments

Description

This PR:

  • Add:
    • Plugin setting validations:
      • Frontend Settings/Configuration form:
        • 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

Closes #4446

Screenshots

  • Input's validation, invalid settings highlight, error count display and disabled of the save button. image

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

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.

Desvelao avatar Sep 13 '22 08:09 Desvelao

  • Fixed some settings validation errors
  • Updated the development branch with the last changes of the base branch

Desvelao avatar Sep 19 '22 13:09 Desvelao

  • Updated the development branch with the last changes of the base branch.

Desvelao avatar Sep 21 '22 12:09 Desvelao

  • Updated the development branch with the last changes of the base branch.

Desvelao avatar Sep 23 '22 08:09 Desvelao

  • Added tests to validate each setting in the endpoint to update the plugin configuration on the backend.
  • Added tests related to validation for useForm hook and InputForm component

Desvelao avatar Sep 26 '22 08:09 Desvelao

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

Desvelao avatar Sep 27 '22 13:09 Desvelao

  • Enhanced the validation of some plugin settings related to indices and index patterns.
  • Added tests for these validations.
  • Added tests for the input validation.

Desvelao avatar Oct 04 '22 15:10 Desvelao

  • Updated the development branch with the base branch

Desvelao avatar Oct 06 '22 09:10 Desvelao

Update

  • Fix a bug in the useForm hook
  • Refactor the definition of the setting validation functions to a class with static methods

Desvelao avatar Oct 21 '22 08:10 Desvelao

Update

  • Enhance the validation of the settings of type number checking if these are integers. Related to https://github.com/wazuh/wazuh-kibana-app/pull/4501#issuecomment-1286687890. image

Desvelao avatar Oct 21 '22 10:10 Desvelao

Code coverage (Jest) % values
Statements 7.93% ( 2897 / 36516 )
Branches 3.57% ( 1005 / 28112 )
Functions 6.8% ( 615 / 9038 )
Lines 7.99% ( 2792 / 34947 )

github-actions[bot] avatar Oct 26 '22 14:10 github-actions[bot]

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.

github-actions[bot] avatar Oct 27 '22 07:10 github-actions[bot]