mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
## For #27454 Consider Fleet web URL to be valid if it: - (Front end and back end): uses “https://” or “http://” scheme and - (Front end) accepts only valid or "localhost" hosts (e.g., "a.b.cc" or "localhost", but not "a.b") - (Back end) accepts any host (e.g., "localhost", "a.b.cc", or even "a.b") ### Setup flow UI URL validation:  ### Org settings UI URL validation:  ### Server URL validation: <img width="1464" alt="invalid-url-server" src="https://github.com/user-attachments/assets/83a112e1-6318-4b09-864d-fe66a223835d" /> ### Invalid Fleet server URL in DB error:  - [x] Changes file added for user-visible changes in `changes/`, - [x] Added/updated automated tests - [ ] A detailed QA plan exists on the associated ticket (if it isn't there, work with the product group's QA engineer to add it) - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Jacob Shandling <[email protected]>
28 lines
644 B
JavaScript
28 lines
644 B
JavaScript
import { size } from "lodash";
|
|
|
|
import validUrl from "components/forms/validators/valid_url";
|
|
|
|
import INVALID_SERVER_URL_MESSAGE from "utilities/error_messages";
|
|
|
|
const validate = (formData) => {
|
|
const errors = {};
|
|
const { server_url: fleetWebAddress } = formData;
|
|
|
|
if (!fleetWebAddress) {
|
|
errors.server_url = "Fleet web address must be completed";
|
|
} else if (
|
|
!validUrl({
|
|
url: fleetWebAddress,
|
|
protocols: ["http", "https"],
|
|
allowLocalHost: true,
|
|
})
|
|
) {
|
|
errors.server_url = INVALID_SERVER_URL_MESSAGE;
|
|
}
|
|
|
|
const valid = !size(errors);
|
|
|
|
return { valid, errors };
|
|
};
|
|
|
|
export default { validate };
|