-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed agent RBAC filters from dashboard queries (#6945)
* Fix 4.9.0 changelog (#6933) * Fix 4.9.0 changelog * Remove 6519 reverted pull request * Bump 4.9.0 rev 06 RC1 (#6934) * Bump 4.9.0 revision 06 RC1 * Format * Remove allowed agents filter in data source * Remove getAuthorizedAgent no authorization * Remove allowedAgents from app state * Remove useAllowedAgents hook * Remove allowed agents related actions * Remove allowed agents in reporting * Apply prettier * Remove allowed agents * Fix unit test * Revert CHANGELOG * Update CHANGELOG --------- Co-authored-by: Federico Rodriguez <[email protected]>
- Loading branch information
1 parent
977a347
commit 60dcc23
Showing
25 changed files
with
333 additions
and
574 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
221 changes: 111 additions & 110 deletions
221
plugins/main/public/components/common/data-source/hooks/use-data-source.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 |
---|---|---|
@@ -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'); | ||
}); | ||
}); |
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
Oops, something went wrong.