Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as NodeHttpClient from "@effect/platform-node/NodeHttpClient";
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { homedir } from "node:os";
import * as NodeOS from "node:os";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
Expand Down Expand Up @@ -60,7 +60,7 @@ const desktopEnvironmentLayer = Layer.unwrap(
const processArch = yield* HostProcessArchitecture;
return DesktopEnvironment.layer({
dirname: __dirname,
homeDirectory: homedir(),
homeDirectory: NodeOS.homedir(),
platform,
processArch,
...metadata,
Expand Down
12 changes: 6 additions & 6 deletions apps/server/src/assets/AssetAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import {
signPayload,
timingSafeEqualBase64Url,
} from "../auth/utils.ts";
import { ServerSecretStore } from "../auth/ServerSecretStore.ts";
import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
import { resolveAttachmentPathById } from "../attachmentStore.ts";
import { ServerConfig } from "../config.ts";
import * as ServerConfig from "../config.ts";
import * as ProjectFaviconResolver from "../project/ProjectFaviconResolver.ts";
import * as WorkspacePaths from "../workspace/WorkspacePaths.ts";

Expand Down Expand Up @@ -181,7 +181,7 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i
break;
}
case "attachment": {
const config = yield* ServerConfig;
const config = yield* ServerConfig.ServerConfig;
const attachmentPath = resolveAttachmentPathById({
attachmentsDir: config.attachmentsDir,
attachmentId: input.resource.attachmentId,
Expand Down Expand Up @@ -225,7 +225,7 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i
}
}

const secretStore = yield* ServerSecretStore;
const secretStore = yield* ServerSecretStore.ServerSecretStore;
const signingSecret = yield* secretStore
.getOrCreateRandom(SIGNING_SECRET_NAME, 32)
.pipe(Effect.mapError((cause) => failAccess(cause.message, cause)));
Expand All @@ -244,7 +244,7 @@ export const resolveAsset = Effect.fn("AssetAccess.resolveAsset")(function* (
const [encodedPayload, signature] = token.split(".");
if (!encodedPayload || !signature) return null;

const secretStore = yield* ServerSecretStore;
const secretStore = yield* ServerSecretStore.ServerSecretStore;
const signingSecret = yield* secretStore
.getOrCreateRandom(SIGNING_SECRET_NAME, 32)
.pipe(Effect.orElseSucceed(() => null));
Expand All @@ -255,7 +255,7 @@ export const resolveAsset = Effect.fn("AssetAccess.resolveAsset")(function* (
if (!claims || claims.expiresAt <= (yield* Clock.currentTimeMillis)) return null;

if (claims.kind === "attachment") {
const config = yield* ServerConfig;
const config = yield* ServerConfig.ServerConfig;
const attachmentPath = resolveAttachmentPathById({
attachmentsDir: config.attachmentsDir,
attachmentId: claims.attachmentId,
Expand Down
27 changes: 10 additions & 17 deletions apps/server/src/auth/EnvironmentAuth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,25 @@ it.layer(NodeServices.layer)("EnvironmentAuth.layer", (it) => {
it.effect("classifies invalid bootstrap credential failures for the HTTP boundary", () =>
Effect.sync(() => {
const error = EnvironmentAuth.toBootstrapExchangeError(
new PairingGrantStore.BootstrapCredentialInvalidError({
message: "Unknown bootstrap credential.",
}),
new PairingGrantStore.UnknownBootstrapCredentialError({}),
);

expect(error._tag).toBe("ServerAuthInvalidCredentialError");
if (error._tag === "ServerAuthInvalidCredentialError") {
expect(error.reason).toBe("invalid_credential");
}
}),
);

it.effect("maps unexpected bootstrap failures to 500", () =>
Effect.sync(() => {
const error = EnvironmentAuth.toBootstrapExchangeError(
new PairingGrantStore.BootstrapCredentialInternalError({
message: "Failed to consume bootstrap credential.",
cause: new Error("sqlite is unavailable"),
}),
);
const cause = new PairingGrantStore.BootstrapCredentialConsumeError({
cause: new Error("sqlite is unavailable"),
});
const error = EnvironmentAuth.toBootstrapExchangeError(cause);

expect(error._tag).toBe("ServerAuthInternalError");
expect(error._tag).toBe("ServerAuthBootstrapCredentialValidationError");
expect(error.message).toBe("Failed to validate bootstrap credential.");
if (error._tag === "ServerAuthBootstrapCredentialValidationError") {
expect(error.cause).toBe(cause);
}
}),
);

Expand Down Expand Up @@ -117,10 +113,7 @@ it.layer(NodeServices.layer)("EnvironmentAuth.layer", (it) => {
)
.pipe(Effect.flip);

expect(error._tag).toBe("ServerAuthInvalidRequestError");
if (error._tag === "ServerAuthInvalidRequestError") {
expect(error.reason).toBe("scope_not_granted");
}
expect(error._tag).toBe("ServerAuthScopeNotGrantedError");
}).pipe(Effect.provide(makeEnvironmentAuthLayer())),
);

Expand Down
Loading
Loading