diff --git a/x-pack/test/observability_ai_assistant_api_integration/common/config.ts b/x-pack/test/observability_ai_assistant_api_integration/common/config.ts index 455004e5339fd..6505ad3e94d64 100644 --- a/x-pack/test/observability_ai_assistant_api_integration/common/config.ts +++ b/x-pack/test/observability_ai_assistant_api_integration/common/config.ts @@ -33,6 +33,16 @@ export type ObservabilityAIAssistantAPIClient = Awaited< export type ObservabilityAIAssistantServices = Awaited>['services']; +export class ForbiddenApiError extends Error { + status: number; + + constructor(message: string = 'Forbidden') { + super(message); + this.name = 'ForbiddenApiError'; + this.status = 403; + } +} + export function createObservabilityAIAssistantAPIConfig({ config, license, diff --git a/x-pack/test/observability_ai_assistant_api_integration/tests/chat/chat.spec.ts b/x-pack/test/observability_ai_assistant_api_integration/tests/chat/chat.spec.ts index c0a3da475e0ca..cedd4c286dc1a 100644 --- a/x-pack/test/observability_ai_assistant_api_integration/tests/chat/chat.spec.ts +++ b/x-pack/test/observability_ai_assistant_api_integration/tests/chat/chat.spec.ts @@ -11,6 +11,7 @@ import { PassThrough } from 'stream'; import { createLlmProxy, LlmProxy } from '../../common/create_llm_proxy'; import { FtrProviderContext } from '../../common/ftr_provider_context'; import { createProxyActionConnector, deleteActionConnector } from '../../common/action_connectors'; +import { ForbiddenApiError } from '../../common/config'; export default function ApiTest({ getService }: FtrProviderContext) { const supertest = getService('supertest'); @@ -200,6 +201,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { }, }, }); + throw new ForbiddenApiError('Expected unauthorizedUser() to throw a 403 Forbidden error'); } catch (e) { expect(e.status).to.be(403); } diff --git a/x-pack/test/observability_ai_assistant_api_integration/tests/complete/complete.spec.ts b/x-pack/test/observability_ai_assistant_api_integration/tests/complete/complete.spec.ts index 5e59eed3a8c2b..86e357e2e7760 100644 --- a/x-pack/test/observability_ai_assistant_api_integration/tests/complete/complete.spec.ts +++ b/x-pack/test/observability_ai_assistant_api_integration/tests/complete/complete.spec.ts @@ -32,6 +32,7 @@ import { getConversationUpdatedEvent, } from '../conversations/helpers'; import { createProxyActionConnector, deleteActionConnector } from '../../common/action_connectors'; +import { ForbiddenApiError } from '../../common/config'; export default function ApiTest({ getService }: FtrProviderContext) { const supertest = getService('supertest'); @@ -502,6 +503,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { }, }, }); + throw new ForbiddenApiError('Expected unauthorizedUser() to throw a 403 Forbidden error'); } catch (e) { expect(e.status).to.be(403); } diff --git a/x-pack/test/observability_ai_assistant_api_integration/tests/connectors/connectors.spec.ts b/x-pack/test/observability_ai_assistant_api_integration/tests/connectors/connectors.spec.ts index 84b044d4b84aa..42e1f8751719e 100644 --- a/x-pack/test/observability_ai_assistant_api_integration/tests/connectors/connectors.spec.ts +++ b/x-pack/test/observability_ai_assistant_api_integration/tests/connectors/connectors.spec.ts @@ -9,6 +9,7 @@ import expect from '@kbn/expect'; import type { Agent as SuperTestAgent } from 'supertest'; import { FtrProviderContext } from '../../common/ftr_provider_context'; import { createProxyActionConnector, deleteActionConnector } from '../../common/action_connectors'; +import { ForbiddenApiError } from '../../common/config'; export default function ApiTest({ getService }: FtrProviderContext) { const observabilityAIAssistantAPIClient = getService('observabilityAIAssistantAPIClient'); @@ -60,6 +61,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { await observabilityAIAssistantAPIClient.unauthorizedUser({ endpoint: `GET ${CONNECTOR_API_URL}`, }); + throw new ForbiddenApiError('Expected unauthorizedUser() to throw a 403 Forbidden error'); } catch (e) { expect(e.status).to.be(403); } diff --git a/x-pack/test/observability_ai_assistant_api_integration/tests/conversations/conversations.spec.ts b/x-pack/test/observability_ai_assistant_api_integration/tests/conversations/conversations.spec.ts index 3db3be8ec6713..bb85e99b99500 100644 --- a/x-pack/test/observability_ai_assistant_api_integration/tests/conversations/conversations.spec.ts +++ b/x-pack/test/observability_ai_assistant_api_integration/tests/conversations/conversations.spec.ts @@ -14,6 +14,7 @@ import { } from '@kbn/observability-ai-assistant-plugin/common/types'; import type { FtrProviderContext } from '../../common/ftr_provider_context'; import type { SupertestReturnType } from '../../common/observability_ai_assistant_api_client'; +import { ForbiddenApiError } from '../../common/config'; export default function ApiTest({ getService }: FtrProviderContext) { const observabilityAIAssistantAPIClient = getService('observabilityAIAssistantAPIClient'); @@ -292,6 +293,9 @@ export default function ApiTest({ getService }: FtrProviderContext) { }, }, }); + throw new ForbiddenApiError( + 'Expected unauthorizedUser() to throw a 403 Forbidden error' + ); } catch (e) { expect(e.status).to.be(403); } @@ -302,6 +306,9 @@ export default function ApiTest({ getService }: FtrProviderContext) { await observabilityAIAssistantAPIClient.unauthorizedUser({ endpoint: 'POST /internal/observability_ai_assistant/conversations', }); + throw new ForbiddenApiError( + 'Expected unauthorizedUser() to throw a 403 Forbidden error' + ); } catch (e) { expect(e.status).to.be(403); } @@ -322,6 +329,9 @@ export default function ApiTest({ getService }: FtrProviderContext) { }, }, }); + throw new ForbiddenApiError( + 'Expected unauthorizedUser() to throw a 403 Forbidden error' + ); } catch (e) { expect(e.status).to.be(403); } @@ -337,6 +347,9 @@ export default function ApiTest({ getService }: FtrProviderContext) { }, }, }); + throw new ForbiddenApiError( + 'Expected unauthorizedUser() to throw a 403 Forbidden error' + ); } catch (e) { expect(e.status).to.be(403); } @@ -352,6 +365,9 @@ export default function ApiTest({ getService }: FtrProviderContext) { }, }, }); + throw new ForbiddenApiError( + 'Expected unauthorizedUser() to throw a 403 Forbidden error' + ); } catch (e) { expect(e.status).to.be(403); } diff --git a/x-pack/test/observability_ai_assistant_api_integration/tests/knowledge_base/knowledge_base.spec.ts b/x-pack/test/observability_ai_assistant_api_integration/tests/knowledge_base/knowledge_base.spec.ts index 73d53ffa6d1f4..9d80db3baeae6 100644 --- a/x-pack/test/observability_ai_assistant_api_integration/tests/knowledge_base/knowledge_base.spec.ts +++ b/x-pack/test/observability_ai_assistant_api_integration/tests/knowledge_base/knowledge_base.spec.ts @@ -15,6 +15,7 @@ import { deleteInferenceEndpoint, deleteKnowledgeBaseModel, } from './helpers'; +import { ForbiddenApiError } from '../../common/config'; export default function ApiTest({ getService }: FtrProviderContext) { const ml = getService('ml'); @@ -225,6 +226,9 @@ export default function ApiTest({ getService }: FtrProviderContext) { }, }, }); + throw new ForbiddenApiError( + 'Expected unauthorizedUser() to throw a 403 Forbidden error' + ); } catch (e) { expect(e.status).to.be(403); } @@ -238,6 +242,9 @@ export default function ApiTest({ getService }: FtrProviderContext) { query: { query: '', sortBy: 'title', sortDirection: 'asc' }, }, }); + throw new ForbiddenApiError( + 'Expected unauthorizedUser() to throw a 403 Forbidden error' + ); } catch (e) { expect(e.status).to.be(403); } @@ -251,6 +258,9 @@ export default function ApiTest({ getService }: FtrProviderContext) { path: { entryId: 'my-doc-id-1' }, }, }); + throw new ForbiddenApiError( + 'Expected unauthorizedUser() to throw a 403 Forbidden error' + ); } catch (e) { expect(e.status).to.be(403); } diff --git a/x-pack/test/observability_ai_assistant_api_integration/tests/knowledge_base/knowledge_base_setup.spec.ts b/x-pack/test/observability_ai_assistant_api_integration/tests/knowledge_base/knowledge_base_setup.spec.ts index 8220c4edc9c63..0d7625bb63ed3 100644 --- a/x-pack/test/observability_ai_assistant_api_integration/tests/knowledge_base/knowledge_base_setup.spec.ts +++ b/x-pack/test/observability_ai_assistant_api_integration/tests/knowledge_base/knowledge_base_setup.spec.ts @@ -13,6 +13,7 @@ import { TINY_ELSER, deleteInferenceEndpoint, } from './helpers'; +import { ForbiddenApiError } from '../../common/config'; export default function ApiTest({ getService }: FtrProviderContext) { const ml = getService('ml'); @@ -74,6 +75,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { }, }, }); + throw new ForbiddenApiError('Expected unauthorizedUser() to throw a 403 Forbidden error'); } catch (e) { expect(e.status).to.be(403); } diff --git a/x-pack/test/observability_ai_assistant_api_integration/tests/knowledge_base/knowledge_base_status.spec.ts b/x-pack/test/observability_ai_assistant_api_integration/tests/knowledge_base/knowledge_base_status.spec.ts index 7ff78751d474f..3f66931ca0719 100644 --- a/x-pack/test/observability_ai_assistant_api_integration/tests/knowledge_base/knowledge_base_status.spec.ts +++ b/x-pack/test/observability_ai_assistant_api_integration/tests/knowledge_base/knowledge_base_status.spec.ts @@ -13,6 +13,7 @@ import { TINY_ELSER, deleteInferenceEndpoint, } from './helpers'; +import { ForbiddenApiError } from '../../common/config'; export default function ApiTest({ getService }: FtrProviderContext) { const ml = getService('ml'); @@ -89,6 +90,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { await observabilityAIAssistantAPIClient.unauthorizedUser({ endpoint: `GET ${KNOWLEDGE_BASE_STATUS_API_URL}`, }); + throw new ForbiddenApiError('Expected unauthorizedUser() to throw a 403 Forbidden error'); } catch (e) { expect(e.status).to.be(403); } diff --git a/x-pack/test/observability_ai_assistant_api_integration/tests/knowledge_base/knowledge_base_user_instructions.spec.ts b/x-pack/test/observability_ai_assistant_api_integration/tests/knowledge_base/knowledge_base_user_instructions.spec.ts index dbb3fa1fada0a..d5022a052d781 100644 --- a/x-pack/test/observability_ai_assistant_api_integration/tests/knowledge_base/knowledge_base_user_instructions.spec.ts +++ b/x-pack/test/observability_ai_assistant_api_integration/tests/knowledge_base/knowledge_base_user_instructions.spec.ts @@ -23,6 +23,7 @@ import { getConversationCreatedEvent } from '../conversations/helpers'; import { LlmProxy, createLlmProxy } from '../../common/create_llm_proxy'; import { createProxyActionConnector, deleteActionConnector } from '../../common/action_connectors'; import { User } from '../../common/users/users'; +import { ForbiddenApiError } from '../../common/config'; export default function ApiTest({ getService }: FtrProviderContext) { const observabilityAIAssistantAPIClient = getService('observabilityAIAssistantAPIClient'); @@ -377,6 +378,9 @@ export default function ApiTest({ getService }: FtrProviderContext) { }, }, }); + throw new ForbiddenApiError( + 'Expected unauthorizedUser() to throw a 403 Forbidden error' + ); } catch (e) { expect(e.status).to.be(403); } @@ -387,6 +391,9 @@ export default function ApiTest({ getService }: FtrProviderContext) { await observabilityAIAssistantAPIClient.unauthorizedUser({ endpoint: 'GET /internal/observability_ai_assistant/kb/user_instructions', }); + throw new ForbiddenApiError( + 'Expected unauthorizedUser() to throw a 403 Forbidden error' + ); } catch (e) { expect(e.status).to.be(403); }