-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cluster's IP and protocol as suggestions in the agent deployment …
…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> (cherry picked from commit d178752)
- Loading branch information
1 parent
6fb45d5
commit 17ebbee
Showing
8 changed files
with
1,043 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
272 changes: 272 additions & 0 deletions
272
public/controllers/agent/components/register-agent-service.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}) | ||
}) | ||
}); |
Oops, something went wrong.