Skip to content

Commit

Permalink
[Painless Lab][Serverless] Add integration tests (#172149)
Browse files Browse the repository at this point in the history
## Summary

This PR adds serverless API integration tests for Painless Lab - for the
Observability and Security projects only, since Painless lab is disabled
in the Search project.
  • Loading branch information
ElenaStoeva authored Nov 29, 2023
1 parent cca28e7 commit ccfc447
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 type { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ loadTestFile }: FtrProviderContext) {
describe('Painless Lab API', function () {
this.tags(['esGate']);

loadTestFile(require.resolve('./painless_lab'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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 expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';

const API_BASE_PATH = '/api/painless_lab';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const svlCommonApi = getService('svlCommonApi');

describe('Painless Lab Routes', function () {
describe('Execute', () => {
it('should execute a valid painless script', async () => {
const script =
'"{\\n \\"script\\": {\\n \\"source\\": \\"return true;\\",\\n \\"params\\": {\\n \\"string_parameter\\": \\"string value\\",\\n \\"number_parameter\\": 1.5,\\n \\"boolean_parameter\\": true\\n}\\n }\\n}"';

const { body } = await supertest
.post(`${API_BASE_PATH}/execute`)
.set(svlCommonApi.getInternalRequestHeader())
.set('Content-Type', 'application/json;charset=UTF-8')
.send(script)
.expect(200);

expect(body).to.eql({
result: 'true',
});
});

it('should return error response for invalid painless script', async () => {
const invalidScript =
'"{\\n \\"script\\": {\\n \\"source\\": \\"foobar\\",\\n \\"params\\": {\\n \\"string_parameter\\": \\"string value\\",\\n \\"number_parameter\\": 1.5,\\n \\"boolean_parameter\\": true\\n}\\n }\\n}"';

const { body } = await supertest
.post(`${API_BASE_PATH}/execute`)
.set(svlCommonApi.getInternalRequestHeader())
.set('Content-Type', 'application/json;charset=UTF-8')
.send(invalidScript)
.expect(200);

expect(body.error).to.not.be(undefined);
expect(body.error.reason).to.eql('compile error');
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
require.resolve('../../common/search_xpack'),
require.resolve('../../common/core'),
require.resolve('../../common/reporting'),
require.resolve('../../common/painless_lab'),
],
junit: {
reportName: 'Serverless Observability API Integration Tests - Common Group 1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
require.resolve('../../common/search_xpack'),
require.resolve('../../common/core'),
require.resolve('../../common/reporting'),
require.resolve('../../common/painless_lab'),
],
junit: {
reportName: 'Serverless Security API Integration Tests - Common Group 1',
Expand Down

0 comments on commit ccfc447

Please sign in to comment.