Skip to content

Commit

Permalink
Add api integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang committed Sep 24, 2024
1 parent e1a3310 commit e1087bc
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ properties:
type: string
download_source_id:
type: string
space_ids:
type: array
items:
type: string
data_output_id:
type: string
required:
- id
- name
Expand All @@ -33,6 +39,10 @@ properties:
$ref: ./fleet_server_host.yaml
host_proxy:
$ref: ./proxies.yaml
es_output:
$ref: ./output_create_request_elasticsearch.yaml
es_output_proxy:
$ref: ./proxies.yaml
required:
- agent_policies
- has_active
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,39 @@ describe('useFleetServerHostsForPolicy', () => {
is_preconfigured: false,
},
has_active: true,
es_output: {
id: 'es-output',
name: 'es-output',
is_default: false,
is_default_monitoring: false,
type: 'elasticsearch',
hosts: ['https://elasticsearch:9200'],
},
es_output_proxy: {
id: 'es-output-proxy',
name: 'es-output-proxy',
url: 'https://es-output-proxy',
proxy_headers: {
'header-key': 'header-value',
},
is_preconfigured: false,
},
},
download_source: {
id: 'default-source',
name: 'default-source',
host: 'https://defaultsource',
is_default: false,
},
download_source_proxy: {
id: 'download-src-proxy',
name: 'download-src-proxy',
url: 'https://download-src-proxy',
proxy_headers: {
'header-key': 'header-value',
},
is_preconfigured: false,
},
},
});
});
Expand All @@ -64,12 +90,38 @@ describe('useFleetServerHostsForPolicy', () => {
url: 'https://defaultproxy',
is_preconfigured: false,
},
esOutput: {
id: 'es-output',
name: 'es-output',
is_default: false,
is_default_monitoring: false,
type: 'elasticsearch',
hosts: ['https://elasticsearch:9200'],
},
esOutputProxy: {
id: 'es-output-proxy',
name: 'es-output-proxy',
url: 'https://es-output-proxy',
proxy_headers: {
'header-key': 'header-value',
},
is_preconfigured: false,
},
downloadSource: {
id: 'default-source',
name: 'default-source',
host: 'https://defaultsource',
is_default: false,
},
downloadSourceProxy: {
id: 'download-src-proxy',
name: 'download-src-proxy',
url: 'https://download-src-proxy',
proxy_headers: {
'header-key': 'header-value',
},
is_preconfigured: false,
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,16 @@ export const getEnrollmentSettingsHandler: FleetRequestHandler<

// Get associated output and proxy (if any) to use for Fleet Server enrollment
try {
const dataOutput = await getDataOutputForAgentPolicy(soClient, scopedAgentPolicy);
if (dataOutput.type === 'elasticsearch' && dataOutput.hosts?.[0]) {
settingsResponse.fleet_server.es_output = dataOutput;
if (dataOutput.proxy_id) {
settingsResponse.fleet_server.es_output_proxy = await getFleetProxy(
soClient,
dataOutput.proxy_id
);
if (settingsResponse.fleet_server.policies.length > 0) {
const dataOutput = await getDataOutputForAgentPolicy(soClient, scopedAgentPolicy);
if (dataOutput.type === 'elasticsearch' && dataOutput.hosts?.[0]) {
settingsResponse.fleet_server.es_output = dataOutput;
if (dataOutput.proxy_id) {
settingsResponse.fleet_server.es_output_proxy = await getFleetProxy(
soClient,
dataOutput.proxy_id
);
}
}
}
} catch (e) {
Expand Down
45 changes: 41 additions & 4 deletions x-pack/test/fleet_api_integration/apis/settings/enrollment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ export default function (providerContext: FtrProviderContext) {
describe('Enrollment settings - get', function () {
skipIfNoDockerRegistry(providerContext);

before(async () => {
await fleetAndAgents.setup();
});

it('should respond with empty enrollment settings on empty cluster', async function () {
await fleetAndAgents.setup();
const response = await supertest
.get(`/internal/fleet/settings/enrollment`)
.set('kbn-xsrf', 'xxxx')
Expand Down Expand Up @@ -51,6 +48,7 @@ export default function (providerContext: FtrProviderContext) {
.set('kbn-xsrf', 'xxxx')
.send({ force: true })
.expect(200);
await fleetAndAgents.setup();
});
after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/fleet/fleet_server');
Expand Down Expand Up @@ -92,12 +90,25 @@ export default function (providerContext: FtrProviderContext) {
host_proxy: {
id: 'my-proxy',
name: 'my proxy',
proxy_headers: {
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.5',
},
url: 'https://my-proxy',
certificate: '',
certificate_authorities: '',
certificate_key: '',
is_preconfigured: false,
},
es_output: {
hosts: ['http://localhost:9200'],
id: 'fleet-default-output',
is_default: true,
is_default_monitoring: true,
name: 'default',
preset: 'balanced',
type: 'elasticsearch',
},
},
download_source: {
id: 'fleet-default-download-source',
Expand Down Expand Up @@ -137,12 +148,25 @@ export default function (providerContext: FtrProviderContext) {
host_proxy: {
id: 'my-proxy',
name: 'my proxy',
proxy_headers: {
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.5',
},
url: 'https://my-proxy',
certificate: '',
certificate_authorities: '',
certificate_key: '',
is_preconfigured: false,
},
es_output: {
hosts: ['http://localhost:9200'],
id: 'fleet-default-output',
is_default: true,
is_default_monitoring: true,
name: 'default',
preset: 'balanced',
type: 'elasticsearch',
},
},
download_source: {
id: 'fleet-default-download-source',
Expand Down Expand Up @@ -178,6 +202,19 @@ export default function (providerContext: FtrProviderContext) {
host: 'https://localhost:2222',
proxy_id: 'my-proxy',
},
download_source_proxy: {
certificate: '',
certificate_authorities: '',
certificate_key: '',
id: 'my-proxy',
is_preconfigured: false,
name: 'my proxy',
proxy_headers: {
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.5',
},
url: 'https://my-proxy',
},
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,11 @@
"certificate_key": "",
"is_preconfigured": false,
"name": "my proxy",
"proxy_headers": null,
"proxy_headers": "{\"Accept-Language\":\"en-US,en;q=0.5\",\"Accept-Encoding\":\"gzip, deflate, br\"}",
"url": "https://my-proxy"
},
"managed": false,
"references": [
],
"references": [],
"type": "fleet-proxy",
"updated_at": "2024-04-22T22:07:16.226Z"
}
Expand Down

0 comments on commit e1087bc

Please sign in to comment.