Skip to content

Commit

Permalink
[Fleet] Fix fleet server host port during settings creation (elastic#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed May 4, 2021
1 parent 187d24b commit 3eb8733
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 6 additions & 6 deletions x-pack/plugins/fleet/server/services/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ export async function saveSettings(
soClient: SavedObjectsClientContract,
newData: Partial<Omit<Settings, 'id'>>
): Promise<Partial<Settings> & Pick<Settings, 'id'>> {
const data = { ...newData };
if (data.fleet_server_hosts) {
data.fleet_server_hosts = data.fleet_server_hosts.map(normalizeFleetServerHost);
}

try {
const settings = await getSettings(soClient);

const data = { ...newData };
if (data.fleet_server_hosts) {
data.fleet_server_hosts = data.fleet_server_hosts.map(normalizeFleetServerHost);
}

const res = await soClient.update<SettingsSOAttributes>(
GLOBAL_SETTINGS_SAVED_OBJECT_TYPE,
settings.id,
Expand All @@ -102,7 +102,7 @@ export async function saveSettings(
const defaultSettings = createDefaultSettings();
const res = await soClient.create<SettingsSOAttributes>(GLOBAL_SETTINGS_SAVED_OBJECT_TYPE, {
...defaultSettings,
...newData,
...data,
});

return {
Expand Down
12 changes: 12 additions & 0 deletions x-pack/test/fleet_api_integration/apis/settings/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ export default function (providerContext: FtrProviderContext) {
after(async () => {
await esArchiver.unload('fleet/empty_fleet_server');
});

it('should explicitly set port on fleet_server_hosts', async function () {
await supertest
.put(`/api/fleet/settings`)
.set('kbn-xsrf', 'xxxx')
.send({ fleet_server_hosts: ['https://test.fr'] })
.expect(200);

const { body: getSettingsRes } = await supertest.get(`/api/fleet/settings`).expect(200);
expect(getSettingsRes.item.fleet_server_hosts).to.eql(['https://test.fr:443']);
});

it("should bump all agent policy's revision", async function () {
const { body: testPolicy1PostRes } = await supertest
.post(`/api/fleet/agent_policies`)
Expand Down

0 comments on commit 3eb8733

Please sign in to comment.