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.3-wzd] Add cluster's IP and protocol as suggestions in the agent deployment wizard #4861

Merged
merged 2 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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