Skip to content

Commit

Permalink
Add
Browse files Browse the repository at this point in the history
  • Loading branch information
timonson committed Apr 29, 2024
1 parent bdba9ff commit d9886d5
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions server/response_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ Deno.test("rpc call with a custom error", async function (): Promise<
Deno.test("rpc call with jwt", async function (): Promise<void> {
const sentToServer = '{"jsonrpc": "2.0", "method": "login", "id": 3}';
const sentToClient = '{"jsonrpc": "2.0", "result": "Bob", "id": 3}';
const authorizationError =
'{"jsonrpc": "2.0", "error": {"code": -32020, "message": "Authorization error"}, "id": 3}';
const reqOne = createReq(sentToServer);
reqOne.headers.append("Authorization", `Bearer ${jwt}`);
assertEquals(
Expand All @@ -273,7 +275,7 @@ Deno.test("rpc call with jwt", async function (): Promise<void> {
reqTwo,
)).text(),
removeWhiteSpace(
'{"jsonrpc": "2.0", "error": {"code": -32020, "message": "Authorization error"}, "id": 3}',
authorizationError,
),
);
const reqThree = createReq(
Expand All @@ -286,7 +288,7 @@ Deno.test("rpc call with jwt", async function (): Promise<void> {
methods: new RegExp(".+"),
})(reqThree)).text(),
removeWhiteSpace(
'{"jsonrpc": "2.0", "error": {"code": -32020, "message": "Authorization error"}, "id": 3}',
authorizationError,
),
);
const reqFour = createReq(
Expand All @@ -311,7 +313,7 @@ Deno.test("rpc call with jwt", async function (): Promise<void> {
methods: ["login"],
})(reqFive)).text(),
removeWhiteSpace(
'{"jsonrpc": "2.0", "error": {"code": -32020, "message": "Authorization error"}, "id": 3}',
authorizationError,
),
);
const reqSix = createReq(sentToServer);
Expand All @@ -337,9 +339,7 @@ Deno.test("rpc call with jwt", async function (): Promise<void> {
}])(
reqSeven,
)).text(),
removeWhiteSpace(
'{"jsonrpc": "2.0", "error": {"code": -32020, "message": "Authorization error"}, "id": 3}',
),
removeWhiteSpace(authorizationError),
);
const reqEight = createReq(sentToServer);
reqEight.headers.append("Authorization", `Bearer ${jwt}`),
Expand All @@ -355,4 +355,21 @@ Deno.test("rpc call with jwt", async function (): Promise<void> {
)).text(),
removeWhiteSpace(sentToClient),
);
const reqNine = createReq(sentToServer);
reqNine.headers.append("Authorization", `Bearer ${jwt}`),
assertEquals(
await (await respond(methods, {}, [{
methods: ["login"],
verification: cryptoKey,
}, {
methods: ["login"],
verification: cryptoKey,
options: {
predicates: [() => false],
},
}])(
reqNine,
)).text(),
removeWhiteSpace(authorizationError),
);
});

0 comments on commit d9886d5

Please sign in to comment.