mirror of
https://github.com/elastic/kibana.git
synced 2025-06-29 03:24:45 -04:00
fix https://github.com/elastic/kibana/issues/192052 ## Summary Internal APIs will be [restricted](https://github.com/elastic/kibana/issues/163654) from public access as of 9.0.0. In non-serverless environments, this breaking change will result in a 400 error if an external request is made to an internal Kibana API (route `access` option as `"internal"` or `"public"`). This PR allows API owners of non-xpack plugins to run their `ftr` API integration tests against the restriction and adds examples of how to handle it. ### 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 Note to reviewers: The header needed to allow access to internal apis shouldn't change your test output, with or without the restriction enabled. ### How to test the changes work: #### Non x-pack: 1. Set `server.restrictInternalApis: true` in `test/common/config.js` 2. Ensure your tests pass #### x-pack: 1. Set `server.restrictInternalApis: true` in `x-pack/test/api_integration/apis/security/config.ts` 2. Ensure the spaces tests pass --------- Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
122 lines
4.3 KiB
TypeScript
122 lines
4.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", the "GNU Affero General Public License v3.0 only", and the "Server Side
|
|
* Public License v 1"; you may not use this file except in compliance with, at
|
|
* your election, the "Elastic License 2.0", the "GNU Affero General Public
|
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
|
*/
|
|
|
|
import expect from '@kbn/expect';
|
|
import {
|
|
ELASTIC_HTTP_VERSION_HEADER,
|
|
X_ELASTIC_INTERNAL_ORIGIN_REQUEST,
|
|
} from '@kbn/core-http-common';
|
|
import { FtrProviderContext } from '../../ftr_provider_context';
|
|
|
|
export default function ({ getService }: FtrProviderContext) {
|
|
const supertest = getService('supertest');
|
|
const esArchiver = getService('esArchiver');
|
|
|
|
const sqlQuery = `SELECT index, bytes FROM "logstash-*" ORDER BY "@timestamp" DESC`;
|
|
|
|
describe('SQL search', () => {
|
|
before(async () => {
|
|
await esArchiver.emptyKibanaIndex();
|
|
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
|
|
});
|
|
|
|
after(async () => {
|
|
await esArchiver.unload('test/functional/fixtures/es_archiver/logstash_functional');
|
|
});
|
|
describe('post', () => {
|
|
it('should return 200 when correctly formatted searches are provided', async () => {
|
|
const resp = await supertest
|
|
.post(`/internal/search/sql`)
|
|
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
|
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
|
|
.send({
|
|
params: {
|
|
query: sqlQuery,
|
|
},
|
|
})
|
|
.expect(200);
|
|
|
|
expect(resp.body).to.have.property('id');
|
|
expect(resp.body).to.have.property('isPartial');
|
|
expect(resp.body).to.have.property('isRunning');
|
|
expect(resp.body).to.have.property('rawResponse');
|
|
expect(resp.header).to.have.property(ELASTIC_HTTP_VERSION_HEADER, '1');
|
|
});
|
|
|
|
it('should fetch search results by id', async () => {
|
|
const resp1 = await supertest
|
|
.post(`/internal/search/sql`)
|
|
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
|
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
|
|
.send({
|
|
params: {
|
|
query: sqlQuery,
|
|
keep_on_completion: true, // force keeping the results even if completes early
|
|
},
|
|
})
|
|
.expect(200);
|
|
const id = resp1.body.id;
|
|
|
|
const resp2 = await supertest
|
|
.post(`/internal/search/sql/${id}`)
|
|
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
|
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
|
|
.send({});
|
|
|
|
expect(resp2.status).to.be(200);
|
|
expect(resp2.body.id).to.be(id);
|
|
expect(resp2.body).to.have.property('isPartial');
|
|
expect(resp2.body).to.have.property('isRunning');
|
|
expect(resp2.body).to.have.property('rawResponse');
|
|
expect(resp2.header).to.have.property(ELASTIC_HTTP_VERSION_HEADER, '1');
|
|
});
|
|
});
|
|
|
|
describe('delete', () => {
|
|
it('should delete search', async () => {
|
|
const resp1 = await supertest
|
|
.post(`/internal/search/sql`)
|
|
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
|
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
|
|
.send({
|
|
params: {
|
|
query: sqlQuery,
|
|
keep_on_completion: true, // force keeping the results even if completes early
|
|
},
|
|
})
|
|
.expect(200);
|
|
const id = resp1.body.id;
|
|
|
|
// confirm it was saved
|
|
await supertest
|
|
.post(`/internal/search/sql/${id}`)
|
|
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
|
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
|
|
.send({})
|
|
.expect(200);
|
|
|
|
// delete it
|
|
await supertest
|
|
.delete(`/internal/search/sql/${id}`)
|
|
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
|
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
|
|
.send()
|
|
.expect(200);
|
|
|
|
// check it was deleted
|
|
await supertest
|
|
.post(`/internal/search/sql/${id}`)
|
|
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
|
|
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
|
|
.send({})
|
|
.expect(404);
|
|
});
|
|
});
|
|
});
|
|
}
|