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

[Backport 4.4-2.4-wzd] Add length validation to agent name #5030

Merged
merged 5 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ 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)
- Deploy new agent section: Added link for additional steps to alpine os. [#4933](https://github.com/wazuh/wazuh-kibana-app/pull/4933)
- Added character validation to avoid invalid agent names in the section 'Deploy new agent'. [#5021](https://github.com/wazuh/wazuh-kibana-app/pull/5021)

### Changed

Expand Down
25 changes: 14 additions & 11 deletions public/controllers/agent/components/register-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,13 @@ 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: [] });
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('')
Expand All @@ -320,8 +320,11 @@ export const RegisterAgent = withErrorBoundary(
.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
});
}
}

Expand Down Expand Up @@ -896,8 +899,8 @@ export const RegisterAgent = withErrorBoundary(
<EuiForm>
<EuiFormRow
isInvalid={this.state.agentNameError}
error={[
`The character${this.state.badCharacters.length <= 1 ? '' : 's'}
error={[this.state.badCharacters.length < 1 ? 'The minimum length is 2 characters.' :
`The character${this.state.badCharacters.length <= 1 ? ('') : ('s')}
${this.state.badCharacters.map(char => ` "${char}"`)}
${this.state.badCharacters.length <= 1 ? 'is' : 'are'}
not valid. Allowed characters are A-Z, a-z, ".", "-", "_"`,
Expand Down