Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed May 9, 2023
1 parent 3b040c8 commit 096531e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 32 deletions.
5 changes: 2 additions & 3 deletions x-pack/plugins/reporting/server/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export const config: PluginConfigDescriptor<ReportingConfigType> = {
},
};

export { registerUiSettings } from './ui_settings';
export type { ReportingConfigType };
export { ConfigSchema };
export { createConfig } from './create_config';
export { registerUiSettings } from './ui_settings';
export { type ReportingConfigType, ConfigSchema };
16 changes: 2 additions & 14 deletions x-pack/plugins/reporting/server/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@ export interface ReportingInternalStart {
taskManager: TaskManagerStartContract;
}

export interface ReportingServerConfig {
basePath: string;
hostname: string;
name: string;
port: number;
uuid: string;
protocol: string;
}

/**
* @internal
*/
Expand Down Expand Up @@ -252,7 +243,7 @@ export class ReportingCore {
/*
* Returns configurable server info
*/
public getServerInfo(): ReportingServerConfig {
public getServerInfo() {
const { http } = this.core;
const serverInfo = http.getServerInfo();
return {
Expand All @@ -268,10 +259,7 @@ export class ReportingCore {
/*
* Gives synchronous access to the config
*/
public getConfig() {
if (!this.config) {
throw new Error('Config is not yet initialized');
}
public getConfig(): ReportingConfigType {
return this.config;
}

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

import { ReportingCore } from '../..';
import { createMockReportingCore, createMockConfigSchema } from '../../test_helpers';
import { createMockConfigSchema, createMockReportingCore } from '../../test_helpers';
import { TaskPayloadPNG } from '../png/types';
import { TaskPayloadPDF } from '../printable_pdf/types';
import { getFullUrls } from './get_full_urls';

let reporting: ReportingCore;
let mockReporting: ReportingCore;

beforeEach(async () => {
reporting = await createMockReportingCore(createMockConfigSchema());
reporting.getServerInfo = jest.fn(() => ({
mockReporting = await createMockReportingCore(createMockConfigSchema());
mockReporting.getServerInfo = jest.fn(() => ({
hostname: 'localhost',
port: 5601,
protocol: 'http',
Expand All @@ -28,7 +28,7 @@ beforeEach(async () => {
const getMockJob = (base: object) => base as TaskPayloadPNG & TaskPayloadPDF;

test(`fails if no URL is passed`, async () => {
const fn = () => getFullUrls(reporting, getMockJob({}));
const fn = () => getFullUrls(mockReporting, getMockJob({}));
expect(fn).toThrowErrorMatchingInlineSnapshot(
`"No valid URL fields found in Job Params! Expected \`job.relativeUrl\` or \`job.objects[{ relativeUrl }]\`"`
);
Expand All @@ -37,7 +37,7 @@ test(`fails if no URL is passed`, async () => {
test(`fails if URLs are file-protocols for PNGs`, async () => {
const forceNow = '2000-01-01T00:00:00.000Z';
const relativeUrl = 'file://etc/passwd/#/something';
const fn = () => getFullUrls(reporting, getMockJob({ relativeUrl, forceNow }));
const fn = () => getFullUrls(mockReporting, getMockJob({ relativeUrl, forceNow }));
expect(fn).toThrowErrorMatchingInlineSnapshot(
`"Found invalid URL(s), all URLs must be relative: file://etc/passwd/#/something"`
);
Expand All @@ -47,7 +47,7 @@ test(`fails if URLs are absolute for PNGs`, async () => {
const forceNow = '2000-01-01T00:00:00.000Z';
const relativeUrl =
'http://169.254.169.254/latest/meta-data/iam/security-credentials/profileName/#/something';
const fn = () => getFullUrls(reporting, getMockJob({ relativeUrl, forceNow }));
const fn = () => getFullUrls(mockReporting, getMockJob({ relativeUrl, forceNow }));
expect(fn).toThrowErrorMatchingInlineSnapshot(
`"Found invalid URL(s), all URLs must be relative: http://169.254.169.254/latest/meta-data/iam/security-credentials/profileName/#/something"`
);
Expand All @@ -56,7 +56,7 @@ test(`fails if URLs are absolute for PNGs`, async () => {
test(`fails if URLs are file-protocols for PDF`, async () => {
const forceNow = '2000-01-01T00:00:00.000Z';
const relativeUrl = 'file://etc/passwd/#/something';
const fn = () => getFullUrls(reporting, getMockJob({ objects: [{ relativeUrl }], forceNow }));
const fn = () => getFullUrls(mockReporting, getMockJob({ objects: [{ relativeUrl }], forceNow }));
expect(fn).toThrowErrorMatchingInlineSnapshot(
`"Found invalid URL(s), all URLs must be relative: file://etc/passwd/#/something"`
);
Expand All @@ -68,7 +68,7 @@ test(`fails if URLs are absolute for PDF`, async () => {
'http://169.254.169.254/latest/meta-data/iam/security-credentials/profileName/#/something';
const fn = () =>
getFullUrls(
reporting,
mockReporting,
getMockJob({
objects: [{ relativeUrl }],
forceNow,
Expand All @@ -90,14 +90,14 @@ test(`fails if any URLs are absolute or file's for PDF`, async () => {
{ relativeUrl: 'file://etc/passwd/#/something' },
];

const fn = () => getFullUrls(reporting, getMockJob({ objects, forceNow }));
const fn = () => getFullUrls(mockReporting, getMockJob({ objects, forceNow }));
expect(fn).toThrowErrorMatchingInlineSnapshot(
`"Found invalid URL(s), all URLs must be relative: http://169.254.169.254/latest/meta-data/iam/security-credentials/profileName/#/something file://etc/passwd/#/something"`
);
});

test(`fails if URL does not route to a visualization`, async () => {
const fn = () => getFullUrls(reporting, getMockJob({ relativeUrl: '/app/phoney' }));
const fn = () => getFullUrls(mockReporting, getMockJob({ relativeUrl: '/app/phoney' }));
expect(fn).toThrowErrorMatchingInlineSnapshot(
`"No valid hash in the URL! A hash is expected for the application to route to the intended visualization."`
);
Expand All @@ -106,7 +106,7 @@ test(`fails if URL does not route to a visualization`, async () => {
test(`adds forceNow to hash's query, if it exists`, async () => {
const forceNow = '2000-01-01T00:00:00.000Z';
const urls = getFullUrls(
reporting,
mockReporting,
getMockJob({ relativeUrl: '/app/kibana#/something', forceNow })
);

Expand All @@ -119,7 +119,7 @@ test(`appends forceNow to hash's query, if it exists`, async () => {
const forceNow = '2000-01-01T00:00:00.000Z';

const urls = getFullUrls(
reporting,
mockReporting,
getMockJob({ relativeUrl: '/app/kibana#/something?_g=something', forceNow })
);

Expand All @@ -129,15 +129,15 @@ test(`appends forceNow to hash's query, if it exists`, async () => {
});

test(`doesn't append forceNow query to url, if it doesn't exists`, async () => {
const urls = getFullUrls(reporting, getMockJob({ relativeUrl: '/app/kibana#/something' }));
const urls = getFullUrls(mockReporting, getMockJob({ relativeUrl: '/app/kibana#/something' }));

expect(urls[0]).toEqual('http://localhost:5601/sbp/app/kibana#/something');
});

test(`adds forceNow to each of multiple urls`, async () => {
const forceNow = '2000-01-01T00:00:00.000Z';
const urls = getFullUrls(
reporting,
mockReporting,
getMockJob({
objects: [
{ relativeUrl: '/app/kibana#/something_aaa' },
Expand Down

0 comments on commit 096531e

Please sign in to comment.