mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[env] throw an error when UUID file is empty (#164802)
## Summary Another victim of the infamous javascript true-ish/false-ish. Fix a bug that allowed an empty UUID file to bypass the regexp validation and use an empty string as instance UUID.
This commit is contained in:
parent
76ac34a9b7
commit
b74311ffc9
2 changed files with 13 additions and 1 deletions
|
@ -158,6 +158,15 @@ describe('resolveInstanceUuid', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('when file exists but is empty', () => {
|
||||
it('throws an explicit error for uuid formatting', async () => {
|
||||
mockReadFile({ uuid: '' });
|
||||
await expect(
|
||||
resolveInstanceUuid({ pathConfig, serverConfig, logger })
|
||||
).rejects.toThrowErrorMatchingInlineSnapshot(`"data-folder/uuid contains an invalid UUID"`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when file contains a trailing new line', () => {
|
||||
it('returns the trimmed file uuid', async () => {
|
||||
mockReadFile({ uuid: DEFAULT_FILE_UUID + '\n' });
|
||||
|
|
|
@ -65,13 +65,16 @@ export async function resolveInstanceUuid({
|
|||
|
||||
async function readUuidFromFile(filepath: string, logger: Logger): Promise<string | undefined> {
|
||||
const content = await readFileContent(filepath);
|
||||
if (content === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (content === UUID_7_6_0_BUG) {
|
||||
logger.debug(`UUID from 7.6.0 bug detected, ignoring file UUID`);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (content && !content.match(uuidRegexp)) {
|
||||
if (!content.match(uuidRegexp)) {
|
||||
throw new Error(`${filepath} contains an invalid UUID`);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue