-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
_import_objects.ts
493 lines (403 loc) · 22.3 KB
/
_import_objects.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
/*
* 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 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 or the Server
* Side Public License, v 1.
*/
import expect from '@kbn/expect';
import path from 'path';
import { keyBy } from 'lodash';
import { FtrProviderContext } from '../../ftr_provider_context';
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
function uniq<T>(input: T[]): T[] {
return [...new Set(input)];
}
export default function ({ getService, getPageObjects }: FtrProviderContext) {
const kibanaServer = getService('kibanaServer');
const esArchiver = getService('esArchiver');
const PageObjects = getPageObjects(['common', 'settings', 'header', 'savedObjects']);
const testSubjects = getService('testSubjects');
const log = getService('log');
describe('import objects', function describeIndexTests() {
describe('.ndjson file', () => {
beforeEach(async function () {
await esArchiver.load('test/functional/fixtures/es_archiver/management');
await kibanaServer.uiSettings.replace({});
await PageObjects.settings.navigateTo();
await PageObjects.settings.clickKibanaSavedObjects();
});
afterEach(async function () {
await esArchiver.unload('test/functional/fixtures/es_archiver/management');
});
it('should import saved objects', async function () {
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects.ndjson')
);
await PageObjects.savedObjects.checkImportSucceeded();
await PageObjects.savedObjects.clickImportDone();
log.debug("check that 'Log Agents' is in table as a visualization");
expect(await PageObjects.savedObjects.getObjectTypeByTitle('Log Agents')).to.eql(
'visualization'
);
await PageObjects.savedObjects.clickRelationshipsByTitle('logstash-*');
const flyout = keyBy(await PageObjects.savedObjects.getRelationshipFlyout(), 'title');
log.debug(
"check that 'Shared-Item Visualization AreaChart' shows 'logstash-*' as it's Parent"
);
expect(flyout['Shared-Item Visualization AreaChart'].relationship).to.eql('Parent');
log.debug("check that 'Log Agents' shows 'logstash-*' as it's Parent");
expect(flyout['Log Agents'].relationship).to.eql('Parent');
});
it('should import saved objects with circular refs', async function () {
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_circular_refs.ndjson')
);
await PageObjects.savedObjects.checkImportSucceeded();
await PageObjects.savedObjects.clickImportDone();
await PageObjects.savedObjects.clickRelationshipsByTitle('dashboard-a');
const flyoutContent = await PageObjects.savedObjects.getRelationshipFlyout();
expect(uniq(flyoutContent.map(({ relationship }) => relationship).sort())).to.eql([
'Child',
'Parent',
]);
expect(uniq(flyoutContent.map(({ title }) => title))).to.eql(['dashboard-b']);
});
it('should provide dialog to allow the importing of saved objects with index pattern conflicts', async function () {
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_conflicts.ndjson')
);
await PageObjects.savedObjects.checkImportConflictsWarning();
await PageObjects.settings.associateIndexPattern(
'd1e4c910-a2e6-11e7-bb30-233be9be6a15',
'logstash-*'
);
await PageObjects.savedObjects.clickConfirmChanges();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.savedObjects.clickImportDone();
const objects = await PageObjects.savedObjects.getRowTitles();
const isSavedObjectImported = objects.includes('saved object with index pattern conflict');
expect(isSavedObjectImported).to.be(true);
});
it('should allow the user to override duplicate saved objects', async function () {
// This data has already been loaded by the "visualize" esArchive. We'll load it again
// so that we can override the existing visualization.
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_exists.ndjson'),
false
);
await PageObjects.savedObjects.checkImportConflictsWarning();
await PageObjects.settings.associateIndexPattern('logstash-*', 'logstash-*');
await PageObjects.savedObjects.clickConfirmChanges();
// Override the visualization.
await PageObjects.common.clickConfirmOnModal();
const isSuccessful = await testSubjects.exists('importSavedObjectsSuccess');
expect(isSuccessful).to.be(true);
});
it('should allow the user to cancel overriding duplicate saved objects', async function () {
// This data has already been loaded by the "visualize" esArchive. We'll load it again
// so that we can be prompted to override the existing visualization.
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_exists.ndjson'),
false
);
await PageObjects.savedObjects.checkImportConflictsWarning();
await PageObjects.settings.associateIndexPattern('logstash-*', 'logstash-*');
await PageObjects.savedObjects.clickConfirmChanges();
// *Don't* override the visualization.
await PageObjects.common.clickCancelOnModal();
const isSuccessful = await testSubjects.exists('importSavedObjectsSuccessNoneImported');
expect(isSuccessful).to.be(true);
});
it('should import saved objects linked to saved searches', async function () {
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_saved_search.ndjson')
);
await PageObjects.savedObjects.checkImportSucceeded();
await PageObjects.savedObjects.clickImportDone();
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_connected_to_saved_search.ndjson')
);
await PageObjects.savedObjects.checkImportSucceeded();
await PageObjects.savedObjects.clickImportDone();
const objects = await PageObjects.savedObjects.getRowTitles();
const isSavedObjectImported = objects.includes('saved object connected to saved search');
expect(isSavedObjectImported).to.be(true);
});
it('should not import saved objects linked to saved searches when saved search does not exist', async function () {
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_connected_to_saved_search.ndjson')
);
await PageObjects.savedObjects.checkNoneImported();
await PageObjects.savedObjects.clickImportDone();
const objects = await PageObjects.savedObjects.getRowTitles();
const isSavedObjectImported = objects.includes('saved object connected to saved search');
expect(isSavedObjectImported).to.be(false);
});
it('should not import saved objects linked to saved searches when saved search index pattern does not exist', async function () {
await PageObjects.savedObjects.clickCheckboxByTitle('logstash-*');
await PageObjects.savedObjects.clickDelete();
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_with_saved_search.ndjson')
);
// Wait for all the saves to happen
await PageObjects.savedObjects.checkImportConflictsWarning();
await PageObjects.savedObjects.clickConfirmChanges();
await PageObjects.savedObjects.clickImportDone();
const objects = await PageObjects.savedObjects.getRowTitles();
const isSavedObjectImported = objects.includes('saved object connected to saved search');
expect(isSavedObjectImported).to.be(false);
});
it('should import saved objects with index patterns when index patterns already exists', async () => {
// First, import the objects
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_with_index_patterns.ndjson')
);
await PageObjects.savedObjects.checkImportSucceeded();
await PageObjects.savedObjects.clickImportDone();
const objects = await PageObjects.savedObjects.getRowTitles();
const isSavedObjectImported = objects.includes('saved object imported with index pattern');
expect(isSavedObjectImported).to.be(true);
});
it('should import saved objects with index patterns when index patterns does not exists', async () => {
// First, we need to delete the index pattern
await PageObjects.savedObjects.clickCheckboxByTitle('logstash-*');
await PageObjects.savedObjects.clickDelete();
// Then, import the objects
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_with_index_patterns.ndjson')
);
await PageObjects.savedObjects.checkImportSucceeded();
await PageObjects.savedObjects.clickImportDone();
const objects = await PageObjects.savedObjects.getRowTitles();
const isSavedObjectImported = objects.includes('saved object imported with index pattern');
expect(isSavedObjectImported).to.be(true);
});
});
describe('.json file', () => {
beforeEach(async function () {
await esArchiver.load('test/functional/fixtures/es_archiver/saved_objects_imports');
await kibanaServer.uiSettings.replace({});
await PageObjects.settings.navigateTo();
await PageObjects.settings.clickKibanaSavedObjects();
});
afterEach(async function () {
await esArchiver.unload('test/functional/fixtures/es_archiver/saved_objects_imports');
});
it('should import saved objects', async function () {
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects.json')
);
await PageObjects.savedObjects.checkImportSucceeded();
await PageObjects.savedObjects.clickImportDone();
const objects = await PageObjects.savedObjects.getRowTitles();
const isSavedObjectImported = objects.includes('Log Agents');
expect(isSavedObjectImported).to.be(true);
});
it('should provide dialog to allow the importing of saved objects with index pattern conflicts', async function () {
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects-conflicts.json')
);
await PageObjects.savedObjects.checkImportLegacyWarning();
await PageObjects.savedObjects.checkImportConflictsWarning();
await PageObjects.settings.associateIndexPattern(
'd1e4c910-a2e6-11e7-bb30-233be9be6a15',
'logstash-*'
);
await PageObjects.savedObjects.clickConfirmChanges();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.savedObjects.clickImportDone();
const objects = await PageObjects.savedObjects.getRowTitles();
const isSavedObjectImported = objects.includes('saved object with index pattern conflict');
expect(isSavedObjectImported).to.be(true);
});
it('should allow the user to override duplicate saved objects', async function () {
// This data has already been loaded by the "visualize" esArchive. We'll load it again
// so that we can override the existing visualization.
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_exists.json'),
false
);
await PageObjects.savedObjects.checkImportLegacyWarning();
await PageObjects.savedObjects.checkImportConflictsWarning();
await PageObjects.settings.associateIndexPattern('logstash-*', 'logstash-*');
await PageObjects.savedObjects.clickConfirmChanges();
// Override the visualization.
await PageObjects.common.clickConfirmOnModal();
const isSuccessful = await testSubjects.exists('importSavedObjectsSuccess');
expect(isSuccessful).to.be(true);
});
it('should allow the user to cancel overriding duplicate saved objects', async function () {
// This data has already been loaded by the "visualize" esArchive. We'll load it again
// so that we can be prompted to override the existing visualization.
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_exists.json'),
false
);
await PageObjects.savedObjects.checkImportLegacyWarning();
await PageObjects.savedObjects.checkImportConflictsWarning();
await PageObjects.settings.associateIndexPattern('logstash-*', 'logstash-*');
await PageObjects.savedObjects.clickConfirmChanges();
// *Don't* override the visualization.
await PageObjects.common.clickCancelOnModal();
const isSuccessful = await testSubjects.exists('importSavedObjectsSuccessNoneImported');
expect(isSuccessful).to.be(true);
});
it('should allow the user to confirm overriding multiple duplicate saved objects', async function () {
// This data has already been loaded by the "visualize" esArchive. We'll load it again
// so that we can override the existing visualization.
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_multiple_exists.json'),
false
);
await PageObjects.savedObjects.checkImportLegacyWarning();
await PageObjects.savedObjects.checkImportConflictsWarning();
await PageObjects.settings.associateIndexPattern('logstash-*', 'logstash-*');
await PageObjects.savedObjects.clickConfirmChanges();
// Override the visualizations.
await PageObjects.common.clickConfirmOnModal(false);
// as the second confirm can pop instantly, we can't wait for it to be hidden
// with is why we call clickConfirmOnModal with ensureHidden: false in previous statement
// but as the initial popin can take a few ms before fading, we need to wait a little
// to avoid clicking twice on the same modal.
await delay(1000);
await PageObjects.common.clickConfirmOnModal(true);
const isSuccessful = await testSubjects.exists('importSavedObjectsSuccess');
expect(isSuccessful).to.be(true);
});
it('should allow the user to confirm overriding multiple duplicate index patterns', async function () {
// This data has already been loaded by the "visualize" esArchive. We'll load it again
// so that we can override the existing visualization.
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_index_patterns_multiple_exists.json'),
false
);
// Override the index patterns.
await PageObjects.common.clickConfirmOnModal(false);
// as the second confirm can pop instantly, we can't wait for it to be hidden
// with is why we call clickConfirmOnModal with ensureHidden: false in previous statement
// but as the initial popin can take a few ms before fading, we need to wait a little
// to avoid clicking twice on the same modal.
await delay(1000);
await PageObjects.common.clickConfirmOnModal(true);
const isSuccessful = await testSubjects.exists('importSavedObjectsSuccess');
expect(isSuccessful).to.be(true);
});
it('should import saved objects linked to saved searches', async function () {
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_saved_search.json')
);
await PageObjects.savedObjects.checkImportSucceeded();
await PageObjects.savedObjects.clickImportDone();
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_connected_to_saved_search.json')
);
await PageObjects.savedObjects.checkImportSucceeded();
await PageObjects.savedObjects.clickImportDone();
const objects = await PageObjects.savedObjects.getRowTitles();
const isSavedObjectImported = objects.includes('saved object connected to saved search');
expect(isSavedObjectImported).to.be(true);
});
it('should not import saved objects linked to saved searches when saved search does not exist', async function () {
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_connected_to_saved_search.json')
);
await PageObjects.savedObjects.checkImportFailedWarning();
await PageObjects.savedObjects.clickImportDone();
const objects = await PageObjects.savedObjects.getRowTitles();
const isSavedObjectImported = objects.includes('saved object connected to saved search');
expect(isSavedObjectImported).to.be(false);
});
it('should not import saved objects linked to saved searches when saved search index pattern does not exist', async function () {
// First, import the saved search
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_saved_search.json')
);
// Wait for all the saves to happen
await PageObjects.savedObjects.checkImportSucceeded();
await PageObjects.savedObjects.clickImportDone();
// Second, we need to delete the index pattern
await PageObjects.savedObjects.clickCheckboxByTitle('logstash-*');
await PageObjects.savedObjects.clickDelete();
// Last, import a saved object connected to the saved search
// This should NOT show the conflicts
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_connected_to_saved_search.json')
);
// Wait for all the saves to happen
await PageObjects.savedObjects.checkNoneImported();
await PageObjects.savedObjects.clickImportDone();
const objects = await PageObjects.savedObjects.getRowTitles();
const isSavedObjectImported = objects.includes('saved object connected to saved search');
expect(isSavedObjectImported).to.be(false);
});
it('should import saved objects with index patterns when index patterns already exists', async () => {
// First, import the objects
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_with_index_patterns.json')
);
await PageObjects.savedObjects.clickImportDone();
const objects = await PageObjects.savedObjects.getRowTitles();
const isSavedObjectImported = objects.includes('saved object imported with index pattern');
expect(isSavedObjectImported).to.be(true);
});
it('should preserve index patterns selection when switching between pages', async () => {
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_objects_missing_all_index_patterns.json')
);
await PageObjects.savedObjects.setOverriddenIndexPatternValue(
'missing-index-pattern-1',
'index-pattern-test-1'
);
const flyout = await testSubjects.find('importSavedObjectsFlyout');
await (await flyout.findByTestSubject('pagination-button-next')).click();
await PageObjects.savedObjects.setOverriddenIndexPatternValue(
'missing-index-pattern-7',
'index-pattern-test-2'
);
await (await flyout.findByTestSubject('pagination-button-previous')).click();
const selectedIdForMissingIndexPattern1 = await testSubjects.getAttribute(
'managementChangeIndexSelection-missing-index-pattern-1',
'value'
);
expect(selectedIdForMissingIndexPattern1).to.eql('f1e4c910-a2e6-11e7-bb30-233be9be6a20');
await (await flyout.findByTestSubject('pagination-button-next')).click();
const selectedIdForMissingIndexPattern7 = await testSubjects.getAttribute(
'managementChangeIndexSelection-missing-index-pattern-7',
'value'
);
expect(selectedIdForMissingIndexPattern7).to.eql('f1e4c910-a2e6-11e7-bb30-233be9be6a87');
});
it('should display an explicit error message when importing object from a higher Kibana version', async () => {
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_higher_version.ndjson')
);
await PageObjects.savedObjects.checkImportError();
const errorText = await PageObjects.savedObjects.getImportErrorText();
expect(errorText).to.contain(
`has property "visualization" which belongs to a more recent version of Kibana [9.15.82]`
);
});
describe('when bigger than savedObjects.maxImportPayloadBytes (not Cloud)', function () {
// see --savedObjects.maxImportPayloadBytes in config file
this.tags(['skipCloud']);
it('should display an explicit error message when importing a file bigger than allowed', async () => {
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_too_big.ndjson')
);
await PageObjects.savedObjects.checkImportError();
const errorText = await PageObjects.savedObjects.getImportErrorText();
expect(errorText).to.contain(`Payload content length greater than maximum allowed`);
});
});
it('should display an explicit error message when importing an invalid file', async () => {
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', '_import_invalid_format.ndjson')
);
await PageObjects.savedObjects.checkImportError();
const errorText = await PageObjects.savedObjects.getImportErrorText();
expect(errorText).to.contain(`Unexpected token T in JSON at position 0`);
});
});
});
}