-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport 4.4-7.16] Enhance the getConfiguration backend service (#5431)
* Enhance the getConfiguration backend service (#5428) * fix(enhance): enhance the the backend service to get the plugin configuration - Enhance the backend service to get the plugin configuration - Tests: - Add testing for the getConfiguration service - Add test to ensure the `GET /utils/configuration` returns the expected host response * changelog: add pull request entry * changelog: fix changelog * Fix get configuration test unlink command error * fix: fix comment on unit test --------- Co-authored-by: Maximiliano Ibarra <[email protected]> (cherry picked from commit 6290e99) * fix: fix accessing to object key
- Loading branch information
Showing
4 changed files
with
106 additions
and
7 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
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,87 @@ | ||
import { WAZUH_DATA_ABSOLUTE_PATH, WAZUH_DATA_CONFIG_DIRECTORY_PATH, WAZUH_DATA_CONFIG_APP_PATH } from '../../common/constants'; | ||
import { createDataDirectoryIfNotExists, createDirectoryIfNotExists } from './filesystem'; | ||
import { getConfiguration } from './get-configuration'; | ||
import { execSync } from 'child_process'; | ||
import { unlinkSync, writeFileSync } from 'fs'; | ||
|
||
beforeAll(() => { | ||
// Create <PLUGIN_PLATFORM_PATH>/data/wazuh directory. | ||
createDataDirectoryIfNotExists(); | ||
// Create <PLUGIN_PLATFORM_PATH>/data/wazuh/config directory. | ||
createDirectoryIfNotExists(WAZUH_DATA_CONFIG_DIRECTORY_PATH); | ||
}); | ||
|
||
afterAll(() => { | ||
// Remove <PLUGIN_PLATFORM_PATH>/data/wazuh directory. | ||
execSync(`rm -rf ${WAZUH_DATA_ABSOLUTE_PATH}`); | ||
}); | ||
|
||
describe('[service] get-configuration', () => { | ||
|
||
afterEach(() => { | ||
// Remove <PLUGIN_PLATFORM_PATH>/data/wazuh/config/wazuh.yml file. | ||
execSync(`rm ${WAZUH_DATA_ABSOLUTE_PATH}/config/wazuh.yml || echo ""`); | ||
}); | ||
|
||
const pluginConfigurationText = [ | ||
`hosts: | ||
- default: | ||
- url: http://wazuh.manager | ||
- port: 55000 | ||
- username: user | ||
- password: password | ||
- run_as: false | ||
`, | ||
`hosts: | ||
- default: | ||
- url: http://wazuh.manager | ||
- port: 55000 | ||
- username: user | ||
- password: password | ||
- run_as: false | ||
- custom: | ||
- url: http://custom.manager | ||
- port: 55000 | ||
- username: custom | ||
- password: custompassword | ||
- run_as: false | ||
`, | ||
`pattern: wazuh-alerts-* | ||
hosts: | ||
- default: | ||
- url: http://wazuh.manager | ||
- port: 55000 | ||
- username: user | ||
- password: password | ||
- run_as: false | ||
- custom: | ||
- url: http://custom.manager | ||
- port: 55000 | ||
- username: custom | ||
- password: custompassword | ||
- run_as: false | ||
- custom2: | ||
- url: http://custom2.manager | ||
- port: 55000 | ||
- username: custom2 | ||
- password: custompassword2 | ||
- run_as: false | ||
` | ||
]; | ||
|
||
it.each` | ||
pluginConfiguration | ||
${pluginConfigurationText[0]} | ||
${pluginConfigurationText[1]} | ||
${pluginConfigurationText[2]} | ||
`('Obfuscate the hosts password', ({pluginConfiguration}) => { | ||
// Create plugin configuration file | ||
writeFileSync(WAZUH_DATA_CONFIG_APP_PATH, pluginConfiguration, { encoding: 'utf8' }); | ||
const configuration = getConfiguration(); | ||
configuration.hosts.forEach(host => { | ||
const hostID = Object.keys(host)[0]; | ||
expect(Object.keys(host).length).toEqual(1); | ||
expect(host[hostID].password).toEqual('*****'); | ||
}); | ||
}); | ||
}); |
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
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