From 6e8284ddf8aceaf24e6dcba5d04edd03c077741f Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Mon, 13 May 2024 14:19:31 -0400 Subject: [PATCH] Fixes a call to dataSource id causing test failures Signed-off-by: Darshit Chanpura --- .../audit-logging-edit-settings.test.tsx.snap | 98 +- .../__snapshots__/audit-logging.test.tsx.snap | 126 +- .../test/audit-logging-edit-settings.test.tsx | 12 + .../audit-logging/test/audit-logging.test.tsx | 12 + .../panels/auth-view/auth-view.tsx | 2 + .../__snapshots__/auth-view.test.tsx.snap | 16 - .../panels/auth-view/test/auth-view.test.tsx | 17 + .../internal-user-edit.test.tsx.snap | 157 +-- .../test/internal-user-edit.test.tsx | 12 + .../permission-list.test.tsx.snap | 282 +--- .../test/permission-list.test.tsx | 12 + .../__snapshots__/role-edit.test.tsx.snap | 1152 +---------------- .../panels/role-edit/test/role-edit.test.tsx | 11 + .../role-edit-mapped-user.test.tsx.snap | 122 +- .../test/role-edit-mapped-user.test.tsx | 11 + .../panels/role-view/role-view.tsx | 7 +- .../__snapshots__/role-view.test.tsx.snap | 345 +---- .../panels/role-view/test/role-view.test.tsx | 16 +- .../__snapshots__/get-started.test.tsx.snap | 368 +----- .../__snapshots__/role-list.test.tsx.snap | 149 --- .../__snapshots__/user-list.test.tsx.snap | 197 +-- .../panels/test/get-started.test.tsx | 11 + .../panels/test/role-list.test.tsx | 11 + .../panels/test/user-list.test.tsx | 11 + .../configuration/test/top-nav-menu.test.tsx | 22 + public/apps/configuration/top-nav-menu.tsx | 13 +- 26 files changed, 316 insertions(+), 2876 deletions(-) diff --git a/public/apps/configuration/panels/audit-logging/test/__snapshots__/audit-logging-edit-settings.test.tsx.snap b/public/apps/configuration/panels/audit-logging/test/__snapshots__/audit-logging-edit-settings.test.tsx.snap index ded6f8f01..2be62a837 100644 --- a/public/apps/configuration/panels/audit-logging/test/__snapshots__/audit-logging-edit-settings.test.tsx.snap +++ b/public/apps/configuration/panels/audit-logging/test/__snapshots__/audit-logging-edit-settings.test.tsx.snap @@ -1,91 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Audit logs edit Render unable to access dataSource when enabled and inaccessible 1`] = ` -
- - - -

- Compliance settings -

-
-
- - - - - - - - Cancel - - - - - Save - - - - -
+ } + navigation={Object {}} +/> `; diff --git a/public/apps/configuration/panels/audit-logging/test/__snapshots__/audit-logging.test.tsx.snap b/public/apps/configuration/panels/audit-logging/test/__snapshots__/audit-logging.test.tsx.snap index 641ba2fed..ae40071a9 100644 --- a/public/apps/configuration/panels/audit-logging/test/__snapshots__/audit-logging.test.tsx.snap +++ b/public/apps/configuration/panels/audit-logging/test/__snapshots__/audit-logging.test.tsx.snap @@ -1,113 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Audit logs Render unable to access dataSource when enabled and inaccessible 1`] = ` -
- - - -

- Audit logging -

-
- - - - Storage location - - } - > - - - - internal_opensearch - , - "opensearchCode": - opensearch.yml - , - } - } - /> - - - - - - - Enable audit logging - - } - > - - - - - -
-
-`; - exports[`Audit logs render compliance settings 1`] = ` `; + +exports[`Audit logs Render unable to access dataSource when enabled and inaccessible 1`] = ` + +`; diff --git a/public/apps/configuration/panels/audit-logging/test/audit-logging-edit-settings.test.tsx b/public/apps/configuration/panels/audit-logging/test/audit-logging-edit-settings.test.tsx index f00680cf4..39df438bf 100644 --- a/public/apps/configuration/panels/audit-logging/test/audit-logging-edit-settings.test.tsx +++ b/public/apps/configuration/panels/audit-logging/test/audit-logging-edit-settings.test.tsx @@ -39,6 +39,14 @@ describe('Audit logs edit', () => { jest.spyOn(React, 'useState').mockImplementation((initialValue) => [initialValue, setState]); }); + afterEach(() => { + React.useContext.mockRestore(); + React.useContext.mockReturnValue({ + dataSource: { id: 'test' }, + setDataSource: jest.fn(), + }); + }); + it('Render edit general settings', (done) => { jest.spyOn(React, 'useEffect').mockImplementationOnce((f) => f()); @@ -174,6 +182,10 @@ describe('Audit logs edit', () => { }); it('Render unable to access dataSource when enabled and inaccessible', () => { + React.useContext.mockImplementation(() => ({ + dataSource: undefined, + setDataSource: jest.fn(), + })); const depsStart = { dataSource: { dataSourceEnabled: true, diff --git a/public/apps/configuration/panels/audit-logging/test/audit-logging.test.tsx b/public/apps/configuration/panels/audit-logging/test/audit-logging.test.tsx index 017ee465e..763e6bea7 100644 --- a/public/apps/configuration/panels/audit-logging/test/audit-logging.test.tsx +++ b/public/apps/configuration/panels/audit-logging/test/audit-logging.test.tsx @@ -46,6 +46,14 @@ describe('Audit logs', () => { jest.spyOn(React, 'useEffect').mockImplementationOnce((f) => f()); }); + afterEach(() => { + React.useContext.mockRestore(); + React.useContext.mockReturnValue({ + dataSource: { id: 'test' }, + setDataSource: jest.fn(), + }); + }); + it('Render disabled', () => { const mockAuditLoggingData = { enabled: false, @@ -210,6 +218,10 @@ describe('Audit logs', () => { }); it('Render unable to access dataSource when enabled and inaccessible', () => { + React.useContext.mockImplementation(() => ({ + dataSource: undefined, + setDataSource: jest.fn(), + })); const depsStart = { dataSource: { dataSourceEnabled: true, diff --git a/public/apps/configuration/panels/auth-view/auth-view.tsx b/public/apps/configuration/panels/auth-view/auth-view.tsx index ccc3668a1..8cbe50b52 100644 --- a/public/apps/configuration/panels/auth-view/auth-view.tsx +++ b/public/apps/configuration/panels/auth-view/auth-view.tsx @@ -53,6 +53,8 @@ export function AuthView(props: AppDependencies) { }, [props.coreStart.http, dataSource]); if (isEmpty(authentication)) { + console.log(dataSource); + console.log(dataSourceEnabled); if (dataSourceEnabled && dataSource === undefined) { return ( <> diff --git a/public/apps/configuration/panels/auth-view/test/__snapshots__/auth-view.test.tsx.snap b/public/apps/configuration/panels/auth-view/test/__snapshots__/auth-view.test.tsx.snap index ce6eab824..e8596c9c0 100644 --- a/public/apps/configuration/panels/auth-view/test/__snapshots__/auth-view.test.tsx.snap +++ b/public/apps/configuration/panels/auth-view/test/__snapshots__/auth-view.test.tsx.snap @@ -8,7 +8,6 @@ exports[`Auth view Render unable to access dataSource when enabled and inaccessi "http": 1, } } - dataSourcePickerReadOnly={false} depsStart={ Object { "dataSource": Object { @@ -17,14 +16,7 @@ exports[`Auth view Render unable to access dataSource when enabled and inaccessi } } navigation={Object {}} - selectedDataSource={ - Object { - "id": "test", - } - } - setDataSource={[MockFunction]} /> - `; @@ -36,7 +28,6 @@ exports[`Auth view Render unable to access dataSource when enabled and inaccessi "http": 1, } } - dataSourcePickerReadOnly={false} depsStart={ Object { "dataSource": Object { @@ -45,13 +36,6 @@ exports[`Auth view Render unable to access dataSource when enabled and inaccessi } } navigation={Object {}} - selectedDataSource={ - Object { - "id": "test", - } - } - setDataSource={[MockFunction]} /> - `; diff --git a/public/apps/configuration/panels/auth-view/test/auth-view.test.tsx b/public/apps/configuration/panels/auth-view/test/auth-view.test.tsx index cb585b1ec..425241fed 100644 --- a/public/apps/configuration/panels/auth-view/test/auth-view.test.tsx +++ b/public/apps/configuration/panels/auth-view/test/auth-view.test.tsx @@ -39,6 +39,14 @@ describe('Auth view', () => { jest.spyOn(React, 'useEffect').mockImplementationOnce((f) => f()); }); + afterEach(() => { + React.useContext.mockRestore(); + React.useContext.mockReturnValue({ + dataSource: { id: 'test' }, + setDataSource: jest.fn(), + }); + }); + it('valid data', (done) => { const config = { authc: { @@ -101,6 +109,10 @@ describe('Auth view', () => { }); it('Render unable to access dataSource when enabled and inaccessible', () => { + React.useContext.mockImplementation(() => ({ + dataSource: undefined, + setDataSource: jest.fn(), + })); const depsStart = { dataSource: { dataSourceEnabled: true, @@ -117,6 +129,11 @@ describe('Auth view', () => { }); it('Render unable to access dataSource when enabled and inaccessible: Empty Authentication', () => { + React.useContext.mockImplementation(() => ({ + dataSource: undefined, + setDataSource: jest.fn(), + })); + mockAuthViewUtils.getSecurityConfig = jest.fn().mockImplementationOnce(() => { throw Error(); }); diff --git a/public/apps/configuration/panels/internal-user-edit/test/__snapshots__/internal-user-edit.test.tsx.snap b/public/apps/configuration/panels/internal-user-edit/test/__snapshots__/internal-user-edit.test.tsx.snap index 14fae931e..b66bd8fab 100644 --- a/public/apps/configuration/panels/internal-user-edit/test/__snapshots__/internal-user-edit.test.tsx.snap +++ b/public/apps/configuration/panels/internal-user-edit/test/__snapshots__/internal-user-edit.test.tsx.snap @@ -1,146 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Internal user edit Render unable to access dataSource when enabled and inaccessible 1`] = ` - - - - - - - -

- - - - - The security plugin includes an internal user database. Use this database in place of, or in addition to, an external authentication system such as LDAP or Active Directory. - - - - - - - - - - - - - - - - - - - - - Cancel - - - - - Create - - - - - + } + params={Object {}} + sourceUserName="user1" +/> `; diff --git a/public/apps/configuration/panels/internal-user-edit/test/internal-user-edit.test.tsx b/public/apps/configuration/panels/internal-user-edit/test/internal-user-edit.test.tsx index 8f526291f..c4902f6fc 100644 --- a/public/apps/configuration/panels/internal-user-edit/test/internal-user-edit.test.tsx +++ b/public/apps/configuration/panels/internal-user-edit/test/internal-user-edit.test.tsx @@ -47,6 +47,14 @@ describe('Internal user edit', () => { const useState = jest.spyOn(React, 'useState'); const setState = jest.fn(); + afterEach(() => { + React.useContext.mockRestore(); + React.useContext.mockReturnValue({ + dataSource: { id: 'test' }, + setDataSource: jest.fn(), + }); + }); + it('basic rendering', () => { const action = 'create'; @@ -150,6 +158,10 @@ describe('Internal user edit', () => { }); it('Render unable to access dataSource when enabled and inaccessible', () => { + React.useContext.mockImplementation(() => ({ + dataSource: undefined, + setDataSource: jest.fn(), + })); const depsStart = { dataSource: { dataSourceEnabled: true, diff --git a/public/apps/configuration/panels/permission-list/test/__snapshots__/permission-list.test.tsx.snap b/public/apps/configuration/panels/permission-list/test/__snapshots__/permission-list.test.tsx.snap index 1074a171c..61db05e08 100644 --- a/public/apps/configuration/panels/permission-list/test/__snapshots__/permission-list.test.tsx.snap +++ b/public/apps/configuration/panels/permission-list/test/__snapshots__/permission-list.test.tsx.snap @@ -1,276 +1,16 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Permission list page Render unable to access dataSource when enabled and inaccessible 1`] = ` - - - - -

- Permissions -

-
-
- - - - -

- Permissions - - - ( - 0 - ) - -

-
- - Permissions are individual actions, such as cluster:admin/snapshot/restore, which lets you restore snapshots. Action groups are reusable collections of permissions, such as MANAGE_SNAPSHOTS, which lets you view, take, delete, and restore snapshots. You can often meet your security needs using the default action groups, but you might find it convenient to create your own. - - -
- - - - - Edit - - - Duplicate - - - Delete - - - - - Create from blank - - - Create from selection - - - - -
- - - - - - - - Reserved - - - , - }, - Object { - "value": false, - "view": - - - - - - Custom - - - , - }, - ], - "type": "field_value_selection", - }, - ], - "onChange": [Function], - } - } - selection={ - Object { - "onSelectionChange": [MockFunction], - } - } - sorting={ - Object { - "sort": Object { - "direction": "asc", - "field": "type", - }, - } - } - tableLayout="auto" - /> - -
- -
+ } + params={Object {}} +/> `; diff --git a/public/apps/configuration/panels/permission-list/test/permission-list.test.tsx b/public/apps/configuration/panels/permission-list/test/permission-list.test.tsx index 2b66a30c8..b7b14f7ba 100644 --- a/public/apps/configuration/panels/permission-list/test/permission-list.test.tsx +++ b/public/apps/configuration/panels/permission-list/test/permission-list.test.tsx @@ -55,6 +55,14 @@ jest.mock('react', () => ({ })); describe('Permission list page ', () => { + afterEach(() => { + React.useContext.mockRestore(); + React.useContext.mockReturnValue({ + dataSource: { id: 'test' }, + setDataSource: jest.fn(), + }); + }); + const sampleActionGroup: PermissionListingItem = { name: 'group', type: 'Action group', @@ -232,6 +240,10 @@ describe('Permission list page ', () => { }); it('Render unable to access dataSource when enabled and inaccessible', () => { + React.useContext.mockImplementation(() => ({ + dataSource: undefined, + setDataSource: jest.fn(), + })); const depsStart = { dataSource: { dataSourceEnabled: true, diff --git a/public/apps/configuration/panels/role-edit/test/__snapshots__/role-edit.test.tsx.snap b/public/apps/configuration/panels/role-edit/test/__snapshots__/role-edit.test.tsx.snap index 5c1ef38a2..2beb5e78b 100644 --- a/public/apps/configuration/panels/role-edit/test/__snapshots__/role-edit.test.tsx.snap +++ b/public/apps/configuration/panels/role-edit/test/__snapshots__/role-edit.test.tsx.snap @@ -1,1141 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Role edit Render unable to access dataSource when enabled and inaccessible 1`] = ` - - - - - -

- - Roles are the core way of controlling access to your cluster. Roles contain any combination of cluster-wide permission, index-specific permissions, document- and field-level security, and tenants. Once you've created the role, you can map users to the roles so that users gain those permissions. - - - - - - - - - - - - - - - - - - - - Cancel - - - - - Create - - - - - + } + params={Object {}} + sourceRoleName="role" +/> `; diff --git a/public/apps/configuration/panels/role-edit/test/role-edit.test.tsx b/public/apps/configuration/panels/role-edit/test/role-edit.test.tsx index 867c8cbe0..35389784b 100644 --- a/public/apps/configuration/panels/role-edit/test/role-edit.test.tsx +++ b/public/apps/configuration/panels/role-edit/test/role-edit.test.tsx @@ -44,6 +44,13 @@ jest.mock('react', () => ({ })); describe('Role edit', () => { + afterEach(() => { + React.useContext.mockRestore(); + React.useContext.mockReturnValue({ + dataSource: { id: 'test' }, + setDataSource: jest.fn(), + }); + }); const sampleSourceRole = 'role'; const mockCoreStart = { http: 1, @@ -138,6 +145,10 @@ describe('Role edit', () => { }); it('Render unable to access dataSource when enabled and inaccessible', () => { + React.useContext.mockImplementation(() => ({ + dataSource: undefined, + setDataSource: jest.fn(), + })); const depsStart = { dataSource: { dataSourceEnabled: true, diff --git a/public/apps/configuration/panels/role-mapping/test/__snapshots__/role-edit-mapped-user.test.tsx.snap b/public/apps/configuration/panels/role-mapping/test/__snapshots__/role-edit-mapped-user.test.tsx.snap index 04e570c50..01ee647c5 100644 --- a/public/apps/configuration/panels/role-mapping/test/__snapshots__/role-edit-mapped-user.test.tsx.snap +++ b/public/apps/configuration/panels/role-mapping/test/__snapshots__/role-edit-mapped-user.test.tsx.snap @@ -1,112 +1,22 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Role mapping edit Render unable to access dataSource when enabled and inaccessible 1`] = ` - - - - - -

- Map user -

-
- Map users to this role to inherit role permissions. Two types of users are supported: user, and backend role. - -
-
- - - - - - - - - Cancel - - - - - Map - - - - -
+ } + params={Object {}} + roleName="role" +/> `; diff --git a/public/apps/configuration/panels/role-mapping/test/role-edit-mapped-user.test.tsx b/public/apps/configuration/panels/role-mapping/test/role-edit-mapped-user.test.tsx index 124499332..7921e5672 100644 --- a/public/apps/configuration/panels/role-mapping/test/role-edit-mapped-user.test.tsx +++ b/public/apps/configuration/panels/role-mapping/test/role-edit-mapped-user.test.tsx @@ -34,6 +34,13 @@ jest.mock('react', () => ({ const roleMappingUtils = require('../../../utils/role-mapping-utils'); describe('Role mapping edit', () => { + afterEach(() => { + React.useContext.mockRestore(); + React.useContext.mockReturnValue({ + dataSource: { id: 'test' }, + setDataSource: jest.fn(), + }); + }); const setState = jest.fn(); const sampleRole = 'role'; const mockCoreStart = { @@ -146,6 +153,10 @@ describe('Role mapping edit', () => { }); it('Render unable to access dataSource when enabled and inaccessible', () => { + React.useContext.mockImplementation(() => ({ + dataSource: undefined, + setDataSource: jest.fn(), + })); const depsStart = { dataSource: { dataSourceEnabled: true, diff --git a/public/apps/configuration/panels/role-view/role-view.tsx b/public/apps/configuration/panels/role-view/role-view.tsx index 39280cdf7..53ccb90f1 100644 --- a/public/apps/configuration/panels/role-view/role-view.tsx +++ b/public/apps/configuration/panels/role-view/role-view.tsx @@ -140,7 +140,7 @@ export function RoleView(props: RoleViewProps) { setRoleTenantPermission(transformRoleTenantPermissions(roleData.tenant_permissions)); } catch (e) { addToast(createUnknownErrorToast('fetchRoleMappingData', 'load data')); - console.log(e); + console.error(e); setErrorFlag(true); } finally { setLoading(false); @@ -169,7 +169,7 @@ export function RoleView(props: RoleViewProps) { setMappedUsers(difference(mappedUsers, selection)); setSelection([]); } catch (e) { - console.log(e); + console.error(e); } }; @@ -272,7 +272,7 @@ export function RoleView(props: RoleViewProps) { coreStart={props.coreStart} loading={loading} isReserved={isReserved} - dataSourceId={dataSource.id} + dataSourceId={dataSource && dataSource.id} /> ), @@ -395,7 +395,6 @@ export function RoleView(props: RoleViewProps) { if (dataSourceEnabled && dataSource === undefined) { return ; } - return ( <> - - - - -

- role -

-
-
- - - - - duplicate - - - delete - - - - - Edit role - - - - -
- - - - - - - - - , - "disabled": false, - "id": "permissions", - "name": "Permissions", - } - } - tabs={ - Array [ - Object { - "content": - - - - - - - - , - "disabled": false, - "id": "permissions", - "name": "Permissions", - }, - Object { - "content": - - - - - -

- Mapped users - - ( - 0 - ) - -

-
- - You can map two types of users: users and backend roles. A user can have its own backend role and host for an external authentication and authorization. A backend role directly maps to roles through an external authentication system. - - - -
- - - - - Delete mapping - - - - - Manage mapping - - - - -
- - - - - - - - - Map users - - - - } - body={ - -

- You can map users or backend roles to this role -

-
- } - title={ -

- No user has been mapped to this role -

- } - titleSize="s" - /> - } - pagination={true} - responsive={true} - selection={ - Object { - "onSelectionChange": [Function], - } - } - sorting={true} - tableLayout="auto" - /> -
-
-
, - "disabled": false, - "id": "users", - "name": "Mapped users", - }, - ] - } - /> - - - + } + params={Object {}} + prevAction="" + roleName="role" +/> `; exports[`Role view basic rendering when permission tab is selected 1`] = ` diff --git a/public/apps/configuration/panels/role-view/test/role-view.test.tsx b/public/apps/configuration/panels/role-view/test/role-view.test.tsx index 5e04af401..41c665027 100644 --- a/public/apps/configuration/panels/role-view/test/role-view.test.tsx +++ b/public/apps/configuration/panels/role-view/test/role-view.test.tsx @@ -92,6 +92,13 @@ describe('Role view', () => { useEffect.mockImplementationOnce((f) => f()); useState.mockImplementation((initialValue) => [initialValue, setState]); }); + afterEach(() => { + React.useContext.mockRestore(); + React.useContext.mockReturnValue({ + dataSource: { id: 'test' }, + setDataSource: jest.fn(), + }); + }); it('basic rendering when permission tab is selected', () => { const component = shallow( @@ -238,11 +245,11 @@ describe('Role view', () => { }); }); - it('should capture error by console.log if error occurred while deleting role mapping', (done) => { + it('should capture error by console.error if error occurred while deleting role mapping', (done) => { (updateRoleMapping as jest.Mock).mockImplementationOnce(() => { throw new Error(); }); - const spy = jest.spyOn(console, 'log').mockImplementationOnce(() => {}); + const spy = jest.spyOn(console, 'error').mockImplementationOnce(() => {}); shallow( { }); it('Render unable to access dataSource when enabled and inaccessible', () => { + React.useContext.mockImplementation(() => ({ + dataSource: undefined, + setDataSource: jest.fn(), + })); + const depsStart = { dataSource: { dataSourceEnabled: true, diff --git a/public/apps/configuration/panels/test/__snapshots__/get-started.test.tsx.snap b/public/apps/configuration/panels/test/__snapshots__/get-started.test.tsx.snap index 35c85010d..bbecedbc5 100644 --- a/public/apps/configuration/panels/test/__snapshots__/get-started.test.tsx.snap +++ b/public/apps/configuration/panels/test/__snapshots__/get-started.test.tsx.snap @@ -1,352 +1,28 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Get started (landing page) Render unable to access dataSource when enabled and inaccessible 1`] = ` - -
- - - -

- Get started -

-
- -
- - -

- The OpenSearch security plugin lets you define the API calls that users can make and the data they can access. The most basic configuration consists of these steps. -

-
- -
- - - - Add authentication - - (authc) - - and authorization - - (authz) - - information to - - config/opensearch-security/config.yml - - . The - - authc - - section contains the backends to check user credentials against. The - - authz - - section contains any backends to fetch backend roles from. The most common example of a backend role is an LDAP group. - - - - - - - - - - Review authentication and authorization - - - - - , - "title": "Add backends", - }, - Object { - "children": - - Roles are reusable collections of permissions. The default roles are a great starting point, but you might need to create custom roles that meet your exact needs. - - - - - - - - Explore existing roles - - - - - Create new role - - - - - , - "title": "Create roles", - }, - Object { - "children": - - After a user successfully authenticates, the security plugin retrieves that user’s roles. You can map roles directly to users, but you can also map them to backend roles. - - - - - - - - Map users to a role - - - - - Create internal user - - - - , - "title": "Map users", - }, - ] - } - /> - - - - -

- Optional: Configure audit logs -

-
- -

- - - -

- - Review Audit Log Configuration - -
-
- - - -

- Optional: Purge cache -

-
- -

- By default, the security plugin caches authenticated users, along with their roles and permissions. This option will purge cached users, roles and permissions. -

- - Purge cache - -
-
- - - -

- Optional: Multi-tenancy -

-
- -

- By default tenancy is activated in Dashboards. Tenants in OpenSearch Dashboards are spaces for saving index patterns, visualizations, dashboards, and other OpenSearch Dashboards objects. -

- - - - Manage Multi-tenancy - - - - - Configure Multi-tenancy - - - -
-
-
- - + `; exports[`Get started (landing page) renders when backend configuration is disabled 1`] = ` diff --git a/public/apps/configuration/panels/test/__snapshots__/role-list.test.tsx.snap b/public/apps/configuration/panels/test/__snapshots__/role-list.test.tsx.snap index 3e33eb730..34bbbc6f1 100644 --- a/public/apps/configuration/panels/test/__snapshots__/role-list.test.tsx.snap +++ b/public/apps/configuration/panels/test/__snapshots__/role-list.test.tsx.snap @@ -42,7 +42,6 @@ exports[`Role list Render unable to access dataSource when enabled and inaccessi "http": 1, } } - dataSourcePickerReadOnly={false} depsStart={ Object { "dataSource": Object { @@ -52,154 +51,6 @@ exports[`Role list Render unable to access dataSource when enabled and inaccessi } navigation={Object {}} params={Object {}} - selectedDataSource={ - Object { - "id": "test", - } - } - setDataSource={[MockFunction]} /> - - -

- Roles -

-
-
- - - - -

- Roles - - - ( - 0 - ) - -

-
- - Roles are the core way of controlling access to your cluster. Roles contain any combination of cluster-wide permission, index-specific permissions, document- and field-level security, and tenants. Then you map users to these roles so that users gain those permissions. - - -
- - - - - Edit - - - Duplicate - - - Delete - - - - - Create role - - - - -
- - - -
`; diff --git a/public/apps/configuration/panels/test/__snapshots__/user-list.test.tsx.snap b/public/apps/configuration/panels/test/__snapshots__/user-list.test.tsx.snap index dd7f12936..35bb2ef2e 100644 --- a/public/apps/configuration/panels/test/__snapshots__/user-list.test.tsx.snap +++ b/public/apps/configuration/panels/test/__snapshots__/user-list.test.tsx.snap @@ -1,186 +1,25 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`User list Render unable to access dataSource when enabled and inaccessible 1`] = ` - - - - -

- Internal users -

-
-
- - - - -

- Internal users - - - ( - 1 - ) - -

-
- - The Security plugin includes an internal user database. Use this database in place of, or in addition to, an external authentication system such as LDAP server or Active Directory. You can map an user account to a role from - - - Roles - - . First, click into the detail page of the role. Then, under “Mapped users”, click “Manage mapping” - - -
- - - - - Edit - - - Duplicate - - - Export JSON - - - Delete - - - - - Create user account - - - - -
- - - -
-
+ } + navigation={Object {}} + params={Object {}} +/> `; diff --git a/public/apps/configuration/panels/test/get-started.test.tsx b/public/apps/configuration/panels/test/get-started.test.tsx index e268aa33f..834b9cdea 100644 --- a/public/apps/configuration/panels/test/get-started.test.tsx +++ b/public/apps/configuration/panels/test/get-started.test.tsx @@ -44,6 +44,13 @@ describe('Get started (landing page)', () => { backend_configurable: true, }, }; + afterEach(() => { + React.useContext.mockRestore(); + React.useContext.mockReturnValue({ + dataSource: { id: 'test' }, + setDataSource: jest.fn(), + }); + }); it('renders when backend configuration is enabled', () => { const component = shallow( @@ -184,6 +191,10 @@ describe('Get started (landing page)', () => { }); it('Render unable to access dataSource when enabled and inaccessible', () => { + React.useContext.mockImplementation(() => ({ + dataSource: undefined, + setDataSource: jest.fn(), + })); const depsStart = { dataSource: { dataSourceEnabled: true, diff --git a/public/apps/configuration/panels/test/role-list.test.tsx b/public/apps/configuration/panels/test/role-list.test.tsx index c6818f462..c7f8db14d 100644 --- a/public/apps/configuration/panels/test/role-list.test.tsx +++ b/public/apps/configuration/panels/test/role-list.test.tsx @@ -55,6 +55,13 @@ describe('Role list', () => { beforeEach(() => { jest.spyOn(React, 'useState').mockImplementation((initialValue) => [initialValue, setState]); }); + afterEach(() => { + React.useContext.mockRestore(); + React.useContext.mockReturnValue({ + dataSource: { id: 'test' }, + setDataSource: jest.fn(), + }); + }); it('Render empty', () => { const mockRoleListingData = [ @@ -267,6 +274,10 @@ describe('Role list', () => { }); it('Render unable to access dataSource when enabled and inaccessible', () => { + React.useContext.mockImplementation(() => ({ + dataSource: undefined, + setDataSource: jest.fn(), + })); const depsStart = { dataSource: { dataSourceEnabled: true, diff --git a/public/apps/configuration/panels/test/user-list.test.tsx b/public/apps/configuration/panels/test/user-list.test.tsx index 3f810032c..36ce2ff78 100644 --- a/public/apps/configuration/panels/test/user-list.test.tsx +++ b/public/apps/configuration/panels/test/user-list.test.tsx @@ -48,6 +48,13 @@ import { Action } from '../../types'; import { ResourceType } from '../../../../../common'; describe('User list', () => { + afterEach(() => { + React.useContext.mockRestore(); + React.useContext.mockReturnValue({ + dataSource: { id: 'test' }, + setDataSource: jest.fn(), + }); + }); describe('dictView', () => { it('- empty', () => { const result = dictView({}); @@ -237,6 +244,10 @@ describe('User list', () => { }); it('Render unable to access dataSource when enabled and inaccessible', () => { + React.useContext.mockImplementation(() => ({ + dataSource: undefined, + setDataSource: jest.fn(), + })); const depsStart = { dataSource: { dataSourceEnabled: true, diff --git a/public/apps/configuration/test/top-nav-menu.test.tsx b/public/apps/configuration/test/top-nav-menu.test.tsx index 2e2872f65..867474aa8 100644 --- a/public/apps/configuration/test/top-nav-menu.test.tsx +++ b/public/apps/configuration/test/top-nav-menu.test.tsx @@ -76,4 +76,26 @@ describe('SecurityPluginTopNavMenu', () => { expect(dataSourceMenuMock).not.toBeCalled(); expect(wrapper.html()).toBe(''); }); + + it('renders null when dataSource is enabled but selectedDataSource is undefined', () => { + const securityPluginStartDepsMock = { + dataSource: { + dataSourceEnabled: true, + }, + }; + + const wrapper = render( + undefined} + params={{}} + /> + ); + + expect(dataSourceMenuMock).toBeCalled(); + expect(wrapper.html()).not.toBe(''); + }); }); diff --git a/public/apps/configuration/top-nav-menu.tsx b/public/apps/configuration/top-nav-menu.tsx index d17bc6c6a..5e5e51893 100644 --- a/public/apps/configuration/top-nav-menu.tsx +++ b/public/apps/configuration/top-nav-menu.tsx @@ -64,12 +64,11 @@ export const SecurityPluginTopNavMenu = React.memo( ) : null; }, (prevProps, newProps) => { - if (prevProps.selectedDataSource && newProps.selectedDataSource) { - return ( - prevProps.selectedDataSource.id === newProps.selectedDataSource.id && - prevProps.dataSourcePickerReadOnly === newProps.dataSourcePickerReadOnly - ); - } - return false; + return ( + prevProps.selectedDataSource && + newProps.selectedDataSource && + prevProps.selectedDataSource.id === newProps.selectedDataSource.id && + prevProps.dataSourcePickerReadOnly === newProps.dataSourcePickerReadOnly + ); } );