Skip to content

Commit

Permalink
[Backport 2.4-wzd] Fixed the manager option in the agent deployment s…
Browse files Browse the repository at this point in the history
…ection (#5026)

* Fixed the manager option in the agent deployment section (#4981)

* add manager option

* add changelog

* add changelog

* fix test

* fix typo

* add getCookies and getHttp (test)

* Fixed unit tests

* fix comment

Co-authored-by: Álex <alejandro.ruiz.becerra@wazuh.com>
Co-authored-by: Maximiliano Ibarra <maximiliano.ibarra@wazuh.com>
(cherry picked from commit 65e156b)

* Update CHANGELOG.md
  • Loading branch information
yenienserrano authored Dec 21, 2022
1 parent 0b8d394 commit 90d9b4b
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 155 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Fixed vulnerabilities default last scan date formatter [#4975](https://github.com/wazuh/wazuh-kibana-app/pull/4975)
- Fixed agent deployment instructions for HP-UX and Solaris. [#4943](https://github.com/wazuh/wazuh-kibana-app/pull/4943)
- Fixed a bug that caused the flyouts to close when clicking inside them [#4638](https://github.com/wazuh/wazuh-kibana-app/pull/4638)
- Fixed the manager option in the agent deployment section [#4981](https://github.com/wazuh/wazuh-kibana-app/pull/4981)
- Fixed Inventory checks table filters by stats [#4999](https://github.com/wazuh/wazuh-kibana-app/pull/4999)
- Fixed agent graph in opensearch dashboard [#4942] (https://github.com/wazuh/wazuh-kibana-app/pull/4942)
- Fixed commands in the deploy new agent section(most of the commands are missing '-1') [#4962](https://github.com/wazuh/wazuh-kibana-app/pull/4962)
Expand Down
262 changes: 151 additions & 111 deletions public/controllers/agent/components/register-agent-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ import { WzRequest } from '../../../react-services/wz-request';
import { ServerAddressOptions } from '../register-agent/steps';

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

const mockedResponseClusterStatus = {
data: {
data: {
enabled: 'yes',
running: 'yes',
},
error: 0,
},
};

describe('Register agent service', () => {
beforeEach(() => jest.clearAllMocks());
Expand Down Expand Up @@ -41,9 +50,15 @@ describe('Register agent service', () => {
},
},
};
WzRequest.apiReq = jest.fn().mockResolvedValueOnce(mockedResponse);

WzRequest.apiReq = jest
.fn()
.mockResolvedValueOnce(mockedResponseClusterStatus)
.mockResolvedValueOnce(mockedResponse);
const nodeName = 'example-node';
const res = await RegisterAgentService.getRemoteConfiguration('example-node');
const res = await RegisterAgentService.getRemoteConfiguration(
'example-node',
);
expect(res.name).toBe(nodeName);
expect(res.haveSecureConnection).toBe(true);
});
Expand All @@ -69,130 +84,149 @@ describe('Register agent service', () => {
},
},
};
WzRequest.apiReq = jest.fn().mockResolvedValueOnce(mockedResponse);
WzRequest.apiReq = jest
.fn()
.mockResolvedValueOnce(mockedResponseClusterStatus)
.mockResolvedValueOnce(mockedResponse);
const nodeName = 'example-node';
const res = await RegisterAgentService.getRemoteConfiguration('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 = {
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: {
data: {
affected_items: [
{
remote: remoteWithSecureAndNoSecure,
},
],
},
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);
});
},
};
WzRequest.apiReq = jest
.fn()
.mockResolvedValueOnce(mockedResponseClusterStatus)
.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 = {
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: {
data: {
affected_items: [
{
remote: remoteWithSecureAndNoSecure,
},
],
},
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);
});
},
};
WzRequest.apiReq = jest
.fn()
.mockResolvedValueOnce(mockedResponseClusterStatus)
.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 = {
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: {
data: {
affected_items: [
{
remote: remoteWithSecureAndNoSecure,
},
],
},
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);
});
},
};
WzRequest.apiReq = jest
.fn()
.mockResolvedValueOnce(mockedResponseClusterStatus)
.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 IS NOT UDP when the server address is typed manually (custom)', async () => {
const nodeSelected: ServerAddressOptions = {
label: 'node-selected',
value: 'node-selected',
nodetype: 'master'
nodetype: 'master',
};

const remoteWithSecureAndNoSecure = [
Expand Down Expand Up @@ -223,17 +257,20 @@ describe('Register agent service', () => {
},
};
WzRequest.apiReq = jest.fn().mockResolvedValueOnce(mockedResponse);

const config = await RegisterAgentService.getConnectionConfig(nodeSelected, 'default-dns-address');

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

it('should return IS NOT 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'
nodetype: 'master',
};

const remoteWithSecureAndNoSecure = [
Expand Down Expand Up @@ -264,9 +301,12 @@ describe('Register agent service', () => {
},
};
WzRequest.apiReq = jest.fn().mockResolvedValueOnce(mockedResponse);

const config = await RegisterAgentService.getConnectionConfig(nodeSelected, 'custom-server-address');

const config = await RegisterAgentService.getConnectionConfig(
nodeSelected,
'custom-server-address',
);
expect(config.udpProtocol).toEqual(false);
})
})
});
});
});
Loading

0 comments on commit 90d9b4b

Please sign in to comment.