diff --git a/x-pack/test/saved_object_api_integration/common/config.js b/x-pack/test/saved_object_api_integration/common/config.ts similarity index 84% rename from x-pack/test/saved_object_api_integration/common/config.js rename to x-pack/test/saved_object_api_integration/common/config.ts index 15dce485d5dc21..48bf64f54c8fd9 100644 --- a/x-pack/test/saved_object_api_integration/common/config.js +++ b/x-pack/test/saved_object_api_integration/common/config.ts @@ -4,23 +4,28 @@ * you may not use this file except in compliance with the Elastic License. */ -import path from 'path'; import { resolveKibanaPath } from '@kbn/plugin-helpers'; +import path from 'path'; +import { TestInvoker } from './lib/types'; import { EsProvider } from './services/es'; +interface CreateTestConfigOptions { + license: string; + disabledPlugins?: [string]; +} -export function createTestConfig(name, { license = 'trial', disabledPlugins = [] } = {}) { - - return async function ({ readConfigFile }) { +export function createTestConfig(name: string, options: CreateTestConfigOptions) { + const { license = 'trial', disabledPlugins = [] } = options; + return async ({ readConfigFile }: TestInvoker) => { const config = { kibana: { api: await readConfigFile(resolveKibanaPath('test/api_integration/config.js')), - functional: await readConfigFile(require.resolve('../../../../test/functional/config.js')) + functional: await readConfigFile(require.resolve('../../../../test/functional/config.js')), }, xpack: { - api: await readConfigFile(require.resolve('../../api_integration/config.js')) - } + api: await readConfigFile(require.resolve('../../api_integration/config.js')), + }, }; return { @@ -39,7 +44,7 @@ export function createTestConfig(name, { license = 'trial', disabledPlugins = [] }, esArchiver: { - directory: path.join(__dirname, 'fixtures', 'es_archiver') + directory: path.join(__dirname, 'fixtures', 'es_archiver'), }, esTestCluster: { diff --git a/x-pack/test/saved_object_api_integration/common/lib/create_users_and_roles.js b/x-pack/test/saved_object_api_integration/common/lib/create_users_and_roles.ts similarity index 72% rename from x-pack/test/saved_object_api_integration/common/lib/create_users_and_roles.js rename to x-pack/test/saved_object_api_integration/common/lib/create_users_and_roles.ts index 1074ae12cb4967..66bcd0e5364291 100644 --- a/x-pack/test/saved_object_api_integration/common/lib/create_users_and_roles.js +++ b/x-pack/test/saved_object_api_integration/common/lib/create_users_and_roles.ts @@ -5,102 +5,100 @@ */ import { AUTHENTICATION } from './authentication'; -export const createUsersAndRoles = async (es, supertest) => { - await supertest.put('/api/security/role/kibana_legacy_user') - .send({ - elasticsearch: { - indices: [{ +export const createUsersAndRoles = async (es: any, supertest: SuperTest) => { + await supertest.put('/api/security/role/kibana_legacy_user').send({ + elasticsearch: { + indices: [ + { names: ['.kibana'], - privileges: ['manage', 'read', 'index', 'delete'] - }] - } - }); - - await supertest.put('/api/security/role/kibana_legacy_dashboard_only_user') - .send({ - elasticsearch: { - indices: [{ + privileges: ['manage', 'read', 'index', 'delete'], + }, + ], + }, + }); + + await supertest.put('/api/security/role/kibana_legacy_dashboard_only_user').send({ + elasticsearch: { + indices: [ + { names: ['.kibana'], - privileges: ['read', 'view_index_metadata'] - }] - } - }); - - await supertest.put('/api/security/role/kibana_dual_privileges_user') - .send({ - elasticsearch: { - indices: [{ + privileges: ['read', 'view_index_metadata'], + }, + ], + }, + }); + + await supertest.put('/api/security/role/kibana_dual_privileges_user').send({ + elasticsearch: { + indices: [ + { names: ['.kibana'], - privileges: ['manage', 'read', 'index', 'delete'] - }] - }, - kibana: { - global: ['all'] - } - }); - - await supertest.put('/api/security/role/kibana_dual_privileges_dashboard_only_user') - .send({ - elasticsearch: { - indices: [{ + privileges: ['manage', 'read', 'index', 'delete'], + }, + ], + }, + kibana: { + global: ['all'], + }, + }); + + await supertest.put('/api/security/role/kibana_dual_privileges_dashboard_only_user').send({ + elasticsearch: { + indices: [ + { names: ['.kibana'], - privileges: ['read', 'view_index_metadata'] - }] + privileges: ['read', 'view_index_metadata'], + }, + ], + }, + kibana: { + global: ['read'], + }, + }); + + await supertest.put('/api/security/role/kibana_rbac_user').send({ + kibana: { + global: ['all'], + }, + }); + + await supertest.put('/api/security/role/kibana_rbac_dashboard_only_user').send({ + kibana: { + global: ['read'], + }, + }); + + await supertest.put('/api/security/role/kibana_rbac_default_space_all_user').send({ + kibana: { + space: { + default: ['all'], + }, + }, + }); + + await supertest.put('/api/security/role/kibana_rbac_default_space_read_user').send({ + kibana: { + space: { + default: ['read'], }, - kibana: { - global: ['read'] - } - }); - - await supertest.put('/api/security/role/kibana_rbac_user') - .send({ - kibana: { - global: ['all'] - } - }); - - await supertest.put('/api/security/role/kibana_rbac_dashboard_only_user') - .send({ - kibana: { - global: ['read'] - } - }); - - await supertest.put('/api/security/role/kibana_rbac_default_space_all_user') - .send({ - kibana: { - space: { - default: ['all'] - } - } - }); - - await supertest.put('/api/security/role/kibana_rbac_default_space_read_user') - .send({ - kibana: { - space: { - default: ['read'] - } - } - }); - - await supertest.put('/api/security/role/kibana_rbac_space_1_all_user') - .send({ - kibana: { - space: { - space_1: ['all'] - } - } - }); - - await supertest.put('/api/security/role/kibana_rbac_space_1_read_user') - .send({ - kibana: { - space: { - space_1: ['read'] - } - } - }); + }, + }); + + await supertest.put('/api/security/role/kibana_rbac_space_1_all_user').send({ + kibana: { + space: { + space_1: ['all'], + }, + }, + }); + + await supertest.put('/api/security/role/kibana_rbac_space_1_read_user').send({ + kibana: { + space: { + space_1: ['read'], + }, + }, + }); await es.shield.putUser({ username: AUTHENTICATION.NOT_A_KIBANA_USER.USERNAME, @@ -109,7 +107,7 @@ export const createUsersAndRoles = async (es, supertest) => { roles: [], full_name: 'not a kibana user', email: 'not_a_kibana_user@elastic.co', - } + }, }); await es.shield.putUser({ @@ -119,17 +117,17 @@ export const createUsersAndRoles = async (es, supertest) => { roles: ['kibana_legacy_user'], full_name: 'a kibana legacy user', email: 'a_kibana_legacy_user@elastic.co', - } + }, }); await es.shield.putUser({ username: AUTHENTICATION.KIBANA_LEGACY_DASHBOARD_ONLY_USER.USERNAME, body: { password: AUTHENTICATION.KIBANA_LEGACY_DASHBOARD_ONLY_USER.PASSWORD, - roles: ["kibana_legacy_dashboard_only_user"], + roles: ['kibana_legacy_dashboard_only_user'], full_name: 'a kibana legacy dashboard only user', email: 'a_kibana_legacy_dashboard_only_user@elastic.co', - } + }, }); await es.shield.putUser({ @@ -139,17 +137,17 @@ export const createUsersAndRoles = async (es, supertest) => { roles: ['kibana_dual_privileges_user'], full_name: 'a kibana dual_privileges user', email: 'a_kibana_dual_privileges_user@elastic.co', - } + }, }); await es.shield.putUser({ username: AUTHENTICATION.KIBANA_DUAL_PRIVILEGES_DASHBOARD_ONLY_USER.USERNAME, body: { password: AUTHENTICATION.KIBANA_DUAL_PRIVILEGES_DASHBOARD_ONLY_USER.PASSWORD, - roles: ["kibana_dual_privileges_dashboard_only_user"], + roles: ['kibana_dual_privileges_dashboard_only_user'], full_name: 'a kibana dual_privileges dashboard only user', email: 'a_kibana_dual_privileges_dashboard_only_user@elastic.co', - } + }, }); await es.shield.putUser({ @@ -159,17 +157,17 @@ export const createUsersAndRoles = async (es, supertest) => { roles: ['kibana_rbac_user'], full_name: 'a kibana user', email: 'a_kibana_rbac_user@elastic.co', - } + }, }); await es.shield.putUser({ username: AUTHENTICATION.KIBANA_RBAC_DASHBOARD_ONLY_USER.USERNAME, body: { password: AUTHENTICATION.KIBANA_RBAC_DASHBOARD_ONLY_USER.PASSWORD, - roles: ["kibana_rbac_dashboard_only_user"], + roles: ['kibana_rbac_dashboard_only_user'], full_name: 'a kibana dashboard only user', email: 'a_kibana_rbac_dashboard_only_user@elastic.co', - } + }, }); await es.shield.putUser({ @@ -179,7 +177,7 @@ export const createUsersAndRoles = async (es, supertest) => { roles: ['kibana_rbac_default_space_all_user'], full_name: 'a kibana default space all user', email: 'a_kibana_rbac_default_space_all_user@elastic.co', - } + }, }); await es.shield.putUser({ @@ -189,7 +187,7 @@ export const createUsersAndRoles = async (es, supertest) => { roles: ['kibana_rbac_default_space_read_user'], full_name: 'a kibana default space read-only user', email: 'a_kibana_rbac_default_space_read_user@elastic.co', - } + }, }); await es.shield.putUser({ @@ -199,7 +197,7 @@ export const createUsersAndRoles = async (es, supertest) => { roles: ['kibana_rbac_space_1_all_user'], full_name: 'a kibana rbac space 1 all user', email: 'a_kibana_rbac_space_1_all_user@elastic.co', - } + }, }); await es.shield.putUser({ @@ -209,6 +207,6 @@ export const createUsersAndRoles = async (es, supertest) => { roles: ['kibana_rbac_space_1_read_user'], full_name: 'a kibana rbac space 1 read-only user', email: 'a_kibana_rbac_space_1_readonly_user@elastic.co', - } + }, }); }; diff --git a/x-pack/test/saved_object_api_integration/common/lib/types.ts b/x-pack/test/saved_object_api_integration/common/lib/types.ts index 47ae6cb7ae2431..fc6d3d8745fb93 100644 --- a/x-pack/test/saved_object_api_integration/common/lib/types.ts +++ b/x-pack/test/saved_object_api_integration/common/lib/types.ts @@ -6,33 +6,19 @@ export type DescribeFn = (text: string, fn: () => void) => void; -export interface TestResultDescriptor { - statusCode: number; - response: (resp: any) => void; - space?: any; -} - -export interface TestsObject { - [key: string]: TestResultDescriptor; -} - export interface TestDefinitionAuthentication { username?: string; password?: string; } -export interface TestOptions { - auth?: TestDefinitionAuthentication; - currentSpaceId?: string; - spaceId?: string; - tests: TestsObject; -} - 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; } diff --git a/x-pack/test/saved_object_api_integration/common/services/es.js b/x-pack/test/saved_object_api_integration/common/services/es.ts similarity index 82% rename from x-pack/test/saved_object_api_integration/common/services/es.js rename to x-pack/test/saved_object_api_integration/common/services/es.ts index c4fa7c504e12cd..f5ef3be4b4bde2 100644 --- a/x-pack/test/saved_object_api_integration/common/services/es.js +++ b/x-pack/test/saved_object_api_integration/common/services/es.ts @@ -8,13 +8,14 @@ import { format as formatUrl } from 'url'; import elasticsearch from 'elasticsearch'; import shieldPlugin from '../../../../server/lib/esjs_shield_plugin'; +import { TestInvoker } from '../lib/types'; -export function EsProvider({ getService }) { +export function EsProvider({ getService }: TestInvoker) { const config = getService('config'); return new elasticsearch.Client({ host: formatUrl(config.get('servers.elasticsearch')), requestTimeout: config.get('timeouts.esRequestTimeout'), - plugins: [shieldPlugin] + plugins: [shieldPlugin], }); } diff --git a/x-pack/test/saved_object_api_integration/common/suites/saved_objects/find.ts b/x-pack/test/saved_object_api_integration/common/suites/saved_objects/find.ts index 12ddad282befac..554b5fc4928d45 100644 --- a/x-pack/test/saved_object_api_integration/common/suites/saved_objects/find.ts +++ b/x-pack/test/saved_object_api_integration/common/suites/saved_objects/find.ts @@ -106,7 +106,7 @@ export function findTestSuiteFactory(esArchiver: any, supertest: SuperTest) }); }; - const createExpectRbacForbidden = (type: string) => (resp: any) => { + const createExpectRbacForbidden = (type?: string) => (resp: any) => { const message = type ? `Unable to find ${type}, missing action:saved_objects/${type}/find` : `Not authorized to find saved_object`; diff --git a/x-pack/test/saved_object_api_integration/security_and_spaces/apis/index.js b/x-pack/test/saved_object_api_integration/security_and_spaces/apis/index.ts similarity index 68% rename from x-pack/test/saved_object_api_integration/security_and_spaces/apis/index.js rename to x-pack/test/saved_object_api_integration/security_and_spaces/apis/index.ts index a0c45c37a3b9ff..8dc2fec5190cd5 100644 --- a/x-pack/test/saved_object_api_integration/security_and_spaces/apis/index.js +++ b/x-pack/test/saved_object_api_integration/security_and_spaces/apis/index.ts @@ -3,9 +3,11 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { createUsersAndRoles } from "../../common/lib/create_users_and_roles"; +import { createUsersAndRoles } from '../../common/lib/create_users_and_roles'; +import { TestInvoker } from '../../common/lib/types'; -export default function ({ loadTestFile, getService }) { +// tslint:disable:no-default-export +export default function({ loadTestFile, getService }: TestInvoker) { const es = getService('es'); const supertest = getService('supertest'); diff --git a/x-pack/test/saved_object_api_integration/security_and_spaces/apis/saved_objects/index.js b/x-pack/test/saved_object_api_integration/security_and_spaces/apis/saved_objects/index.ts similarity index 79% rename from x-pack/test/saved_object_api_integration/security_and_spaces/apis/saved_objects/index.js rename to x-pack/test/saved_object_api_integration/security_and_spaces/apis/saved_objects/index.ts index 4c15c8044436db..b0f3ceb14e8a60 100644 --- a/x-pack/test/saved_object_api_integration/security_and_spaces/apis/saved_objects/index.js +++ b/x-pack/test/saved_object_api_integration/security_and_spaces/apis/saved_objects/index.ts @@ -4,9 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ +import { TestInvoker } from '../../../common/lib/types'; - -export default function ({ loadTestFile }) { +// tslint:disable:no-default-export +export default function({ loadTestFile }: TestInvoker) { describe('saved_objects', () => { loadTestFile(require.resolve('./bulk_get')); loadTestFile(require.resolve('./create')); diff --git a/x-pack/test/saved_object_api_integration/security_and_spaces/config.js b/x-pack/test/saved_object_api_integration/security_and_spaces/config.ts similarity index 91% rename from x-pack/test/saved_object_api_integration/security_and_spaces/config.js rename to x-pack/test/saved_object_api_integration/security_and_spaces/config.ts index 5873a050577d7b..81cf9d85671d18 100644 --- a/x-pack/test/saved_object_api_integration/security_and_spaces/config.js +++ b/x-pack/test/saved_object_api_integration/security_and_spaces/config.ts @@ -6,4 +6,5 @@ import { createTestConfig } from '../common/config'; +// tslint:disable:no-default-export export default createTestConfig('security_and_spaces', { license: 'trial' }); diff --git a/x-pack/test/saved_object_api_integration/security_only/apis/index.js b/x-pack/test/saved_object_api_integration/security_only/apis/index.ts similarity index 78% rename from x-pack/test/saved_object_api_integration/security_only/apis/index.js rename to x-pack/test/saved_object_api_integration/security_only/apis/index.ts index 5fbea60eb56291..a4cc59af0b7305 100644 --- a/x-pack/test/saved_object_api_integration/security_only/apis/index.js +++ b/x-pack/test/saved_object_api_integration/security_only/apis/index.ts @@ -4,8 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ import { createUsersAndRoles } from '../../common/lib/create_users_and_roles'; +import { TestInvoker } from '../../common/lib/types'; -export default function ({ loadTestFile, getService }) { +// tslint:disable:no-default-export +export default function({ loadTestFile, getService }: TestInvoker) { const es = getService('es'); const supertest = getService('supertest'); diff --git a/x-pack/test/saved_object_api_integration/security_only/apis/saved_objects/index.js b/x-pack/test/saved_object_api_integration/security_only/apis/saved_objects/index.ts similarity index 59% rename from x-pack/test/saved_object_api_integration/security_only/apis/saved_objects/index.js rename to x-pack/test/saved_object_api_integration/security_only/apis/saved_objects/index.ts index 4c15c8044436db..1b1ae2c8a3c4de 100644 --- a/x-pack/test/saved_object_api_integration/security_only/apis/saved_objects/index.js +++ b/x-pack/test/saved_object_api_integration/security_only/apis/saved_objects/index.ts @@ -4,9 +4,16 @@ * you may not use this file except in compliance with the Elastic License. */ +import { TestInvoker } from '../../../common/lib/types'; +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ -export default function ({ loadTestFile }) { +// tslint:disable:no-default-export +export default function({ loadTestFile }: TestInvoker) { describe('saved_objects', () => { loadTestFile(require.resolve('./bulk_get')); loadTestFile(require.resolve('./create')); diff --git a/x-pack/test/saved_object_api_integration/security_only/config.js b/x-pack/test/saved_object_api_integration/security_only/config.ts similarity index 83% rename from x-pack/test/saved_object_api_integration/security_only/config.js rename to x-pack/test/saved_object_api_integration/security_only/config.ts index d76161b08d0032..f71cc9207b3cc7 100644 --- a/x-pack/test/saved_object_api_integration/security_only/config.js +++ b/x-pack/test/saved_object_api_integration/security_only/config.ts @@ -6,4 +6,5 @@ import { createTestConfig } from '../common/config'; -export default createTestConfig('security_only', { disabledPlugins: ['spaces'], license: 'trial', }); +// tslint:disable:no-default-export +export default createTestConfig('security_only', { disabledPlugins: ['spaces'], license: 'trial' }); diff --git a/x-pack/test/saved_object_api_integration/spaces_only/apis/index.js b/x-pack/test/saved_object_api_integration/spaces_only/apis/index.js deleted file mode 100644 index 3c747f65541329..00000000000000 --- a/x-pack/test/saved_object_api_integration/spaces_only/apis/index.js +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -export default function ({ loadTestFile }) { - describe('apis spaces', () => { - loadTestFile(require.resolve('./saved_objects')); - }); -} diff --git a/x-pack/test/saved_object_api_integration/spaces_only/apis/index.ts b/x-pack/test/saved_object_api_integration/spaces_only/apis/index.ts new file mode 100644 index 00000000000000..a1c07ab90e7628 --- /dev/null +++ b/x-pack/test/saved_object_api_integration/spaces_only/apis/index.ts @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { TestInvoker } from '../../common/lib/types'; + +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +// tslint:disable:no-default-export +export default function({ loadTestFile }: TestInvoker) { + describe('apis spaces', () => { + loadTestFile(require.resolve('./saved_objects')); + }); +} diff --git a/x-pack/test/saved_object_api_integration/spaces_only/apis/saved_objects/index.js b/x-pack/test/saved_object_api_integration/spaces_only/apis/saved_objects/index.ts similarity index 59% rename from x-pack/test/saved_object_api_integration/spaces_only/apis/saved_objects/index.js rename to x-pack/test/saved_object_api_integration/spaces_only/apis/saved_objects/index.ts index c74b03792ba034..1b1ae2c8a3c4de 100644 --- a/x-pack/test/saved_object_api_integration/spaces_only/apis/saved_objects/index.js +++ b/x-pack/test/saved_object_api_integration/spaces_only/apis/saved_objects/index.ts @@ -4,9 +4,16 @@ * you may not use this file except in compliance with the Elastic License. */ +import { TestInvoker } from '../../../common/lib/types'; -export default function ({ loadTestFile }) { +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +// tslint:disable:no-default-export +export default function({ loadTestFile }: TestInvoker) { describe('saved_objects', () => { loadTestFile(require.resolve('./bulk_get')); loadTestFile(require.resolve('./create')); diff --git a/x-pack/test/saved_object_api_integration/spaces_only/config.js b/x-pack/test/saved_object_api_integration/spaces_only/config.ts similarity index 91% rename from x-pack/test/saved_object_api_integration/spaces_only/config.js rename to x-pack/test/saved_object_api_integration/spaces_only/config.ts index 9390ef12f51d0a..38d65bab1b107b 100644 --- a/x-pack/test/saved_object_api_integration/spaces_only/config.js +++ b/x-pack/test/saved_object_api_integration/spaces_only/config.ts @@ -6,4 +6,5 @@ import { createTestConfig } from '../common/config'; +// tslint:disable:no-default-export export default createTestConfig('spaces_only', { license: 'basic' });