Support Kibana URL parts with stripped default port (#197418)

## Summary

This PR adds support for getting Kibana URL parts with stripped default
port.

### Details

* Adds method `getUrlPartsWithStrippedDefaultPort` to `kbnTestConfig`
* Can be used when asserting URLs where the browser strips the default
port
This commit is contained in:
Robert Oskamp 2024-10-23 17:11:22 +02:00 committed by GitHub
parent 5adb0ea5d2
commit 629edc03da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -54,4 +54,21 @@ export const kbnTestConfig = new (class KbnTestConfig {
password,
};
}
/**
* Use to get `port:undefined` for assertions if the port is default for the
* used protocol and thus would be stripped by the browser
*/
getUrlPartsWithStrippedDefaultPort(user: UserAuth = kibanaTestUser): UrlParts {
const urlParts = this.getUrlParts(user);
if (
(urlParts.protocol === 'http' && urlParts.port === 80) ||
(urlParts.protocol === 'https' && urlParts.port === 443)
) {
urlParts.port = undefined;
}
return urlParts;
}
})();