diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.test.ts index fcaa847c47f3..09ba41f81d76 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.test.ts @@ -20,8 +20,14 @@ jest.mock('../../../../app_logic', () => ({ })); import { AppLogic } from '../../../../app_logic'; -import { ADD_GITHUB_PATH, SOURCES_PATH, getSourcesPath } from '../../../../routes'; +import { + ADD_GITHUB_PATH, + SOURCES_PATH, + PERSONAL_SOURCES_PATH, + getSourcesPath, +} from '../../../../routes'; import { CustomSource } from '../../../../types'; +import { PERSONAL_DASHBOARD_SOURCE_ERROR } from '../../constants'; import { SourcesLogic } from '../../sources_logic'; import { @@ -36,7 +42,7 @@ describe('AddSourceLogic', () => { const { mount } = new LogicMounter(AddSourceLogic); const { http } = mockHttpValues; const { navigateToUrl } = mockKibanaValues; - const { clearFlashMessages, flashAPIErrors } = mockFlashMessageHelpers; + const { clearFlashMessages, flashAPIErrors, setErrorMessage } = mockFlashMessageHelpers; const defaultValues = { addSourceCurrentStep: AddSourceSteps.ConfigIntroStep, @@ -353,6 +359,33 @@ describe('AddSourceLogic', () => { expect(navigateToUrl).toHaveBeenCalledWith(`${ADD_GITHUB_PATH}/configure${queryString}`); }); + describe('Github error edge case', () => { + const getGithubQueryString = (context: 'organization' | 'account') => + `?error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2Fdocs.github.com%2Fapps%2Fmanaging-oauth-apps%2Ftroubleshooting-authorization-request-errors%2F%23redirect-uri-mismatch&state=%7B%22action%22%3A%22create%22%2C%22context%22%3A%22${context}%22%2C%22service_type%22%3A%22github%22%2C%22csrf_token%22%3A%22TOKEN%3D%3D%22%2C%22index_permissions%22%3Afalse%7D`; + + it('handles "organization" redirect and displays error', () => { + const githubQueryString = getGithubQueryString('organization'); + AddSourceLogic.actions.saveSourceParams(githubQueryString); + + expect(navigateToUrl).toHaveBeenCalledWith('/'); + expect(setErrorMessage).toHaveBeenCalledWith( + 'The redirect_uri MUST match the registered callback URL for this application.' + ); + }); + + it('handles "account" redirect and displays error', () => { + const githubQueryString = getGithubQueryString('account'); + AddSourceLogic.actions.saveSourceParams(githubQueryString); + + expect(navigateToUrl).toHaveBeenCalledWith(PERSONAL_SOURCES_PATH); + expect(setErrorMessage).toHaveBeenCalledWith( + PERSONAL_DASHBOARD_SOURCE_ERROR( + 'The redirect_uri MUST match the registered callback URL for this application.' + ) + ); + }); + }); + it('handles error', async () => { http.get.mockReturnValue(Promise.reject('this is an error')); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.ts index 0bd37aed81c3..81e27f07293d 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.ts @@ -16,14 +16,21 @@ import { flashAPIErrors, setSuccessMessage, clearFlashMessages, + setErrorMessage, } from '../../../../../shared/flash_messages'; import { HttpLogic } from '../../../../../shared/http'; import { KibanaLogic } from '../../../../../shared/kibana'; import { parseQueryParams } from '../../../../../shared/query_params'; import { AppLogic } from '../../../../app_logic'; import { CUSTOM_SERVICE_TYPE, WORKPLACE_SEARCH_URL_PREFIX } from '../../../../constants'; -import { SOURCES_PATH, ADD_GITHUB_PATH, getSourcesPath } from '../../../../routes'; +import { + SOURCES_PATH, + ADD_GITHUB_PATH, + PERSONAL_SOURCES_PATH, + getSourcesPath, +} from '../../../../routes'; import { CustomSource } from '../../../../types'; +import { PERSONAL_DASHBOARD_SOURCE_ERROR } from '../../constants'; import { staticSourceData } from '../../source_data'; import { SourcesLogic } from '../../sources_logic'; @@ -50,6 +57,8 @@ export interface OauthParams { state: string; session_state: string; oauth_verifier?: string; + error?: string; + error_description?: string; } export interface AddSourceActions { @@ -501,6 +510,22 @@ export const AddSourceLogic = kea + i18n.translate('xpack.enterpriseSearch.workplaceSearch.personalDashboardSourceError', { + defaultMessage: + 'Could not connect the source, reach out to your admin for help. Error message: {error}', + values: { error }, + });