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>
119 lines
3.9 KiB
TypeScript
119 lines
3.9 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 { 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 kibanaServer = getService('kibanaServer');
|
|
|
|
describe('bulk_delete', () => {
|
|
before(async () => {
|
|
await kibanaServer.importExport.load(
|
|
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
|
|
);
|
|
});
|
|
after(async () => {
|
|
await kibanaServer.importExport.unload(
|
|
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
|
|
);
|
|
});
|
|
|
|
it('should return 200 with individual responses when deleting many docs', async () =>
|
|
await supertest
|
|
.post(`/api/saved_objects/_bulk_delete`)
|
|
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
|
|
.send([
|
|
{
|
|
type: 'visualization',
|
|
id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
|
|
},
|
|
{
|
|
type: 'dashboard',
|
|
id: 'be3733a0-9efe-11e7-acb3-3dab96693fab',
|
|
},
|
|
])
|
|
.expect(200)
|
|
.then((resp) => {
|
|
expect(resp.body).to.eql({
|
|
statuses: [
|
|
{
|
|
success: true,
|
|
type: 'visualization',
|
|
id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
|
|
},
|
|
{
|
|
success: true,
|
|
type: 'dashboard',
|
|
id: 'be3733a0-9efe-11e7-acb3-3dab96693fab',
|
|
},
|
|
],
|
|
});
|
|
}));
|
|
|
|
it('should return generic 404 when deleting an unknown doc', async () =>
|
|
await supertest
|
|
.post(`/api/saved_objects/_bulk_delete`)
|
|
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
|
|
.send([{ type: 'dashboard', id: 'not-a-real-id' }])
|
|
.expect(200)
|
|
.then((resp) => {
|
|
expect(resp.body).to.eql({
|
|
statuses: [
|
|
{
|
|
error: {
|
|
error: 'Not Found',
|
|
message: 'Saved object [dashboard/not-a-real-id] not found',
|
|
statusCode: 404,
|
|
},
|
|
id: 'not-a-real-id',
|
|
type: 'dashboard',
|
|
success: false,
|
|
},
|
|
],
|
|
});
|
|
}));
|
|
|
|
it('should return the result of deleting valid and invalid objects in the same request', async () =>
|
|
await supertest
|
|
.post(`/api/saved_objects/_bulk_delete`)
|
|
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
|
|
.send([
|
|
{ type: 'visualization', id: 'not-a-real-vis-id' },
|
|
{
|
|
type: 'index-pattern',
|
|
id: '91200a00-9efd-11e7-acb3-3dab96693fab',
|
|
},
|
|
])
|
|
.expect(200)
|
|
.then((resp) => {
|
|
expect(resp.body).to.eql({
|
|
statuses: [
|
|
{
|
|
error: {
|
|
error: 'Not Found',
|
|
message: 'Saved object [visualization/not-a-real-vis-id] not found',
|
|
statusCode: 404,
|
|
},
|
|
id: 'not-a-real-vis-id',
|
|
type: 'visualization',
|
|
success: false,
|
|
},
|
|
{
|
|
success: true,
|
|
type: 'index-pattern',
|
|
id: '91200a00-9efd-11e7-acb3-3dab96693fab',
|
|
},
|
|
],
|
|
});
|
|
}));
|
|
});
|
|
}
|