Skip to content

Commit 0fec6cb

Browse files
Spencerspalgerkibanamachine
authored
[ci] run server integration tests (#81698)
Co-authored-by: spalger <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
1 parent 25f680e commit 0fec6cb

File tree

19 files changed

+132
-89
lines changed

19 files changed

+132
-89
lines changed

packages/kbn-dev-utils/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export {
3434
KBN_P12_PATH,
3535
KBN_P12_PASSWORD,
3636
} from './certs';
37-
export { KbnClient } from './kbn_client';
37+
export * from './kbn_client';
3838
export * from './run';
3939
export * from './axios';
4040
export * from './stdio';

packages/kbn-dev-utils/src/kbn_client/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
* under the License.
1818
*/
1919

20-
export { KbnClient } from './kbn_client';
20+
export * from './kbn_client';
2121
export { uriencode } from './kbn_client_requester';

packages/kbn-dev-utils/src/kbn_client/kbn_client.ts

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,55 @@
1818
*/
1919

2020
import { ToolingLog } from '../tooling_log';
21-
import { KibanaConfig, KbnClientRequester, ReqOptions } from './kbn_client_requester';
21+
import { KbnClientRequester, ReqOptions } from './kbn_client_requester';
2222
import { KbnClientStatus } from './kbn_client_status';
2323
import { KbnClientPlugins } from './kbn_client_plugins';
2424
import { KbnClientVersion } from './kbn_client_version';
2525
import { KbnClientSavedObjects } from './kbn_client_saved_objects';
2626
import { KbnClientUiSettings, UiSettingValues } from './kbn_client_ui_settings';
2727

28+
export interface KbnClientOptions {
29+
url: string;
30+
certificateAuthorities?: Buffer[];
31+
log: ToolingLog;
32+
uiSettingDefaults?: UiSettingValues;
33+
}
34+
2835
export class KbnClient {
29-
private readonly requester = new KbnClientRequester(this.log, this.kibanaConfig);
30-
readonly status = new KbnClientStatus(this.requester);
31-
readonly plugins = new KbnClientPlugins(this.status);
32-
readonly version = new KbnClientVersion(this.status);
33-
readonly savedObjects = new KbnClientSavedObjects(this.log, this.requester);
34-
readonly uiSettings = new KbnClientUiSettings(this.log, this.requester, this.uiSettingDefaults);
36+
readonly status: KbnClientStatus;
37+
readonly plugins: KbnClientPlugins;
38+
readonly version: KbnClientVersion;
39+
readonly savedObjects: KbnClientSavedObjects;
40+
readonly uiSettings: KbnClientUiSettings;
41+
42+
private readonly requester: KbnClientRequester;
43+
private readonly log: ToolingLog;
44+
private readonly uiSettingDefaults?: UiSettingValues;
3545

3646
/**
3747
* Basic Kibana server client that implements common behaviors for talking
3848
* to the Kibana server from dev tooling.
39-
*
40-
* @param log ToolingLog
41-
* @param kibanaUrls Array of kibana server urls to send requests to
42-
* @param uiSettingDefaults Map of uiSetting values that will be merged with all uiSetting resets
4349
*/
44-
constructor(
45-
private readonly log: ToolingLog,
46-
private readonly kibanaConfig: KibanaConfig,
47-
private readonly uiSettingDefaults?: UiSettingValues
48-
) {
49-
if (!kibanaConfig.url) {
50-
throw new Error('missing Kibana urls');
50+
constructor(options: KbnClientOptions) {
51+
if (!options.url) {
52+
throw new Error('missing Kibana url');
5153
}
54+
if (!options.log) {
55+
throw new Error('missing ToolingLog');
56+
}
57+
58+
this.log = options.log;
59+
this.uiSettingDefaults = options.uiSettingDefaults;
60+
61+
this.requester = new KbnClientRequester(this.log, {
62+
url: options.url,
63+
certificateAuthorities: options.certificateAuthorities,
64+
});
65+
this.status = new KbnClientStatus(this.requester);
66+
this.plugins = new KbnClientPlugins(this.status);
67+
this.version = new KbnClientVersion(this.status);
68+
this.savedObjects = new KbnClientSavedObjects(this.log, this.requester);
69+
this.uiSettings = new KbnClientUiSettings(this.log, this.requester, this.uiSettingDefaults);
5270
}
5371

5472
/**

packages/kbn-dev-utils/src/kbn_client/kbn_client_requester.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,27 @@ const delay = (ms: number) =>
6969
setTimeout(resolve, ms);
7070
});
7171

72-
export interface KibanaConfig {
72+
interface Options {
7373
url: string;
74-
ssl?: {
75-
enabled: boolean;
76-
key: string;
77-
certificate: string;
78-
certificateAuthorities: string;
79-
};
74+
certificateAuthorities?: Buffer[];
8075
}
8176

8277
export class KbnClientRequester {
78+
private readonly url: string;
8379
private readonly httpsAgent: Https.Agent | null;
84-
constructor(private readonly log: ToolingLog, private readonly kibanaConfig: KibanaConfig) {
80+
81+
constructor(private readonly log: ToolingLog, options: Options) {
82+
this.url = options.url;
8583
this.httpsAgent =
86-
kibanaConfig.ssl && kibanaConfig.ssl.enabled
84+
Url.parse(options.url).protocol === 'https:'
8785
? new Https.Agent({
88-
cert: kibanaConfig.ssl.certificate,
89-
key: kibanaConfig.ssl.key,
90-
ca: kibanaConfig.ssl.certificateAuthorities,
86+
ca: options.certificateAuthorities,
9187
})
9288
: null;
9389
}
9490

9591
private pickUrl() {
96-
return this.kibanaConfig.url;
92+
return this.url;
9793
}
9894

9995
public resolveUrl(relativeUrl: string = '/') {
@@ -132,7 +128,7 @@ export class KbnClientRequester {
132128
errorMessage = `Conflict on GET (path=${options.path}, attempt=${attempt}/${maxAttempts})`;
133129
this.log.error(errorMessage);
134130
} else if (requestedRetries || failedToGetResponse) {
135-
errorMessage = `[${description}] request failed (attempt=${attempt}/${maxAttempts})`;
131+
errorMessage = `[${description}] request failed (attempt=${attempt}/${maxAttempts}): ${error.message}`;
136132
this.log.error(errorMessage);
137133
} else {
138134
throw error;

packages/kbn-es-archiver/src/es_archiver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class EsArchiver {
4949
this.client = client;
5050
this.dataDir = dataDir;
5151
this.log = log;
52-
this.kbnClient = new KbnClient(log, { url: kibanaUrl });
52+
this.kbnClient = new KbnClient({ log, url: kibanaUrl });
5353
}
5454

5555
/**

packages/kbn-test/src/functional_test_runner/lib/config/schema.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,7 @@ const urlPartsSchema = () =>
3838
password: Joi.string(),
3939
pathname: Joi.string().regex(/^\//, 'start with a /'),
4040
hash: Joi.string().regex(/^\//, 'start with a /'),
41-
ssl: Joi.object()
42-
.keys({
43-
enabled: Joi.boolean().default(false),
44-
certificate: Joi.string().optional(),
45-
certificateAuthorities: Joi.string().optional(),
46-
key: Joi.string().optional(),
47-
})
48-
.default(),
41+
certificateAuthorities: Joi.array().items(Joi.binary()).optional(),
4942
})
5043
.default();
5144

test/common/services/kibana_server/kibana_server.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ export function KibanaServerProvider({ getService }: FtrProviderContext) {
2727
const config = getService('config');
2828
const lifecycle = getService('lifecycle');
2929
const url = Url.format(config.get('servers.kibana'));
30-
const ssl = config.get('servers.kibana').ssl;
3130
const defaults = config.get('uiSettings.defaults');
32-
const kbn = new KbnClient(log, { url, ssl }, defaults);
31+
const kbn = new KbnClient({
32+
log,
33+
url,
34+
certificateAuthorities: config.get('servers.kibana.certificateAuthorities'),
35+
uiSettingDefaults: defaults,
36+
});
3337

3438
if (defaults) {
3539
lifecycle.beforeTests.add(async () => {

test/scripts/server_integration.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
source test/scripts/jenkins_test_setup_oss.sh
4+
5+
yarn run grunt run:serverIntegrationTests

test/server_integration/http/ssl/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,22 @@ import { createKibanaSupertestProvider } from '../../services';
2323

2424
export default async function ({ readConfigFile }) {
2525
const httpConfig = await readConfigFile(require.resolve('../../config'));
26+
const certificateAuthorities = [readFileSync(CA_CERT_PATH)];
2627

2728
return {
2829
testFiles: [require.resolve('./')],
2930
services: {
3031
...httpConfig.get('services'),
3132
supertest: createKibanaSupertestProvider({
32-
certificateAuthorities: [readFileSync(CA_CERT_PATH)],
33+
certificateAuthorities,
3334
}),
3435
},
3536
servers: {
3637
...httpConfig.get('servers'),
3738
kibana: {
3839
...httpConfig.get('servers.kibana'),
3940
protocol: 'https',
41+
certificateAuthorities,
4042
},
4143
},
4244
junit: {

test/server_integration/http/ssl_redirect/config.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,30 @@
1717
* under the License.
1818
*/
1919

20+
import Url from 'url';
2021
import { readFileSync } from 'fs';
2122
import { CA_CERT_PATH, KBN_CERT_PATH, KBN_KEY_PATH } from '@kbn/dev-utils';
2223

2324
import { createKibanaSupertestProvider } from '../../services';
2425

2526
export default async function ({ readConfigFile }) {
2627
const httpConfig = await readConfigFile(require.resolve('../../config'));
28+
const certificateAuthorities = [readFileSync(CA_CERT_PATH)];
2729

28-
const redirectPort = httpConfig.get('servers.kibana.port') + 1;
29-
const supertestOptions = {
30-
...httpConfig.get('servers.kibana'),
31-
port: redirectPort,
32-
// test with non ssl protocol
33-
protocol: 'http',
34-
};
30+
const redirectPort = httpConfig.get('servers.kibana.port') + 1234;
3531

3632
return {
3733
testFiles: [require.resolve('./')],
3834
services: {
3935
...httpConfig.get('services'),
4036
supertest: createKibanaSupertestProvider({
41-
certificateAuthorities: [readFileSync(CA_CERT_PATH)],
42-
options: supertestOptions,
37+
certificateAuthorities,
38+
kibanaUrl: Url.format({
39+
...httpConfig.get('servers.kibana'),
40+
port: redirectPort,
41+
// test with non ssl protocol
42+
protocol: 'http',
43+
}),
4344
}),
4445
},
4546
servers: {
@@ -48,6 +49,7 @@ export default async function ({ readConfigFile }) {
4849
...httpConfig.get('servers.kibana'),
4950
// start the server with https
5051
protocol: 'https',
52+
certificateAuthorities,
5153
},
5254
},
5355
junit: {

0 commit comments

Comments
 (0)