Skip to content

Commit 9946258

Browse files
authored
fix(8.19, fips): skip tests not compatible with FIPS when running in FIPS mode (elastic#219914)
## Summary Skip tests not compatible with FIPS when running in FIPS mode.
1 parent 6400493 commit 9946258

File tree

4 files changed

+282
-254
lines changed

4 files changed

+282
-254
lines changed

src/core/server/integration_tests/saved_objects/migrations/group2/batch_size_bytes.test.ts

Lines changed: 88 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { LogRecord } from '@kbn/logging';
2424
import { retryAsync } from '@kbn/core-saved-objects-migration-server-mocks';
2525
import { delay } from '../test_utils';
2626
import { EsVersion } from '@kbn/test';
27+
import { getFips } from 'crypto';
2728

2829
const kibanaVersion = Env.createDefault(REPO_ROOT, getEnvOptions()).packageInfo.version;
2930
const targetIndex = `.kibana_${kibanaVersion}_001`;
@@ -33,6 +34,7 @@ async function removeLogFile() {
3334
// ignore errors if it doesn't exist
3435
await fs.unlink(logFilePath).catch(() => void 0);
3536
}
37+
3638
function sortByTypeAndId(a: { type: string; id: string }, b: { type: string; id: string }) {
3739
return a.type.localeCompare(b.type) || a.id.localeCompare(b.id);
3840
}
@@ -64,88 +66,94 @@ describe('migration v2', () => {
6466
let startES: () => Promise<TestElasticsearchUtils>;
6567
let dataArchive: string;
6668

67-
beforeAll(async () => {
68-
const willRunESv9 = EsVersion.getDefault({ integrationTest: true }).matchRange('9');
69-
dataArchive = Path.join(
70-
__dirname,
71-
'..',
72-
'archives',
73-
willRunESv9
74-
? '8.18.0_xpack_sample_saved_objects.zip'
75-
: '7.14.0_xpack_sample_saved_objects.zip'
76-
);
77-
await removeLogFile();
78-
});
79-
80-
beforeEach(() => {
81-
({ startES } = createTestServers({
82-
adjustTimeout: (t: number) => jest.setTimeout(t),
83-
settings: {
84-
es: {
85-
license: 'basic',
86-
dataArchive,
87-
esArgs: ['http.max_content_length=1715329b'],
69+
if (getFips() === 0) {
70+
beforeAll(async () => {
71+
const willRunESv9 = EsVersion.getDefault({ integrationTest: true }).matchRange('9');
72+
dataArchive = Path.join(
73+
__dirname,
74+
'..',
75+
'archives',
76+
willRunESv9
77+
? '8.18.0_xpack_sample_saved_objects.zip'
78+
: '7.14.0_xpack_sample_saved_objects.zip'
79+
);
80+
await removeLogFile();
81+
});
82+
83+
beforeEach(() => {
84+
({ startES } = createTestServers({
85+
adjustTimeout: (t: number) => jest.setTimeout(t),
86+
settings: {
87+
es: {
88+
license: 'basic',
89+
dataArchive,
90+
esArgs: ['http.max_content_length=1715329b'],
91+
},
8892
},
89-
},
90-
}));
91-
});
92-
93-
afterEach(async () => {
94-
if (root) {
95-
await root.shutdown();
96-
}
97-
if (esServer) {
98-
await esServer.stop();
99-
await delay(10);
100-
}
101-
});
102-
103-
it('completes the migration even when a full batch would exceed ES http.max_content_length', async () => {
104-
root = createRoot({ maxBatchSizeBytes: 1715329 });
105-
esServer = await startES();
106-
await root.preboot();
107-
await root.setup();
108-
await expect(root.start()).resolves.toBeTruthy();
109-
110-
// After plugins start, some saved objects are deleted/recreated, so we
111-
// wait a bit for the count to settle.
112-
await new Promise((resolve) => setTimeout(resolve, 5000));
113-
114-
const esClient: ElasticsearchClient = esServer.es.getClient();
115-
116-
// assert that the docs from the original index have been migrated rather than comparing a doc count after startup
117-
const originalDocs = await fetchDocuments(esClient, '.kibana_7.14.0_001');
118-
const migratedDocs = await fetchDocuments(esClient, targetIndex);
119-
expect(assertMigratedDocuments(migratedDocs, originalDocs));
120-
});
121-
122-
it('fails with a descriptive message when a single document exceeds maxBatchSizeBytes', async () => {
123-
root = createRoot({ maxBatchSizeBytes: 1015275 });
124-
esServer = await startES();
125-
await root.preboot();
126-
await root.setup();
127-
await expect(root.start()).rejects.toMatchInlineSnapshot(
128-
`[Error: Unable to complete saved object migrations for the [.kibana] index: The document with _id "canvas-workpad-template:workpad-template-061d7868-2b4e-4dc8-8bf7-3772b52926e5" is 1715319 bytes which exceeds the configured maximum batch size of 1015275 bytes. To proceed, please increase the 'migrations.maxBatchSizeBytes' Kibana configuration option and ensure that the Elasticsearch 'http.max_content_length' configuration option is set to an equal or larger value.]`
129-
);
130-
131-
await retryAsync(
132-
async () => {
133-
const logFileContent = await fs.readFile(logFilePath, 'utf-8');
134-
const records = logFileContent
135-
.split('\n')
136-
.filter(Boolean)
137-
.map((str) => JSON5.parse(str)) as LogRecord[];
138-
expect(
139-
records.find((rec) =>
140-
rec.message.startsWith(
141-
`Reason: Unable to complete saved object migrations for the [.kibana] index: The document with _id "canvas-workpad-template:workpad-template-061d7868-2b4e-4dc8-8bf7-3772b52926e5" is 1715319 bytes which exceeds the configured maximum batch size of 1015275 bytes. To proceed, please increase the 'migrations.maxBatchSizeBytes' Kibana configuration option and ensure that the Elasticsearch 'http.max_content_length' configuration option is set to an equal or larger value.`
93+
}));
94+
});
95+
96+
afterEach(async () => {
97+
if (root) {
98+
await root.shutdown();
99+
}
100+
if (esServer) {
101+
await esServer.stop();
102+
await delay(10);
103+
}
104+
});
105+
106+
it('completes the migration even when a full batch would exceed ES http.max_content_length', async () => {
107+
root = createRoot({ maxBatchSizeBytes: 1715329 });
108+
esServer = await startES();
109+
await root.preboot();
110+
await root.setup();
111+
await expect(root.start()).resolves.toBeTruthy();
112+
113+
// After plugins start, some saved objects are deleted/recreated, so we
114+
// wait a bit for the count to settle.
115+
await new Promise((resolve) => setTimeout(resolve, 5000));
116+
117+
const esClient: ElasticsearchClient = esServer.es.getClient();
118+
119+
// assert that the docs from the original index have been migrated rather than comparing a doc count after startup
120+
const originalDocs = await fetchDocuments(esClient, '.kibana_7.14.0_001');
121+
const migratedDocs = await fetchDocuments(esClient, targetIndex);
122+
expect(assertMigratedDocuments(migratedDocs, originalDocs));
123+
});
124+
125+
it('fails with a descriptive message when a single document exceeds maxBatchSizeBytes', async () => {
126+
root = createRoot({ maxBatchSizeBytes: 1015275 });
127+
esServer = await startES();
128+
await root.preboot();
129+
await root.setup();
130+
await expect(root.start()).rejects.toMatchInlineSnapshot(
131+
`[Error: Unable to complete saved object migrations for the [.kibana] index: The document with _id "canvas-workpad-template:workpad-template-061d7868-2b4e-4dc8-8bf7-3772b52926e5" is 1715319 bytes which exceeds the configured maximum batch size of 1015275 bytes. To proceed, please increase the 'migrations.maxBatchSizeBytes' Kibana configuration option and ensure that the Elasticsearch 'http.max_content_length' configuration option is set to an equal or larger value.]`
132+
);
133+
134+
await retryAsync(
135+
async () => {
136+
const logFileContent = await fs.readFile(logFilePath, 'utf-8');
137+
const records = logFileContent
138+
.split('\n')
139+
.filter(Boolean)
140+
.map((str) => JSON5.parse(str)) as LogRecord[];
141+
expect(
142+
records.find((rec) =>
143+
rec.message.startsWith(
144+
`Reason: Unable to complete saved object migrations for the [.kibana] index: The document with _id "canvas-workpad-template:workpad-template-061d7868-2b4e-4dc8-8bf7-3772b52926e5" is 1715319 bytes which exceeds the configured maximum batch size of 1015275 bytes. To proceed, please increase the 'migrations.maxBatchSizeBytes' Kibana configuration option and ensure that the Elasticsearch 'http.max_content_length' configuration option is set to an equal or larger value.`
145+
)
142146
)
143-
)
144-
).toBeDefined();
145-
},
146-
{ retryAttempts: 10, retryDelayMs: 200 }
147-
);
148-
});
147+
).toBeDefined();
148+
},
149+
{ retryAttempts: 10, retryDelayMs: 200 }
150+
);
151+
});
152+
} else {
153+
it('cannot run tests with dataArchives that have a basic license in FIPS mode', () => {
154+
expect(getFips()).toBe(1);
155+
});
156+
}
149157
});
150158

151159
function createRoot(options: { maxBatchSizeBytes?: number }) {

src/core/server/integration_tests/saved_objects/migrations/group3/migration_from_older_v1.test.ts

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@ import {
2525
import { InternalCoreStart } from '@kbn/core-lifecycle-server-internal';
2626
import { Root } from '@kbn/core-root-server-internal';
2727
import { EsVersion } from '@kbn/test';
28+
import { getFips } from 'crypto';
2829

2930
const kibanaVersion = Env.createDefault(REPO_ROOT, getEnvOptions()).packageInfo.version;
3031

3132
const logFilePath = Path.join(__dirname, 'migration_from_older_v1.log');
3233

3334
const asyncUnlink = Util.promisify(Fs.unlink);
35+
3436
async function removeLogFile() {
3537
// ignore errors if it doesn't exist
3638
await asyncUnlink(logFilePath).catch(() => void 0);
3739
}
40+
3841
const assertMigratedDocuments = (arr: any[], target: any[]) => target.every((v) => arr.includes(v));
3942

4043
function sortByTypeAndId(a: { type: string; id: string }, b: { type: string; id: string }) {
@@ -177,51 +180,59 @@ describeIf('migrating from 7.3.0-xpack which used v1 migrations', () => {
177180
await esServer.stop();
178181
}
179182
};
180-
181-
beforeAll(async () => {
182-
await removeLogFile();
183-
await startServers({
184-
oss: false,
185-
dataArchive: Path.join(__dirname, '..', 'archives', '7.3.0_xpack_sample_saved_objects.zip'),
183+
if (getFips() === 0) {
184+
beforeAll(async () => {
185+
await removeLogFile();
186+
await startServers({
187+
oss: false,
188+
dataArchive: Path.join(__dirname, '..', 'archives', '7.3.0_xpack_sample_saved_objects.zip'),
189+
});
186190
});
187-
});
188191

189-
afterAll(async () => {
190-
await stopServers();
191-
});
192+
afterAll(async () => {
193+
await stopServers();
194+
});
192195

193-
it('creates the new index and the correct aliases', async () => {
194-
const body = await esClient.indices.get(
195-
{
196-
index: migratedIndex,
197-
},
198-
{ ignore: [404] }
199-
);
196+
it('creates the new index and the correct aliases', async () => {
197+
const body = await esClient.indices.get(
198+
{
199+
index: migratedIndex,
200+
},
201+
{ ignore: [404] }
202+
);
200203

201-
const response = body[migratedIndex];
204+
const response = body[migratedIndex];
202205

203-
expect(response).toBeDefined();
204-
expect(Object.keys(response.aliases!).sort()).toEqual(['.kibana', `.kibana_${kibanaVersion}`]);
205-
});
206+
expect(response).toBeDefined();
207+
expect(Object.keys(response.aliases!).sort()).toEqual([
208+
'.kibana',
209+
`.kibana_${kibanaVersion}`,
210+
]);
211+
});
206212

207-
it('copies all the document of the previous index to the new one', async () => {
208-
const originalDocs = await fetchDocuments(esClient, originalIndex);
209-
const migratedDocs = await fetchDocuments(esClient, migratedIndex);
210-
expect(assertMigratedDocuments(migratedDocs, originalDocs));
211-
});
213+
it('copies all the document of the previous index to the new one', async () => {
214+
const originalDocs = await fetchDocuments(esClient, originalIndex);
215+
const migratedDocs = await fetchDocuments(esClient, migratedIndex);
216+
expect(assertMigratedDocuments(migratedDocs, originalDocs));
217+
});
212218

213-
it('migrates the documents to the highest version', async () => {
214-
const expectedVersions = getExpectedVersionPerType();
215-
const res = await esClient.search({
216-
index: migratedIndex,
217-
body: {
218-
sort: ['_doc'],
219-
},
220-
size: 10000,
219+
it('migrates the documents to the highest version', async () => {
220+
const expectedVersions = getExpectedVersionPerType();
221+
const res = await esClient.search({
222+
index: migratedIndex,
223+
body: {
224+
sort: ['_doc'],
225+
},
226+
size: 10000,
227+
});
228+
const allDocuments = res.hits.hits as SavedObjectsRawDoc[];
229+
allDocuments.forEach((doc) => {
230+
assertMigrationVersion(doc, expectedVersions);
231+
});
221232
});
222-
const allDocuments = res.hits.hits as SavedObjectsRawDoc[];
223-
allDocuments.forEach((doc) => {
224-
assertMigrationVersion(doc, expectedVersions);
233+
} else {
234+
it('cannot run tests with dataArchives that have a basic license in FIPS mode', () => {
235+
expect(getFips()).toBe(1);
225236
});
226-
});
237+
}
227238
});

0 commit comments

Comments
 (0)