diff --git a/x-pack/plugins/fleet/common/services/decode_cloud_id.test.ts b/x-pack/plugins/fleet/common/services/decode_cloud_id.test.ts index 5ec709b1c8ccd..6ab8942f0078c 100644 --- a/x-pack/plugins/fleet/common/services/decode_cloud_id.test.ts +++ b/x-pack/plugins/fleet/common/services/decode_cloud_id.test.ts @@ -13,34 +13,34 @@ describe('Fleet - decodeCloudId', () => { { cloudID: 'staging:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyRjZWM2ZjI2MWE3NGJmMjRjZTMzYmI4ODExYjg0Mjk0ZiRjNmMyY2E2ZDA0MjI0OWFmMGNjN2Q3YTllOTYyNTc0Mw==', - expectedEsURL: 'https://cec6f261a74bf24ce33bb8811b84294f.us-east-1.aws.found.io:443', - expectedKibanaURL: 'https://c6c2ca6d042249af0cc7d7a9e9625743.us-east-1.aws.found.io:443', + expectedEsURL: 'https://cec6f261a74bf24ce33bb8811b84294f.us-east-1.aws.found.io:9243', + expectedKibanaURL: 'https://c6c2ca6d042249af0cc7d7a9e9625743.us-east-1.aws.found.io:9243', }, { cloudID: 'dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyRjZWM2ZjI2MWE3NGJmMjRjZTMzYmI4ODExYjg0Mjk0ZiRjNmMyY2E2ZDA0MjI0OWFmMGNjN2Q3YTllOTYyNTc0Mw==', - expectedEsURL: 'https://cec6f261a74bf24ce33bb8811b84294f.us-east-1.aws.found.io:443', - expectedKibanaURL: 'https://c6c2ca6d042249af0cc7d7a9e9625743.us-east-1.aws.found.io:443', + expectedEsURL: 'https://cec6f261a74bf24ce33bb8811b84294f.us-east-1.aws.found.io:9243', + expectedKibanaURL: 'https://c6c2ca6d042249af0cc7d7a9e9625743.us-east-1.aws.found.io:9243', }, { cloudID: ':dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyRjZWM2ZjI2MWE3NGJmMjRjZTMzYmI4ODExYjg0Mjk0ZiRjNmMyY2E2ZDA0MjI0OWFmMGNjN2Q3YTllOTYyNTc0Mw==', - expectedEsURL: 'https://cec6f261a74bf24ce33bb8811b84294f.us-east-1.aws.found.io:443', - expectedKibanaURL: 'https://c6c2ca6d042249af0cc7d7a9e9625743.us-east-1.aws.found.io:443', + expectedEsURL: 'https://cec6f261a74bf24ce33bb8811b84294f.us-east-1.aws.found.io:9243', + expectedKibanaURL: 'https://c6c2ca6d042249af0cc7d7a9e9625743.us-east-1.aws.found.io:9243', }, { cloudID: 'gcp-cluster:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJDhhMDI4M2FmMDQxZjE5NWY3NzI5YmMwNGM2NmEwZmNlJDBjZDVjZDU2OGVlYmU1M2M4OWViN2NhZTViYWM4YjM3', - expectedEsURL: 'https://8a0283af041f195f7729bc04c66a0fce.us-central1.gcp.cloud.es.io:443', + expectedEsURL: 'https://8a0283af041f195f7729bc04c66a0fce.us-central1.gcp.cloud.es.io:9243', expectedKibanaURL: - 'https://0cd5cd568eebe53c89eb7cae5bac8b37.us-central1.gcp.cloud.es.io:443', + 'https://0cd5cd568eebe53c89eb7cae5bac8b37.us-central1.gcp.cloud.es.io:9243', }, { cloudID: - 'custom-port:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvOjkyNDMkYWMzMWViYjkwMjQxNzczMTU3MDQzYzM0ZmQyNmZkNDYkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA=', - expectedEsURL: 'https://ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io:9243', + 'custom-port:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvOjk5OTkkYWMzMWViYjkwMjQxNzczMTU3MDQzYzM0ZmQyNmZkNDYkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA=', + expectedEsURL: 'https://ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io:9999', expectedKibanaURL: - 'https://a4c06230e48c8fce7be88a074a3bb3e0.us-central1.gcp.cloud.es.io:9243', + 'https://a4c06230e48c8fce7be88a074a3bb3e0.us-central1.gcp.cloud.es.io:9999', }, { cloudID: @@ -52,7 +52,7 @@ describe('Fleet - decodeCloudId', () => { { cloudID: 'only-kb-set:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJGFjMzFlYmI5MDI0MTc3MzE1NzA0M2MzNGZkMjZmZDQ2JGE0YzA2MjMwZTQ4YzhmY2U3YmU4OGEwNzRhM2JiM2UwOjkyNDQ=', - expectedEsURL: 'https://ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io:443', + expectedEsURL: 'https://ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io:9243', expectedKibanaURL: 'https://a4c06230e48c8fce7be88a074a3bb3e0.us-central1.gcp.cloud.es.io:9244', }, @@ -66,17 +66,17 @@ describe('Fleet - decodeCloudId', () => { { cloudID: 'extra-items:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJGFjMzFlYmI5MDI0MTc3MzE1NzA0M2MzNGZkMjZmZDQ2JGE0YzA2MjMwZTQ4YzhmY2U3YmU4OGEwNzRhM2JiM2UwJGFub3RoZXJpZCRhbmRhbm90aGVy', - expectedEsURL: 'https://ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io:443', + expectedEsURL: 'https://ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io:9243', expectedKibanaURL: - 'https://a4c06230e48c8fce7be88a074a3bb3e0.us-central1.gcp.cloud.es.io:443', + 'https://a4c06230e48c8fce7be88a074a3bb3e0.us-central1.gcp.cloud.es.io:9243', }, ]; for (const test of tests) { const decoded = decodeCloudId(test.cloudID); expect(decoded).toBeTruthy(); - expect(decoded?.elasticsearchUrl === test.expectedEsURL).toBe(true); - expect(decoded?.kibanaUrl === test.expectedKibanaURL).toBe(true); + expect(decoded?.elasticsearchUrl).toBe(test.expectedEsURL); + expect(decoded?.kibanaUrl).toBe(test.expectedKibanaURL); } }); diff --git a/x-pack/plugins/fleet/common/services/decode_cloud_id.ts b/x-pack/plugins/fleet/common/services/decode_cloud_id.ts index e4952e6b22356..978e3297973fc 100644 --- a/x-pack/plugins/fleet/common/services/decode_cloud_id.ts +++ b/x-pack/plugins/fleet/common/services/decode_cloud_id.ts @@ -5,6 +5,8 @@ * 2.0. */ +const CLOUD_DEFAULT_PORT = '9243'; + // decodeCloudId decodes the c.id into c.esURL and c.kibURL export function decodeCloudId( cid: string @@ -51,6 +53,7 @@ export function decodeCloudId( // 5. form the URLs const esUrl = `https://${esId}.${host}:${esPort}`; const kbUrl = `https://${kbId}.${host}:${kbPort}`; + return { host, defaultPort, @@ -60,7 +63,7 @@ export function decodeCloudId( } // extractPortFromName takes a string in the form `id:port` and returns the // Id and the port. If there's no `:`, the default port is returned -function extractPortFromName(word: string, defaultPort = '443') { +function extractPortFromName(word: string, defaultPort = CLOUD_DEFAULT_PORT) { const [host, port = defaultPort] = word.split(':'); return [host, port]; } diff --git a/x-pack/plugins/fleet/server/services/settings.test.ts b/x-pack/plugins/fleet/server/services/settings.test.ts index 87b3e163c1bb3..27aa1f02460c1 100644 --- a/x-pack/plugins/fleet/server/services/settings.test.ts +++ b/x-pack/plugins/fleet/server/services/settings.test.ts @@ -17,7 +17,7 @@ describe('getCloudFleetServersHosts', () => { expect(getCloudFleetServersHosts()).toBeUndefined(); }); - it('should return fleet server hosts if cloud is correctly setup with default port == 443', () => { + it('should return fleet server hosts if cloud is correctly setup with no default port in the cloud ID', () => { mockedAppContextService.getCloud.mockReturnValue({ cloudId: 'dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyRjZWM2ZjI2MWE3NGJmMjRjZTMzYmI4ODExYjg0Mjk0ZiRjNmMyY2E2ZDA0MjI0OWFmMGNjN2Q3YTllOTYyNTc0Mw==', @@ -26,6 +26,22 @@ describe('getCloudFleetServersHosts', () => { apm: {}, }); + expect(getCloudFleetServersHosts()).toMatchInlineSnapshot(` + Array [ + "https://deployment-id-1.fleet.us-east-1.aws.found.io:9243", + ] + `); + }); + + it('should return fleet server hosts if cloud is correctly setup with a default port of 443 in the cloud ID', () => { + mockedAppContextService.getCloud.mockReturnValue({ + cloudId: + 'dXMtZWFzdC0xLmF3cy5mb3VuZC5pbzo0NDMkY2VjNmYyNjFhNzRiZjI0Y2UzM2JiODgxMWI4NDI5NGYkYzZjMmNhNmQwNDIyNDlhZjBjYzdkN2E5ZTk2MjU3NDM=', + isCloudEnabled: true, + deploymentId: 'deployment-id-1', + apm: {}, + }); + expect(getCloudFleetServersHosts()).toMatchInlineSnapshot(` Array [ "https://deployment-id-1.fleet.us-east-1.aws.found.io",