From 35363a2bd6c822654d563a98d77833b472c1c13c Mon Sep 17 00:00:00 2001 From: Nicolas Guevara Date: Wed, 21 Dec 2022 13:35:09 -0300 Subject: [PATCH 1/4] Reduce number of setState --- public/controllers/agent/components/register-agent.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/public/controllers/agent/components/register-agent.js b/public/controllers/agent/components/register-agent.js index f59ea22697..3de5135652 100644 --- a/public/controllers/agent/components/register-agent.js +++ b/public/controllers/agent/components/register-agent.js @@ -299,18 +299,15 @@ export const RegisterAgent = withErrorBoundary( setAgentName(event) { const validation = /^[a-z0-9-_.]+$/i; - this.setState({ agentName: event.target.value }); if (validation.test(event.target.value) || event.target.value.length <= 0) { - this.setState({ agentNameError: false }); - this.setState({ badCharacters: [] }); + this.setState({ agentName: event.target.value, agentNameError: false, badCharacters: [] }); } else { let badCharacters = event.target.value.split('').map(char => char.replace(validation, '')).join(''); badCharacters = badCharacters.split('').map(char => char.replace(/\s/, 'whitespace')); const characters = [...new Set(badCharacters)]; - this.setState({ badCharacters: characters }); - this.setState({ agentNameError: true }); + this.setState({ agentName: event.target.value, badCharacters: characters, agentNameError: true }); } } From 7c2789268c357750fcf3ce7ed73710b389b8f077 Mon Sep 17 00:00:00 2001 From: Nicolas Guevara Date: Wed, 21 Dec 2022 13:52:57 -0300 Subject: [PATCH 2/4] Add length validation --- .../agent/components/register-agent.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/public/controllers/agent/components/register-agent.js b/public/controllers/agent/components/register-agent.js index 3de5135652..9214b49c66 100644 --- a/public/controllers/agent/components/register-agent.js +++ b/public/controllers/agent/components/register-agent.js @@ -299,15 +299,24 @@ export const RegisterAgent = withErrorBoundary( setAgentName(event) { const validation = /^[a-z0-9-_.]+$/i; - if (validation.test(event.target.value) || event.target.value.length <= 0) { - this.setState({ agentName: event.target.value, agentNameError: false, badCharacters: [] }); + if ((validation.test(event.target.value) && event.target.value.length >= 2) + || event.target.value.length <= 0) { + this.setState({ + agentName: event.target.value, + agentNameError: false, + badCharacters: [] + }); } else { let badCharacters = event.target.value.split('').map(char => char.replace(validation, '')).join(''); badCharacters = badCharacters.split('').map(char => char.replace(/\s/, 'whitespace')); const characters = [...new Set(badCharacters)]; - this.setState({ agentName: event.target.value, badCharacters: characters, agentNameError: true }); + this.setState({ + agentName: event.target.value, + badCharacters: characters, + agentNameError: true + }); } } @@ -879,7 +888,8 @@ export const RegisterAgent = withErrorBoundary( ` "${char}"`)} ${this.state.badCharacters.length <= 1 ? ('is') : ('are')} not valid. Allowed characters are A-Z, a-z, ".", "-", "_"`]}> From b0be45d3a1866f484f0061197496bbea21271d99 Mon Sep 17 00:00:00 2001 From: Nicolas Guevara Date: Wed, 21 Dec 2022 14:07:27 -0300 Subject: [PATCH 3/4] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee340a57ba..3451091900 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ All notable changes to the Wazuh app project will be documented in this file. - Added a centralized service to handle the requests [#4831](https://github.com/wazuh/wazuh-kibana-app/pull/4831) - Added data-test-subj create policy [#4873](https://github.com/wazuh/wazuh-kibana-app/pull/4873) - Added file saving conditions in File Editor [#4970](https://github.com/wazuh/wazuh-kibana-app/pull/4970) -- Added character validation to avoid invalid agent names in the section 'Deploy new agent'. [#5021](https://github.com/wazuh/wazuh-kibana-app/pull/5021) +- Added character validation to avoid invalid agent names in the section 'Deploy new agent'. [#5021](https://github.com/wazuh/wazuh-kibana-app/pull/5021)[#5028](https://github.com/wazuh/wazuh-kibana-app/pull/5028) ### Changed From ec8679c6db9eb8c85b012dfaa567565c3a70361a Mon Sep 17 00:00:00 2001 From: Federico Rodriguez Date: Thu, 22 Dec 2022 15:26:01 +0100 Subject: [PATCH 4/4] Update CHANGELOG.md Add space between two pull request references. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57b8f0c74f..d8ce1152a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ All notable changes to the Wazuh app project will be documented in this file. - Added a centralized service to handle the requests [#4831](https://github.com/wazuh/wazuh-kibana-app/pull/4831) - Added data-test-subj create policy [#4873](https://github.com/wazuh/wazuh-kibana-app/pull/4873) - Added file saving conditions in File Editor [#4970](https://github.com/wazuh/wazuh-kibana-app/pull/4970) -- Added character validation to avoid invalid agent names in the section 'Deploy new agent'. [#5021](https://github.com/wazuh/wazuh-kibana-app/pull/5021)[#5028](https://github.com/wazuh/wazuh-kibana-app/pull/5028) +- Added character validation to avoid invalid agent names in the section 'Deploy new agent'. [#5021](https://github.com/wazuh/wazuh-kibana-app/pull/5021) [#5028](https://github.com/wazuh/wazuh-kibana-app/pull/5028) - Deploy new agent section: Added link for additional steps to alpine os. [#4933](https://github.com/wazuh/wazuh-kibana-app/pull/4933) ### Changed