Skip to content

Commit

Permalink
[Tests] Update missing kibana and elastic references
Browse files Browse the repository at this point in the history
While generating more snapshots more Kibana and Elastic references
were caught. Updated the source code and re-ran yarn test:jest -u.

Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Mar 23, 2021
1 parent b70caf9 commit b16b428
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 39 deletions.
18 changes: 9 additions & 9 deletions src/core/server/environment/resolve_uuid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('resolveInstanceUuid', () => {
expect(logger.debug).toHaveBeenCalledTimes(1);
expect(logger.debug.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"Updating Kibana instance UUID to: CONFIG_UUID (was: FILE_UUID)",
"Updating OpenSearch Dashboards instance UUID to: CONFIG_UUID (was: FILE_UUID)",
]
`);
});
Expand All @@ -117,7 +117,7 @@ describe('resolveInstanceUuid', () => {
expect(logger.debug).toHaveBeenCalledTimes(1);
expect(logger.debug.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"Kibana instance UUID: CONFIG_UUID",
"OpenSearch Dashboards instance UUID: CONFIG_UUID",
]
`);
});
Expand All @@ -137,7 +137,7 @@ describe('resolveInstanceUuid', () => {
expect(logger.debug).toHaveBeenCalledTimes(1);
expect(logger.debug.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"Setting new Kibana instance UUID: CONFIG_UUID",
"Setting new OpenSearch Dashboards instance UUID: CONFIG_UUID",
]
`);
});
Expand All @@ -152,7 +152,7 @@ describe('resolveInstanceUuid', () => {
expect(logger.debug).toHaveBeenCalledTimes(1);
expect(logger.debug.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"Resuming persistent Kibana instance UUID: FILE_UUID",
"Resuming persistent OpenSearch Dashboards instance UUID: FILE_UUID",
]
`);
});
Expand All @@ -178,7 +178,7 @@ describe('resolveInstanceUuid', () => {
"UUID from 7.6.0 bug detected, ignoring file UUID",
],
Array [
"Setting new Kibana instance UUID: NEW_UUID",
"Setting new OpenSearch Dashboards instance UUID: NEW_UUID",
],
]
`);
Expand All @@ -204,7 +204,7 @@ describe('resolveInstanceUuid', () => {
"UUID from 7.6.0 bug detected, ignoring file UUID",
],
Array [
"Setting new Kibana instance UUID: CONFIG_UUID",
"Setting new OpenSearch Dashboards instance UUID: CONFIG_UUID",
],
]
`);
Expand All @@ -226,7 +226,7 @@ describe('resolveInstanceUuid', () => {
expect(logger.debug).toHaveBeenCalledTimes(1);
expect(logger.debug.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"Setting new Kibana instance UUID: NEW_UUID",
"Setting new OpenSearch Dashboards instance UUID: NEW_UUID",
]
`);
});
Expand All @@ -238,15 +238,15 @@ describe('resolveInstanceUuid', () => {
await expect(
resolveInstanceUuid({ pathConfig, serverConfig, logger })
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Unable to read Kibana UUID file, please check the uuid.server configuration value in opensearch_dashboards.yml and ensure Kibana has sufficient permissions to read / write to this file. Error was: EACCES"`
`"Unable to read OpenSearch Dashboards UUID file, please check the uuid.server configuration value in opensearch_dashboards.yml and ensure OpenSearch Dashboards has sufficient permissions to read / write to this file. Error was: EACCES"`
);
});
it('throws an explicit error for file write errors', async () => {
mockWriteFile(isDirectoryError);
await expect(
resolveInstanceUuid({ pathConfig, serverConfig, logger })
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Unable to write Kibana UUID file, please check the uuid.server configuration value in opensearch_dashboards.yml and ensure Kibana has sufficient permissions to read / write to this file. Error was: EISDIR"`
`"Unable to write OpenSearch Dashboards UUID file, please check the uuid.server configuration value in opensearch_dashboards.yml and ensure OpenSearch Dashboards has sufficient permissions to read / write to this file. Error was: EISDIR"`
);
});
});
Expand Down
20 changes: 11 additions & 9 deletions src/core/server/environment/resolve_uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ export async function resolveInstanceUuid({
if (uuidFromConfig) {
if (uuidFromConfig === uuidFromFile) {
// uuid matches, nothing to do
logger.debug(`Kibana instance UUID: ${uuidFromConfig}`);
logger.debug(`OpenSearch Dashboards instance UUID: ${uuidFromConfig}`);
return uuidFromConfig;
} else {
// uuid in file don't match, or file was not present, we need to write it.
if (uuidFromFile === undefined) {
logger.debug(`Setting new Kibana instance UUID: ${uuidFromConfig}`);
logger.debug(`Setting new OpenSearch Dashboards instance UUID: ${uuidFromConfig}`);
} else {
logger.debug(`Updating Kibana instance UUID to: ${uuidFromConfig} (was: ${uuidFromFile})`);
logger.debug(
`Updating OpenSearch Dashboards instance UUID to: ${uuidFromConfig} (was: ${uuidFromFile})`
);
}
await writeUuidToFile(uuidFilePath, uuidFromConfig);
return uuidFromConfig;
Expand All @@ -64,12 +66,12 @@ export async function resolveInstanceUuid({
if (uuidFromFile === undefined) {
const newUuid = uuid.v4();
// no uuid either in config or file, we need to generate and write it.
logger.debug(`Setting new Kibana instance UUID: ${newUuid}`);
logger.debug(`Setting new OpenSearch Dashboards instance UUID: ${newUuid}`);
await writeUuidToFile(uuidFilePath, newUuid);
return newUuid;
}

logger.debug(`Resuming persistent Kibana instance UUID: ${uuidFromFile}`);
logger.debug(`Resuming persistent OpenSearch Dashboards instance UUID: ${uuidFromFile}`);
return uuidFromFile;
}

Expand All @@ -90,8 +92,8 @@ async function readUuidFromFile(filepath: string, logger: Logger): Promise<strin
return undefined;
}
throw new Error(
'Unable to read Kibana UUID file, please check the uuid.server configuration ' +
'value in opensearch_dashboards.yml and ensure Kibana has sufficient permissions to read / write to this file. ' +
'Unable to read OpenSearch Dashboards UUID file, please check the uuid.server configuration ' +
'value in opensearch_dashboards.yml and ensure OpenSearch Dashboards has sufficient permissions to read / write to this file. ' +
`Error was: ${e.code}`
);
}
Expand All @@ -102,8 +104,8 @@ async function writeUuidToFile(filepath: string, uuidValue: string) {
return await writeFile(filepath, uuidValue, { encoding: FILE_ENCODING });
} catch (e) {
throw new Error(
'Unable to write Kibana UUID file, please check the uuid.server configuration ' +
'value in opensearch_dashboards.yml and ensure Kibana has sufficient permissions to read / write to this file. ' +
'Unable to write OpenSearch Dashboards UUID file, please check the uuid.server configuration ' +
'value in opensearch_dashboards.yml and ensure OpenSearch Dashboards has sufficient permissions to read / write to this file. ' +
`Error was: ${e.code}`
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/opensearch/default_headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ export const DEFAULT_HEADERS = deepFreeze({
// OpenSearch uses this to identify when a request is coming from OpenSearch Dashboards, to allow OpenSearch Dashboards to
// access system indices using the standard OpenSearch APIs without logging a warning. After migrating to
// use the new system index APIs, this header can be removed.
'x-elastic-product-origin': 'opensearch-dashboards',
'x-opensearch-product-origin': 'opensearch-dashboards',
});
38 changes: 19 additions & 19 deletions src/core/server/opensearch/legacy/opensearch_client_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test('parses minimally specified config', () => {
"hosts": Array [
Object {
"headers": Object {
"x-elastic-product-origin": "opensearch-dashboards",
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "localhost",
Expand Down Expand Up @@ -78,7 +78,7 @@ test('parses fully specified config', () => {
'https://opensearch.local',
],
requestHeadersWhitelist: [],
username: 'elastic',
username: 'opensearch',
password: 'changeme',
pingTimeout: 12345,
requestTimeout: 54321,
Expand Down Expand Up @@ -107,9 +107,9 @@ test('parses fully specified config', () => {
"apiVersion": "v7.0.0",
"hosts": Array [
Object {
"auth": "elastic:changeme",
"auth": "opensearch:changeme",
"headers": Object {
"x-elastic-product-origin": "opensearch-dashboards",
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "localhost",
Expand All @@ -119,9 +119,9 @@ test('parses fully specified config', () => {
"query": null,
},
Object {
"auth": "elastic:changeme",
"auth": "opensearch:changeme",
"headers": Object {
"x-elastic-product-origin": "opensearch-dashboards",
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "domain.com",
Expand All @@ -131,9 +131,9 @@ test('parses fully specified config', () => {
"query": null,
},
Object {
"auth": "elastic:changeme",
"auth": "opensearch:changeme",
"headers": Object {
"x-elastic-product-origin": "opensearch-dashboards",
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "opensearch.local",
Expand Down Expand Up @@ -188,7 +188,7 @@ test('parses config timeouts of moment.Duration type', () => {
"hosts": Array [
Object {
"headers": Object {
"x-elastic-product-origin": "opensearch-dashboards",
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "localhost",
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('#auth', () => {
sniffOnStart: true,
sniffOnConnectionFault: true,
hosts: ['http://user:password@localhost/opensearch', 'https://opensearch.local'],
username: 'elastic',
username: 'opensearch',
password: 'changeme',
requestHeadersWhitelist: [],
},
Expand All @@ -233,7 +233,7 @@ describe('#auth', () => {
"hosts": Array [
Object {
"headers": Object {
"x-elastic-product-origin": "opensearch-dashboards",
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "localhost",
Expand All @@ -244,7 +244,7 @@ describe('#auth', () => {
},
Object {
"headers": Object {
"x-elastic-product-origin": "opensearch-dashboards",
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "opensearch.local",
Expand Down Expand Up @@ -284,7 +284,7 @@ describe('#auth', () => {
"hosts": Array [
Object {
"headers": Object {
"x-elastic-product-origin": "opensearch-dashboards",
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "opensearch.local",
Expand Down Expand Up @@ -313,7 +313,7 @@ describe('#auth', () => {
sniffOnConnectionFault: true,
hosts: ['https://opensearch.local'],
requestHeadersWhitelist: [],
username: 'elastic',
username: 'opensearch',
},
logger.get(),
{ auth: true }
Expand All @@ -324,7 +324,7 @@ describe('#auth', () => {
"hosts": Array [
Object {
"headers": Object {
"x-elastic-product-origin": "opensearch-dashboards",
"x-opensearch-product-origin": "opensearch-dashboards",
"xsrf": "something",
},
"host": "opensearch.local",
Expand Down Expand Up @@ -509,7 +509,7 @@ describe('#ssl', () => {
"hosts": Array [
Object {
"headers": Object {
"x-elastic-product-origin": "opensearch-dashboards",
"x-opensearch-product-origin": "opensearch-dashboards",
},
"host": "opensearch.local",
"path": "/",
Expand Down Expand Up @@ -556,7 +556,7 @@ describe('#ssl', () => {
"hosts": Array [
Object {
"headers": Object {
"x-elastic-product-origin": "opensearch-dashboards",
"x-opensearch-product-origin": "opensearch-dashboards",
},
"host": "opensearch.local",
"path": "/",
Expand Down Expand Up @@ -599,7 +599,7 @@ describe('#ssl', () => {
"hosts": Array [
Object {
"headers": Object {
"x-elastic-product-origin": "opensearch-dashboards",
"x-opensearch-product-origin": "opensearch-dashboards",
},
"host": "opensearch.local",
"path": "/",
Expand Down Expand Up @@ -667,7 +667,7 @@ describe('#ssl', () => {
"hosts": Array [
Object {
"headers": Object {
"x-elastic-product-origin": "opensearch-dashboards",
"x-opensearch-product-origin": "opensearch-dashboards",
},
"host": "opensearch.local",
"path": "/",
Expand Down
1 change: 0 additions & 1 deletion src/core/server/plugins/plugins_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ describe('PluginsService', () => {
initialize: true,
pluginSearchPaths: [
resolve(process.cwd(), 'src', 'plugins'),
resolve(process.cwd(), 'x-pack', 'plugins'),
resolve(process.cwd(), 'plugins'),
resolve(process.cwd(), '..', 'opensearch-dashboards-extra'),
],
Expand Down

0 comments on commit b16b428

Please sign in to comment.