Skip to content

Commit 189f17c

Browse files
authored
Merge branch 'main' into security/tests/162839-exceptions-read-only-view
2 parents 0e5695f + c328d2d commit 189f17c

6 files changed

Lines changed: 78 additions & 50 deletions

File tree

x-pack/plugins/reporting/common/constants/report_types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
// Export Type Definitions
9-
export const CSV_REPORT_TYPE = 'CSV';
9+
export const CSV_REPORT_TYPE = 'csv_searchsource';
1010
export const CSV_REPORT_TYPE_V2 = 'csv_v2';
1111

1212
export const PDF_REPORT_TYPE = 'printablePdf';

x-pack/plugins/reporting/public/share_context_menu/reporting_panel_content/reporting_panel_content.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ class ReportingPanelContentUi extends Component<Props, State> {
251251
case PDF_REPORT_TYPE:
252252
case PDF_REPORT_TYPE_V2:
253253
return 'PDF';
254-
case 'csv_searchsource':
255-
return CSV_REPORT_TYPE;
254+
case CSV_REPORT_TYPE:
255+
return 'csv';
256256
case 'png':
257257
case PNG_REPORT_TYPE_V2:
258258
return PNG_REPORT_TYPE;

x-pack/plugins/reporting/server/core.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,22 +226,27 @@ export class ReportingCore {
226226
* only CSV export types should be registered in the export types registry for serverless
227227
*/
228228
private getExportTypes(): ExportType[] {
229+
const { csv, pdf, png } = this.config.export_types;
229230
const exportTypes = [];
230-
if (!this.config.export_types.pdf.enabled || !this.config.export_types.png.enabled) {
231-
exportTypes.push(
232-
new CsvSearchSourceExportType(this.core, this.config, this.logger, this.context)
233-
);
234-
exportTypes.push(new CsvV2ExportType(this.core, this.config, this.logger, this.context));
235-
} else {
231+
232+
if (csv.enabled) {
233+
// NOTE: CsvSearchSourceExportType should be deprecated and replaced with V2 in the UI: https://github.com/elastic/kibana/issues/151190
236234
exportTypes.push(
237235
new CsvSearchSourceExportType(this.core, this.config, this.logger, this.context)
238236
);
239237
exportTypes.push(new CsvV2ExportType(this.core, this.config, this.logger, this.context));
238+
}
239+
240+
if (pdf.enabled) {
241+
// NOTE: PdfV1ExportType is deprecated and tagged for removal: https://github.com/elastic/kibana/issues/154601
242+
exportTypes.push(new PdfV1ExportType(this.core, this.config, this.logger, this.context));
240243
exportTypes.push(new PdfExportType(this.core, this.config, this.logger, this.context));
244+
}
245+
246+
if (png.enabled) {
241247
exportTypes.push(new PngExportType(this.core, this.config, this.logger, this.context));
242-
// deprecated export types for tests
243-
exportTypes.push(new PdfV1ExportType(this.core, this.config, this.logger, this.context));
244248
}
249+
245250
return exportTypes;
246251
}
247252

x-pack/plugins/reporting/server/plugin.test.ts

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@
77

88
import type { CoreSetup, CoreStart, Logger } from '@kbn/core/server';
99
import { coreMock, loggingSystemMock } from '@kbn/core/server/mocks';
10-
import { PDF_REPORT_TYPE_V2, PNG_REPORT_TYPE_V2 } from '../common/constants/report_types';
10+
import {
11+
CSV_REPORT_TYPE,
12+
CSV_REPORT_TYPE_V2,
13+
PDF_REPORT_TYPE,
14+
PDF_REPORT_TYPE_V2,
15+
PNG_REPORT_TYPE_V2,
16+
} from '../common/constants';
1117
import type { ReportingCore, ReportingInternalStart } from './core';
18+
import { ExportTypesRegistry } from './lib/export_types_registry';
1219
import { ReportingPlugin } from './plugin';
1320
import {
1421
createMockConfigSchema,
@@ -30,6 +37,8 @@ describe('Reporting Plugin', () => {
3037
let plugin: ReportingPlugin;
3138

3239
beforeEach(async () => {
40+
jest.clearAllMocks();
41+
3342
configSchema = createMockConfigSchema();
3443
initContext = coreMock.createPluginInitializerContext(configSchema);
3544
coreSetup = coreMock.createSetup(configSchema);
@@ -81,50 +90,62 @@ describe('Reporting Plugin', () => {
8190
`);
8291
expect(logger.error).toHaveBeenCalledTimes(2);
8392
});
84-
describe('config and export types registry validation', () => {
85-
it('expect image reporting to be in registry by default', async () => {
86-
// wait for the setup phase background work
87-
plugin.setup(coreSetup, pluginSetup);
88-
await new Promise(setImmediate);
89-
90-
// create a way for an error to happen
91-
const reportingCore = (plugin as unknown as { reportingCore: ReportingCore }).reportingCore;
92-
93-
// wait for the startup phase background work
94-
plugin.start(coreStart, pluginStart);
95-
await new Promise(setImmediate);
96-
expect(reportingCore.getExportTypesRegistry().getById(PDF_REPORT_TYPE_V2)).toHaveProperty(
97-
'id',
98-
PDF_REPORT_TYPE_V2
99-
);
100-
expect(reportingCore.getExportTypesRegistry().getById(PNG_REPORT_TYPE_V2)).toHaveProperty(
101-
'id',
102-
PNG_REPORT_TYPE_V2
103-
);
93+
94+
describe('config and export types registration', () => {
95+
jest.mock('./lib/export_types_registry');
96+
ExportTypesRegistry.prototype.getAll = jest.fn(() => []); // code breaks if getAll returns undefined
97+
let registerSpy: jest.SpyInstance;
98+
99+
beforeEach(async () => {
100+
registerSpy = jest.spyOn(ExportTypesRegistry.prototype, 'register');
101+
pluginSetup = createMockPluginSetup({}) as unknown as ReportingSetupDeps;
102+
pluginStart = await createMockPluginStart(coreStart, configSchema);
103+
plugin = new ReportingPlugin(initContext);
104+
});
105+
106+
it('expect all report types to be in registry', async () => {
107+
// check the spy function
108+
expect(registerSpy).toHaveBeenCalledTimes(5);
109+
expect(registerSpy).toHaveBeenCalledWith(expect.objectContaining({ id: CSV_REPORT_TYPE }));
110+
expect(registerSpy).toHaveBeenCalledWith(expect.objectContaining({ id: CSV_REPORT_TYPE_V2 }));
111+
expect(registerSpy).toHaveBeenCalledWith(expect.objectContaining({ id: PDF_REPORT_TYPE }));
112+
expect(registerSpy).toHaveBeenCalledWith(expect.objectContaining({ id: PDF_REPORT_TYPE_V2 }));
113+
expect(registerSpy).toHaveBeenCalledWith(expect.objectContaining({ id: PNG_REPORT_TYPE_V2 }));
104114
});
105-
it('expect pdf to not be in registry if config does not enable it', async () => {
106-
configSchema = { ...createMockConfigSchema(), export_types: { pdf: { enabled: false } } };
115+
116+
it('expect image report types not to be in registry if disabled', async () => {
117+
jest.clearAllMocks();
118+
119+
configSchema = createMockConfigSchema({
120+
export_types: {
121+
csv: { enabled: true },
122+
pdf: { enabled: false },
123+
png: { enabled: false },
124+
},
125+
});
126+
107127
initContext = coreMock.createPluginInitializerContext(configSchema);
108128
coreSetup = coreMock.createSetup(configSchema);
109129
coreStart = coreMock.createStart();
110130
pluginSetup = createMockPluginSetup({}) as unknown as ReportingSetupDeps;
111131
pluginStart = await createMockPluginStart(coreStart, configSchema);
112-
113132
plugin = new ReportingPlugin(initContext);
114-
// wait for the setup phase background work
115-
plugin.setup(coreSetup, pluginSetup);
116-
await new Promise(setImmediate);
117-
118-
// create a way for an error to happen
119-
const reportingCore = (plugin as unknown as { reportingCore: ReportingCore }).reportingCore;
120-
121-
// wait for the startup phase background work
122-
plugin.start(coreStart, pluginStart);
123-
await new Promise(setImmediate);
124-
const checkPdf = () => reportingCore.getExportTypesRegistry().getById(PDF_REPORT_TYPE_V2);
125-
const checkPng = () => reportingCore.getExportTypesRegistry().getById(PNG_REPORT_TYPE_V2);
126-
expect(checkPdf).toThrowError(`Unknown id ${PDF_REPORT_TYPE_V2}`);
127-
expect(checkPng).toThrowError(`Unknown id ${PNG_REPORT_TYPE_V2}`);
133+
134+
// check the spy function was called with CSV
135+
expect(registerSpy).toHaveBeenCalledTimes(2);
136+
expect(registerSpy).toHaveBeenCalledWith(expect.objectContaining({ id: CSV_REPORT_TYPE }));
137+
expect(registerSpy).toHaveBeenCalledWith(expect.objectContaining({ id: CSV_REPORT_TYPE_V2 }));
138+
139+
// check the spy function was NOT called with anything else
140+
expect(registerSpy).not.toHaveBeenCalledWith(
141+
expect.objectContaining({ id: PDF_REPORT_TYPE })
142+
);
143+
expect(registerSpy).not.toHaveBeenCalledWith(
144+
expect.objectContaining({ id: PDF_REPORT_TYPE_V2 })
145+
);
146+
expect(registerSpy).not.toHaveBeenCalledWith(
147+
expect.objectContaining({ id: PNG_REPORT_TYPE_V2 })
148+
);
128149
});
129150
});
130151
});

x-pack/plugins/reporting/server/test_helpers/create_mock_reportingplugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export const createMockConfigSchema = (
115115
pdf: { enabled: true },
116116
png: { enabled: true },
117117
csv: { enabled: true },
118+
...overrides.export_types,
118119
},
119120
} as ReportingConfigType;
120121
};

x-pack/test/detection_engine_api_integration/security_and_spaces/group4/telemetry/task_based/detection_rules.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export default ({ getService }: FtrProviderContext) => {
3434
const log = getService('log');
3535
const retry = getService('retry');
3636

37-
describe('Detection rule task telemetry', async () => {
37+
// Failing: See https://github.com/elastic/kibana/issues/164318
38+
describe.skip('Detection rule task telemetry', async () => {
3839
before(async () => {
3940
await esArchiver.load('x-pack/test/functional/es_archives/security_solution/telemetry');
4041
});

0 commit comments

Comments
 (0)