Skip to content

Commit

Permalink
merge: merge 4.10.0 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Desvelao committed Sep 9, 2024
2 parents 0c78a4b + ee74a59 commit c87acca
Show file tree
Hide file tree
Showing 41 changed files with 8,497 additions and 769 deletions.
63 changes: 38 additions & 25 deletions CHANGELOG.md

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions docker/osd-dev/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ os_versions=(
'2.12.0'
'2.13.0'
'2.14.0'
'2.15.0'
'2.16.0'
)

osd_versions=(
Expand All @@ -36,12 +38,19 @@ osd_versions=(
'2.12.0'
'2.13.0'
'2.14.0'
'2.15.0'
'2.16.0'
)

wzs_version=(
'4.7.0'
'4.7.1'
'4.7.2'
'4.7.3'
'4.7.4'
'4.7.5'
'4.8.0'
'4.8.1'
)

usage() {
Expand Down
4 changes: 2 additions & 2 deletions plugins/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "5.0.0",
"revision": "00",
"pluginPlatform": {
"version": "2.13.0"
"version": "2.16.0"
},
"description": "Wazuh dashboard",
"keywords": [
Expand Down Expand Up @@ -48,7 +48,7 @@
"knip": "knip --files"
},
"dependencies": {
"axios": "^1.6.1",
"axios": "^1.7.4",
"dompurify": "^3.1.3",
"install": "^0.13.0",
"js2xmlparser": "^5.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,129 +1,130 @@
import { useDataSource } from './use-data-source';
import { renderHook } from '@testing-library/react-hooks';
import {
tDataSourceRepository,
tFilter,
PatternDataSource,
tParsedIndexPattern
import {
tDataSourceRepository,
tFilter,
PatternDataSource,
tParsedIndexPattern,
} from '../index';
import { IndexPatternsService, IndexPattern } from '../../../../../../../src/plugins/data/common';
import {
IndexPatternsService,
IndexPattern,
} from '../../../../../../../src/plugins/data/common';

jest.mock('../../../../kibana-services', () => ({
...(jest.requireActual('../../../../kibana-services') as object),
getDataPlugin: () => ({
// mock indexPatterns getter
indexPatterns: {
get: jest.fn().mockResolvedValue({
fields: {
replaceAll: jest.fn(),
map: jest.fn().mockReturnValue([]),
},
getScriptedFields: jest.fn().mockReturnValue([]),
}),
getFieldsForIndexPattern: jest.fn().mockResolvedValue([]),
updateSavedObject: jest.fn().mockResolvedValue({}),
...(jest.requireActual('../../../../kibana-services') as object),
getDataPlugin: () => ({
// mock indexPatterns getter
indexPatterns: {
get: jest.fn().mockResolvedValue({
fields: {
replaceAll: jest.fn(),
map: jest.fn().mockReturnValue([]),
},
query: {
filterManager: {
getFilters: jest.fn().mockReturnValue([]),
setFilters: jest.fn(),
getUpdates$: jest.fn().mockReturnValue({
subscribe: jest.fn()
})
}
}
}),
getScriptedFields: jest.fn().mockReturnValue([]),
}),
getFieldsForIndexPattern: jest.fn().mockResolvedValue([]),
updateSavedObject: jest.fn().mockResolvedValue({}),
},
query: {
filterManager: {
getFilters: jest.fn().mockReturnValue([]),
setFilters: jest.fn(),
getUpdates$: jest.fn().mockReturnValue({
subscribe: jest.fn(),
}),
},
},
}),
}));

const mockedGetFilters = jest.fn().mockReturnValue([]);

class DataSourceMocked implements PatternDataSource {
constructor(public id: string, public title: string) {
this.id = id;
this.title = title;
}
fields: any[];
patternService: IndexPatternsService;
indexPattern: IndexPattern;
defaultFixedFilters: tFilter[];
filters: tFilter[];
init = jest.fn();
select = jest.fn();
fetch = jest.fn();
getFilters = mockedGetFilters;
setFilters = jest.fn();
getFields = mockedGetFilters
getFixedFilters = mockedGetFilters
getFetchFilters = mockedGetFilters
toJSON(): tParsedIndexPattern {
return {
id: this.id,
title: this.title,
} as tParsedIndexPattern;
}
getClusterManagerFilters = mockedGetFilters
getPinnedAgentFilter = mockedGetFilters
getExcludeManagerFilter = mockedGetFilters
getAllowAgentsFilter = mockedGetFilters
constructor(public id: string, public title: string) {
this.id = id;
this.title = title;
}
fields: any[];
patternService: IndexPatternsService;
indexPattern: IndexPattern;
defaultFixedFilters: tFilter[];
filters: tFilter[];
init = jest.fn();
select = jest.fn();
fetch = jest.fn();
getFilters = mockedGetFilters;
setFilters = jest.fn();
getFields = mockedGetFilters;
getFixedFilters = mockedGetFilters;
getFetchFilters = mockedGetFilters;
toJSON(): tParsedIndexPattern {
return {
id: this.id,
title: this.title,
} as tParsedIndexPattern;
}
getClusterManagerFilters = mockedGetFilters;
getPinnedAgentFilter = mockedGetFilters;
getExcludeManagerFilter = mockedGetFilters;
}

class ExampleRepository implements tDataSourceRepository<tParsedIndexPattern> {
getDefault = jest.fn();
setDefault = jest.fn();
get = jest.fn();
getAll = jest.fn();
getDefault = jest.fn();
setDefault = jest.fn();
get = jest.fn();
getAll = jest.fn();
}

describe('useDataSource hook', () => {
it('shoudl throw ERROR when the repository is not defined', () => {
try {
renderHook(() =>
useDataSource({
DataSource: DataSourceMocked,
repository: undefined as any,
}),
);
} catch (error) {
expect(error).toBeDefined();
expect(error.message).toBe('DataSource and repository are required');
}
});

it('shoudl throw ERROR when the repository is not defined', () => {

try {
renderHook(() => useDataSource({
DataSource: DataSourceMocked,
repository: undefined as any
}));
} catch(error){
expect(error).toBeDefined();
expect(error.message).toBe('DataSource and repository are required');
}

})

it('should throw ERROR when the DataSource is not defined', () => {

try {
renderHook(() => useDataSource({
DataSource: undefined as any,
repository: new ExampleRepository()
}));
} catch(error){
expect(error).toBeDefined();
expect(error.message).toBe('DataSource and repository are required');
}

})

// FIXME:
it.skip('should initialize the hook with only receiving the dataSource and repository', async () => {
const repository = new ExampleRepository();
const indexMocked = {
id: 'test',
title: 'Test'
}
jest.spyOn(repository, 'getAll').mockResolvedValueOnce([indexMocked]);
jest.spyOn(repository, 'getDefault').mockResolvedValueOnce(indexMocked);
const { result, waitForNextUpdate } = renderHook(() => useDataSource({
DataSource: DataSourceMocked,
repository
}));
// wait for the promise to resolve
await waitForNextUpdate();
expect(result.current.isLoading).toBeFalsy();
expect(result.current.dataSource).toBeDefined();
expect(result.current.dataSource?.id).toBe('test');
expect(result.current.dataSource?.title).toBe('Test');
})

it('should throw ERROR when the DataSource is not defined', () => {
try {
renderHook(() =>
useDataSource({
DataSource: undefined as any,
repository: new ExampleRepository(),
}),
);
} catch (error) {
expect(error).toBeDefined();
expect(error.message).toBe('DataSource and repository are required');
}
});

})
// FIXME:
it.skip('should initialize the hook with only receiving the dataSource and repository', async () => {
const repository = new ExampleRepository();
const indexMocked = {
id: 'test',
title: 'Test',
};
jest.spyOn(repository, 'getAll').mockResolvedValueOnce([indexMocked]);
jest.spyOn(repository, 'getDefault').mockResolvedValueOnce(indexMocked);
const { result, waitForNextUpdate } = renderHook(() =>
useDataSource({
DataSource: DataSourceMocked,
repository,
}),
);
// wait for the promise to resolve
await waitForNextUpdate();
expect(result.current.isLoading).toBeFalsy();
expect(result.current.dataSource).toBeDefined();
expect(result.current.dataSource?.id).toBe('test');
expect(result.current.dataSource?.title).toBe('Test');
});
});
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { tFilter } from '../../../index';
import { DATA_SOURCE_FILTER_CONTROLLED_MALWARE_DETECTION_RULE_GROUP } from '../../../../../../../common/constants';
import { AlertsDataSource } from '../alerts-data-source';
import { FILTER_OPERATOR, PatternDataSourceFilterManager } from '../../..';

const MALWARE_DETECTION_GROUP_KEY = 'rule.groups';
const MALWARE_DETECTION_GROUP_VALUE = 'rootcheck';
const MALWARE_DETECTION_GROUP_VALUES = ['rootcheck', 'virustotal', 'yara'];

export class MalwareDetectionDataSource extends AlertsDataSource {
constructor(id: string, title: string) {
super(id, title);
}

getRuleGroupsFilter() {
return super.getRuleGroupsFilter(
MALWARE_DETECTION_GROUP_KEY,
MALWARE_DETECTION_GROUP_VALUE,
DATA_SOURCE_FILTER_CONTROLLED_MALWARE_DETECTION_RULE_GROUP,
);
return [
PatternDataSourceFilterManager.createFilter(
FILTER_OPERATOR.IS_ONE_OF,
MALWARE_DETECTION_GROUP_KEY,
MALWARE_DETECTION_GROUP_VALUES,
this.id,
DATA_SOURCE_FILTER_CONTROLLED_MALWARE_DETECTION_RULE_GROUP,
),
];
}

getFixedFilters(): tFilter[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class DataSourceMocked implements PatternDataSource {
getClusterManagerFilters = mockedGetFilters;
getPinnedAgentFilter = mockedGetFilters;
getExcludeManagerFilter = mockedGetFilters;
getAllowAgentsFilter = mockedGetFilters;
}

const createFilter = (id: string, value: string, index: string): tFilter => {
Expand Down Expand Up @@ -374,27 +373,6 @@ describe('PatternDataSourceFilterManager', () => {
expect(filter.length).toBe(0);
});

it('should return the filters to fetch the data merging the filters stored and the allowed agents filter', () => {
(store.getState as jest.Mock).mockReturnValue({
appStateReducers: {
allowedAgents: ['001'],
},
});
const filter =
PatternDataSourceFilterManager.getAllowAgentsFilter('index-title');
expect(filter.length).toBe(1);
expect(filter[0].meta.controlledBy).toBe(AUTHORIZED_AGENTS);
});

it('should return the filters to fetch the data merging the filters stored without the allowed agents filter when is not defined', () => {
(store.getState as jest.Mock).mockReturnValue({
appStateReducers: {},
});
const filter =
PatternDataSourceFilterManager.getAllowAgentsFilter('index-title');
expect(filter.length).toBe(0);
});

// FIXME:
it.skip('should return the fixed filters merged with the pinned agent filter when correspond', () => {
// mock store.getState
Expand Down
Loading

0 comments on commit c87acca

Please sign in to comment.