Skip to content

Commit

Permalink
[Obs AI Assistant] Update tests to definetely throw an error
Browse files Browse the repository at this point in the history
  • Loading branch information
viduni94 committed Dec 4, 2024
1 parent 0131d78 commit 4cfde64
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ export type ObservabilityAIAssistantAPIClient = Awaited<

export type ObservabilityAIAssistantServices = Awaited<ReturnType<CreateTestConfig>>['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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
deleteInferenceEndpoint,
deleteKnowledgeBaseModel,
} from './helpers';
import { ForbiddenApiError } from '../../common/config';

export default function ApiTest({ getService }: FtrProviderContext) {
const ml = getService('ml');
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 4cfde64

Please sign in to comment.