mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Fleet] Fix Fleet server host default conflict creation (#163826)
This commit is contained in:
parent
3efc0a7c45
commit
1c0d656ae1
3 changed files with 58 additions and 3 deletions
|
@ -48,7 +48,7 @@ export async function createFleetServerHost(
|
|||
): Promise<FleetServerHost> {
|
||||
if (data.is_default) {
|
||||
const defaultItem = await getDefaultFleetServerHost(soClient);
|
||||
if (defaultItem) {
|
||||
if (defaultItem && defaultItem.id !== options?.id) {
|
||||
await updateFleetServerHost(
|
||||
soClient,
|
||||
defaultItem.id,
|
||||
|
|
|
@ -432,7 +432,7 @@ class OutputService {
|
|||
|
||||
// ensure only default output exists
|
||||
if (data.is_default) {
|
||||
if (defaultDataOutputId) {
|
||||
if (defaultDataOutputId && defaultDataOutputId !== options?.id) {
|
||||
await this._updateDefaultOutput(
|
||||
soClient,
|
||||
defaultDataOutputId,
|
||||
|
@ -443,7 +443,7 @@ class OutputService {
|
|||
}
|
||||
if (data.is_default_monitoring) {
|
||||
const defaultMonitoringOutputId = await this.getDefaultMonitoringOutputId(soClient);
|
||||
if (defaultMonitoringOutputId) {
|
||||
if (defaultMonitoringOutputId && defaultMonitoringOutputId !== options?.id) {
|
||||
await this._updateDefaultOutput(
|
||||
soClient,
|
||||
defaultMonitoringOutputId,
|
||||
|
|
|
@ -117,5 +117,60 @@ export default function (providerContext: FtrProviderContext) {
|
|||
.expect(404);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /fleet_server_hosts', () => {
|
||||
it('should allow to create a default fleet server host with id', async function () {
|
||||
const id = `test-${Date.now()}`;
|
||||
|
||||
await supertest
|
||||
.post(`/api/fleet/fleet_server_hosts`)
|
||||
.set('kbn-xsrf', 'xxxx')
|
||||
.send({
|
||||
name: `Default ${Date.now()}`,
|
||||
host_urls: ['https://test.fr:8080', 'https://test.fr:8081'],
|
||||
is_default: true,
|
||||
id,
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const {
|
||||
body: { item: fleetServerHost },
|
||||
} = await supertest.get(`/api/fleet/fleet_server_hosts/${id}`).expect(200);
|
||||
|
||||
expect(fleetServerHost.is_default).to.be(true);
|
||||
});
|
||||
|
||||
it('should not unset default fleet server host on id conflict', async function () {
|
||||
const id = `test-${Date.now()}`;
|
||||
|
||||
await supertest
|
||||
.post(`/api/fleet/fleet_server_hosts`)
|
||||
.set('kbn-xsrf', 'xxxx')
|
||||
.send({
|
||||
name: `Default ${Date.now()}`,
|
||||
host_urls: ['https://test.fr:8080', 'https://test.fr:8081'],
|
||||
is_default: true,
|
||||
id,
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
await supertest
|
||||
.post(`/api/fleet/fleet_server_hosts`)
|
||||
.set('kbn-xsrf', 'xxxx')
|
||||
.send({
|
||||
name: `Default ${Date.now()}`,
|
||||
host_urls: ['https://test.fr:8080', 'https://test.fr:8081'],
|
||||
is_default: true,
|
||||
id,
|
||||
})
|
||||
.expect(409);
|
||||
|
||||
const {
|
||||
body: { item: fleetServerHost },
|
||||
} = await supertest.get(`/api/fleet/fleet_server_hosts/${id}`).expect(200);
|
||||
|
||||
expect(fleetServerHost.is_default).to.be(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue