diff --git a/x-pack/plugins/fleet/server/routes/fleet_server_hosts/handler.test.ts b/x-pack/plugins/fleet/server/routes/fleet_server_hosts/handler.test.ts index e65942a50c9345..3d7b35682dc6e2 100644 --- a/x-pack/plugins/fleet/server/routes/fleet_server_hosts/handler.test.ts +++ b/x-pack/plugins/fleet/server/routes/fleet_server_hosts/handler.test.ts @@ -33,14 +33,10 @@ describe('fleet server hosts handler', () => { jest .spyOn(fleetServerService, 'updateFleetServerHost') .mockResolvedValue({ id: 'host1' } as any); - jest.spyOn(fleetServerService, 'listFleetServerHosts').mockResolvedValue({ - items: [ - { id: SERVERLESS_DEFAULT_FLEET_SERVER_HOST_ID, host_urls: ['http://elasticsearch:9200'] }, - ] as any, - total: 1, - page: 1, - perPage: 1, - }); + jest.spyOn(fleetServerService, 'getFleetServerHost').mockResolvedValue({ + id: SERVERLESS_DEFAULT_FLEET_SERVER_HOST_ID, + host_urls: ['http://elasticsearch:9200'], + } as any); jest .spyOn(agentPolicyService, 'bumpAllAgentPoliciesForFleetServerHosts') .mockResolvedValue({} as any); @@ -118,17 +114,17 @@ describe('fleet server hosts handler', () => { expect(res).toEqual({ body: { item: { id: 'host1' } } }); }); - // it('should return ok on put in stateful if host url is different from default', async () => { - // jest - // .spyOn(appContextService, 'getCloud') - // .mockReturnValue({ isServerlessEnabled: false } as any); + it('should return ok on put in stateful if host url is different from default', async () => { + jest + .spyOn(appContextService, 'getCloud') + .mockReturnValue({ isServerlessEnabled: false } as any); - // const res = await putFleetServerHostHandler( - // mockContext, - // { body: { host_urls: ['http://localhost:8080'] }, params: { outputId: 'host1' } } as any, - // mockResponse as any - // ); + const res = await putFleetServerHostHandler( + mockContext, + { body: { host_urls: ['http://localhost:8080'] }, params: { outputId: 'host1' } } as any, + mockResponse as any + ); - // expect(res).toEqual({ body: { item: { id: 'host1' } } }); - // }); + expect(res).toEqual({ body: { item: { id: 'host1' } } }); + }); }); diff --git a/x-pack/plugins/fleet/server/routes/fleet_server_hosts/handler.ts b/x-pack/plugins/fleet/server/routes/fleet_server_hosts/handler.ts index eddce8df7c3e0b..7e6c14506f3da0 100644 --- a/x-pack/plugins/fleet/server/routes/fleet_server_hosts/handler.ts +++ b/x-pack/plugins/fleet/server/routes/fleet_server_hosts/handler.ts @@ -36,27 +36,17 @@ async function checkFleetServerHostsWriteAPIsAllowed( return; } - const defaultFleetServerHost = await getDefaultFleetServerHost(soClient); - if ( - defaultFleetServerHost === undefined || - !isEqual(hostUrls, defaultFleetServerHost.host_urls) - ) { + const serverlessDefaultFleetServerHost = await getFleetServerHost( + soClient, + SERVERLESS_DEFAULT_FLEET_SERVER_HOST_ID + ); + if (!isEqual(hostUrls, serverlessDefaultFleetServerHost.host_urls)) { throw new FleetServerHostUnauthorizedError( - `Fleet server host must have default URL in serverless${ - defaultFleetServerHost ? ': ' + defaultFleetServerHost.host_urls : '' - }` + `Fleet server host must have default URL in serverless: ${serverlessDefaultFleetServerHost.host_urls}` ); } } -async function getDefaultFleetServerHost(soClient: SavedObjectsClientContract) { - const res = await listFleetServerHosts(soClient); - const fleetServerHosts = res.items; - return fleetServerHosts.find( - (fleetServerHost) => fleetServerHost.id === SERVERLESS_DEFAULT_FLEET_SERVER_HOST_ID - ); -} - export const postFleetServerHost: RequestHandler< undefined, undefined, diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/fleet/fleet.ts b/x-pack/test_serverless/api_integration/test_suites/observability/fleet/fleet.ts index 73f582f9aa9cb4..98866bc50f4316 100644 --- a/x-pack/test_serverless/api_integration/test_suites/observability/fleet/fleet.ts +++ b/x-pack/test_serverless/api_integration/test_suites/observability/fleet/fleet.ts @@ -12,8 +12,7 @@ export default function ({ getService }: FtrProviderContext) { const svlCommonApi = getService('svlCommonApi'); const supertest = getService('supertest'); - // Failing: See https://github.com/elastic/kibana/issues/176352 - describe.skip('fleet', function () { + describe('fleet', function () { it('rejects request to create a new fleet server hosts if host url is different from default', async () => { const { body, status } = await supertest .post('/api/fleet/fleet_server_hosts') diff --git a/x-pack/test_serverless/api_integration/test_suites/security/fleet/fleet.ts b/x-pack/test_serverless/api_integration/test_suites/security/fleet/fleet.ts index ba184e76877947..98866bc50f4316 100644 --- a/x-pack/test_serverless/api_integration/test_suites/security/fleet/fleet.ts +++ b/x-pack/test_serverless/api_integration/test_suites/security/fleet/fleet.ts @@ -12,8 +12,7 @@ export default function ({ getService }: FtrProviderContext) { const svlCommonApi = getService('svlCommonApi'); const supertest = getService('supertest'); - // FLAKY: https://github.com/elastic/kibana/issues/176399 - describe.skip('fleet', function () { + describe('fleet', function () { it('rejects request to create a new fleet server hosts if host url is different from default', async () => { const { body, status } = await supertest .post('/api/fleet/fleet_server_hosts')