mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
## Summary Follow up to #170274. Part of #181111 and #181603. We had v1 and v2 of the log rate analysis API for a while now (Nov 23). Originally we did this to practice API versioning for serverless. Enough time has passed so we can remove v1 which this PR does. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
* 2.0.
|
|
*/
|
|
|
|
import fetch from 'node-fetch';
|
|
import { format as formatUrl } from 'url';
|
|
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
|
|
|
|
import expect from '@kbn/expect';
|
|
import type {
|
|
AiopsLogRateAnalysisSchema,
|
|
AiopsLogRateAnalysisApiVersion as ApiVersion,
|
|
} from '@kbn/aiops-log-rate-analysis/api/schema';
|
|
|
|
import type { FtrProviderContext } from '../../ftr_provider_context';
|
|
|
|
const API_VERSIONS: ApiVersion[] = ['2'];
|
|
|
|
export default ({ getService }: FtrProviderContext) => {
|
|
const supertest = getService('supertest');
|
|
const config = getService('config');
|
|
const kibanaServerUrl = formatUrl(config.get('servers.kibana'));
|
|
|
|
describe('POST /internal/aiops/log_rate_analysis', () => {
|
|
API_VERSIONS.forEach((apiVersion) => {
|
|
describe(`with API v${apiVersion}`, () => {
|
|
const requestBody: AiopsLogRateAnalysisSchema<typeof apiVersion> = {
|
|
baselineMax: 1561719083292,
|
|
baselineMin: 1560954147006,
|
|
deviationMax: 1562254538692,
|
|
deviationMin: 1561986810992,
|
|
end: 2147483647000,
|
|
index: 'ft_ecommerce',
|
|
searchQuery: '{"bool":{"filter":[],"must":[{"match_all":{}}],"must_not":[]}}',
|
|
start: 0,
|
|
timeFieldName: 'order_date',
|
|
};
|
|
|
|
it('should return permission denied without streaming', async () => {
|
|
await supertest
|
|
.post(`/internal/aiops/log_rate_analysis`)
|
|
.set('kbn-xsrf', 'kibana')
|
|
.set(ELASTIC_HTTP_VERSION_HEADER, apiVersion)
|
|
.send(requestBody)
|
|
.expect(403);
|
|
});
|
|
|
|
it('should return permission denied with streaming', async () => {
|
|
const response = await fetch(`${kibanaServerUrl}/internal/aiops/log_rate_analysis`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'kbn-xsrf': 'stream',
|
|
[ELASTIC_HTTP_VERSION_HEADER]: apiVersion,
|
|
},
|
|
body: JSON.stringify(requestBody),
|
|
});
|
|
|
|
expect(response.ok).to.be(false);
|
|
expect(response.status).to.be(403);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
};
|