-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filter high level groups and action groups by cluster and index (#1482)
* filter high level groups and action groups by cluster and index Signed-off-by: Derek Ho <[email protected]> * remove unecessary console Signed-off-by: Derek Ho <[email protected]> * add semicolon back Signed-off-by: Derek Ho <[email protected]> * use map instead of flat map Signed-off-by: Derek Ho <[email protected]> * fix lint Signed-off-by: Derek Ho <[email protected]> * fix tests Signed-off-by: Derek Ho <[email protected]> * revert file Signed-off-by: Derek Ho <[email protected]> * fix up tests Signed-off-by: Derek Ho <[email protected]> * lint Signed-off-by: Derek Ho <[email protected]> --------- Signed-off-by: Derek Ho <[email protected]> (cherry picked from commit 5fd8018)
- Loading branch information
1 parent
b988375
commit 52eb90c
Showing
2 changed files
with
179 additions
and
5 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
161 changes: 161 additions & 0 deletions
161
public/apps/configuration/panels/role-edit/test/role-edit-filtering.test.tsx
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,161 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { ClusterPermissionPanel } from '../cluster-permission-panel'; | ||
import { RoleEdit } from '../role-edit'; | ||
import { ActionGroupItem } from '../../../types'; | ||
import { fetchActionGroups } from '../../../utils/action-groups-utils'; | ||
|
||
import { render, waitFor } from '@testing-library/react'; | ||
|
||
import { act } from 'react-dom/test-utils'; | ||
import { IndexPermissionPanel } from '../index-permission-panel'; | ||
import { CLUSTER_PERMISSIONS, INDEX_PERMISSIONS } from '../../../constants'; | ||
|
||
jest.mock('../../../utils/role-detail-utils', () => ({ | ||
getRoleDetail: jest.fn().mockReturnValue({ | ||
cluster_permissions: [], | ||
index_permissions: [], | ||
tenant_permissions: [], | ||
reserved: false, | ||
}), | ||
updateRole: jest.fn(), | ||
})); | ||
jest.mock('../../../utils/action-groups-utils'); | ||
|
||
jest.mock('../cluster-permission-panel', () => ({ | ||
ClusterPermissionPanel: jest.fn(() => null) as jest.Mock, | ||
})); | ||
|
||
jest.mock('../index-permission-panel', () => ({ | ||
IndexPermissionPanel: jest.fn(() => null) as jest.Mock, | ||
})); | ||
|
||
describe('Role edit filtering', () => { | ||
const sampleSourceRole = 'role'; | ||
const mockCoreStart = { | ||
http: 1, | ||
}; | ||
|
||
(fetchActionGroups as jest.Mock).mockResolvedValue({ | ||
data_access: { | ||
reserved: true, | ||
hidden: false, | ||
allowed_actions: ['indices:data/*', 'crud'], | ||
type: 'index', | ||
description: 'Allow all read/write operations on data', | ||
static: true, | ||
}, | ||
cluster_manage_pipelines: { | ||
reserved: true, | ||
hidden: false, | ||
allowed_actions: ['cluster:admin/ingest/pipeline/*'], | ||
type: 'cluster', | ||
description: 'Manage pipelines', | ||
static: true, | ||
}, | ||
}); | ||
|
||
it('basic cluster permission panel rendering', async () => { | ||
const action = 'create'; | ||
const buildBreadcrumbs = jest.fn(); | ||
|
||
render( | ||
<RoleEdit | ||
action={action} | ||
sourceRoleName={sampleSourceRole} | ||
buildBreadcrumbs={buildBreadcrumbs} | ||
coreStart={mockCoreStart as any} | ||
navigation={{} as any} | ||
params={{} as any} | ||
config={{} as any} | ||
/> | ||
); | ||
|
||
await act(async () => { | ||
await waitFor(() => { | ||
expect(ClusterPermissionPanel).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
const lastCallArgs = | ||
ClusterPermissionPanel.mock.calls[ClusterPermissionPanel.mock.calls.length - 1]; | ||
const [props] = lastCallArgs; | ||
|
||
// Cluster Permission Panel props is filtered to action groups with type cluster, and only the cluster permission constants | ||
expect(props.optionUniverse).toEqual([ | ||
{ | ||
label: 'Permission groups', | ||
options: [ | ||
{ | ||
label: 'cluster_manage_pipelines', | ||
}, | ||
], | ||
}, | ||
{ | ||
label: 'Cluster permissions', | ||
options: CLUSTER_PERMISSIONS.map((x) => { | ||
return { label: x }; | ||
}), | ||
}, | ||
]); | ||
}); | ||
|
||
it('basic index permission panel rendering', async () => { | ||
const action = 'create'; | ||
const buildBreadcrumbs = jest.fn(); | ||
|
||
render( | ||
<RoleEdit | ||
action={action} | ||
sourceRoleName={sampleSourceRole} | ||
buildBreadcrumbs={buildBreadcrumbs} | ||
coreStart={mockCoreStart as any} | ||
navigation={{} as any} | ||
params={{} as any} | ||
config={{} as any} | ||
/> | ||
); | ||
|
||
await act(async () => { | ||
await waitFor(() => { | ||
expect(IndexPermissionPanel).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
const lastCallArgs = | ||
IndexPermissionPanel.mock.calls[IndexPermissionPanel.mock.calls.length - 1]; | ||
const [props] = lastCallArgs; | ||
|
||
// Index Permission Panel props is filtered to action groups with type index, and only the index permission constants | ||
expect(props.optionUniverse).toEqual([ | ||
{ | ||
label: 'Permission groups', | ||
options: [ | ||
{ | ||
label: 'data_access', | ||
}, | ||
], | ||
}, | ||
{ | ||
label: 'Index permissions', | ||
options: INDEX_PERMISSIONS.map((x) => { | ||
return { label: x }; | ||
}), | ||
}, | ||
]); | ||
}); | ||
}); |