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
1 change: 1 addition & 0 deletions .buildkite/scout_ci_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins:
enabled:
- apm
- console
- dashboard
- discover_enhanced
- index_management
- infra
Expand Down
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -1768,7 +1768,6 @@ x-pack/solutions/observability/plugins/observability/server/lib/esql_extensions
/x-pack/platform/test/fixtures/es_archives/dashboard/async_search @elastic/kibana-presentation
/src/platform/test/functional/fixtures/kbn_archiver/dashboard @elastic/kibana-presentation
/src/platform/test/functional/fixtures/kbn_archiver/canvas @elastic/kibana-presentation
/src/platform/test/api_integration/apis/dashboards @elastic/kibana-presentation
/src/platform/test/interpreter_functional/snapshots @elastic/kibana-presentation # Assigned per https://github.com/elastic/kibana/pull/54342
/src/platform/test/functional/services/inspector.ts @elastic/kibana-presentation
/x-pack/platform/test/functional/services/canvas_element.ts @elastic/kibana-presentation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { servers as defaultConfig } from '../../../default/serverless/es.serverless.config';
import type { ScoutServerConfig } from '../../../../../types';

/**
* Custom Scout server configuration for OAS (OpenAPI Specification) schema validation tests.
* Enables the OAS endpoint which is required for schema validation.
*
* This config is automatically used when running tests from:
* dashboard/test/scout_oas_schema/
*
* Usage:
* node scripts/scout.js start-server --serverless=es --config-dir oas_schema
*/
export const servers: ScoutServerConfig = {
...defaultConfig,
kbnTestServer: {
...defaultConfig.kbnTestServer,
serverArgs: [
...defaultConfig.kbnTestServer.serverArgs,
// Enable OpenAPI specification endpoint for schema validation tests
'--server.oas.enabled=true',
],
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { servers as defaultConfig } from '../../../default/serverless/oblt.serverless.config';
import type { ScoutServerConfig } from '../../../../../types';

/**
* Custom Scout server configuration for OAS (OpenAPI Specification) schema validation tests.
* Enables the OAS endpoint which is required for schema validation.
*
* This config is automatically used when running tests from:
* dashboard/test/scout_oas_schema/
*
* Usage:
* node scripts/scout.js start-server --serverless=oblt --config-dir oas_schema
*/
export const servers: ScoutServerConfig = {
...defaultConfig,
kbnTestServer: {
...defaultConfig.kbnTestServer,
serverArgs: [
...defaultConfig.kbnTestServer.serverArgs,
// Enable OpenAPI specification endpoint for schema validation tests
'--server.oas.enabled=true',
],
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { servers as defaultConfig } from '../../../default/serverless/security.serverless.config';
import type { ScoutServerConfig } from '../../../../../types';

/**
* Custom Scout server configuration for OAS (OpenAPI Specification) schema validation tests.
* Enables the OAS endpoint which is required for schema validation.
*
* This config is automatically used when running tests from:
* dashboard/test/scout_oas_schema/
*
* Usage:
* node scripts/scout.js start-server --serverless=security --config-dir oas_schema
*/
export const servers: ScoutServerConfig = {
...defaultConfig,
kbnTestServer: {
...defaultConfig.kbnTestServer,
serverArgs: [
...defaultConfig.kbnTestServer.serverArgs,
// Enable OpenAPI specification endpoint for schema validation tests
'--server.oas.enabled=true',
],
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { ScoutServerConfig } from '../../../../../types';
import { defaultConfig } from '../../../default/stateful/base.config';

/**
* Custom Scout server configuration for OAS (OpenAPI Specification) schema validation tests.
* Enables the OAS endpoint which is required for schema validation.
*
* This config is automatically used when running tests from:
* dashboard/test/scout_oas_schema/
*
* Usage:
* node scripts/scout.js start-server --stateful --config-dir oas_schema
*/
export const servers: ScoutServerConfig = {
...defaultConfig,
kbnTestServer: {
...defaultConfig.kbnTestServer,
serverArgs: [
...defaultConfig.kbnTestServer.serverArgs,
// Enable OpenAPI specification endpoint for schema validation tests
'--server.oas.enabled=true',
],
},
};
4 changes: 4 additions & 0 deletions src/platform/plugins/shared/dashboard/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ dependsOn:
- '@kbn/core-http-server'
- '@kbn/core-chrome-layout-utils'
- '@kbn/cps'
- '@kbn/scout'
tags:
- plugin
- prod
Expand All @@ -123,6 +124,9 @@ fileGroups:
- common/**/*
- public/**/*
- server/**/*
- test/scout/**/*
- test/scout_oas_schema/**/*
- test/scout_oas_schema/**/*.json
- '!target/**/*'
tasks:
jest:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

/** The base API path for dashboard endpoints (no leading slash for apiClient). */
export const DASHBOARD_API_PATH = 'api/dashboards';

/** Common headers for Dashboard API requests (internal API version 1) */
export const COMMON_HEADERS = {
'kbn-xsrf': 'some-xsrf-token',
'x-elastic-internal-origin': 'kibana',
'elastic-api-version': '1',
} as const;

/** Test data paths */
export const KBN_ARCHIVES = {
BASIC: 'src/platform/test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json',
TAGS: 'src/platform/test/api_integration/fixtures/kbn_archiver/saved_objects/tags.json',
MANY_DASHBOARDS:
'src/platform/test/api_integration/fixtures/kbn_archiver/saved_objects/many-dashboards.json',
} as const;

/** Test dashboard ID used in fixtures - is a saved object loaded by the kbn_archiver */
export const TEST_DASHBOARD_ID = 'be3733a0-9efe-11e7-acb3-3dab96693fab';
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { FtrProviderContext } from '../../ftr_provider_context';
import type { ScoutTestFixtures, ScoutWorkerFixtures } from '@kbn/scout';
import { apiTest as baseApiTest } from '@kbn/scout';

export default function ({ loadTestFile }: FtrProviderContext) {
describe('dashboards', () => {
loadTestFile(require.resolve('./create_dashboard'));
loadTestFile(require.resolve('./delete_dashboard'));
loadTestFile(require.resolve('./get_dashboard'));
loadTestFile(require.resolve('./update_dashboard'));
loadTestFile(require.resolve('./search_dashboards'));
});
}
export const apiTest = baseApiTest.extend<ScoutTestFixtures, ScoutWorkerFixtures>({});

export { COMMON_HEADERS, DASHBOARD_API_PATH, KBN_ARCHIVES, TEST_DASHBOARD_ID } from './constants';
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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { createPlaywrightConfig } from '@kbn/scout';

export default createPlaywrightConfig({
testDir: './tests',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { RoleApiCredentials } from '@kbn/scout';
import { expect } from '@kbn/scout/api';
import { tags } from '@kbn/scout';
import {
apiTest,
COMMON_HEADERS,
DASHBOARD_API_PATH,
KBN_ARCHIVES,
TEST_DASHBOARD_ID,
} from '../fixtures';

apiTest.describe('dashboards - create', { tag: tags.ESS_ONLY }, () => {
let editorCredentials: RoleApiCredentials;

apiTest.beforeAll(async ({ kbnClient, requestAuth }) => {
editorCredentials = await requestAuth.getApiKey('editor');
await kbnClient.importExport.load(KBN_ARCHIVES.BASIC);
await kbnClient.importExport.load(KBN_ARCHIVES.TAGS);
});

apiTest.afterAll(async ({ kbnClient }) => {
await kbnClient.savedObjects.cleanStandardList();
});

apiTest('should create a dashboard', async ({ apiClient }) => {
const title = 'Hello world dashboard';

const response = await apiClient.post(DASHBOARD_API_PATH, {
headers: {
...COMMON_HEADERS,
...editorCredentials.apiKeyHeader,
},
body: {
data: {
title,
},
},
responseType: 'json',
});

expect(response).toHaveStatusCode(200);
expect(response.body.spaces).toStrictEqual(['default']);
expect(response.body.data).toStrictEqual({
title,
});
});

apiTest('can create a dashboard with a specific id', async ({ apiClient }) => {
const title = `foo-${Date.now()}-${Math.random()}`;
const id = `bar-${Date.now()}-${Math.random()}`;

const response = await apiClient.post(DASHBOARD_API_PATH, {
headers: {
...COMMON_HEADERS,
...editorCredentials.apiKeyHeader,
},
body: {
id,
data: {
title,
},
},
responseType: 'json',
});

expect(response).toHaveStatusCode(200);
expect(response.body.id).toBe(id);
});

// TODO Maybe move this test to x-pack/platform/test/api_integration/dashboards
apiTest('can create a dashboard in a defined space', async ({ apiClient }) => {
const title = `foo-${Date.now()}-${Math.random()}`;
const spaceId = 'space-1';

const response = await apiClient.post(DASHBOARD_API_PATH, {
headers: {
...COMMON_HEADERS,
...editorCredentials.apiKeyHeader,
},
body: {
data: {
title,
},
spaces: [spaceId],
},
responseType: 'json',
});

expect(response).toHaveStatusCode(200);
expect(response.body.spaces).toStrictEqual([spaceId]);
});

apiTest('return error if provided id already exists', async ({ apiClient }) => {
const title = `foo-${Date.now()}-${Math.random()}`;

const response = await apiClient.post(DASHBOARD_API_PATH, {
headers: {
...COMMON_HEADERS,
...editorCredentials.apiKeyHeader,
},
body: {
id: TEST_DASHBOARD_ID,
data: {
title,
},
},
responseType: 'json',
});

expect(response).toHaveStatusCode(409);
expect(response.body.message).toBe(`A dashboard with ID ${TEST_DASHBOARD_ID} already exists.`);
});

apiTest('validation - returns error when title is not provided', async ({ apiClient }) => {
const response = await apiClient.post(DASHBOARD_API_PATH, {
headers: {
...COMMON_HEADERS,
...editorCredentials.apiKeyHeader,
},
body: {
data: {},
},
responseType: 'json',
});

expect(response).toHaveStatusCode(400);
expect(response.body.message).toBe(
'[request body.data.title]: expected value of type [string] but got [undefined]'
);
});

apiTest('validation - returns error if panels is not an array', async ({ apiClient }) => {
const response = await apiClient.post(DASHBOARD_API_PATH, {
headers: {
...COMMON_HEADERS,
...editorCredentials.apiKeyHeader,
},
body: {
data: {
title: 'foo',
panels: {},
},
},
responseType: 'json',
});

expect(response).toHaveStatusCode(400);
expect(response.body.message).toBe(
'[request body.data.panels]: expected value of type [array] but got [Object]'
);
});
});
Loading