From 2a2d75754f1c592dc0c290a484d4457bb6d206a7 Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Thu, 9 May 2024 13:20:41 -0400 Subject: [PATCH 01/13] Adds a separate handler for unknown datasource Signed-off-by: Darshit Chanpura --- .../audit-logging-edit-settings.tsx | 20 ++++++- .../panels/audit-logging/audit-logging.tsx | 21 ++++++- .../panels/auth-view/auth-view.tsx | 20 ++++++- .../apps/configuration/panels/get-started.tsx | 17 ++++++ .../internal-user-edit/internal-user-edit.tsx | 20 ++++++- .../permission-list/permission-list.tsx | 22 ++++++- .../panels/role-edit/role-edit.tsx | 24 +++++++- .../apps/configuration/panels/role-list.tsx | 23 +++++++- .../role-mapping/role-edit-mapped-user.tsx | 22 ++++++- .../panels/role-view/role-view.tsx | 20 ++++++- .../apps/configuration/panels/user-list.tsx | 21 ++++++- public/apps/configuration/top-nav-menu.tsx | 12 ++-- .../apps/configuration/unknown-datasource.tsx | 57 +++++++++++++++++++ public/utils/datasource-utils.ts | 8 ++- 14 files changed, 288 insertions(+), 19 deletions(-) create mode 100644 public/apps/configuration/unknown-datasource.tsx diff --git a/public/apps/configuration/panels/audit-logging/audit-logging-edit-settings.tsx b/public/apps/configuration/panels/audit-logging/audit-logging-edit-settings.tsx index 8e89d62a7..b04b6b3c0 100644 --- a/public/apps/configuration/panels/audit-logging/audit-logging-edit-settings.tsx +++ b/public/apps/configuration/panels/audit-logging/audit-logging-edit-settings.tsx @@ -38,6 +38,7 @@ import { setCrossPageToast } from '../../utils/storage-utils'; import { SecurityPluginTopNavMenu } from '../../top-nav-menu'; import { DataSourceContext } from '../../app-router'; import { getClusterInfo } from '../../../../utils/datasource-utils'; +import { UnknownDataSourcePage } from '../../unknown-datasource'; interface AuditLoggingEditSettingProps extends AppDependencies { setting: 'general' | 'compliance'; @@ -76,7 +77,7 @@ export function AuditLoggingEditSettings(props: AuditLoggingEditSettingProps) { }; fetchConfig(); - }, [props.coreStart.http, dataSource.id]); + }, [props.coreStart.http, dataSource]); const renderSaveAndCancel = () => { return ( @@ -248,6 +249,23 @@ export function AuditLoggingEditSettings(props: AuditLoggingEditSettingProps) { content = renderComplianceSetting(); } + if (dataSourceEnabled && dataSource === undefined) { + return ( + <> + + + + ) + } + return (
({}); const { dataSource, setDataSource } = useContext(DataSourceContext)!; @@ -163,7 +165,7 @@ export function AuditLogging(props: AuditLoggingProps) { }; fetchData(); - }, [props.coreStart.http, props.fromType, dataSource.id]); + }, [props.coreStart.http, props.fromType, dataSource]); const statusPanel = renderStatusPanel(onSwitchChange, configuration.enabled || false); @@ -229,6 +231,23 @@ export function AuditLogging(props: AuditLoggingProps) { ); } + if (dataSourceEnabled && dataSource === undefined) { + return ( + <> + + + + ) + } + return (
{ @@ -48,12 +50,28 @@ export function AuthView(props: AppDependencies) { }; fetchData(); - }, [props.coreStart.http, dataSource.id]); + }, [props.coreStart.http, dataSource]); if (isEmpty(authentication)) { return ; } + if (dataSourceEnabled && dataSource === undefined) { + return ( + <> + + + + ) + } return ( <> + + + + ) + } return ( <>
diff --git a/public/apps/configuration/panels/internal-user-edit/internal-user-edit.tsx b/public/apps/configuration/panels/internal-user-edit/internal-user-edit.tsx index 70ba39be8..1fae30748 100644 --- a/public/apps/configuration/panels/internal-user-edit/internal-user-edit.tsx +++ b/public/apps/configuration/panels/internal-user-edit/internal-user-edit.tsx @@ -49,6 +49,7 @@ import { constructErrorMessageAndLog } from '../../../error-utils'; import { BackendRolePanel } from './backend-role-panel'; import { DataSourceContext } from '../../app-router'; import { SecurityPluginTopNavMenu } from '../../top-nav-menu'; +import { UnknownDataSourcePage } from '../../unknown-datasource'; interface InternalUserEditDeps extends BreadcrumbsPageDependencies { action: 'create' | 'edit' | 'duplicate'; @@ -98,7 +99,7 @@ export function InternalUserEdit(props: InternalUserEditDeps) { fetchData(); } - }, [addToast, props.action, props.coreStart.http, props.sourceUserName, dataSource.id]); + }, [addToast, props.action, props.coreStart.http, props.sourceUserName, dataSource]); const updateUserHandler = async () => { try { @@ -147,6 +148,23 @@ export function InternalUserEdit(props: InternalUserEditDeps) { } }; + if (dataSourceEnabled && dataSource === undefined) { + return ( + <> + + + + ) + } + return ( <> : ''; @@ -215,11 +216,11 @@ export function PermissionList(props: AppDependencies) { } finally { setLoading(false); } - }, [props.coreStart.http, dataSource.id]); + }, [props.coreStart.http, dataSource]); React.useEffect(() => { fetchData(); - }, [props.coreStart.http, fetchData, dataSource.id]); + }, [props.coreStart.http, fetchData, dataSource]); const handleDelete = async () => { const groupsToDelete: string[] = selection.map((r) => r.name); @@ -347,6 +348,23 @@ export function PermissionList(props: AppDependencies) { createActionGroupMenuItems ); + if (dataSourceEnabled && dataSource === undefined) { + return ( + <> + + + + ) + } + return ( <> >([]); React.useEffect(() => { @@ -129,7 +130,7 @@ export function RoleEdit(props: RoleEditDeps) { }; fetchActionGroupNames(); - }, [addToast, props.coreStart.http, dataSource.id]); + }, [addToast, props.coreStart.http, dataSource]); const [tenantNames, setTenantNames] = React.useState([]); React.useEffect(() => { @@ -143,7 +144,7 @@ export function RoleEdit(props: RoleEditDeps) { }; fetchTenantNames(); - }, [addToast, props.coreStart.http, dataSource.id]); + }, [addToast, props.coreStart.http, dataSource]); const updateRoleHandler = async () => { try { @@ -233,6 +234,23 @@ export function RoleEdit(props: RoleEditDeps) { const tenantOptions = tenantNames.map(stringToComboBoxOption); + if (dataSourceEnabled && dataSource === undefined) { + return ( + <> + + + + ) + } + return ( <> > = [ { @@ -103,6 +104,7 @@ const columns: Array> = [ ]; export function RoleList(props: AppDependencies) { + const dataSourceEnabled = !!props.depsStart.dataSource?.dataSourceEnabled; const [roleData, setRoleData] = React.useState([]); const [errorFlag, setErrorFlag] = React.useState(false); const [selection, setSelection] = React.useState([]); @@ -126,7 +128,7 @@ export function RoleList(props: AppDependencies) { }; fetchData(); - }, [props.coreStart.http, dataSource.id]); + }, [props.coreStart.http, dataSource]); const handleDelete = async () => { const rolesToDelete: string[] = selection.map((r) => r.roleName); @@ -251,6 +253,25 @@ export function RoleList(props: AppDependencies) { }); }, [roleData]); + if (dataSourceEnabled && dataSource === undefined) { + return ( + <> + + + + ) + } + return ( <> { const fetchInternalUserNames = async () => { @@ -101,7 +102,7 @@ export function RoleEditMappedUser(props: RoleEditMappedUserProps) { }; fetchInternalUserNames(); - }, [addToast, props.coreStart.http, dataSource.id]); + }, [addToast, props.coreStart.http, dataSource]); const internalUserOptions = userNames.map(stringToComboBoxOption); const updateRoleMappingHandler = async () => { @@ -144,6 +145,23 @@ export function RoleEditMappedUser(props: RoleEditMappedUserProps) { } }; + if (dataSourceEnabled && dataSource === undefined) { + return ( + <> + + + + ) + } + return ( <> { try { @@ -391,6 +392,23 @@ export function RoleView(props: RoleViewProps) { ); } + if (dataSourceEnabled && dataSource === undefined) { + return ( + <> + + + + ) + } + return ( <> ) { if (isEmpty(items)) { @@ -99,6 +100,7 @@ export function getColumns(currentUsername: string) { } export function UserList(props: AppDependencies) { + const dataSourceEnabled = !!props.depsStart.dataSource?.dataSourceEnabled; const [userData, setUserData] = React.useState([]); const [errorFlag, setErrorFlag] = React.useState(false); const [selection, setSelection] = React.useState([]); @@ -127,7 +129,7 @@ export function UserList(props: AppDependencies) { }; fetchData(); - }, [props.coreStart.http, dataSource.id]); + }, [props.coreStart.http, dataSource]); const handleDelete = async () => { const usersToDelete: string[] = selection.map((r) => r.username); @@ -199,6 +201,23 @@ export function UserList(props: AppDependencies) { const [actionsMenu, closeActionsMenu] = useContextMenuState('Actions', {}, actionsMenuItems); + if (dataSourceEnabled && dataSource === undefined) { + return ( + <> + + + + ) + } + return ( <> ) : null; }, - (prevProps, newProps) => - prevProps.selectedDataSource.id === newProps.selectedDataSource.id && - prevProps.dataSourcePickerReadOnly === newProps.dataSourcePickerReadOnly + (prevProps, newProps) => { + if (prevProps.selectedDataSource && newProps.selectedDataSource) { + return prevProps.selectedDataSource.id === newProps.selectedDataSource.id && + prevProps.dataSourcePickerReadOnly === newProps.dataSourcePickerReadOnly; + } + return false; + } ); diff --git a/public/apps/configuration/unknown-datasource.tsx b/public/apps/configuration/unknown-datasource.tsx new file mode 100644 index 000000000..0cf0c9759 --- /dev/null +++ b/public/apps/configuration/unknown-datasource.tsx @@ -0,0 +1,57 @@ +/* + * 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 { DataSourceOption } from 'src/plugins/data_source_management/public/components/data_source_menu/types'; +import { AppDependencies } from '../types'; +import { setDataSourceInUrl } from '../../utils/datasource-utils'; +import { + EuiPageHeader, + EuiTitle, + EuiButton +} from '@elastic/eui' + +const LocalCluster = { + label: 'Local Cluster', + id: '' +}; + +export interface UnknownDataSourceProps extends AppDependencies { + setDataSource: React.Dispatch>; +} + +export const UnknownDataSourcePage = React.memo( + (props: UnknownDataSourceProps) => { + const { + setDataSource, + } = props; + + const wrapSetDataSourceWithUpdateUrl = () => { + setDataSourceInUrl(LocalCluster); + console.log(window.location.href) + setDataSource(LocalCluster); + }; + + return ( + <> + + +

Unknown DataSource

+
+
+ wrapSetDataSourceWithUpdateUrl()}>Switch to default + + ); + }); diff --git a/public/utils/datasource-utils.ts b/public/utils/datasource-utils.ts index 84b7cc135..1f4971b70 100644 --- a/public/utils/datasource-utils.ts +++ b/public/utils/datasource-utils.ts @@ -27,7 +27,13 @@ export function getClusterInfo(dataSourceEnabled: boolean, cluster: DataSourceOp export function getDataSourceFromUrl(): DataSourceOption { const urlParams = new URLSearchParams(window.location.search); const dataSourceParam = (urlParams && urlParams.get(DATASOURCEURLKEY)) || '{}'; - return JSON.parse(dataSourceParam); + // following block is needed if the dataSource param is set to non-JSON value, say 'undefined' + try { + return JSON.parse(dataSourceParam); + } catch (e) { + console.error('Failed to parse dataSourceParam:', dataSourceParam); + return JSON.parse('{}'); // Return an empty object or some default value if parsing fails + } } export function setDataSourceInUrl(dataSource: DataSourceOption) { From 9d6aa1d5096359a32656811ad98a39faa4b3b20c Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Thu, 9 May 2024 13:25:31 -0400 Subject: [PATCH 02/13] Fixes linter errors Signed-off-by: Darshit Chanpura --- .../audit-logging-edit-settings.tsx | 23 +++++------ .../panels/audit-logging/audit-logging.tsx | 23 +++++------ .../panels/auth-view/auth-view.tsx | 23 +++++------ .../apps/configuration/panels/get-started.tsx | 23 +++++------ .../internal-user-edit/internal-user-edit.tsx | 23 +++++------ .../permission-list/permission-list.tsx | 23 +++++------ .../panels/role-edit/role-edit.tsx | 23 +++++------ .../apps/configuration/panels/role-list.tsx | 2 +- .../role-mapping/role-edit-mapped-user.tsx | 23 +++++------ .../panels/role-view/role-view.tsx | 23 +++++------ .../apps/configuration/panels/user-list.tsx | 23 +++++------ public/apps/configuration/top-nav-menu.tsx | 12 ++++-- .../apps/configuration/unknown-datasource.tsx | 39 ++++++++----------- public/utils/datasource-utils.ts | 2 +- 14 files changed, 127 insertions(+), 158 deletions(-) diff --git a/public/apps/configuration/panels/audit-logging/audit-logging-edit-settings.tsx b/public/apps/configuration/panels/audit-logging/audit-logging-edit-settings.tsx index b04b6b3c0..3a8662d5b 100644 --- a/public/apps/configuration/panels/audit-logging/audit-logging-edit-settings.tsx +++ b/public/apps/configuration/panels/audit-logging/audit-logging-edit-settings.tsx @@ -251,19 +251,16 @@ export function AuditLoggingEditSettings(props: AuditLoggingEditSettingProps) { if (dataSourceEnabled && dataSource === undefined) { return ( - <> - - - - ) + <> + + + + ); } return ( diff --git a/public/apps/configuration/panels/audit-logging/audit-logging.tsx b/public/apps/configuration/panels/audit-logging/audit-logging.tsx index 948cbc449..14faf6a82 100644 --- a/public/apps/configuration/panels/audit-logging/audit-logging.tsx +++ b/public/apps/configuration/panels/audit-logging/audit-logging.tsx @@ -233,19 +233,16 @@ export function AuditLogging(props: AuditLoggingProps) { if (dataSourceEnabled && dataSource === undefined) { return ( - <> - - - - ) + <> + + + + ); } return ( diff --git a/public/apps/configuration/panels/auth-view/auth-view.tsx b/public/apps/configuration/panels/auth-view/auth-view.tsx index a56436a7d..504590ae1 100644 --- a/public/apps/configuration/panels/auth-view/auth-view.tsx +++ b/public/apps/configuration/panels/auth-view/auth-view.tsx @@ -58,19 +58,16 @@ export function AuthView(props: AppDependencies) { if (dataSourceEnabled && dataSource === undefined) { return ( - <> - - - - ) + <> + + + + ); } return ( <> diff --git a/public/apps/configuration/panels/get-started.tsx b/public/apps/configuration/panels/get-started.tsx index 2270da6e1..af66ad3be 100644 --- a/public/apps/configuration/panels/get-started.tsx +++ b/public/apps/configuration/panels/get-started.tsx @@ -176,19 +176,16 @@ export function GetStarted(props: AppDependencies) { if (dataSourceEnabled && dataSource === undefined) { return ( - <> - - - - ) + <> + + + + ); } return ( <> diff --git a/public/apps/configuration/panels/internal-user-edit/internal-user-edit.tsx b/public/apps/configuration/panels/internal-user-edit/internal-user-edit.tsx index 1fae30748..2287ebabd 100644 --- a/public/apps/configuration/panels/internal-user-edit/internal-user-edit.tsx +++ b/public/apps/configuration/panels/internal-user-edit/internal-user-edit.tsx @@ -150,19 +150,16 @@ export function InternalUserEdit(props: InternalUserEditDeps) { if (dataSourceEnabled && dataSource === undefined) { return ( - <> - - - - ) + <> + + + + ); } return ( diff --git a/public/apps/configuration/panels/permission-list/permission-list.tsx b/public/apps/configuration/panels/permission-list/permission-list.tsx index 08fc69cf0..a7c4e6885 100644 --- a/public/apps/configuration/panels/permission-list/permission-list.tsx +++ b/public/apps/configuration/panels/permission-list/permission-list.tsx @@ -350,19 +350,16 @@ export function PermissionList(props: AppDependencies) { if (dataSourceEnabled && dataSource === undefined) { return ( - <> - - - - ) + <> + + + + ); } return ( diff --git a/public/apps/configuration/panels/role-edit/role-edit.tsx b/public/apps/configuration/panels/role-edit/role-edit.tsx index c0ef81193..408eec161 100644 --- a/public/apps/configuration/panels/role-edit/role-edit.tsx +++ b/public/apps/configuration/panels/role-edit/role-edit.tsx @@ -236,19 +236,16 @@ export function RoleEdit(props: RoleEditDeps) { if (dataSourceEnabled && dataSource === undefined) { return ( - <> - - - - ) + <> + + + + ); } return ( diff --git a/public/apps/configuration/panels/role-list.tsx b/public/apps/configuration/panels/role-list.tsx index edccc20b3..b8ec02b13 100644 --- a/public/apps/configuration/panels/role-list.tsx +++ b/public/apps/configuration/panels/role-list.tsx @@ -269,7 +269,7 @@ export function RoleList(props: AppDependencies) { selectedDataSource={dataSource} /> - ) + ); } return ( diff --git a/public/apps/configuration/panels/role-mapping/role-edit-mapped-user.tsx b/public/apps/configuration/panels/role-mapping/role-edit-mapped-user.tsx index 9f42efd17..8bd25349e 100644 --- a/public/apps/configuration/panels/role-mapping/role-edit-mapped-user.tsx +++ b/public/apps/configuration/panels/role-mapping/role-edit-mapped-user.tsx @@ -147,19 +147,16 @@ export function RoleEditMappedUser(props: RoleEditMappedUserProps) { if (dataSourceEnabled && dataSource === undefined) { return ( - <> - - - - ) + <> + + + + ); } return ( diff --git a/public/apps/configuration/panels/role-view/role-view.tsx b/public/apps/configuration/panels/role-view/role-view.tsx index 118bffc73..7f34ad747 100644 --- a/public/apps/configuration/panels/role-view/role-view.tsx +++ b/public/apps/configuration/panels/role-view/role-view.tsx @@ -394,19 +394,16 @@ export function RoleView(props: RoleViewProps) { if (dataSourceEnabled && dataSource === undefined) { return ( - <> - - - - ) + <> + + + + ); } return ( diff --git a/public/apps/configuration/panels/user-list.tsx b/public/apps/configuration/panels/user-list.tsx index f4986a50f..5fb8a3dc9 100644 --- a/public/apps/configuration/panels/user-list.tsx +++ b/public/apps/configuration/panels/user-list.tsx @@ -203,19 +203,16 @@ export function UserList(props: AppDependencies) { if (dataSourceEnabled && dataSource === undefined) { return ( - <> - - - - ) + <> + + + + ); } return ( diff --git a/public/apps/configuration/top-nav-menu.tsx b/public/apps/configuration/top-nav-menu.tsx index 492ba26e5..d17bc6c6a 100644 --- a/public/apps/configuration/top-nav-menu.tsx +++ b/public/apps/configuration/top-nav-menu.tsx @@ -54,7 +54,9 @@ export const SecurityPluginTopNavMenu = React.memo( savedObjects: coreStart.savedObjects.client, notifications: coreStart.notifications, activeOption: - selectedDataSource && (selectedDataSource.id || selectedDataSource.label) ? [selectedDataSource] : undefined, + selectedDataSource && (selectedDataSource.id || selectedDataSource.label) + ? [selectedDataSource] + : undefined, onSelectedDataSources: wrapSetDataSourceWithUpdateUrl, fullWidth: true, }} @@ -63,9 +65,11 @@ export const SecurityPluginTopNavMenu = React.memo( }, (prevProps, newProps) => { if (prevProps.selectedDataSource && newProps.selectedDataSource) { - return prevProps.selectedDataSource.id === newProps.selectedDataSource.id && - prevProps.dataSourcePickerReadOnly === newProps.dataSourcePickerReadOnly; + return ( + prevProps.selectedDataSource.id === newProps.selectedDataSource.id && + prevProps.dataSourcePickerReadOnly === newProps.dataSourcePickerReadOnly + ); } return false; - } + } ); diff --git a/public/apps/configuration/unknown-datasource.tsx b/public/apps/configuration/unknown-datasource.tsx index 0cf0c9759..819cbabaa 100644 --- a/public/apps/configuration/unknown-datasource.tsx +++ b/public/apps/configuration/unknown-datasource.tsx @@ -15,43 +15,38 @@ import React from 'react'; import { DataSourceOption } from 'src/plugins/data_source_management/public/components/data_source_menu/types'; +import { EuiPageHeader, EuiTitle, EuiButton } from '@elastic/eui'; import { AppDependencies } from '../types'; import { setDataSourceInUrl } from '../../utils/datasource-utils'; -import { - EuiPageHeader, - EuiTitle, - EuiButton -} from '@elastic/eui' const LocalCluster = { label: 'Local Cluster', - id: '' + id: '', }; export interface UnknownDataSourceProps extends AppDependencies { setDataSource: React.Dispatch>; } -export const UnknownDataSourcePage = React.memo( - (props: UnknownDataSourceProps) => { - const { - setDataSource, - } = props; +export const UnknownDataSourcePage = React.memo((props: UnknownDataSourceProps) => { + const { setDataSource } = props; - const wrapSetDataSourceWithUpdateUrl = () => { - setDataSourceInUrl(LocalCluster); - console.log(window.location.href) - setDataSource(LocalCluster); - }; + const wrapSetDataSourceWithUpdateUrl = () => { + setDataSourceInUrl(LocalCluster); + console.log(window.location.href); + setDataSource(LocalCluster); + }; - return ( - <> + return ( + <>

Unknown DataSource

- wrapSetDataSourceWithUpdateUrl()}>Switch to default - - ); - }); + wrapSetDataSourceWithUpdateUrl()}> + Switch to default + + + ); +}); diff --git a/public/utils/datasource-utils.ts b/public/utils/datasource-utils.ts index 1f4971b70..80a137a55 100644 --- a/public/utils/datasource-utils.ts +++ b/public/utils/datasource-utils.ts @@ -32,7 +32,7 @@ export function getDataSourceFromUrl(): DataSourceOption { return JSON.parse(dataSourceParam); } catch (e) { console.error('Failed to parse dataSourceParam:', dataSourceParam); - return JSON.parse('{}'); // Return an empty object or some default value if parsing fails + return JSON.parse('{}'); // Return an empty object or some default value if parsing fails } } From 2775a8cceeee899580de94d98a5276a09d113cbe Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Fri, 10 May 2024 17:51:48 -0400 Subject: [PATCH 03/13] Changes button text Signed-off-by: Darshit Chanpura --- public/apps/configuration/unknown-datasource.tsx | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/public/apps/configuration/unknown-datasource.tsx b/public/apps/configuration/unknown-datasource.tsx index 819cbabaa..c0c286502 100644 --- a/public/apps/configuration/unknown-datasource.tsx +++ b/public/apps/configuration/unknown-datasource.tsx @@ -18,11 +18,7 @@ import { DataSourceOption } from 'src/plugins/data_source_management/public/comp import { EuiPageHeader, EuiTitle, EuiButton } from '@elastic/eui'; import { AppDependencies } from '../types'; import { setDataSourceInUrl } from '../../utils/datasource-utils'; - -const LocalCluster = { - label: 'Local Cluster', - id: '', -}; +import { LocalCluster } from './app-router'; export interface UnknownDataSourceProps extends AppDependencies { setDataSource: React.Dispatch>; @@ -31,9 +27,8 @@ export interface UnknownDataSourceProps extends AppDependencies { export const UnknownDataSourcePage = React.memo((props: UnknownDataSourceProps) => { const { setDataSource } = props; - const wrapSetDataSourceWithUpdateUrl = () => { + const defaultToLocalCluster = () => { setDataSourceInUrl(LocalCluster); - console.log(window.location.href); setDataSource(LocalCluster); }; @@ -44,8 +39,8 @@ export const UnknownDataSourcePage = React.memo((props: UnknownDataSourceProps)

Unknown DataSource

- wrapSetDataSourceWithUpdateUrl()}> - Switch to default + defaultToLocalCluster()}> + Switch to Local Cluster ); From 3e05fc46755e6b0c74739fb98c9d04610da5ab9f Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Fri, 10 May 2024 18:56:49 -0400 Subject: [PATCH 04/13] Remove button and adds text to keep better user experience Signed-off-by: Darshit Chanpura --- .../audit-logging-edit-settings.tsx | 12 +------ .../panels/audit-logging/audit-logging.tsx | 12 +------ .../panels/auth-view/auth-view.tsx | 19 +++++------ .../apps/configuration/panels/get-started.tsx | 12 +------ .../internal-user-edit/internal-user-edit.tsx | 12 +------ .../permission-list/permission-list.tsx | 12 +------ .../panels/role-edit/role-edit.tsx | 12 +------ .../apps/configuration/panels/role-list.tsx | 13 +------ .../role-mapping/role-edit-mapped-user.tsx | 12 +------ .../panels/role-view/role-view.tsx | 12 +------ .../apps/configuration/panels/user-list.tsx | 12 +------ .../apps/configuration/unknown-datasource.tsx | 34 +++++++++---------- 12 files changed, 34 insertions(+), 140 deletions(-) diff --git a/public/apps/configuration/panels/audit-logging/audit-logging-edit-settings.tsx b/public/apps/configuration/panels/audit-logging/audit-logging-edit-settings.tsx index 3a8662d5b..c81f154b8 100644 --- a/public/apps/configuration/panels/audit-logging/audit-logging-edit-settings.tsx +++ b/public/apps/configuration/panels/audit-logging/audit-logging-edit-settings.tsx @@ -250,17 +250,7 @@ export function AuditLoggingEditSettings(props: AuditLoggingEditSettingProps) { } if (dataSourceEnabled && dataSource === undefined) { - return ( - <> - - - - ); + return ; } return ( diff --git a/public/apps/configuration/panels/audit-logging/audit-logging.tsx b/public/apps/configuration/panels/audit-logging/audit-logging.tsx index 14faf6a82..4caa9d442 100644 --- a/public/apps/configuration/panels/audit-logging/audit-logging.tsx +++ b/public/apps/configuration/panels/audit-logging/audit-logging.tsx @@ -232,17 +232,7 @@ export function AuditLogging(props: AuditLoggingProps) { } if (dataSourceEnabled && dataSource === undefined) { - return ( - <> - - - - ); + return ; } return ( diff --git a/public/apps/configuration/panels/auth-view/auth-view.tsx b/public/apps/configuration/panels/auth-view/auth-view.tsx index cec0801f0..ccc3668a1 100644 --- a/public/apps/configuration/panels/auth-view/auth-view.tsx +++ b/public/apps/configuration/panels/auth-view/auth-view.tsx @@ -53,6 +53,13 @@ export function AuthView(props: AppDependencies) { }, [props.coreStart.http, dataSource]); if (isEmpty(authentication)) { + if (dataSourceEnabled && dataSource === undefined) { + return ( + <> + + + ); + } return ( <> - - - - ); + return ; } return ( <> diff --git a/public/apps/configuration/panels/get-started.tsx b/public/apps/configuration/panels/get-started.tsx index af66ad3be..ced4503c2 100644 --- a/public/apps/configuration/panels/get-started.tsx +++ b/public/apps/configuration/panels/get-started.tsx @@ -175,17 +175,7 @@ export function GetStarted(props: AppDependencies) { const [toasts, addToast, removeToast] = useToastState(); if (dataSourceEnabled && dataSource === undefined) { - return ( - <> - - - - ); + return ; } return ( <> diff --git a/public/apps/configuration/panels/internal-user-edit/internal-user-edit.tsx b/public/apps/configuration/panels/internal-user-edit/internal-user-edit.tsx index 2287ebabd..afe7d8ece 100644 --- a/public/apps/configuration/panels/internal-user-edit/internal-user-edit.tsx +++ b/public/apps/configuration/panels/internal-user-edit/internal-user-edit.tsx @@ -149,17 +149,7 @@ export function InternalUserEdit(props: InternalUserEditDeps) { }; if (dataSourceEnabled && dataSource === undefined) { - return ( - <> - - - - ); + return ; } return ( diff --git a/public/apps/configuration/panels/permission-list/permission-list.tsx b/public/apps/configuration/panels/permission-list/permission-list.tsx index 85a5bc9bd..f99ac2c59 100644 --- a/public/apps/configuration/panels/permission-list/permission-list.tsx +++ b/public/apps/configuration/panels/permission-list/permission-list.tsx @@ -350,17 +350,7 @@ export function PermissionList(props: AppDependencies) { ); if (dataSourceEnabled && dataSource === undefined) { - return ( - <> - - - - ); + return ; } return ( diff --git a/public/apps/configuration/panels/role-edit/role-edit.tsx b/public/apps/configuration/panels/role-edit/role-edit.tsx index 408eec161..064e81e18 100644 --- a/public/apps/configuration/panels/role-edit/role-edit.tsx +++ b/public/apps/configuration/panels/role-edit/role-edit.tsx @@ -235,17 +235,7 @@ export function RoleEdit(props: RoleEditDeps) { const tenantOptions = tenantNames.map(stringToComboBoxOption); if (dataSourceEnabled && dataSource === undefined) { - return ( - <> - - - - ); + return ; } return ( diff --git a/public/apps/configuration/panels/role-list.tsx b/public/apps/configuration/panels/role-list.tsx index bee1e18c6..134806138 100644 --- a/public/apps/configuration/panels/role-list.tsx +++ b/public/apps/configuration/panels/role-list.tsx @@ -257,18 +257,7 @@ export function RoleList(props: AppDependencies) { if (dataSourceEnabled && dataSource === undefined) { return ( <> - - + ); } diff --git a/public/apps/configuration/panels/role-mapping/role-edit-mapped-user.tsx b/public/apps/configuration/panels/role-mapping/role-edit-mapped-user.tsx index 8bd25349e..e4610e3e9 100644 --- a/public/apps/configuration/panels/role-mapping/role-edit-mapped-user.tsx +++ b/public/apps/configuration/panels/role-mapping/role-edit-mapped-user.tsx @@ -146,17 +146,7 @@ export function RoleEditMappedUser(props: RoleEditMappedUserProps) { }; if (dataSourceEnabled && dataSource === undefined) { - return ( - <> - - - - ); + return ; } return ( diff --git a/public/apps/configuration/panels/role-view/role-view.tsx b/public/apps/configuration/panels/role-view/role-view.tsx index 7f34ad747..39280cdf7 100644 --- a/public/apps/configuration/panels/role-view/role-view.tsx +++ b/public/apps/configuration/panels/role-view/role-view.tsx @@ -393,17 +393,7 @@ export function RoleView(props: RoleViewProps) { } if (dataSourceEnabled && dataSource === undefined) { - return ( - <> - - - - ); + return ; } return ( diff --git a/public/apps/configuration/panels/user-list.tsx b/public/apps/configuration/panels/user-list.tsx index 45349ab9b..96f770b8b 100644 --- a/public/apps/configuration/panels/user-list.tsx +++ b/public/apps/configuration/panels/user-list.tsx @@ -203,17 +203,7 @@ export function UserList(props: AppDependencies) { const [actionsMenu, closeActionsMenu] = useContextMenuState('Actions', {}, actionsMenuItems); if (dataSourceEnabled && dataSource === undefined) { - return ( - <> - - - - ); + return ; } return ( diff --git a/public/apps/configuration/unknown-datasource.tsx b/public/apps/configuration/unknown-datasource.tsx index c0c286502..5caccfbab 100644 --- a/public/apps/configuration/unknown-datasource.tsx +++ b/public/apps/configuration/unknown-datasource.tsx @@ -14,34 +14,32 @@ */ import React from 'react'; -import { DataSourceOption } from 'src/plugins/data_source_management/public/components/data_source_menu/types'; -import { EuiPageHeader, EuiTitle, EuiButton } from '@elastic/eui'; +import { EuiPageHeader, EuiTitle, EuiText, EuiPageBody } from '@opensearch-project/oui'; import { AppDependencies } from '../types'; -import { setDataSourceInUrl } from '../../utils/datasource-utils'; -import { LocalCluster } from './app-router'; -export interface UnknownDataSourceProps extends AppDependencies { - setDataSource: React.Dispatch>; -} +export type UnknownDataSourceProps = AppDependencies; export const UnknownDataSourcePage = React.memo((props: UnknownDataSourceProps) => { - const { setDataSource } = props; - - const defaultToLocalCluster = () => { - setDataSourceInUrl(LocalCluster); - setDataSource(LocalCluster); - }; - return ( <> -

Unknown DataSource

+

Unable to list data-source connections

- defaultToLocalCluster()}> - Switch to Local Cluster - + + +

+ It seems like you do not have access to list all data-source connections. +
+ Likely cause is that aggregation view setting + `opensearch_security.multitenancy.enable_aggregation_view` is enabled. +
+ Please contact your administrator to grant you access to global tenant to be able to + view the data-sources. +

+
+
); }); From ad30c1d09af8de1aad2036a430af8d9c76e2cb19 Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Fri, 10 May 2024 18:57:07 -0400 Subject: [PATCH 05/13] Adds @opensearch-project/oui dependency Signed-off-by: Darshit Chanpura --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index c8b786ad8..3e37f1ac1 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "dependencies": { "@hapi/cryptiles": "5.0.0", "@hapi/wreck": "^17.1.0", + "@opensearch-project/oui": "^1.6.0", "html-entities": "1.3.1", "zxcvbn": "^4.4.2" }, From 891e1bfa570b69f4bbb73a5801121ba2b19761e1 Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Sat, 11 May 2024 12:47:40 -0400 Subject: [PATCH 06/13] Removes @opensearch-project/oui dependency due to compilation failures Signed-off-by: Darshit Chanpura --- package.json | 1 - public/apps/configuration/unknown-datasource.tsx | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 3e37f1ac1..c8b786ad8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "dependencies": { "@hapi/cryptiles": "5.0.0", "@hapi/wreck": "^17.1.0", - "@opensearch-project/oui": "^1.6.0", "html-entities": "1.3.1", "zxcvbn": "^4.4.2" }, diff --git a/public/apps/configuration/unknown-datasource.tsx b/public/apps/configuration/unknown-datasource.tsx index 5caccfbab..78b97c979 100644 --- a/public/apps/configuration/unknown-datasource.tsx +++ b/public/apps/configuration/unknown-datasource.tsx @@ -14,7 +14,7 @@ */ import React from 'react'; -import { EuiPageHeader, EuiTitle, EuiText, EuiPageBody } from '@opensearch-project/oui'; +import { EuiPageHeader, EuiTitle, EuiText, EuiPageBody } from '@elastic/eui'; import { AppDependencies } from '../types'; export type UnknownDataSourceProps = AppDependencies; From 62f28a9e2292158ddc63d0b5baf201cfcc98f98c Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Sat, 11 May 2024 13:34:34 -0400 Subject: [PATCH 07/13] Fixes unit tests Signed-off-by: Darshit Chanpura --- .../__snapshots__/audit-logging.test.tsx.snap | 1 + .../audit-logging/test/audit-logging.test.tsx | 54 ++++++++++++++++--- .../panels/auth-view/test/auth-view.test.tsx | 18 ++++++- .../panels/test/role-list.test.tsx | 10 ++++ 4 files changed, 73 insertions(+), 10 deletions(-) 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 9fdee791a..f5c891359 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 @@ -248,6 +248,7 @@ exports[`Audit logs render when AuditLoggingSettings.enabled is true 1`] = ` } } dataSourcePickerReadOnly={false} + depsStart={Object {}} navigation={Object {}} selectedDataSource={ Object { 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 3f5c6e8da..bbbe43064 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 @@ -39,6 +39,8 @@ describe('Audit logs', () => { http: 1, }; + const mockDepsStart = {}; + beforeEach(() => { jest.spyOn(React, 'useState').mockImplementation((initialValue) => [initialValue, setState]); jest.spyOn(React, 'useEffect').mockImplementationOnce((f) => f()); @@ -54,7 +56,11 @@ describe('Audit logs', () => { mockAuditLoggingUtils.getAuditLogging = jest.fn().mockReturnValue(mockAuditLoggingData); const component = shallow( - + ); const switchFound = component.find(EuiSwitch); @@ -72,7 +78,13 @@ describe('Audit logs', () => { mockAuditLoggingUtils.getAuditLogging = jest.fn().mockReturnValue(mockAuditLoggingData); - shallow(); + shallow( + + ); process.nextTick(() => { expect(mockAuditLoggingUtils.getAuditLogging).toHaveBeenCalledTimes(1); @@ -90,7 +102,13 @@ describe('Audit logs', () => { throw Error(); }); - shallow(); + shallow( + + ); process.nextTick(() => { expect(mockAuditLoggingUtils.getAuditLogging).toHaveBeenCalledTimes(1); @@ -116,7 +134,11 @@ describe('Audit logs', () => { it('audit logging switch change', () => { const component = shallow( - + ); component.find('[data-test-subj="audit-logging-enabled-switch"]').simulate('change'); expect(mockAuditLoggingUtils.updateAuditLogging).toHaveBeenCalledTimes(1); @@ -130,7 +152,11 @@ describe('Audit logs', () => { throw Error(); }); const component = shallow( - + ); component.find('[data-test-subj="audit-logging-enabled-switch"]').simulate('change'); @@ -142,7 +168,11 @@ describe('Audit logs', () => { const auditLoggingSettings = { enabled: true }; jest.spyOn(React, 'useState').mockImplementation(() => [auditLoggingSettings, setState]); const component = shallow( - + ); expect(component).toMatchSnapshot(); }); @@ -151,7 +181,11 @@ describe('Audit logs', () => { const auditLoggingSettings = { enabled: true }; jest.spyOn(React, 'useState').mockImplementation(() => [auditLoggingSettings, setState]); const component = shallow( - + ); component.find('[data-test-subj="general-settings-configure"]').simulate('click'); expect(window.location.hash).toBe( @@ -163,7 +197,11 @@ describe('Audit logs', () => { const auditLoggingSettings = { enabled: true }; jest.spyOn(React, 'useState').mockImplementation(() => [auditLoggingSettings, setState]); const component = shallow( - + ); component.find('[data-test-subj="compliance-settings-configure"]').simulate('click'); expect(window.location.hash).toBe( 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 8a97113ec..192913cad 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 @@ -30,6 +30,8 @@ describe('Auth view', () => { http: 1, }; + const mockDepsStart = {}; + const setState = jest.fn(); beforeEach(() => { @@ -56,7 +58,13 @@ describe('Auth view', () => { mockAuthViewUtils.getSecurityConfig = jest.fn().mockReturnValue(config); - shallow(); + shallow( + + ); process.nextTick(() => { expect(mockAuthViewUtils.getSecurityConfig).toHaveBeenCalledTimes(1); @@ -75,7 +83,13 @@ describe('Auth view', () => { jest.spyOn(console, 'log').mockImplementationOnce(() => {}); - shallow(); + shallow( + + ); process.nextTick(() => { expect(mockAuthViewUtils.getSecurityConfig).toHaveBeenCalledTimes(1); diff --git a/public/apps/configuration/panels/test/role-list.test.tsx b/public/apps/configuration/panels/test/role-list.test.tsx index becbfe806..a87f295bd 100644 --- a/public/apps/configuration/panels/test/role-list.test.tsx +++ b/public/apps/configuration/panels/test/role-list.test.tsx @@ -50,6 +50,8 @@ describe('Role list', () => { http: 1, }; + const mockDepsStart = {}; + beforeEach(() => { jest.spyOn(React, 'useState').mockImplementation((initialValue) => [initialValue, setState]); }); @@ -72,6 +74,7 @@ describe('Role list', () => { const component = shallow( { shallow( { shallow( { shallow( { shallow( { component = shallow( { const wrapper = shallow( { const wrapper = shallow( Date: Sat, 11 May 2024 13:49:26 -0400 Subject: [PATCH 08/13] Fixes remainder unit tests Signed-off-by: Darshit Chanpura --- public/apps/configuration/panels/test/user-list.test.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/public/apps/configuration/panels/test/user-list.test.tsx b/public/apps/configuration/panels/test/user-list.test.tsx index 2e96573f5..ac4935671 100644 --- a/public/apps/configuration/panels/test/user-list.test.tsx +++ b/public/apps/configuration/panels/test/user-list.test.tsx @@ -91,6 +91,7 @@ describe('User list', () => { const mockCoreStart = { http: 1, }; + const mockDepsStart = {}; const setState = jest.fn(); jest.spyOn(React, 'useState').mockImplementation((initValue) => [initValue, setState]); @@ -98,6 +99,7 @@ describe('User list', () => { const component = shallow( { shallow( { shallow( { shallow( { shallow( { }, }, }; + const mockDepsStart = {}; let component; const mockUserListingData: InternalUsersListing = { username: 'user_1', @@ -206,6 +213,7 @@ describe('User list', () => { component = shallow( Date: Sat, 11 May 2024 19:46:45 -0400 Subject: [PATCH 09/13] Adds unit tests to expand code coverage Signed-off-by: Darshit Chanpura --- .../panels/audit-logging/audit-logging.tsx | 2 + .../audit-logging-edit-settings.test.tsx.snap | 91 ++ .../__snapshots__/audit-logging.test.tsx.snap | 108 ++ .../test/audit-logging-edit-settings.test.tsx | 16 + .../audit-logging/test/audit-logging.test.tsx | 16 + .../__snapshots__/auth-view.test.tsx.snap | 57 + .../panels/auth-view/test/auth-view.test.tsx | 38 + .../internal-user-edit.test.tsx.snap | 146 +++ .../test/internal-user-edit.test.tsx | 20 + .../permission-list.test.tsx.snap | 276 ++++ .../test/permission-list.test.tsx | 17 + .../__snapshots__/role-edit.test.tsx.snap | 1141 +++++++++++++++++ .../panels/role-edit/test/role-edit.test.tsx | 21 + .../role-edit-mapped-user.test.tsx.snap | 112 ++ .../test/role-edit-mapped-user.test.tsx | 19 + .../__snapshots__/role-view.test.tsx.snap | 333 +++++ .../panels/role-view/test/role-view.test.tsx | 20 + .../__snapshots__/get-started.test.tsx.snap | 349 +++++ .../__snapshots__/role-list.test.tsx.snap | 171 +++ .../__snapshots__/user-list.test.tsx.snap | 186 +++ .../panels/test/get-started.test.tsx | 17 + .../panels/test/role-list.test.tsx | 18 + .../panels/test/user-list.test.tsx | 25 + 23 files changed, 3199 insertions(+) create mode 100644 public/apps/configuration/panels/audit-logging/test/__snapshots__/audit-logging-edit-settings.test.tsx.snap create mode 100644 public/apps/configuration/panels/auth-view/test/__snapshots__/auth-view.test.tsx.snap create mode 100644 public/apps/configuration/panels/internal-user-edit/test/__snapshots__/internal-user-edit.test.tsx.snap create mode 100644 public/apps/configuration/panels/permission-list/test/__snapshots__/permission-list.test.tsx.snap create mode 100644 public/apps/configuration/panels/role-edit/test/__snapshots__/role-edit.test.tsx.snap create mode 100644 public/apps/configuration/panels/role-mapping/test/__snapshots__/role-edit-mapped-user.test.tsx.snap create mode 100644 public/apps/configuration/panels/test/__snapshots__/user-list.test.tsx.snap diff --git a/public/apps/configuration/panels/audit-logging/audit-logging.tsx b/public/apps/configuration/panels/audit-logging/audit-logging.tsx index 4caa9d442..497939573 100644 --- a/public/apps/configuration/panels/audit-logging/audit-logging.tsx +++ b/public/apps/configuration/panels/audit-logging/audit-logging.tsx @@ -137,8 +137,10 @@ export function renderComplianceSettings(config: AuditLoggingSettings) { export function AuditLogging(props: AuditLoggingProps) { const dataSourceEnabled = !!props.depsStart.dataSource?.dataSourceEnabled; + console.log(props.depsStart); const [configuration, setConfiguration] = React.useState({}); const { dataSource, setDataSource } = useContext(DataSourceContext)!; + console.log(dataSource); const onSwitchChange = async () => { try { 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 new file mode 100644 index 000000000..ded6f8f01 --- /dev/null +++ b/public/apps/configuration/panels/audit-logging/test/__snapshots__/audit-logging-edit-settings.test.tsx.snap @@ -0,0 +1,91 @@ +// 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 + + + + +
+`; 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 f5c891359..641ba2fed 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,5 +1,113 @@ // 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`] = ` { expect(mockAuditLoggingUtils.updateAuditLogging).toBeCalled(); expect(window.location.hash).toBe(buildHashUrl(ResourceType.auditLogging)); }); + + it('Render unable to access dataSource when enabled and inaccessible', () => { + const depsStart = { + dataSource: { + dataSourceEnabled: true, + }, + }; + const component = shallow( + + ); + expect(component).toMatchSnapshot(); + }); }); 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 bbbe43064..017ee465e 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 @@ -208,4 +208,20 @@ describe('Audit logs', () => { buildHashUrl(ResourceType.auditLogging) + SUB_URL_FOR_COMPLIANCE_SETTINGS_EDIT ); }); + + it('Render unable to access dataSource when enabled and inaccessible', () => { + const depsStart = { + dataSource: { + dataSourceEnabled: true, + }, + }; + const component = shallow( + + ); + expect(component).toMatchSnapshot(); + }); }); 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 new file mode 100644 index 000000000..ce6eab824 --- /dev/null +++ b/public/apps/configuration/panels/auth-view/test/__snapshots__/auth-view.test.tsx.snap @@ -0,0 +1,57 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Auth view Render unable to access dataSource when enabled and inaccessible 1`] = ` + + + + +`; + +exports[`Auth view Render unable to access dataSource when enabled and inaccessible: Empty Authentication 1`] = ` + + + + +`; 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 192913cad..cb585b1ec 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 @@ -99,4 +99,42 @@ describe('Auth view', () => { done(); }); }); + + it('Render unable to access dataSource when enabled and inaccessible', () => { + const depsStart = { + dataSource: { + dataSourceEnabled: true, + }, + }; + const component = shallow( + + ); + expect(component).toMatchSnapshot(); + }); + + it('Render unable to access dataSource when enabled and inaccessible: Empty Authentication', () => { + mockAuthViewUtils.getSecurityConfig = jest.fn().mockImplementationOnce(() => { + throw Error(); + }); + + jest.spyOn(console, 'log').mockImplementationOnce(() => {}); + + const depsStart = { + dataSource: { + dataSourceEnabled: true, + }, + }; + const component = shallow( + + ); + expect(component).toMatchSnapshot(); + }); }); 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 new file mode 100644 index 000000000..14fae931e --- /dev/null +++ b/public/apps/configuration/panels/internal-user-edit/test/__snapshots__/internal-user-edit.test.tsx.snap @@ -0,0 +1,146 @@ +// 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 + + + + + +`; 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 241f4e14f..8f526291f 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 @@ -148,4 +148,24 @@ describe('Internal user edit', () => { expect(createErrorToast).toBeCalled(); expect(updateUser).toBeCalledTimes(0); }); + + it('Render unable to access dataSource when enabled and inaccessible', () => { + const depsStart = { + dataSource: { + dataSourceEnabled: true, + }, + }; + const component = shallow( + + ); + expect(component).toMatchSnapshot(); + }); }); 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 new file mode 100644 index 000000000..1074a171c --- /dev/null +++ b/public/apps/configuration/panels/permission-list/test/__snapshots__/permission-list.test.tsx.snap @@ -0,0 +1,276 @@ +// 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" + /> + +
+ +
+`; 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 0d72b6ea4..2b66a30c8 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 @@ -230,4 +230,21 @@ describe('Permission list page ', () => { expect(component.find('#duplicate').prop('disabled')).toBe(false); }); }); + + it('Render unable to access dataSource when enabled and inaccessible', () => { + const depsStart = { + dataSource: { + dataSourceEnabled: true, + }, + }; + const component = shallow( + + ); + expect(component).toMatchSnapshot(); + }); }); 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 new file mode 100644 index 000000000..5c1ef38a2 --- /dev/null +++ b/public/apps/configuration/panels/role-edit/test/__snapshots__/role-edit.test.tsx.snap @@ -0,0 +1,1141 @@ +// 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 + + + + + +`; 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 6e0b61237..867c8cbe0 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 @@ -136,4 +136,25 @@ describe('Role edit', () => { done(); }); }); + + it('Render unable to access dataSource when enabled and inaccessible', () => { + const depsStart = { + dataSource: { + dataSourceEnabled: true, + }, + }; + const buildBreadcrumbs = jest.fn(); + const component = shallow( + + ); + expect(component).toMatchSnapshot(); + }); }); 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 new file mode 100644 index 000000000..04e570c50 --- /dev/null +++ b/public/apps/configuration/panels/role-mapping/test/__snapshots__/role-edit-mapped-user.test.tsx.snap @@ -0,0 +1,112 @@ +// 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 + + + + +
+`; 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 44d4d0a2f..124499332 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 @@ -144,4 +144,23 @@ describe('Role mapping edit', () => { component.find('#map').last().simulate('click'); expect(consoleError).toBeCalledWith(error); }); + + it('Render unable to access dataSource when enabled and inaccessible', () => { + const depsStart = { + dataSource: { + dataSourceEnabled: true, + }, + }; + const component = shallow( + + ); + expect(component).toMatchSnapshot(); + }); }); diff --git a/public/apps/configuration/panels/role-view/test/__snapshots__/role-view.test.tsx.snap b/public/apps/configuration/panels/role-view/test/__snapshots__/role-view.test.tsx.snap index 833c64f6f..281db1c7f 100644 --- a/public/apps/configuration/panels/role-view/test/__snapshots__/role-view.test.tsx.snap +++ b/public/apps/configuration/panels/role-view/test/__snapshots__/role-view.test.tsx.snap @@ -1,5 +1,338 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Role view Render unable to access dataSource when enabled and inaccessible 1`] = ` + + + + + +

+ 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", + }, + ] + } + /> + + +
+`; + exports[`Role view basic rendering when permission tab is selected 1`] = ` { component.find('[data-test-subj="delete"]').simulate('click'); expect(createUnknownErrorToast).toBeCalled(); }); + + it('Render unable to access dataSource when enabled and inaccessible', () => { + const depsStart = { + dataSource: { + dataSourceEnabled: true, + }, + }; + const component = shallow( + + ); + expect(component).toMatchSnapshot(); + }); }); 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 0b2126950..35c85010d 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,5 +1,354 @@ // 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`] = `
`; + +exports[`Role list Render unable to access dataSource when enabled and inaccessible 1`] = ` + + + + +

+ 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 new file mode 100644 index 000000000..dd7f12936 --- /dev/null +++ b/public/apps/configuration/panels/test/__snapshots__/user-list.test.tsx.snap @@ -0,0 +1,186 @@ +// 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 + + + + +
+ + + +
+
+`; diff --git a/public/apps/configuration/panels/test/get-started.test.tsx b/public/apps/configuration/panels/test/get-started.test.tsx index 0823cdbb9..e268aa33f 100644 --- a/public/apps/configuration/panels/test/get-started.test.tsx +++ b/public/apps/configuration/panels/test/get-started.test.tsx @@ -182,4 +182,21 @@ describe('Get started (landing page)', () => { expect(ToastUtils.createSuccessToast).toHaveBeenCalledTimes(1); }); }); + + it('Render unable to access dataSource when enabled and inaccessible', () => { + const depsStart = { + dataSource: { + dataSourceEnabled: true, + }, + }; + const component = shallow( + + ); + expect(component).toMatchSnapshot(); + }); }); diff --git a/public/apps/configuration/panels/test/role-list.test.tsx b/public/apps/configuration/panels/test/role-list.test.tsx index a87f295bd..c6818f462 100644 --- a/public/apps/configuration/panels/test/role-list.test.tsx +++ b/public/apps/configuration/panels/test/role-list.test.tsx @@ -265,4 +265,22 @@ describe('Role list', () => { expect(result).toMatchSnapshot(); }); }); + + it('Render unable to access dataSource when enabled and inaccessible', () => { + const depsStart = { + dataSource: { + dataSourceEnabled: true, + }, + }; + const component = shallow( + + ); + expect(component).toMatchSnapshot(); + }); }); diff --git a/public/apps/configuration/panels/test/user-list.test.tsx b/public/apps/configuration/panels/test/user-list.test.tsx index ac4935671..3f810032c 100644 --- a/public/apps/configuration/panels/test/user-list.test.tsx +++ b/public/apps/configuration/panels/test/user-list.test.tsx @@ -235,4 +235,29 @@ describe('User list', () => { ); }); }); + + it('Render unable to access dataSource when enabled and inaccessible', () => { + const depsStart = { + dataSource: { + dataSourceEnabled: true, + }, + }; + const mockCoreStart = { + http: { + basePath: { + serverBasePath: '', + }, + }, + }; + const component = shallow( + + ); + expect(component).toMatchSnapshot(); + }); }); From 7a26e9f30d7dfe90d8dd00f9de0cd360217264af Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Sat, 11 May 2024 19:52:43 -0400 Subject: [PATCH 10/13] Adds couple more unit tests Signed-off-by: Darshit Chanpura --- public/utils/datasource-utils.ts | 1 - public/utils/test/datasource-utils.test.ts | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/public/utils/datasource-utils.ts b/public/utils/datasource-utils.ts index 80a137a55..638c515eb 100644 --- a/public/utils/datasource-utils.ts +++ b/public/utils/datasource-utils.ts @@ -31,7 +31,6 @@ export function getDataSourceFromUrl(): DataSourceOption { try { return JSON.parse(dataSourceParam); } catch (e) { - console.error('Failed to parse dataSourceParam:', dataSourceParam); return JSON.parse('{}'); // Return an empty object or some default value if parsing fails } } diff --git a/public/utils/test/datasource-utils.test.ts b/public/utils/test/datasource-utils.test.ts index 040166ec8..33aef7905 100644 --- a/public/utils/test/datasource-utils.test.ts +++ b/public/utils/test/datasource-utils.test.ts @@ -69,4 +69,13 @@ describe('Tests datasource utils', () => { 'http://localhost:5601/app/security-dashboards-plugin?dataSource=%7B%22id%22%3A%22%22%2C%22label%22%3A%22Local+cluster%22%7D#/auth' ); }); + + it('Tests getting the datasource from the url with undefined dataSource', () => { + const mockSearchUndefinedDataSource = '?dataSource=undefined'; + Object.defineProperty(window, 'location', { + value: { search: mockSearchUndefinedDataSource }, + writable: true, + }); + expect(getDataSourceFromUrl()).toEqual({}); + }); }); From 6e8284ddf8aceaf24e6dcba5d04edd03c077741f Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Mon, 13 May 2024 14:19:31 -0400 Subject: [PATCH 11/13] 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 + ); } ); From 76880f87da811cba6844848847bb70ae3c5e7f63 Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Fri, 17 May 2024 13:31:41 -0400 Subject: [PATCH 12/13] Removes console logs Signed-off-by: Darshit Chanpura --- .../apps/configuration/panels/audit-logging/audit-logging.tsx | 2 -- public/apps/configuration/panels/auth-view/auth-view.tsx | 2 -- 2 files changed, 4 deletions(-) diff --git a/public/apps/configuration/panels/audit-logging/audit-logging.tsx b/public/apps/configuration/panels/audit-logging/audit-logging.tsx index 497939573..4caa9d442 100644 --- a/public/apps/configuration/panels/audit-logging/audit-logging.tsx +++ b/public/apps/configuration/panels/audit-logging/audit-logging.tsx @@ -137,10 +137,8 @@ export function renderComplianceSettings(config: AuditLoggingSettings) { export function AuditLogging(props: AuditLoggingProps) { const dataSourceEnabled = !!props.depsStart.dataSource?.dataSourceEnabled; - console.log(props.depsStart); const [configuration, setConfiguration] = React.useState({}); const { dataSource, setDataSource } = useContext(DataSourceContext)!; - console.log(dataSource); const onSwitchChange = async () => { try { diff --git a/public/apps/configuration/panels/auth-view/auth-view.tsx b/public/apps/configuration/panels/auth-view/auth-view.tsx index 8cbe50b52..ccc3668a1 100644 --- a/public/apps/configuration/panels/auth-view/auth-view.tsx +++ b/public/apps/configuration/panels/auth-view/auth-view.tsx @@ -53,8 +53,6 @@ export function AuthView(props: AppDependencies) { }, [props.coreStart.http, dataSource]); if (isEmpty(authentication)) { - console.log(dataSource); - console.log(dataSourceEnabled); if (dataSourceEnabled && dataSource === undefined) { return ( <> From 773087f165db8c14f3cce96722c60b7386c66d7f Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Tue, 21 May 2024 10:49:38 -0400 Subject: [PATCH 13/13] Fixes unit test broken due to recent commit @a202d48 in main Signed-off-by: Darshit Chanpura --- .../panels/test/__snapshots__/get-started.test.tsx.snap | 3 +++ 1 file changed, 3 insertions(+) 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 9c4bdb223..d2bf420cf 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 @@ -4,6 +4,9 @@ exports[`Get started (landing page) Render unable to access dataSource when enab