Unverified Commit c5893c1a authored by Hong Minhee's avatar Hong Minhee
Browse files

Get rid of calls to deprecated APIs

parent dace8380
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
    "mock_fetch": "https://deno.land/x/mock_fetch@0.3.0/mod.ts",
    "uri-template-router": "npm:uri-template-router@^0.0.16",
    "url-template": "npm:url-template@^3.1.1",
    "@fedify/fedify/sig": ".././sig/mod.ts",
    "@cliffy/ansi": "jsr:@cliffy/ansi@1.0.0-rc.4",
    "@cliffy/command": "jsr:@cliffy/command@1.0.0-rc.4",
    "@cliffy/prompt": "jsr:@cliffy/prompt@1.0.0-rc.4",
+3 −2
Original line number Diff line number Diff line
import { getLogger } from "@logtape/logtape";
import { accepts } from "@std/http/negotiation";
import { doesActorOwnKey, verify } from "../httpsig/mod.ts";
import { verifyRequest } from "../sig/http.ts";
import { doesActorOwnKey } from "../sig/owner.ts";
import type { DocumentLoader } from "../runtime/docloader.ts";
import type { Recipient } from "../vocab/actor.ts";
import {
@@ -343,7 +344,7 @@ export async function handleInbox<TContextData>(
      return await onNotFound(request);
    }
  }
  const key = await verify(request, {
  const key = await verifyRequest(request, {
    ...context,
    timeWindow: signatureTimeWindow,
  });
+14 −14
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ import {
} from "@std/assert";
import { dirname, join } from "@std/path";
import * as mf from "mock_fetch";
import { sign, verify } from "../httpsig/mod.ts";
import { signRequest, verifyRequest } from "../sig/http.ts";
import {
  FetchError,
  getAuthenticatedDocumentLoader,
@@ -34,7 +34,7 @@ Deno.test("Federation.createContext()", async (t) => {
  mf.install();

  mf.mock("GET@/object", async (req) => {
    const v = await verify(
    const v = await verifyRequest(
      req,
      {
        contextLoader: mockDocumentLoader,
@@ -267,7 +267,7 @@ Deno.test("Federation.createContext()", async (t) => {
      "No actor dispatcher registered",
    );

    const signedReq = await sign(
    const signedReq = await signRequest(
      new Request("https://example.com/"),
      privateKey2,
      publicKey2.id!,
@@ -282,7 +282,7 @@ Deno.test("Federation.createContext()", async (t) => {
    assertEquals(await signedCtx.getSignedKey(), publicKey2);
    assertEquals(await signedCtx.getSignedKeyOwner(), null);

    const signedReq2 = await sign(
    const signedReq2 = await signRequest(
      new Request("https://example.com/"),
      privateKey3,
      publicKey3.id!,
@@ -386,7 +386,7 @@ Deno.test("Federation.setInboxListeners()", async (t) => {
        inbox.push([ctx, create]);
      });

    let response = await federation.handle(
    let response = await federation.fetch(
      new Request("https://example.com/inbox", { method: "POST" }),
      { contextData: undefined },
    );
@@ -402,21 +402,21 @@ Deno.test("Federation.setInboxListeners()", async (t) => {
        privateKey: privateKey2,
        publicKey: publicKey2.publicKey!,
      }));
    response = await federation.handle(
    response = await federation.fetch(
      new Request("https://example.com/inbox", { method: "POST" }),
      { contextData: undefined },
    );
    assertEquals(inbox, []);
    assertEquals(response.status, 401);

    response = await federation.handle(
    response = await federation.fetch(
      new Request("https://example.com/users/no-one/inbox", { method: "POST" }),
      { contextData: undefined },
    );
    assertEquals(inbox, []);
    assertEquals(response.status, 404);

    response = await federation.handle(
    response = await federation.fetch(
      new Request("https://example.com/users/john/inbox", { method: "POST" }),
      { contextData: undefined },
    );
@@ -433,12 +433,12 @@ Deno.test("Federation.setInboxListeners()", async (t) => {
        await activity.toJsonLd({ contextLoader: mockDocumentLoader }),
      ),
    });
    request = await sign(
    request = await signRequest(
      request,
      privateKey2,
      new URL("https://example.com/key2"),
    );
    response = await federation.handle(request, { contextData: undefined });
    response = await federation.fetch(request, { contextData: undefined });
    assertEquals(inbox.length, 1);
    assertEquals(inbox[0][1], activity);
    assertEquals(response.status, 202);
@@ -458,12 +458,12 @@ Deno.test("Federation.setInboxListeners()", async (t) => {
        await activity.toJsonLd({ contextLoader: mockDocumentLoader }),
      ),
    });
    request = await sign(
    request = await signRequest(
      request,
      privateKey2,
      new URL("https://example.com/key2"),
    );
    response = await federation.handle(request, { contextData: undefined });
    response = await federation.fetch(request, { contextData: undefined });
    assertEquals(inbox.length, 1);
    assertEquals(inbox[0][1], activity);
    assertEquals(response.status, 202);
@@ -515,12 +515,12 @@ Deno.test("Federation.setInboxListeners()", async (t) => {
        await activity.toJsonLd({ contextLoader: mockDocumentLoader }),
      ),
    });
    request = await sign(
    request = await signRequest(
      request,
      privateKey2,
      new URL("https://example.com/key2"),
    );
    const response = await federation.handle(request, {
    const response = await federation.fetch(request, {
      contextData: undefined,
    });
    assertEquals(errors.length, 1);
+3 −2
Original line number Diff line number Diff line
@@ -6,7 +6,8 @@ import {
  assertStrictEquals,
} from "@std/assert";
import * as mf from "mock_fetch";
import { doesActorOwnKey, verify } from "../httpsig/mod.ts";
import { verifyRequest } from "../sig/http.ts";
import { doesActorOwnKey } from "../sig/owner.ts";
import { mockDocumentLoader } from "../testing/docloader.ts";
import { privateKey2, publicKey2 } from "../testing/keys.ts";
import type { Actor } from "../vocab/actor.ts";
@@ -145,7 +146,7 @@ Deno.test("sendActivity()", async (t) => {
      documentLoader: mockDocumentLoader,
      contextLoader: mockDocumentLoader,
    };
    const key = await verify(req, options);
    const key = await verifyRequest(req, options);
    const activity = await Activity.fromJsonLd(await req.json(), options);
    if (key != null && await doesActorOwnKey(activity, key, options)) {
      verified = true;
+2 −2
Original line number Diff line number Diff line
import { getLogger } from "@logtape/logtape";
import { sign } from "../httpsig/mod.ts";
import { signRequest } from "../sig/http.ts";
import type { DocumentLoader } from "../runtime/docloader.ts";
import type { Recipient } from "../vocab/actor.ts";
import type { Activity } from "../vocab/mod.ts";
@@ -125,7 +125,7 @@ export async function sendActivity(
    headers,
    body: JSON.stringify(jsonLd),
  });
  request = await sign(request, privateKey, keyId);
  request = await signRequest(request, privateKey, keyId);
  const response = await fetch(request);
  if (!response.ok) {
    let error;
Loading