Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions x-pack/test/api_integration/apis/security/index_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,11 @@

import expect from '@kbn/expect/expect.js';
import { FtrProviderContext } from '../../ftr_provider_context';
interface FLSMappingResponse {
flstest: {
mappings: {
runtime?: {
[fieldName: string]: {
type: string;
};
};
properties: {
[fieldName: string]: {
type: string;
};
};
};
};
}

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
const es = getService('legacyEs');
const es = getService('es');

describe('Index Fields', () => {
before(async () => {
Expand Down Expand Up @@ -59,7 +43,9 @@ export default function ({ getService }: FtrProviderContext) {

it('should not include runtime fields', async () => {
// First, make sure the mapping actually includes a runtime field
const mapping = (await es.indices.getMapping({ index: 'flstest' })) as FLSMappingResponse;
const { body: mapping } = await es.indices.getMapping({
index: 'flstest',
});

expect(Object.keys(mapping.flstest.mappings)).to.contain('runtime');
expect(Object.keys(mapping.flstest.mappings.runtime!)).to.contain('runtime_customer_ssn');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SavedObject } from 'src/core/server';
import { FtrProviderContext } from '../ftr_provider_context';

export default function ({ getService }: FtrProviderContext) {
const es = getService('legacyEs');
const es = getService('es');
const randomness = getService('randomness');
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
Expand All @@ -29,14 +29,13 @@ export default function ({ getService }: FtrProviderContext) {
) {
async function getRawSavedObjectAttributes({ id, type }: SavedObject) {
const {
_source: { [type]: savedObject },
body: { _source },
} = await es.get<Record<string, any>>({
id: generateRawID(id, type),
type: '_doc',
index: '.kibana',
} as any);

return savedObject;
});
return _source?.[type];
}

let savedObjectOriginalAttributes: {
Expand Down Expand Up @@ -444,8 +443,10 @@ export default function ({ getService }: FtrProviderContext) {
afterEach(async () => {
await es.deleteByQuery({
index: '.kibana',
// @ts-expect-error @elastic/elasticsearch `DeleteByQueryRequest` type doesn't define `q`.
q: `type:${SAVED_OBJECT_WITH_SECRET_TYPE} OR type:${HIDDEN_SAVED_OBJECT_WITH_SECRET_TYPE} OR type:${SAVED_OBJECT_WITH_SECRET_AND_MULTIPLE_SPACES_TYPE} OR type:${SAVED_OBJECT_WITHOUT_SECRET_TYPE}`,
refresh: true,
body: {},
});
});

Expand Down Expand Up @@ -492,8 +493,10 @@ export default function ({ getService }: FtrProviderContext) {
afterEach(async () => {
await es.deleteByQuery({
index: '.kibana',
// @ts-expect-error @elastic/elasticsearch `DeleteByQueryRequest` type doesn't define `q`.
q: `type:${SAVED_OBJECT_WITH_SECRET_TYPE} OR type:${HIDDEN_SAVED_OBJECT_WITH_SECRET_TYPE} OR type:${SAVED_OBJECT_WITH_SECRET_AND_MULTIPLE_SPACES_TYPE} OR type:${SAVED_OBJECT_WITHOUT_SECRET_TYPE}`,
refresh: true,
body: {},
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import expect from '@kbn/expect';
import type { KibanaClient } from '@elastic/elasticsearch/api/kibana';
import { SavedObjectsErrorHelpers } from '../../../../../src/core/server';
import { SPACES, ALL_SPACES_ID } from './spaces';
import { AUTHENTICATION } from './authentication';
Expand Down Expand Up @@ -178,11 +179,11 @@ export const expectResponses = {
* Additional assertions that we use in `import` and `resolve_import_errors` to ensure that
* newly-created (or overwritten) objects don't have unexpected properties
*/
successCreated: async (es: any, spaceId: string, type: string, id: string) => {
successCreated: async (es: KibanaClient, spaceId: string, type: string, id: string) => {
const isNamespaceUndefined =
spaceId === SPACES.DEFAULT.spaceId || isNamespaceAgnostic(type) || isMultiNamespace(type);
const expectedSpacePrefix = isNamespaceUndefined ? '' : `${spaceId}:`;
const savedObject = await es.get({
const { body: savedObject } = await es.get<Record<string, any>>({
id: `${expectedSpacePrefix}${type}:${id}`,
index: '.kibana',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const createRequest = ({ type, id, initialNamespaces }: BulkCreateTestCase) => (
...(initialNamespaces && { initialNamespaces }),
});

export function bulkCreateTestSuiteFactory(es: any, esArchiver: any, supertest: SuperTest<any>) {
export function bulkCreateTestSuiteFactory(esArchiver: any, supertest: SuperTest<any>) {
const expectSavedObjectForbidden = expectResponses.forbiddenTypes('bulk_create');
const expectResponseBody = (
testCases: BulkCreateTestCase | BulkCreateTestCase[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const createRequest = ({ type, id, initialNamespaces }: CreateTestCase) => ({
initialNamespaces,
});

export function createTestSuiteFactory(es: any, esArchiver: any, supertest: SuperTest<any>) {
export function createTestSuiteFactory(esArchiver: any, supertest: SuperTest<any>) {
const expectSavedObjectForbidden = expectResponses.forbiddenTypes('create');
const expectResponseBody = (
testCase: CreateTestCase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import expect from '@kbn/expect';
import { SuperTest } from 'supertest';
import type { KibanaClient } from '@elastic/elasticsearch/api/kibana';
import { SAVED_OBJECT_TEST_CASES as CASES } from '../lib/saved_object_test_cases';
import { SPACES } from '../lib/spaces';
import { expectResponses, getUrlPrefix, getTestTitle } from '../lib/saved_object_test_utils';
Expand Down Expand Up @@ -71,7 +72,11 @@ const getConflictDest = (id: string) => ({
updatedAt: '2017-09-21T18:59:16.270Z',
});

export function importTestSuiteFactory(es: any, esArchiver: any, supertest: SuperTest<any>) {
export function importTestSuiteFactory(
es: KibanaClient,
esArchiver: any,
supertest: SuperTest<any>
) {
const expectSavedObjectForbidden = expectResponses.forbiddenTypes('bulk_create');
const expectResponseBody = (
testCases: ImportTestCase | ImportTestCase[],
Expand Down Expand Up @@ -140,7 +145,7 @@ export function importTestSuiteFactory(es: any, esArchiver: any, supertest: Supe
type,
destinationId ?? id
);
expect(_source[type][NEW_ATTRIBUTE_KEY]).to.eql(NEW_ATTRIBUTE_VAL);
expect(_source?.[type][NEW_ATTRIBUTE_KEY]).to.eql(NEW_ATTRIBUTE_VAL);
}
}
for (let i = 0; i < expectedFailures.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import expect from '@kbn/expect';
import { SuperTest } from 'supertest';
import type { KibanaClient } from '@elastic/elasticsearch/api/kibana';
import { SAVED_OBJECT_TEST_CASES as CASES } from '../lib/saved_object_test_cases';
import { SPACES } from '../lib/spaces';
import { expectResponses, getUrlPrefix, getTestTitle } from '../lib/saved_object_test_utils';
Expand Down Expand Up @@ -91,7 +92,7 @@ const createRequest = (
});

export function resolveImportErrorsTestSuiteFactory(
es: any,
es: KibanaClient,
esArchiver: any,
supertest: SuperTest<any>
) {
Expand Down Expand Up @@ -161,7 +162,7 @@ export function resolveImportErrorsTestSuiteFactory(
type,
destinationId ?? id
);
expect(_source[type][NEW_ATTRIBUTE_KEY]).to.eql(NEW_ATTRIBUTE_VAL);
expect(_source?.[type][NEW_ATTRIBUTE_KEY]).to.eql(NEW_ATTRIBUTE_VAL);
}
}
for (let i = 0; i < expectedFailures.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,12 @@ const createTestCases = (overwrite: boolean, spaceId: string) => {
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertestWithoutAuth');
const esArchiver = getService('esArchiver');
const es = getService('legacyEs');

const {
addTests,
createTestDefinitions,
expectSavedObjectForbidden,
} = bulkCreateTestSuiteFactory(es, esArchiver, supertest);
} = bulkCreateTestSuiteFactory(esArchiver, supertest);
const createTests = (overwrite: boolean, spaceId: string, user: TestUser) => {
const { normalTypes, crossNamespace, hiddenType, allTypes } = createTestCases(
overwrite,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ const createTestCases = (overwrite: boolean, spaceId: string) => {
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertestWithoutAuth');
const esArchiver = getService('esArchiver');
const es = getService('legacyEs');

const { addTests, createTestDefinitions } = createTestSuiteFactory(es, esArchiver, supertest);
const { addTests, createTestDefinitions } = createTestSuiteFactory(esArchiver, supertest);
const createTests = (overwrite: boolean, spaceId: string, user: TestUser) => {
const { normalTypes, crossNamespace, hiddenType, allTypes } = createTestCases(
overwrite,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const createTestCases = (overwrite: boolean, spaceId: string) => {
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertestWithoutAuth');
const esArchiver = getService('esArchiver');
const es = getService('legacyEs');
const es = getService('es');

const { addTests, createTestDefinitions, expectSavedObjectForbidden } = importTestSuiteFactory(
es,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const createTestCases = (overwrite: boolean, spaceId: string) => {
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertestWithoutAuth');
const esArchiver = getService('esArchiver');
const es = getService('legacyEs');
const es = getService('es');

const {
addTests,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ const createTestCases = (overwrite: boolean) => {
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertestWithoutAuth');
const esArchiver = getService('esArchiver');
const es = getService('legacyEs');

const {
addTests,
createTestDefinitions,
expectSavedObjectForbidden,
} = bulkCreateTestSuiteFactory(es, esArchiver, supertest);
} = bulkCreateTestSuiteFactory(esArchiver, supertest);
const createTests = (overwrite: boolean, user: TestUser) => {
const { normalTypes, hiddenType, allTypes } = createTestCases(overwrite);
// use singleRequest to reduce execution time and/or test combined cases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ const createTestCases = (overwrite: boolean) => {
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertestWithoutAuth');
const esArchiver = getService('esArchiver');
const es = getService('legacyEs');

const { addTests, createTestDefinitions } = createTestSuiteFactory(es, esArchiver, supertest);
const { addTests, createTestDefinitions } = createTestSuiteFactory(esArchiver, supertest);
const createTests = (overwrite: boolean, user: TestUser) => {
const { normalTypes, hiddenType, allTypes } = createTestCases(overwrite);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const createTestCases = (overwrite: boolean) => {
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertestWithoutAuth');
const esArchiver = getService('esArchiver');
const es = getService('legacyEs');
const es = getService('es');

const { addTests, createTestDefinitions, expectSavedObjectForbidden } = importTestSuiteFactory(
es,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const createTestCases = (overwrite: boolean) => {
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertestWithoutAuth');
const esArchiver = getService('esArchiver');
const es = getService('legacyEs');
const es = getService('es');

const {
addTests,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ const createTestCases = (overwrite: boolean, spaceId: string) => {
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
const es = getService('legacyEs');

const { addTests, createTestDefinitions } = bulkCreateTestSuiteFactory(es, esArchiver, supertest);
const { addTests, createTestDefinitions } = bulkCreateTestSuiteFactory(esArchiver, supertest);
const createTests = (overwrite: boolean, spaceId: string) => {
const testCases = createTestCases(overwrite, spaceId);
return createTestDefinitions(testCases, false, overwrite, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ const createTestCases = (overwrite: boolean, spaceId: string) => {
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertestWithoutAuth');
const esArchiver = getService('esArchiver');
const es = getService('legacyEs');

const { addTests, createTestDefinitions } = createTestSuiteFactory(es, esArchiver, supertest);
const { addTests, createTestDefinitions } = createTestSuiteFactory(esArchiver, supertest);
const createTests = (overwrite: boolean, spaceId: string) => {
const testCases = createTestCases(overwrite, spaceId);
return createTestDefinitions(testCases, false, overwrite, { spaceId });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const createTestCases = (overwrite: boolean, spaceId: string) => {
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
const es = getService('legacyEs');
const es = getService('es');

const { addTests, createTestDefinitions } = importTestSuiteFactory(es, esArchiver, supertest);
const createTests = (overwrite: boolean, createNewCopies: boolean, spaceId: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const createTestCases = (overwrite: boolean, spaceId: string) => {
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
const es = getService('legacyEs');
const es = getService('es');

const { addTests, createTestDefinitions } = resolveImportErrorsTestSuiteFactory(
es,
Expand Down
7 changes: 2 additions & 5 deletions x-pack/test/spaces_api_integration/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
*/

import path from 'path';

import { REPO_ROOT } from '@kbn/utils';

import { TestInvoker } from './lib/types';
import { FtrConfigProviderContext } from '@kbn/test/types/ftr';

interface CreateTestConfigOptions {
license: string;
Expand All @@ -19,7 +17,7 @@ interface CreateTestConfigOptions {
export function createTestConfig(name: string, options: CreateTestConfigOptions) {
const { license, disabledPlugins = [] } = options;

return async ({ readConfigFile }: TestInvoker) => {
return async ({ readConfigFile }: FtrConfigProviderContext) => {
const config = {
kibana: {
api: await readConfigFile(path.resolve(REPO_ROOT, 'test/api_integration/config.js')),
Expand All @@ -35,7 +33,6 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions)
servers: config.xpack.api.get('servers'),
services: {
es: config.kibana.api.get('services.es'),
legacyEs: config.kibana.api.get('services.legacyEs'),
esSupertestWithoutAuth: config.xpack.api.get('services.esSupertestWithoutAuth'),
supertest: config.kibana.api.get('services.supertest'),
supertestWithoutAuth: config.xpack.api.get('services.supertestWithoutAuth'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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 { GenericFtrProviderContext } from '@kbn/test/types/ftr';

import { services } from './services';

export type FtrProviderContext = GenericFtrProviderContext<typeof services, {}>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* 2.0.
*/

import { Client } from '@elastic/elasticsearch';
import { SuperTest } from 'supertest';
import type { KibanaClient } from '@elastic/elasticsearch/api/kibana';
import { AUTHENTICATION } from './authentication';

export const createUsersAndRoles = async (es: Client, supertest: SuperTest<any>) => {
export const createUsersAndRoles = async (es: KibanaClient, supertest: SuperTest<any>) => {
await supertest
.put('/api/security/role/kibana_legacy_user')
.send({
Expand Down
11 changes: 0 additions & 11 deletions x-pack/test/spaces_api_integration/common/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,3 @@ export interface TestDefinitionAuthentication {
username?: string;
password?: string;
}
export type LoadTestFileFn = (path: string) => string;

export type GetServiceFn = (service: string) => any;

export type ReadConfigFileFn = (path: string) => any;

export interface TestInvoker {
getService: GetServiceFn;
loadTestFile: LoadTestFileFn;
readConfigFile: ReadConfigFileFn;
}
14 changes: 14 additions & 0 deletions x-pack/test/spaces_api_integration/common/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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 { services as commonServices } from '../../common/services';
import { services as apiIntegrationServices } from '../../api_integration/services';

export const services = {
...commonServices,
supertestWithoutAuth: apiIntegrationServices.supertestWithoutAuth,
};
Loading