Skip to content

Commit

Permalink
Even more typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
kobelb committed Sep 7, 2018
1 parent 369a429 commit 1b2708f
Show file tree
Hide file tree
Showing 15 changed files with 173 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>) => {
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,
Expand All @@ -109,7 +107,7 @@ export const createUsersAndRoles = async (es, supertest) => {
roles: [],
full_name: 'not a kibana user',
email: '[email protected]',
}
},
});

await es.shield.putUser({
Expand All @@ -119,17 +117,17 @@ export const createUsersAndRoles = async (es, supertest) => {
roles: ['kibana_legacy_user'],
full_name: 'a kibana legacy user',
email: '[email protected]',
}
},
});

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: '[email protected]',
}
},
});

await es.shield.putUser({
Expand All @@ -139,17 +137,17 @@ export const createUsersAndRoles = async (es, supertest) => {
roles: ['kibana_dual_privileges_user'],
full_name: 'a kibana dual_privileges user',
email: '[email protected]',
}
},
});

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: '[email protected]',
}
},
});

await es.shield.putUser({
Expand All @@ -159,17 +157,17 @@ export const createUsersAndRoles = async (es, supertest) => {
roles: ['kibana_rbac_user'],
full_name: 'a kibana user',
email: '[email protected]',
}
},
});

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: '[email protected]',
}
},
});

await es.shield.putUser({
Expand All @@ -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: '[email protected]',
}
},
});

await es.shield.putUser({
Expand All @@ -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: '[email protected]',
}
},
});

await es.shield.putUser({
Expand All @@ -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: '[email protected]',
}
},
});

await es.shield.putUser({
Expand All @@ -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: '[email protected]',
}
},
});
};
20 changes: 3 additions & 17 deletions x-pack/test/saved_object_api_integration/common/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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],
});
}
Loading

0 comments on commit 1b2708f

Please sign in to comment.