-
-
Notifications
You must be signed in to change notification settings - Fork 124
Fix fedify/next test-each failure, add fedify/next tests #978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+131
−7
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3dbd090
Fix fedify/next test-each failure
Bananamilk452 45ec80f
Add Accept header detection test in fedify/next
Bananamilk452 e303b17
Add Content-Type header detection test in fedify/next
Bananamilk452 eae229c
Add NodeInfo route detection test in fedify/next
Bananamilk452 f3e2434
Add non-federation request delegation test in fedify/next
Bananamilk452 ccddfbf
Add custom not found/not acceptable handler
Bananamilk452 6f7a221
Edit deno.json, mise.toml, package.json to fix test in fedify/next
Bananamilk452 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { | ||
| createFederation, | ||
| InProcessMessageQueue, | ||
| MemoryKvStore, | ||
| } from "@fedify/fedify"; | ||
| import { test } from "@fedify/fixture"; | ||
| import { strict as assert } from "node:assert"; | ||
|
2chanhaeng marked this conversation as resolved.
|
||
| import { | ||
| fedifyWith, | ||
| integrateFederation, | ||
| isFederationRequest, | ||
| isNodeInfoRequest, | ||
| } from "./index.ts"; | ||
|
|
||
| test("Accept header detection", () => { | ||
| const request = new Request("https://example.com/", { | ||
| headers: { | ||
| Accept: "application/activity+json", | ||
| }, | ||
| }); | ||
|
|
||
| assert.strictEqual(isFederationRequest(request), true); | ||
| }); | ||
|
|
||
| test("Content-Type header detection", () => { | ||
| const request = new Request("https://example.com/", { | ||
| method: "POST", | ||
| headers: { | ||
| "Content-Type": "application/activity+json", | ||
| }, | ||
| }); | ||
|
|
||
| assert.strictEqual(isFederationRequest(request), true); | ||
| }); | ||
|
|
||
| test("NodeInfo route detection", () => { | ||
| const request1 = new Request("https://example.com/.well-known/nodeinfo", {}); | ||
|
|
||
| const request2 = new Request( | ||
| "https://example.com/.well-known/x-nodeinfo2", | ||
| {}, | ||
| ); | ||
|
|
||
| assert.strictEqual(isNodeInfoRequest(request1), true); | ||
| assert.strictEqual(isNodeInfoRequest(request2), true); | ||
| }); | ||
|
|
||
| test("Non-federation request delegation", async () => { | ||
| const federation = createFederation({ | ||
| kv: new MemoryKvStore(), | ||
| queue: new InProcessMessageQueue(), | ||
| }); | ||
| const customMiddleware = (request: Request) => { | ||
| if (request.url === "https://example.com/test") { | ||
| return new Response("Custom middleware response"); | ||
| } | ||
| return new Response("Default response"); | ||
| }; | ||
| const middleware = fedifyWith(federation)(customMiddleware); | ||
|
|
||
| const request = new Request("https://example.com/", { | ||
| headers: { | ||
| Accept: "text/html", | ||
| }, | ||
| }); | ||
|
|
||
| const request2 = new Request("https://example.com/test", { | ||
| headers: { | ||
| Accept: "text/html", | ||
| }, | ||
| }); | ||
|
|
||
| assert.strictEqual(isFederationRequest(request), false); | ||
| assert.strictEqual(isFederationRequest(request2), false); | ||
|
|
||
| const response1 = await middleware(request); | ||
| const response2 = await middleware(request2); | ||
|
|
||
| assert.strictEqual(await response1.text(), "Default response"); | ||
| assert.strictEqual(await response2.text(), "Custom middleware response"); | ||
| }); | ||
|
|
||
| test("Custom not-found/not acceptable handler", async () => { | ||
| const federation = createFederation({ | ||
| kv: new MemoryKvStore(), | ||
| queue: new InProcessMessageQueue(), | ||
| }); | ||
|
|
||
| // Set up a dispatcher that always returns null to simulate a not acceptable scenario | ||
| federation.setActorDispatcher("/users/{identifier}", () => null); | ||
|
|
||
| const handler = integrateFederation(federation, undefined, { | ||
| onNotFound: () => new Response("Custom not found", { status: 418 }), | ||
| onNotAcceptable: () => | ||
| new Response("Custom not acceptable", { status: 418 }), | ||
| }); | ||
|
|
||
| const response1 = await handler( | ||
| new Request("https://example.com/missing", { | ||
| headers: { Accept: "application/activity+json" }, | ||
| }), | ||
| ); | ||
|
|
||
| assert.strictEqual(response1.status, 418); | ||
| assert.strictEqual(await response1.text(), "Custom not found"); | ||
|
|
||
| const response2 = await handler( | ||
| new Request("https://example.com/users/123", { | ||
| headers: { Accept: "text/html" }, | ||
| }), | ||
| ); | ||
|
|
||
| assert.strictEqual(response2.status, 418); | ||
| assert.strictEqual(await response2.text(), "Custom not acceptable"); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.