Skip to content

Commit

Permalink
Add cluster's IP and protocol as suggestions in the agent deployment …
Browse files Browse the repository at this point in the history
…wizard (#4776)

* section deploy new agent in progress

* tabSystemD and tabSysV

* section deploy a new agent done

* cleaning code

* cleaning code

* test

* CHANGELOG

* code cleaning

* design for when a user selects an obsolete system version

* code cleanup

* changed macOS for macOS and updated the macOS version view

* development with information update provided by ci cd

* applying some of the new changes that the ci cd team sent us today

* delete

* updating information sent by ci/cd on operating systems, commands, etc.

* logic of displaying message to rare operating systems and redirecting them to documentation

* logic of displaying message to rare operating systems and redirecting them to documentation

* wazuh protocol variable

* Ordered OS buttons in deploy new agent steps

* Replaced input server address

* Testing signed commits

* Added server address component isolated from register-agent component

* Added test for multiple nodes rendered in combobox

* Added wazuh manager multiple ips in command definition

* Refactored and cleaned code

* Added unit test

* Updated CHANGELOG

* Added default option and paste only name in combo tag

* variable of deployment wazuh protocol

* merge 4.4-7.10

* Added free option enter and cleaned code

* removing spaces, css den deshuso, unify uppercase

* Refactored code and added new tests and fixed old tests

* removing link space

* fixed labels

* Resolved review comments following dev style guide

* change of logic in links

* Added OS delimiter condition

* Added and updated unit tests

* Resolved review comments

* Removed empty file

* Removed snapshot to fix unit tests workflow

* message + error handling

* Detached getRemoteInfo request in service to ease unit testing

* Add agent name to the deployment command (#4739)

* Add variable for the agent's name

* input is cleaned if there is no data

* design input name

* Update CHANGELOG

* Resolved review comment, unused code and code format

Co-authored-by: Maximiliano Ibarra <maximilianoaibarra@gmail.com>

* Fixing tests

* Testing signed commit with updated email

* Fixing unverified commit

* Fixing eslint errors

* Added get remote info by node and unit tests

* Added server address and protocol behavior

* Updated Server address unit tests

* Updated and added register agent service unit tests

* Added error managment in register agent and server address component

* Updated CHANGELOG

* Fixed tests workflow

* CHANGELOG

* udpProtocol:false

* constants for repeated text

Co-authored-by: chantal.kelm <chantal.belen.kelm@gmail.com>
Co-authored-by: Chantal Belén kelm <99441266+chantal-kelm@users.noreply.github.com>
Co-authored-by: Álex <alejandro.ruiz.becerra@wazuh.com>
  • Loading branch information
4 people authored Nov 10, 2022
1 parent 3048aab commit d178752
Show file tree
Hide file tree
Showing 8 changed files with 1,041 additions and 65 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Updated and added operating systems, versions, architectures commands of Install and enroll the agent and
commands of Start the agent in the deploy new agent section [#4458](https://github.com/wazuh/wazuh-kibana-app/pull/4458)
- Makes Agents Overview loading icons independent [#4363](https://github.com/wazuh/wazuh-kibana-app/pull/4363)
- Added cluster's IP and protocol as suggestions in the agent deployment wizard. [#4776](https://github.com/wazuh/wazuh-kibana-app/pull/4776)

### Fixed

Expand Down
272 changes: 272 additions & 0 deletions public/controllers/agent/components/register-agent-service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
import * as RegisterAgentService from './register-agent-service';
import { WzRequest } from '../../../react-services/wz-request';
import { ServerAddressOptions } from '../register-agent/steps';

jest.mock('../../../react-services', () => ({
...jest.requireActual('../../../react-services') as object,
WzRequest: () => ({
apiReq: jest.fn(),
}),
}));


describe('Register agent service', () => {
beforeEach(() => jest.clearAllMocks());
describe('getRemoteConfiguration', () => {
it('should return secure connection = TRUE when have connection secure', async () => {
const remoteWithSecureAndNoSecure = [
{
connection: 'syslog',
ipv6: 'no',
protocol: ['UDP'],
port: '514',
'allowed-ips': ['0.0.0.0/0'],
},
{
connection: 'secure',
ipv6: 'no',
protocol: ['UDP'],
port: '1514',
queue_size: '131072',
},
];
const mockedResponse = {
data: {
data: {
affected_items: [
{
remote: remoteWithSecureAndNoSecure,
},
],
},
},
};
WzRequest.apiReq = jest.fn().mockResolvedValueOnce(mockedResponse);
const nodeName = 'example-node';
const res = await RegisterAgentService.getRemoteConfiguration('example-node');
expect(res.name).toBe(nodeName);
expect(res.haveSecureConnection).toBe(true);
});

it('should return secure connection = FALSE available when dont have connection secure', async () => {
const remoteWithSecureAndNoSecure = [
{
connection: 'syslog',
ipv6: 'no',
protocol: ['UDP', 'TCP'],
port: '514',
'allowed-ips': ['0.0.0.0/0'],
},
];
const mockedResponse = {
data: {
data: {
affected_items: [
{
remote: remoteWithSecureAndNoSecure,
},
],
},
},
};
WzRequest.apiReq = jest.fn().mockResolvedValueOnce(mockedResponse);
const nodeName = 'example-node';
const res = await RegisterAgentService.getRemoteConfiguration('example-node');
expect(res.name).toBe(nodeName);
expect(res.haveSecureConnection).toBe(false);
});

it('should return protocols UDP when is the only connection protocol available', async () => {
const remoteWithSecureAndNoSecure = [
{
connection: 'syslog',
ipv6: 'no',
protocol: ['UDP'],
port: '514',
'allowed-ips': ['0.0.0.0/0'],
},
{
connection: 'secure',
ipv6: 'no',
protocol: ['UDP'],
port: '1514',
queue_size: '131072',
},
];
const mockedResponse = {
data: {
data: {
affected_items: [
{
remote: remoteWithSecureAndNoSecure,
},
],
},
},
};
WzRequest.apiReq = jest.fn().mockResolvedValueOnce(mockedResponse);
const nodeName = 'example-node';
const res = await RegisterAgentService.getRemoteConfiguration('example-node');
expect(res.name).toBe(nodeName);
expect(res.isUdp).toEqual(true);
});

it('should return protocols TCP when is the only connection protocol available', async () => {
const remoteWithSecureAndNoSecure = [
{
connection: 'syslog',
ipv6: 'no',
protocol: ['TCP'],
port: '514',
'allowed-ips': ['0.0.0.0/0'],
},
{
connection: 'secure',
ipv6: 'no',
protocol: ['TCP'],
port: '1514',
queue_size: '131072',
},
];
const mockedResponse = {
data: {
data: {
affected_items: [
{
remote: remoteWithSecureAndNoSecure,
},
],
},
},
};
WzRequest.apiReq = jest.fn().mockResolvedValueOnce(mockedResponse);
const nodeName = 'example-node';
const res = await RegisterAgentService.getRemoteConfiguration('example-node');
expect(res.name).toBe(nodeName);
expect(res.isUdp).toEqual(false);
});

it('should return is not UDP when have UDP and TCP protocols available', async () => {
const remoteWithSecureAndNoSecure = [
{
connection: 'syslog',
ipv6: 'no',
protocol: ['TCP'],
port: '514',
'allowed-ips': ['0.0.0.0/0'],
},
{
connection: 'secure',
ipv6: 'no',
protocol: ['UDP'],
port: '1514',
queue_size: '131072',
},
];
const mockedResponse = {
data: {
data: {
affected_items: [
{
remote: remoteWithSecureAndNoSecure,
},
],
},
},
};
WzRequest.apiReq = jest.fn().mockResolvedValueOnce(mockedResponse);
const nodeName = 'example-node';
const res = await RegisterAgentService.getRemoteConfiguration('example-node');
expect(res.name).toBe(nodeName);
expect(res.isUdp).toEqual(false);
});
});

describe('getConnectionConfig', () => {

beforeAll(() => {
jest.clearAllMocks();
})

it('should return UDP when the server address is typed manually (custom)', async () => {
const nodeSelected: ServerAddressOptions = {
label: 'node-selected',
value: 'node-selected',
nodetype: 'master'
};

const remoteWithSecureAndNoSecure = [
{
connection: 'syslog',
ipv6: 'no',
protocol: ['UDP'],
port: '514',
'allowed-ips': ['0.0.0.0/0'],
},
{
connection: 'secure',
ipv6: 'no',
protocol: ['UDP'],
port: '1514',
queue_size: '131072',
},
];
const mockedResponse = {
data: {
data: {
affected_items: [
{
remote: remoteWithSecureAndNoSecure,
},
],
},
},
};
WzRequest.apiReq = jest.fn().mockResolvedValueOnce(mockedResponse);

const config = await RegisterAgentService.getConnectionConfig(nodeSelected, 'default-dns-address');
expect(config.udpProtocol).toEqual(true);
expect(config.serverAddress).toBe('default-dns-address');
})

it('should return UDP when the server address is received like default server address dns (custom)', async () => {
const nodeSelected: ServerAddressOptions = {
label: 'node-selected',
value: 'node-selected',
nodetype: 'master'
};

const remoteWithSecureAndNoSecure = [
{
connection: 'syslog',
ipv6: 'no',
protocol: ['UDP'],
port: '514',
'allowed-ips': ['0.0.0.0/0'],
},
{
connection: 'secure',
ipv6: 'no',
protocol: ['UDP'],
port: '1514',
queue_size: '131072',
},
];
const mockedResponse = {
data: {
data: {
affected_items: [
{
remote: remoteWithSecureAndNoSecure,
},
],
},
},
};
WzRequest.apiReq = jest.fn().mockResolvedValueOnce(mockedResponse);

const config = await RegisterAgentService.getConnectionConfig(nodeSelected);
expect(config.udpProtocol).toEqual(true);
})
})
});
Loading

0 comments on commit d178752

Please sign in to comment.