Skip to content

Commit

Permalink
[FTR](management && painless_lab) update common serverless api tests …
Browse files Browse the repository at this point in the history
…to use api keys (elastic#184304)

## Summary

Use api keys for api calls, to act as the user, within:
`x-pack/test_serverless/api_integration/test_suites/common/management/`
&&

`x-pack/test_serverless/api_integration/test_suites/common/painless_lab/`

Contributes to: elastic#180834

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
wayneseymour and kibanamachine committed May 28, 2024
1 parent 5d0f09a commit b1891e4
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,34 @@
import expect from '@kbn/expect';
import { IngestPutPipelineRequest } from '@elastic/elasticsearch/lib/api/types';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { InternalRequestHeader, RoleCredentials } from '../../../../shared/services';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const ingestPipelines = getService('ingestPipelines');
const log = getService('log');
const svlCommonApi = getService('svlCommonApi');
const svlUserManager = getService('svlUserManager');
const supertestWithoutAuth = getService('supertestWithoutAuth');
let roleAuthc: RoleCredentials;
let internalReqHeader: InternalRequestHeader;

describe('Ingest Pipelines', function () {
before(async () => {
roleAuthc = await svlUserManager.createApiKeyForRole('admin');
internalReqHeader = svlCommonApi.getInternalRequestHeader();
});
after(async () => {
await ingestPipelines.api.deletePipelines();
await svlUserManager.invalidateApiKeyForRole(roleAuthc);
});

describe('Create', () => {
it('should create a pipeline', async () => {
const pipelineRequestBody = ingestPipelines.fixtures.createPipelineBody();
const { body } = await supertest
const { body } = await supertestWithoutAuth
.post(ingestPipelines.fixtures.apiBasePath)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.send(pipelineRequestBody);

expect(body).to.eql({
Expand All @@ -36,10 +46,10 @@ export default function ({ getService }: FtrProviderContext) {
it('should create a pipeline with only required fields', async () => {
const pipelineRequestBody = ingestPipelines.fixtures.createPipelineBodyWithRequiredFields(); // Includes name and processors[] only

const { body } = await supertest
const { body } = await supertestWithoutAuth
.post(ingestPipelines.fixtures.apiBasePath)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.send(pipelineRequestBody)
.expect(200);

Expand All @@ -56,10 +66,10 @@ export default function ({ getService }: FtrProviderContext) {
await ingestPipelines.api.createPipeline({ id: name, ...esPipelineRequestBody });

// Then, create a pipeline with our internal API
const { body } = await supertest
const { body } = await supertestWithoutAuth
.post(ingestPipelines.fixtures.apiBasePath)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.send(pipelineRequestBody)
.expect(409);

Expand Down Expand Up @@ -94,10 +104,10 @@ export default function ({ getService }: FtrProviderContext) {
it('should allow an existing pipeline to be updated', async () => {
const uri = `${ingestPipelines.fixtures.apiBasePath}/${pipelineName}`;

const { body } = await supertest
const { body } = await supertestWithoutAuth
.put(uri)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.send({
...pipeline,
description: 'updated test pipeline description',
Expand All @@ -116,10 +126,10 @@ export default function ({ getService }: FtrProviderContext) {
it('should allow optional fields to be removed', async () => {
const uri = `${ingestPipelines.fixtures.apiBasePath}/${pipelineName}`;

const { body } = await supertest
const { body } = await supertestWithoutAuth
.put(uri)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.send({
// removes description, version, on_failure, and _meta
processors: pipeline.processors,
Expand All @@ -134,10 +144,10 @@ export default function ({ getService }: FtrProviderContext) {
it('should not allow a non-existing pipeline to be updated', async () => {
const uri = `${ingestPipelines.fixtures.apiBasePath}/pipeline_does_not_exist`;

const { body } = await supertest
const { body } = await supertestWithoutAuth
.put(uri)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.send({
...pipeline,
description: 'updated test pipeline description',
Expand Down Expand Up @@ -179,10 +189,10 @@ export default function ({ getService }: FtrProviderContext) {

describe('all pipelines', () => {
it('should return an array of pipelines', async () => {
const { body } = await supertest
const { body } = await supertestWithoutAuth
.get(ingestPipelines.fixtures.apiBasePath)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.expect(200);

expect(Array.isArray(body)).to.be(true);
Expand All @@ -202,10 +212,10 @@ export default function ({ getService }: FtrProviderContext) {
it('should return a single pipeline', async () => {
const uri = `${ingestPipelines.fixtures.apiBasePath}/${pipelineName}`;

const { body } = await supertest
const { body } = await supertestWithoutAuth
.get(uri)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.expect(200);

expect(body).to.eql({
Expand Down Expand Up @@ -244,10 +254,10 @@ export default function ({ getService }: FtrProviderContext) {

const uri = `${ingestPipelines.fixtures.apiBasePath}/${pipelineA}`;

const { body } = await supertest
const { body } = await supertestWithoutAuth
.delete(uri)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.expect(200);

expect(body).to.eql({
Expand All @@ -263,10 +273,10 @@ export default function ({ getService }: FtrProviderContext) {

const {
body: { itemsDeleted, errors },
} = await supertest
} = await supertestWithoutAuth
.delete(uri)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.expect(200);

expect(errors).to.eql([]);
Expand All @@ -283,10 +293,10 @@ export default function ({ getService }: FtrProviderContext) {

const uri = `${ingestPipelines.fixtures.apiBasePath}/${pipelineD},${PIPELINE_DOES_NOT_EXIST}`;

const { body } = await supertest
const { body } = await supertestWithoutAuth
.delete(uri)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.expect(200);

expect(body).to.eql({
Expand Down Expand Up @@ -315,10 +325,10 @@ export default function ({ getService }: FtrProviderContext) {
it('should successfully simulate a pipeline', async () => {
const { name, ...pipeline } = ingestPipelines.fixtures.createPipelineBody();
const documents = ingestPipelines.fixtures.createDocuments();
const { body } = await supertest
const { body } = await supertestWithoutAuth
.post(`${ingestPipelines.fixtures.apiBasePath}/simulate`)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.send({
pipeline,
documents,
Expand All @@ -334,10 +344,10 @@ export default function ({ getService }: FtrProviderContext) {
const { name, ...pipeline } =
ingestPipelines.fixtures.createPipelineBodyWithRequiredFields();
const documents = ingestPipelines.fixtures.createDocuments();
const { body } = await supertest
const { body } = await supertestWithoutAuth
.post(`${ingestPipelines.fixtures.apiBasePath}/simulate`)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.send({
pipeline,
documents,
Expand Down Expand Up @@ -380,10 +390,10 @@ export default function ({ getService }: FtrProviderContext) {
it('should return a document', async () => {
const uri = `${ingestPipelines.fixtures.apiBasePath}/documents/${INDEX}/${DOCUMENT_ID}`;

const { body } = await supertest
const { body } = await supertestWithoutAuth
.get(uri)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.expect(200);

expect(body).to.eql({
Expand All @@ -396,10 +406,10 @@ export default function ({ getService }: FtrProviderContext) {
it('should return an error if the document does not exist', async () => {
const uri = `${ingestPipelines.fixtures.apiBasePath}/documents/${INDEX}/2`; // Document 2 does not exist

const { body } = await supertest
const { body } = await supertestWithoutAuth
.get(uri)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.expect(404);

expect(body).to.eql({
Expand All @@ -415,10 +425,10 @@ export default function ({ getService }: FtrProviderContext) {
it('should map to a pipeline', async () => {
const validCsv =
'source_field,copy_action,format_action,timestamp_format,destination_field,Notes\nsrcip,,,,source.address,Copying srcip to source.address';
const { body } = await supertest
const { body } = await supertestWithoutAuth
.post(`${ingestPipelines.fixtures.apiBasePath}/parse_csv`)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.send({
copyAction: 'copy',
file: validCsv,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,41 @@ import { X_ELASTIC_INTERNAL_ORIGIN_REQUEST } from '@kbn/core-http-common/src/con
import { FIELDS_FOR_WILDCARD_PATH as BASE_URI } from '@kbn/data-views-plugin/common/constants';
import { DataViewType } from '@kbn/data-views-plugin/common';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { InternalRequestHeader, RoleCredentials } from '../../../../shared/services';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
const svlCommonApi = getService('svlCommonApi');
const svlUserManager = getService('svlUserManager');
const supertestWithoutAuth = getService('supertestWithoutAuth');
let roleAuthc: RoleCredentials;
let internalReqHeader: InternalRequestHeader;

describe('rollup data views - fields for wildcard', function () {
before(async () => {
roleAuthc = await svlUserManager.createApiKeyForRole('admin');
internalReqHeader = svlCommonApi.getInternalRequestHeader();
await esArchiver.load('test/api_integration/fixtures/es_archiver/index_patterns/basic_index');
});

after(async () => {
await esArchiver.unload(
'test/api_integration/fixtures/es_archiver/index_patterns/basic_index'
);
await svlUserManager.invalidateApiKeyForRole(roleAuthc);
});
it('returns 200 and best effort response despite lack of rollup support', async () => {
const response = await supertest
const response = await supertestWithoutAuth
.get(BASE_URI)
.query({
pattern: 'basic_index',
type: DataViewType.ROLLUP,
rollup_index: 'bar',
})
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'true');
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'true')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader);

expect(response.status).toBe(200);
expect(response.body.fields.length).toEqual(5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@
import expect from 'expect';
import { DATA_VIEW_PATH } from '@kbn/data-views-plugin/server';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { InternalRequestHeader, RoleCredentials } from '../../../../shared/services';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');
const svlCommonApi = getService('svlCommonApi');
const svlUserManager = getService('svlUserManager');
const supertestWithoutAuth = getService('supertestWithoutAuth');
let roleAuthc: RoleCredentials;
let internalReqHeader: InternalRequestHeader;

describe('scripted fields disabled', function () {
before(async () => {
roleAuthc = await svlUserManager.createApiKeyForRole('admin');
internalReqHeader = svlCommonApi.getInternalRequestHeader();
// TODO: We're running into a 'Duplicate data view: basic_index'
// error in Serverless, so make sure to clean up first
await kibanaServer.savedObjects.cleanStandardList();
Expand All @@ -26,11 +33,13 @@ export default function ({ getService }: FtrProviderContext) {
await esArchiver.unload(
'test/api_integration/fixtures/es_archiver/index_patterns/basic_index'
);
await svlUserManager.invalidateApiKeyForRole(roleAuthc);
});
it('scripted fields are ignored when disabled', async () => {
const response = await supertest
const response = await supertestWithoutAuth
.post(DATA_VIEW_PATH)
.set('kbn-xsrf', 'some-xsrf-token')
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.send({
data_view: {
title: 'basic_index',
Expand Down
Loading

0 comments on commit b1891e4

Please sign in to comment.