Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Logstash Output - being compliant to RFC-952 #176298

Merged
merged 5 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ describe('Output form validation', () => {

expect(res).toBeUndefined();
});

it('should work with hostnames using uppercase letters', () => {
const res = validateLogstashHosts(['tEsT.fr:9200', 'TEST2.fr:9200', 'teSt.fR:9999']);

expect(res).toBeUndefined();
});

it('should throw for invalid hosts starting with http', () => {
const res = validateLogstashHosts(['https://test.fr:5044']);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export function validateLogstashHosts(value: string[]) {

const url = new URL(`http://${val}`);

if (url.host !== val) {
if (url.host !== val.toLowerCase()) {
throw new Error('Invalid host');
}
} catch (error) {
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/fleet/server/types/models/output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ describe('Output model', () => {
expect(validateLogstashHost('test.fr:5044')).toBeUndefined();
});

it('should support valid host with uppercase letters', () => {
expect(validateLogstashHost('tEsT.fr:5044')).toBeUndefined();
});

it('should return an error for an invalid host', () => {
expect(validateLogstashHost('!@#%&!#!@')).toMatchInlineSnapshot(`"Invalid Logstash host"`);
});
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/server/types/models/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function validateLogstashHost(val: string) {
try {
const url = new URL(`http://${val}`);

if (url.host !== val) {
if (url.host !== val.toLowerCase()) {
return 'Invalid host';
}
} catch (err) {
Expand Down