fix(onboarding): accept self-hosted addresses
This commit is contained in:
1 parent
9c5ab62b3a
commit
f1ce0fffad
5 files changed
+43
-29
No files matched your search
@@ -52,6 +52,7 @@ services:
|
|||||||
|
|
||||||
Use an address that is reachable where it is needed. A Docker service name can work for server-side integration
|
Use an address that is reachable where it is needed. A Docker service name can work for server-side integration
|
||||||
requests, while an app link opened in a browser usually needs a LAN hostname, IP address, or reverse-proxy address.
|
requests, while an app link opened in a browser usually needs a LAN hostname, IP address, or reverse-proxy address.
|
||||||
|
Onboarding accepts these self-hosted address formats directly and only requires the field to be non-empty.
|
||||||
|
|
||||||
## Homepage label fallback
|
## Homepage label fallback
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,6 @@ import { OnboardingBackdrop } from "./onboarding-backdrop";
|
|||||||
import { OnboardingWordmark } from "./onboarding-wordmark";
|
import { OnboardingWordmark } from "./onboarding-wordmark";
|
||||||
import { useOnboardingSounds } from "./use-onboarding-sounds";
|
import { useOnboardingSounds } from "./use-onboarding-sounds";
|
||||||
import {
|
import {
|
||||||
isHttpUrl,
|
|
||||||
normalizeServiceUrl,
|
normalizeServiceUrl,
|
||||||
resolveDiscoveredAppUrl,
|
resolveDiscoveredAppUrl,
|
||||||
resolveIntegrationDraftUrl,
|
resolveIntegrationDraftUrl,
|
||||||
@@ -127,7 +126,7 @@ interface IntegrationDraft {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isIntegrationDraftComplete = (draft: IntegrationDraft) =>
|
const isIntegrationDraftComplete = (draft: IntegrationDraft) =>
|
||||||
isHttpUrl(draft.url) && draft.secrets.every((secret) => secret.value.trim().length > 0);
|
draft.url.trim().length > 0 && draft.secrets.every((secret) => secret.value.trim().length > 0);
|
||||||
|
|
||||||
type DockerDiscoveryData = RouterOutputs["onboard"]["discoverDockerServices"];
|
type DockerDiscoveryData = RouterOutputs["onboard"]["discoverDockerServices"];
|
||||||
type RuntimeCapabilitiesQuery = Omit<
|
type RuntimeCapabilitiesQuery = Omit<
|
||||||
@@ -435,7 +434,9 @@ export const SetupStudio = ({ environment, assistantConfiguration }: OnboardingS
|
|||||||
}
|
}
|
||||||
const draftsToApply = drafts.filter(isIntegrationDraftComplete);
|
const draftsToApply = drafts.filter(isIntegrationDraftComplete);
|
||||||
const appsToCreate = discoveredApps.filter((app) => selectedAppIds.includes(app.sourceId));
|
const appsToCreate = discoveredApps.filter((app) => selectedAppIds.includes(app.sourceId));
|
||||||
const appWithoutAddress = appsToCreate.find((app) => !isHttpUrl(discoveredAppUrls[app.sourceId] ?? ""));
|
const appWithoutAddress = appsToCreate.find(
|
||||||
|
(app) => (discoveredAppUrls[app.sourceId] ?? "").trim().length === 0,
|
||||||
|
);
|
||||||
if (appWithoutAddress) {
|
if (appWithoutAddress) {
|
||||||
const message = t("connect.appAddressRequired", { name: appWithoutAddress.containerName });
|
const message = t("connect.appAddressRequired", { name: appWithoutAddress.containerName });
|
||||||
setAppError(message);
|
setAppError(message);
|
||||||
@@ -493,7 +494,8 @@ export const SetupStudio = ({ environment, assistantConfiguration }: OnboardingS
|
|||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
apps: appsToCreate.flatMap((app) => {
|
apps: appsToCreate.flatMap((app) => {
|
||||||
const href = normalizeServiceUrl(discoveredAppUrls[app.sourceId] ?? "");
|
const enteredAddress = (discoveredAppUrls[app.sourceId] ?? "").trim();
|
||||||
|
const href = normalizeServiceUrl(enteredAddress) ?? enteredAddress;
|
||||||
return href
|
return href
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
@@ -635,13 +637,27 @@ export const SetupStudio = ({ environment, assistantConfiguration }: OnboardingS
|
|||||||
appErrorSourceId,
|
appErrorSourceId,
|
||||||
};
|
};
|
||||||
const hasIncompleteIntegrations = drafts.some((draft) => !isIntegrationDraftComplete(draft));
|
const hasIncompleteIntegrations = drafts.some((draft) => !isIntegrationDraftComplete(draft));
|
||||||
|
const selectedAppWithoutAddress = discoveredApps.find(
|
||||||
|
(app) => selectedAppIds.includes(app.sourceId) && (discoveredAppUrls[app.sourceId] ?? "").trim().length === 0,
|
||||||
|
);
|
||||||
const continueDisabled = isApplying || (activeSection === "essentials" && serverOrigin.trim().length === 0);
|
const continueDisabled = isApplying || (activeSection === "essentials" && serverOrigin.trim().length === 0);
|
||||||
const continueOnboarding = () => {
|
const continueOnboarding = () => {
|
||||||
if (continueDisabled) return;
|
if (continueDisabled) return;
|
||||||
if (activeSection === "review") {
|
if (activeSection === "review") {
|
||||||
void applySetupAsync();
|
void applySetupAsync();
|
||||||
} else if (activeSection === "connect" && hasIncompleteIntegrations) {
|
} else if (activeSection === "connect") {
|
||||||
setIncompleteIntegrationConfirmationOpened(true);
|
if (selectedAppWithoutAddress) {
|
||||||
|
setAppError(t("connect.appAddressRequired", { name: selectedAppWithoutAddress.containerName }));
|
||||||
|
setAppErrorSourceId(selectedAppWithoutAddress.sourceId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setAppError(null);
|
||||||
|
setAppErrorSourceId(null);
|
||||||
|
if (hasIncompleteIntegrations) {
|
||||||
|
setIncompleteIntegrationConfirmationOpened(true);
|
||||||
|
} else {
|
||||||
|
move(1);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
move(1);
|
move(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,7 +114,7 @@
|
|||||||
"otherIntegrations": "Add another integration",
|
"otherIntegrations": "Add another integration",
|
||||||
"configureIntegrations": "Configure integrations",
|
"configureIntegrations": "Configure integrations",
|
||||||
"discoveredApps": "Detected apps ({count})",
|
"discoveredApps": "Detected apps ({count})",
|
||||||
"appAddressRequired": "Add an HTTP or HTTPS address for {name}, or remove it from the selection.",
|
"appAddressRequired": "Add an address for {name}, or remove it from the selection.",
|
||||||
"empty": "No integrations selected. Homarr will still create a useful starter board with general widgets.",
|
"empty": "No integrations selected. Homarr will still create a useful starter board with general widgets.",
|
||||||
"dockerSource": "Docker",
|
"dockerSource": "Docker",
|
||||||
"manualSource": "Manual",
|
"manualSource": "Manual",
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import {
|
|||||||
onboardingDiscoveredAppSchema,
|
onboardingDiscoveredAppSchema,
|
||||||
} from "./onboarding";
|
} from "./onboarding";
|
||||||
|
|
||||||
describe("onboarding URL validation", () => {
|
describe("onboarding address validation", () => {
|
||||||
test.each(["javascript:alert(1)", "data:text/html,hello", "file:///etc/passwd"])(
|
test.each(["server.local:8989", "0.0.0.0:3000", "sonarr", "/services/sonarr"])(
|
||||||
"rejects the %s scheme for integrations",
|
"accepts the self-hosted address %s",
|
||||||
(url) => {
|
(url) => {
|
||||||
expect(onboardingCreateIntegrationSchema.safeParse({ name: "Unsafe", url }).success).toBe(false);
|
expect(onboardingCreateIntegrationSchema.safeParse({ name: "Service", url }).success).toBe(true);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ describe("onboarding URL validation", () => {
|
|||||||
).toBe(true);
|
).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("accepts bounded integration metadata and rejects invalid metadata", () => {
|
test("accepts bounded integration metadata and rejects empty or oversized metadata", () => {
|
||||||
expect(
|
expect(
|
||||||
onboardingCreateIntegrationSchema.safeParse({
|
onboardingCreateIntegrationSchema.safeParse({
|
||||||
name: "Sonarr",
|
name: "Sonarr",
|
||||||
@@ -41,7 +41,7 @@ describe("onboarding URL validation", () => {
|
|||||||
onboardingCreateIntegrationSchema.safeParse({
|
onboardingCreateIntegrationSchema.safeParse({
|
||||||
name: "Sonarr",
|
name: "Sonarr",
|
||||||
url: "http://sonarr:8989",
|
url: "http://sonarr:8989",
|
||||||
pingUrl: "file:///etc/passwd",
|
pingUrl: "",
|
||||||
}).success,
|
}).success,
|
||||||
).toBe(false);
|
).toBe(false);
|
||||||
expect(
|
expect(
|
||||||
@@ -53,18 +53,18 @@ describe("onboarding URL validation", () => {
|
|||||||
).toBe(false);
|
).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("rejects non-web app and ping URLs", () => {
|
test("accepts custom app and ping addresses", () => {
|
||||||
expect(
|
expect(
|
||||||
onboardingDiscoveredAppSchema.safeParse({
|
onboardingDiscoveredAppSchema.safeParse({
|
||||||
name: "Unsafe",
|
name: "Database",
|
||||||
href: "javascript:alert(1)",
|
href: "postgres://database:5432",
|
||||||
pingUrl: "file:///etc/passwd",
|
pingUrl: "database.local:5432",
|
||||||
iconUrl: null,
|
iconUrl: null,
|
||||||
}).success,
|
}).success,
|
||||||
).toBe(false);
|
).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("requires every app submitted to completeSetup to have an HTTP(S) href", () => {
|
test("requires every app submitted to completeSetup to have a non-empty address", () => {
|
||||||
const input = {
|
const input = {
|
||||||
server: { defaultLocale: "en", defaultColorScheme: "dark" },
|
server: { defaultLocale: "en", defaultColorScheme: "dark" },
|
||||||
board: {
|
board: {
|
||||||
@@ -80,7 +80,7 @@ describe("onboarding URL validation", () => {
|
|||||||
expect(
|
expect(
|
||||||
onboardingCompleteSetupSchema.safeParse({
|
onboardingCompleteSetupSchema.safeParse({
|
||||||
...input,
|
...input,
|
||||||
apps: [{ ...input.apps[0], href: "https://status.example.com" }],
|
apps: [{ ...input.apps[0], href: "status.local:3001" }],
|
||||||
}).success,
|
}).success,
|
||||||
).toBe(true);
|
).toBe(true);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ import { boardNameSchema } from "./board";
|
|||||||
import { zodEnumFromArray } from "./enums";
|
import { zodEnumFromArray } from "./enums";
|
||||||
|
|
||||||
const hexColorSchema = z.string().regex(/^#[0-9A-Fa-f]{6}$/);
|
const hexColorSchema = z.string().regex(/^#[0-9A-Fa-f]{6}$/);
|
||||||
const httpUrlSchema = z.url().refine((value) => {
|
const serviceAddressSchema = z.string().trim().min(1).max(2048);
|
||||||
const protocol = new URL(value).protocol;
|
|
||||||
return protocol === "http:" || protocol === "https:";
|
|
||||||
}, "Only HTTP and HTTPS URLs are permitted");
|
|
||||||
const uniqueIdsSchema = (maxLength = 255) =>
|
const uniqueIdsSchema = (maxLength = 255) =>
|
||||||
z
|
z
|
||||||
.array(z.string().trim().min(1).max(maxLength))
|
.array(z.string().trim().min(1).max(maxLength))
|
||||||
@@ -26,11 +23,11 @@ const sourceIdSchema = z.string().trim().min(1).max(512);
|
|||||||
|
|
||||||
export const onboardingCreateIntegrationSchema = z.object({
|
export const onboardingCreateIntegrationSchema = z.object({
|
||||||
name: z.string().trim().min(1).max(127),
|
name: z.string().trim().min(1).max(127),
|
||||||
url: httpUrlSchema,
|
url: serviceAddressSchema,
|
||||||
sourceId: sourceIdSchema.optional(),
|
sourceId: sourceIdSchema.optional(),
|
||||||
iconUrl: z.string().trim().min(1).max(2048).nullable().optional(),
|
iconUrl: z.string().trim().min(1).max(2048).nullable().optional(),
|
||||||
description: z.string().trim().max(512).nullable().optional(),
|
description: z.string().trim().max(512).nullable().optional(),
|
||||||
pingUrl: httpUrlSchema.nullable().optional(),
|
pingUrl: serviceAddressSchema.nullable().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const onboardingIntegrationDraftSchema = onboardingCreateIntegrationSchema.extend({
|
export const onboardingIntegrationDraftSchema = onboardingCreateIntegrationSchema.extend({
|
||||||
@@ -47,15 +44,15 @@ export const onboardingIntegrationDraftSchema = onboardingCreateIntegrationSchem
|
|||||||
export const onboardingDiscoveredAppSchema = z.object({
|
export const onboardingDiscoveredAppSchema = z.object({
|
||||||
sourceId: sourceIdSchema.optional(),
|
sourceId: sourceIdSchema.optional(),
|
||||||
name: z.string().trim().min(1).max(127),
|
name: z.string().trim().min(1).max(127),
|
||||||
href: httpUrlSchema.nullable(),
|
href: serviceAddressSchema.nullable(),
|
||||||
pingUrl: httpUrlSchema.nullable().optional(),
|
pingUrl: serviceAddressSchema.nullable().optional(),
|
||||||
iconUrl: z.string().trim().min(1).nullable(),
|
iconUrl: z.string().trim().min(1).nullable(),
|
||||||
description: z.string().trim().max(512).nullable().optional(),
|
description: z.string().trim().max(512).nullable().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const onboardingAppDraftSchema = onboardingDiscoveredAppSchema.extend({
|
export const onboardingAppDraftSchema = onboardingDiscoveredAppSchema.extend({
|
||||||
sourceId: sourceIdSchema,
|
sourceId: sourceIdSchema,
|
||||||
href: httpUrlSchema,
|
href: serviceAddressSchema,
|
||||||
});
|
});
|
||||||
|
|
||||||
const integrationDraftsSchema = z
|
const integrationDraftsSchema = z
|
||||||
|
|||||||
Reference in new issue
Block a user