Commit 0c1f6103 authored by Grant's avatar Grant
Browse files

Reorganize file structure & move flags to dedicated file

parent b82c680b
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -5,3 +5,13 @@ Built with Prisma, TypeScript and oidc-provider
## Development

Move `example.env` to `.env` and edit to your desires

### Development Environment Behavior

These all have the prereq of `NODE_ENV = development`

| Env var                         | Example | Purpose                                                                                   |
| ------------------------------- | ------- | ----------------------------------------------------------------------------------------- |
| `DEV_TRUST_PROXIES`             | `true`  | Forces proxies to be trusted while still in development (behind ngrok or other dev proxy) |
| `DEV_USE_APUB_STUB`             | `true`  | Use a placeholder implementation of activitypub federation                                |
| `DEV_BYPASS_TOKEN_VERIFICATION` | `true`  | Disable verification of tokens                                                            |
+9 −9
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ import {
import { AuthSession } from "../controllers/AuthSession.js";
import { openTunnel, Tunnel } from "@hongminhee/localtunnel";
import { Server } from "node:http";
import { type APub as TAPub } from "../lib/apub/utils.js";
import { type APub as TAPub } from "../apub/utils.js";
import { type Federation } from "@fedify/fedify";
import { randomUUID } from "node:crypto";
import { configure, getConsoleSink } from "@logtape/logtape";
@@ -86,7 +86,7 @@ const getTestConfig = async (): Promise<{
        typeof entry.auth === "string" &&
        //
        "label" in entry &&
        typeof entry.label === "string"
        typeof entry.label === "string",
    )
  ) {
    return {
@@ -106,9 +106,9 @@ let federation: Federation<any>;
 * These modules may use process.env immediately
 */
const load = async () => {
  const lib_express = await import("../lib/express.js");
  const lib_apub_utils = await import("../lib/apub/utils.js");
  const lib_apub_federation = await import("../lib/apub/federation.js");
  const lib_express = await import("../routes/express.js");
  const lib_apub_utils = await import("../apub/utils.js");
  const lib_apub_federation = await import("../apub/federation.js");

  Express = lib_express.app;
  APub = lib_apub_utils.APub;
@@ -137,7 +137,7 @@ beforeAll(async () => {

  ActiveTunnel = await openTunnel({ port: PORT, service: "localhost.run" });
  console.log(
    `[Prepare] Tunnel localhost:${PORT} -> ${ActiveTunnel.url} (pid: ${ActiveTunnel.pid})`
    `[Prepare] Tunnel localhost:${PORT} -> ${ActiveTunnel.url} (pid: ${ActiveTunnel.pid})`,
  );

  // modify environment
@@ -171,7 +171,7 @@ afterAll(async () => {
});

describe.for(
  TestConfig.accounts.map(({ label, ...account }) => ({ label, account }))
  TestConfig.accounts.map(({ label, ...account }) => ({ label, account })),
)("Deliver to $label", { concurrent: true }, async ({ label, account }) => {
  let TestKit: FediTestKit;
  let sessionId: string;
@@ -195,7 +195,7 @@ describe.for(

      if (!DRY_SEND) await TestKit.setup();
    },
    account.type === "MBIN" ? 60000 : 10000
    account.type === "MBIN" ? 60000 : 10000,
  );

  test.sequential("APub#sendDM", async () => {
@@ -208,7 +208,7 @@ describe.for(
    } else {
      const version = await TestKit.getVersion();
      await ctx.annotate(
        `${label} reports as using version ${account.type} ${version}`
        `${label} reports as using version ${account.type} ${version}`,
      );
      await TestKit.expectToHave(sessionCode, 1000);
    }
+10 −11
Original line number Diff line number Diff line
@@ -16,9 +16,9 @@ import {
import { RedisKvStore, RedisMessageQueue } from "@fedify/redis";
import { Redis } from "ioredis";
import { FedifyTransformers } from "./transformers.js";
import { prisma } from "../prisma.js";
import { prisma } from "../lib/prisma.js";
import { APub } from "./utils.js";
import { Handoff } from "../../handoff/index.js";
import { Handoff } from "../handoff/index.js";

// @auth@some.domain
export const USER_IDENTIFIER = "auth";
@@ -81,9 +81,8 @@ federation
        publicKey: await importJwk(publicKey, "public"),
      });
    } else {
      const { privateKey, publicKey } = await generateCryptoKeyPair(
        "RSASSA-PKCS1-v1_5"
      );
      const { privateKey, publicKey } =
        await generateCryptoKeyPair("RSASSA-PKCS1-v1_5");
      await prisma.fediverseKeyPair.create({
        data: {
          keyType: "RSASSA-PKCS1-v1_5",
@@ -127,7 +126,7 @@ federation
      new Reject({
        actor: follow.objectId,
        object: follow,
      })
      }),
    );
  })
  .on(Create, async (ctx, create) => {
@@ -156,7 +155,7 @@ federation.setOutboxDispatcher(
    return {
      items: [],
    };
  }
  },
);

federation.setObjectDispatcher(
@@ -173,7 +172,7 @@ federation.setObjectDispatcher(

    const recipient = await lookupObject(
      authSession.user_sub,
      APub.options(ctx)
      APub.options(ctx),
    );
    const apub = new APub(ctx);

@@ -183,7 +182,7 @@ federation.setObjectDispatcher(
      ...authSession,
      target: recipient!,
    });
  }
  },
);

federation.setObjectDispatcher(
@@ -200,7 +199,7 @@ federation.setObjectDispatcher(

    const recipient = await lookupObject(
      authSession.user_sub,
      APub.options(ctx)
      APub.options(ctx),
    );
    const apub = new APub(ctx);

@@ -210,5 +209,5 @@ federation.setObjectDispatcher(
      ...authSession,
      target: recipient!,
    });
  }
  },
);
+3 −3
Original line number Diff line number Diff line
@@ -14,9 +14,9 @@ import {
} from "@fedify/fedify";
import { federation, USER_IDENTIFIER } from "./federation.js";
import { Temporal } from "@js-temporal/polyfill";
import { AuthSession } from "../../controllers/AuthSession.js";
import { IProfile } from "../instance/userMeta.js";
import { getSafeURL } from "../utils.js";
import { AuthSession } from "../controllers/AuthSession.js";
import { IProfile } from "../lib/instance/userMeta.js";
import { getSafeURL } from "../lib/utils.js";

type BuildObjectOpts = {
  id: string;
Loading