diff --git a/app/scenes/Settings/Details.tsx b/app/scenes/Settings/Details.tsx index a41b45dc5..dcc6ef5fe 100644 --- a/app/scenes/Settings/Details.tsx +++ b/app/scenes/Settings/Details.tsx @@ -18,7 +18,6 @@ import InputColor from "~/components/InputColor"; import Scene from "~/components/Scene"; import Switch from "~/components/Switch"; import Text from "~/components/Text"; -import env from "~/env"; import useCurrentTeam from "~/hooks/useCurrentTeam"; import usePolicy from "~/hooks/usePolicy"; import useStores from "~/hooks/useStores"; @@ -255,7 +254,7 @@ function Details() { {t("Behavior")} { + beforeEach(setCloudHosted); + it("should require email param", async () => { const res = await server.post("/auth/email", { body: {}, @@ -21,11 +21,19 @@ describe("email", () => { it("should respond with redirect location when user is SSO enabled", async () => { const spy = jest.spyOn(WelcomeEmail.prototype, "schedule"); - const user = await buildUser(); + const team = await buildTeam({ + subdomain: "example", + }); + const user = await buildUser({ + teamId: team.id, + }); const res = await server.post("/auth/email", { body: { email: user.email, }, + headers: { + host: "example.outline.dev", + }, }); const body = await res.json(); expect(res.status).toEqual(200); @@ -71,10 +79,6 @@ describe("email", () => { }); it("should not send email when user is on another subdomain but respond with success", async () => { - env.URL = sharedEnv.URL = "https://app.outline.dev"; - env.SUBDOMAINS_ENABLED = sharedEnv.SUBDOMAINS_ENABLED = true; - env.DEPLOYMENT = "hosted"; - const user = await buildUser(); const spy = jest.spyOn(WelcomeEmail.prototype, "schedule"); await buildTeam({ @@ -138,11 +142,10 @@ describe("email", () => { expect(spy).not.toHaveBeenCalled(); spy.mockRestore(); }); + describe("with multiple users matching email", () => { it("should default to current subdomain with SSO", async () => { const spy = jest.spyOn(SigninEmail.prototype, "schedule"); - env.URL = sharedEnv.URL = "https://app.outline.dev"; - env.SUBDOMAINS_ENABLED = sharedEnv.SUBDOMAINS_ENABLED = true; const email = "sso-user@example.org"; const team = await buildTeam({ subdomain: "example", @@ -171,8 +174,6 @@ describe("email", () => { it("should default to current subdomain with guest email", async () => { const spy = jest.spyOn(SigninEmail.prototype, "schedule"); - env.URL = sharedEnv.URL = "https://app.outline.dev"; - env.SUBDOMAINS_ENABLED = sharedEnv.SUBDOMAINS_ENABLED = true; const email = "guest-user@example.org"; const team = await buildTeam({ subdomain: "example", diff --git a/plugins/email/server/auth/email.ts b/plugins/email/server/auth/email.ts index 3cc1f862f..1ec173b8b 100644 --- a/plugins/email/server/auth/email.ts +++ b/plugins/email/server/auth/email.ts @@ -25,13 +25,13 @@ router.post( const domain = parseDomain(ctx.request.hostname); let team: Team | null | undefined; - if (!env.isCloudHosted()) { + if (!env.isCloudHosted) { team = await Team.scope("withAuthenticationProviders").findOne(); } else if (domain.custom) { team = await Team.scope("withAuthenticationProviders").findOne({ where: { domain: domain.host }, }); - } else if (env.SUBDOMAINS_ENABLED && domain.teamSubdomain) { + } else if (domain.teamSubdomain) { team = await Team.scope("withAuthenticationProviders").findOne({ where: { subdomain: domain.teamSubdomain }, }); diff --git a/plugins/webhooks/server/tasks/DeliverWebhookTask.ts b/plugins/webhooks/server/tasks/DeliverWebhookTask.ts index 7e1ae1cbb..db2f2e4f2 100644 --- a/plugins/webhooks/server/tasks/DeliverWebhookTask.ts +++ b/plugins/webhooks/server/tasks/DeliverWebhookTask.ts @@ -599,7 +599,7 @@ export default class DeliverWebhookTask extends BaseTask { }); status = response.ok ? "success" : "failed"; } catch (err) { - if (err instanceof FetchError && env.DEPLOYMENT === "hosted") { + if (err instanceof FetchError && env.isCloudHosted) { Logger.warn(`Failed to send webhook: ${err.message}`, { event, deliveryId: delivery.id, diff --git a/server/commands/accountProvisioner.test.ts b/server/commands/accountProvisioner.test.ts index e3609354c..4968626fb 100644 --- a/server/commands/accountProvisioner.test.ts +++ b/server/commands/accountProvisioner.test.ts @@ -1,10 +1,14 @@ import WelcomeEmail from "@server/emails/templates/WelcomeEmail"; -import env from "@server/env"; import { TeamDomain } from "@server/models"; import Collection from "@server/models/Collection"; import UserAuthentication from "@server/models/UserAuthentication"; import { buildUser, buildTeam } from "@server/test/factories"; -import { setupTestDatabase, seed } from "@server/test/support"; +import { + setupTestDatabase, + seed, + setCloudHosted, + setSelfHosted, +} from "@server/test/support"; import accountProvisioner from "./accountProvisioner"; setupTestDatabase(); @@ -13,9 +17,7 @@ describe("accountProvisioner", () => { const ip = "127.0.0.1"; describe("hosted", () => { - beforeEach(() => { - env.DEPLOYMENT = "hosted"; - }); + beforeEach(setCloudHosted); it("should create a new user and team", async () => { const spy = jest.spyOn(WelcomeEmail.prototype, "schedule"); @@ -325,9 +327,7 @@ describe("accountProvisioner", () => { }); describe("self hosted", () => { - beforeEach(() => { - env.DEPLOYMENT = undefined; - }); + beforeEach(setSelfHosted); it("should fail if existing team and domain not in allowed list", async () => { let error; diff --git a/server/commands/teamProvisioner.test.ts b/server/commands/teamProvisioner.test.ts index ef355dfe3..d6ee2d8fe 100644 --- a/server/commands/teamProvisioner.test.ts +++ b/server/commands/teamProvisioner.test.ts @@ -1,7 +1,10 @@ -import env from "@server/env"; import TeamDomain from "@server/models/TeamDomain"; import { buildTeam, buildUser } from "@server/test/factories"; -import { setupTestDatabase } from "@server/test/support"; +import { + setCloudHosted, + setSelfHosted, + setupTestDatabase, +} from "@server/test/support"; import teamProvisioner from "./teamProvisioner"; setupTestDatabase(); @@ -10,9 +13,7 @@ describe("teamProvisioner", () => { const ip = "127.0.0.1"; describe("hosted", () => { - beforeEach(() => { - env.DEPLOYMENT = "hosted"; - }); + beforeEach(setCloudHosted); it("should create team and authentication provider", async () => { const result = await teamProvisioner({ @@ -127,9 +128,7 @@ describe("teamProvisioner", () => { }); describe("self hosted", () => { - beforeEach(() => { - env.DEPLOYMENT = undefined; - }); + beforeEach(setSelfHosted); it("should allow creating first team", async () => { const { team, isNewTeam } = await teamProvisioner({ diff --git a/server/commands/teamProvisioner.ts b/server/commands/teamProvisioner.ts index 15182308c..af694209a 100644 --- a/server/commands/teamProvisioner.ts +++ b/server/commands/teamProvisioner.ts @@ -78,7 +78,7 @@ async function teamProvisioner({ }; } else if (teamId) { // The user is attempting to log into a team with an unfamiliar SSO provider - if (env.isCloudHosted()) { + if (env.isCloudHosted) { throw InvalidAuthenticationError(); } diff --git a/server/commands/teamUpdater.ts b/server/commands/teamUpdater.ts index 3d9b30a4d..0ff784d17 100644 --- a/server/commands/teamUpdater.ts +++ b/server/commands/teamUpdater.ts @@ -34,7 +34,7 @@ const teamUpdater = async ({ preferences, } = params; - if (subdomain !== undefined && env.SUBDOMAINS_ENABLED) { + if (subdomain !== undefined && env.isCloudHosted) { team.subdomain = subdomain === "" ? null : subdomain; } diff --git a/server/emails/mailer.tsx b/server/emails/mailer.tsx index ab303792d..4d4f6f09c 100644 --- a/server/emails/mailer.tsx +++ b/server/emails/mailer.tsx @@ -164,7 +164,7 @@ export class Mailer { }, } : undefined, - attachments: env.isCloudHosted() + attachments: env.isCloudHosted ? undefined : [ { diff --git a/server/emails/templates/components/Header.tsx b/server/emails/templates/components/Header.tsx index d89db5b42..5475639d2 100644 --- a/server/emails/templates/components/Header.tsx +++ b/server/emails/templates/components/Header.tsx @@ -14,7 +14,7 @@ export default () => ( {env.APP_NAME} { + beforeEach(setCloudHosted); + describe("create", () => { it("should allow creation of domains", async () => { const team = await buildTeam(); @@ -37,7 +38,6 @@ describe("team domain model", () => { }); it("should not allow creation of domains within restricted list", async () => { - env.DEPLOYMENT = "hosted"; const TeamDomain = await import("./TeamDomain"); const team = await buildTeam(); const user = await buildAdmin({ teamId: team.id }); @@ -57,7 +57,6 @@ describe("team domain model", () => { }); it("should ignore casing and spaces when creating domains", async () => { - env.DEPLOYMENT = "hosted"; const TeamDomain = await import("./TeamDomain"); const team = await buildTeam(); const user = await buildAdmin({ teamId: team.id }); diff --git a/server/models/TeamDomain.ts b/server/models/TeamDomain.ts index 844419bc6..f96f63383 100644 --- a/server/models/TeamDomain.ts +++ b/server/models/TeamDomain.ts @@ -23,7 +23,7 @@ import Length from "./validators/Length"; @Fix class TeamDomain extends IdModel { @NotIn({ - args: env.isCloudHosted() ? [emailProviders] : [], + args: env.isCloudHosted ? [emailProviders] : [], msg: "You chose a restricted domain, please try another.", }) @NotEmpty diff --git a/server/models/helpers/AuthenticationHelper.ts b/server/models/helpers/AuthenticationHelper.ts index c20b5c281..f99f2789a 100644 --- a/server/models/helpers/AuthenticationHelper.ts +++ b/server/models/helpers/AuthenticationHelper.ts @@ -74,7 +74,7 @@ export default class AuthenticationHelper { * @returns A list of authentication providers */ public static providersForTeam(team?: Team) { - const isCloudHosted = env.isCloudHosted(); + const isCloudHosted = env.isCloudHosted; return AuthenticationHelper.providers .sort((config) => (config.id === "email" ? 1 : -1)) diff --git a/server/policies/team.test.ts b/server/policies/team.test.ts index ce20ad72c..3c1824ae8 100644 --- a/server/policies/team.test.ts +++ b/server/policies/team.test.ts @@ -1,11 +1,16 @@ -import env from "@server/env"; import { buildUser, buildTeam, buildAdmin } from "@server/test/factories"; -import { setupTestDatabase } from "@server/test/support"; +import { + setCloudHosted, + setSelfHosted, + setupTestDatabase, +} from "@server/test/support"; import { serialize } from "./index"; setupTestDatabase(); it("should allow reading only", async () => { + setSelfHosted(); + const team = await buildTeam(); const user = await buildUser({ teamId: team.id, @@ -21,6 +26,8 @@ it("should allow reading only", async () => { }); it("should allow admins to manage", async () => { + setSelfHosted(); + const team = await buildTeam(); const admin = await buildAdmin({ teamId: team.id, @@ -36,7 +43,7 @@ it("should allow admins to manage", async () => { }); it("should allow creation on hosted envs", async () => { - env.DEPLOYMENT = "hosted"; + setCloudHosted(); const team = await buildTeam(); const admin = await buildAdmin({ diff --git a/server/policies/team.ts b/server/policies/team.ts index 70ffffe07..f09aef0c0 100644 --- a/server/policies/team.ts +++ b/server/policies/team.ts @@ -13,7 +13,7 @@ allow(User, "share", Team, (user, team) => { }); allow(User, "createTeam", Team, () => { - if (!env.isCloudHosted()) { + if (!env.isCloudHosted) { throw IncorrectEditionError("Functionality is only available on cloud"); } return true; @@ -27,7 +27,7 @@ allow(User, "update", Team, (user, team) => { }); allow(User, ["delete", "audit"], Team, (user, team) => { - if (!env.isCloudHosted()) { + if (!env.isCloudHosted) { throw IncorrectEditionError("Functionality is only available on cloud"); } if (!team || user.isViewer || user.teamId !== team.id) { diff --git a/server/presenters/env.ts b/server/presenters/env.ts index a34414e17..ce90e34fe 100644 --- a/server/presenters/env.ts +++ b/server/presenters/env.ts @@ -16,14 +16,12 @@ export default function present( COLLABORATION_URL: (env.COLLABORATION_URL || env.URL) .replace(/\/$/, "") .replace(/^http/, "ws"), - DEPLOYMENT: env.DEPLOYMENT, ENVIRONMENT: env.ENVIRONMENT, SENTRY_DSN: env.SENTRY_DSN, SENTRY_TUNNEL: env.SENTRY_TUNNEL, SLACK_CLIENT_ID: env.SLACK_CLIENT_ID, SLACK_APP_ID: env.SLACK_APP_ID, MAXIMUM_IMPORT_SIZE: env.MAXIMUM_IMPORT_SIZE, - SUBDOMAINS_ENABLED: env.SUBDOMAINS_ENABLED, PDF_EXPORT_ENABLED: false, DEFAULT_LANGUAGE: env.DEFAULT_LANGUAGE, EMAIL_ENABLED: !!env.SMTP_HOST || env.ENVIRONMENT === "development", diff --git a/server/routes/api/auth/auth.test.ts b/server/routes/api/auth/auth.test.ts index b95a0c85d..b07b51132 100644 --- a/server/routes/api/auth/auth.test.ts +++ b/server/routes/api/auth/auth.test.ts @@ -1,7 +1,9 @@ -import sharedEnv from "@shared/env"; -import env from "@server/env"; import { buildUser, buildTeam } from "@server/test/factories"; -import { getTestServer } from "@server/test/support"; +import { + getTestServer, + setCloudHosted, + setSelfHosted, +} from "@server/test/support"; const mockTeamInSessionId = "1e023d05-951c-41c6-9012-c9fa0402e1c3"; @@ -14,6 +16,8 @@ jest.mock("@server/utils/authentication", () => ({ const server = getTestServer(); describe("#auth.info", () => { + beforeEach(setCloudHosted); + it("should return current authentication", async () => { const team = await buildTeam(); const team2 = await buildTeam(); @@ -93,8 +97,6 @@ describe("#auth.delete", () => { describe("#auth.config", () => { it("should return available SSO providers", async () => { - env.DEPLOYMENT = "hosted"; - const res = await server.post("/api/auth.config"); const body = await res.json(); expect(res.status).toEqual(200); @@ -105,10 +107,6 @@ describe("#auth.config", () => { }); it("should return available providers for team subdomain", async () => { - env.URL = sharedEnv.URL = "https://app.outline.dev"; - env.SUBDOMAINS_ENABLED = sharedEnv.SUBDOMAINS_ENABLED = true; - env.DEPLOYMENT = "hosted"; - await buildTeam({ guestSignin: false, subdomain: "example", @@ -131,8 +129,6 @@ describe("#auth.config", () => { }); it("should return available providers for team custom domain", async () => { - env.DEPLOYMENT = "hosted"; - await buildTeam({ guestSignin: false, domain: "docs.mycompany.com", @@ -155,9 +151,6 @@ describe("#auth.config", () => { }); it("should return email provider for team when guest signin enabled", async () => { - env.URL = sharedEnv.URL = "https://app.outline.dev"; - env.DEPLOYMENT = "hosted"; - await buildTeam({ guestSignin: true, subdomain: "example", @@ -181,9 +174,6 @@ describe("#auth.config", () => { }); it("should not return provider when disabled", async () => { - env.URL = sharedEnv.URL = "https://app.outline.dev"; - env.DEPLOYMENT = "hosted"; - await buildTeam({ guestSignin: false, subdomain: "example", @@ -206,8 +196,9 @@ describe("#auth.config", () => { }); describe("self hosted", () => { + beforeEach(setSelfHosted); + it("should return all configured providers but respect email setting", async () => { - env.DEPLOYMENT = ""; await buildTeam({ guestSignin: false, authenticationProviders: [ @@ -227,7 +218,6 @@ describe("#auth.config", () => { }); it("should return email provider for team when guest signin enabled", async () => { - env.DEPLOYMENT = ""; await buildTeam({ guestSignin: true, authenticationProviders: [ diff --git a/server/routes/api/auth/auth.ts b/server/routes/api/auth/auth.ts index 5467260d9..9bfb16fa4 100644 --- a/server/routes/api/auth/auth.ts +++ b/server/routes/api/auth/auth.ts @@ -26,7 +26,7 @@ router.post("auth.config", async (ctx: APIContext) => { // If self hosted AND there is only one team then that team becomes the // brand for the knowledge base and it's guest signin option is used for the // root login page. - if (!env.isCloudHosted()) { + if (!env.isCloudHosted) { const team = await Team.scope("withAuthenticationProviders").findOne(); if (team) { @@ -75,7 +75,7 @@ router.post("auth.config", async (ctx: APIContext) => { // If subdomain signin page then we return minimal team details to allow // for a custom screen showing only relevant signin options for that team. - else if (env.SUBDOMAINS_ENABLED && domain.teamSubdomain) { + else if (env.isCloudHosted && domain.teamSubdomain) { const team = await Team.scope("withAuthenticationProviders").findOne({ where: { subdomain: domain.teamSubdomain, @@ -179,7 +179,7 @@ router.post( ctx.cookies.set("accessToken", "", { expires: subMinutes(new Date(), 1), - domain: getCookieDomain(ctx.hostname), + domain: getCookieDomain(ctx.hostname, env.isCloudHosted), }); ctx.body = { diff --git a/server/routes/api/events/events.test.ts b/server/routes/api/events/events.test.ts index 29de1ee6e..1861c15db 100644 --- a/server/routes/api/events/events.test.ts +++ b/server/routes/api/events/events.test.ts @@ -1,13 +1,10 @@ -import env from "@server/env"; import { buildEvent, buildUser } from "@server/test/factories"; -import { seed, getTestServer } from "@server/test/support"; +import { seed, getTestServer, setCloudHosted } from "@server/test/support"; const server = getTestServer(); describe("#events.list", () => { - beforeEach(() => { - env.DEPLOYMENT = "hosted"; - }); + beforeEach(setCloudHosted); it("should only return activity events", async () => { const { user, admin, document, collection } = await seed(); diff --git a/server/routes/api/teams/teams.test.ts b/server/routes/api/teams/teams.test.ts index 59d9678bf..88b106eaf 100644 --- a/server/routes/api/teams/teams.test.ts +++ b/server/routes/api/teams/teams.test.ts @@ -1,13 +1,18 @@ -import env from "@server/env"; import { TeamDomain } from "@server/models"; import { buildAdmin, buildCollection, buildTeam } from "@server/test/factories"; -import { seed, getTestServer } from "@server/test/support"; +import { + seed, + getTestServer, + setCloudHosted, + setSelfHosted, +} from "@server/test/support"; const server = getTestServer(); describe("teams.create", () => { it("creates a team", async () => { - env.DEPLOYMENT = "hosted"; + setCloudHosted(); + const team = await buildTeam(); const user = await buildAdmin({ teamId: team.id }); const res = await server.post("/api/teams.create", { @@ -23,7 +28,8 @@ describe("teams.create", () => { }); it("requires a cloud hosted deployment", async () => { - env.DEPLOYMENT = ""; + setSelfHosted(); + const team = await buildTeam(); const user = await buildAdmin({ teamId: team.id }); const res = await server.post("/api/teams.create", { diff --git a/server/test/env.ts b/server/test/env.ts index 31c47802f..9a300a204 100644 --- a/server/test/env.ts +++ b/server/test/env.ts @@ -17,7 +17,6 @@ env.OIDC_TOKEN_URI = "http://localhost/token"; env.OIDC_USERINFO_URI = "http://localhost/userinfo"; env.RATE_LIMITER_ENABLED = false; -env.DEPLOYMENT = undefined; if (process.env.DATABASE_URL_TEST) { env.DATABASE_URL = process.env.DATABASE_URL_TEST; diff --git a/server/test/support.ts b/server/test/support.ts index e924ca8e7..59b485f39 100644 --- a/server/test/support.ts +++ b/server/test/support.ts @@ -1,6 +1,8 @@ import TestServer from "fetch-test-server"; import { v4 as uuidv4 } from "uuid"; +import sharedEnv from "@shared/env"; import { CollectionPermission } from "@shared/types"; +import env from "@server/env"; import { User, Document, Collection, Team } from "@server/models"; import onerror from "@server/onerror"; import webService from "@server/services/web"; @@ -137,3 +139,17 @@ export function setupTestDatabase() { afterAll(disconnect); beforeEach(flush); } + +/** + * Set the environment to be cloud hosted + */ +export function setCloudHosted() { + return (env.URL = sharedEnv.URL = "https://app.outline.dev"); +} + +/** + * Set the environment to be self hosted + */ +export function setSelfHosted() { + return (env.URL = sharedEnv.URL = "https://wiki.example.com"); +} diff --git a/server/utils/authentication.ts b/server/utils/authentication.ts index 39c09b6da..c9b85fbe2 100644 --- a/server/utils/authentication.ts +++ b/server/utils/authentication.ts @@ -71,7 +71,7 @@ export async function signIn( }, ip: ctx.request.ip, }); - const domain = getCookieDomain(ctx.request.hostname); + const domain = getCookieDomain(ctx.request.hostname, env.isCloudHosted); const expires = addMonths(new Date(), 3); // set a cookie for which service we last signed in with. This is @@ -85,7 +85,7 @@ export async function signIn( // set a transfer cookie for the access token itself and redirect // to the teams subdomain if subdomains are enabled - if (env.SUBDOMAINS_ENABLED && team.subdomain) { + if (env.isCloudHosted && team.subdomain) { // get any existing sessions (teams signed in) and add this team const existing = getSessionsInCookie(ctx); const sessions = encodeURIComponent( diff --git a/server/utils/azure.ts b/server/utils/azure.ts index da954d619..69350d20f 100644 --- a/server/utils/azure.ts +++ b/server/utils/azure.ts @@ -22,7 +22,7 @@ export default class AzureClient extends OAuthClient { refreshToken?: string; expiresAt: Date; }> { - if (env.isCloudHosted()) { + if (env.isCloudHosted) { return super.rotateToken(accessToken, refreshToken); } diff --git a/server/utils/fetch.ts b/server/utils/fetch.ts index b255f721e..2a66bb1c3 100644 --- a/server/utils/fetch.ts +++ b/server/utils/fetch.ts @@ -19,10 +19,10 @@ export default function fetch( ): Promise { // In self-hosted, webhooks support proxying and are also allowed to connect // to internal services, so use fetchWithProxy without the filtering agent. - const fetch = env.isCloudHosted() ? nodeFetch : fetchWithProxy; + const fetch = env.isCloudHosted ? nodeFetch : fetchWithProxy; return fetch(url, { ...init, - agent: env.isCloudHosted() ? useAgent(url) : undefined, + agent: env.isCloudHosted ? useAgent(url) : undefined, }); } diff --git a/server/utils/passport.ts b/server/utils/passport.ts index e4cd2dfd9..708440a90 100644 --- a/server/utils/passport.ts +++ b/server/utils/passport.ts @@ -28,7 +28,7 @@ export class StateStore { ctx.cookies.set(this.key, state, { expires: addMinutes(new Date(), 10), - domain: getCookieDomain(ctx.hostname), + domain: getCookieDomain(ctx.hostname, env.isCloudHosted), }); callback(null, token); @@ -54,7 +54,7 @@ export class StateStore { // Destroy the one-time pad token and ensure it matches ctx.cookies.set(this.key, "", { expires: subMinutes(new Date(), 1), - domain: getCookieDomain(ctx.hostname), + domain: getCookieDomain(ctx.hostname, env.isCloudHosted), }); if (!token || token !== providedToken) { @@ -100,11 +100,11 @@ export async function getTeamFromContext(ctx: Context) { const domain = parseDomain(host); let team; - if (!env.isCloudHosted()) { + if (!env.isCloudHosted) { team = await Team.findOne(); } else if (domain.custom) { team = await Team.findOne({ where: { domain: domain.host } }); - } else if (env.SUBDOMAINS_ENABLED && domain.teamSubdomain) { + } else if (domain.teamSubdomain) { team = await Team.findOne({ where: { subdomain: domain.teamSubdomain }, }); diff --git a/server/utils/robots.ts b/server/utils/robots.ts index c5f85bc1d..c92545323 100644 --- a/server/utils/robots.ts +++ b/server/utils/robots.ts @@ -1,7 +1,7 @@ import env from "@server/env"; export const robotsResponse = () => { - if (env.isCloudHosted()) { + if (env.isCloudHosted) { return ` User-agent: * Allow: / diff --git a/server/utils/startup.ts b/server/utils/startup.ts index 6ec03f9f2..ffd762ea9 100644 --- a/server/utils/startup.ts +++ b/server/utils/startup.ts @@ -10,7 +10,7 @@ export async function checkPendingMigrations() { try { const pending = await migrations.pending(); if (!isEmpty(pending)) { - if (env.isCloudHosted()) { + if (env.isCloudHosted) { Logger.warn(chalk.red("Migrations are pending")); process.exit(1); } else { @@ -34,7 +34,7 @@ export async function checkPendingMigrations() { } export async function checkDataMigrations() { - if (env.isCloudHosted()) { + if (env.isCloudHosted) { return; } diff --git a/shared/types.ts b/shared/types.ts index 1d32d4065..6d9475717 100644 --- a/shared/types.ts +++ b/shared/types.ts @@ -44,14 +44,12 @@ export type PublicEnv = { COLLABORATION_URL: string; AWS_S3_UPLOAD_BUCKET_URL: string; AWS_S3_ACCELERATE_URL: string; - DEPLOYMENT: string | undefined; ENVIRONMENT: string; SENTRY_DSN: string | undefined; SENTRY_TUNNEL: string | undefined; SLACK_CLIENT_ID: string | undefined; SLACK_APP_ID: string | undefined; MAXIMUM_IMPORT_SIZE: number; - SUBDOMAINS_ENABLED: boolean; EMAIL_ENABLED: boolean; PDF_EXPORT_ENABLED: boolean; DEFAULT_LANGUAGE: string; diff --git a/shared/utils/domains.test.ts b/shared/utils/domains.test.ts index 64f04543e..85e680bde 100644 --- a/shared/utils/domains.test.ts +++ b/shared/utils/domains.test.ts @@ -169,27 +169,27 @@ describe("#slugifyDomain", () => { describe("#getCookieDomain", () => { beforeEach(() => { env.URL = "https://example.com"; - env.SUBDOMAINS_ENABLED = true; }); it("returns the normalized app host when on the host domain", () => { - expect(getCookieDomain("subdomain.example.com")).toBe("example.com"); - expect(getCookieDomain("www.example.com")).toBe("example.com"); - expect(getCookieDomain("http://example.com:3000")).toBe("example.com"); - expect(getCookieDomain("myteam.example.com/document/12345?q=query")).toBe( + expect(getCookieDomain("subdomain.example.com", true)).toBe("example.com"); + expect(getCookieDomain("www.example.com", true)).toBe("example.com"); + expect(getCookieDomain("http://example.com:3000", true)).toBe( "example.com" ); + expect( + getCookieDomain("myteam.example.com/document/12345?q=query", true) + ).toBe("example.com"); }); it("returns the input if not on the host domain", () => { - expect(getCookieDomain("www.blogspot.com")).toBe("www.blogspot.com"); - expect(getCookieDomain("anything else")).toBe("anything else"); + expect(getCookieDomain("www.blogspot.com", true)).toBe("www.blogspot.com"); + expect(getCookieDomain("anything else", true)).toBe("anything else"); }); - it("always returns the input when subdomains are not enabled", () => { - env.SUBDOMAINS_ENABLED = false; - expect(getCookieDomain("example.com")).toBe("example.com"); - expect(getCookieDomain("www.blogspot.com")).toBe("www.blogspot.com"); - expect(getCookieDomain("anything else")).toBe("anything else"); + it("always returns the input when not cloud hosted", () => { + expect(getCookieDomain("example.com", false)).toBe("example.com"); + expect(getCookieDomain("www.blogspot.com", false)).toBe("www.blogspot.com"); + expect(getCookieDomain("anything else", false)).toBe("anything else"); }); }); diff --git a/shared/utils/domains.ts b/shared/utils/domains.ts index 69a2a5a49..95eb997ae 100644 --- a/shared/utils/domains.ts +++ b/shared/utils/domains.ts @@ -65,10 +65,10 @@ export function parseDomain(url: string): Domain { }; } -export function getCookieDomain(domain: string) { +export function getCookieDomain(domain: string, isCloudHosted: boolean) { // always use the base URL for cookies when in hosted mode // and the domain is not custom - if (env.SUBDOMAINS_ENABLED) { + if (isCloudHosted) { const parsed = parseDomain(domain); if (!parsed.custom) {