Files
upstream-mirror 906fb231cc
Some checks failed
Lint and Test / Lint/Test (push) Has been cancelled
Generate Sponsors README / deploy (push) Has been skipped
snapshot of https://github.com/mountain-loop/yaak.git (main, 2026-09-23; blobs > 131072B omitted)
2026-09-23 17:39:41 +05:00

88 lines
2.3 KiB
TypeScript

import type { Context } from "@yaakapp/api";
import { describe, expect, test } from "vite-plus/test";
import { plugin } from "../src";
const ctx = {} as Context;
describe("auth-basic", () => {
test("Both username and password", async () => {
expect(
await plugin.authentication?.onApply(ctx, {
values: { username: "user", password: "pass" },
headers: [],
url: "https://yaak.app",
method: "POST",
contextId: "111",
}),
).toEqual({
setHeaders: [
{ name: "Authorization", value: `Basic ${Buffer.from("user:pass").toString("base64")}` },
],
});
});
test("Empty password", async () => {
expect(
await plugin.authentication?.onApply(ctx, {
values: { username: "apikey", password: "" },
headers: [],
url: "https://yaak.app",
method: "POST",
contextId: "111",
}),
).toEqual({
setHeaders: [
{ name: "Authorization", value: `Basic ${Buffer.from("apikey:").toString("base64")}` },
],
});
});
test("Missing password (undefined)", async () => {
expect(
await plugin.authentication?.onApply(ctx, {
values: { username: "apikey" },
headers: [],
url: "https://yaak.app",
method: "POST",
contextId: "111",
}),
).toEqual({
setHeaders: [
{ name: "Authorization", value: `Basic ${Buffer.from("apikey:").toString("base64")}` },
],
});
});
test("Missing username (undefined)", async () => {
expect(
await plugin.authentication?.onApply(ctx, {
values: { password: "secret" },
headers: [],
url: "https://yaak.app",
method: "POST",
contextId: "111",
}),
).toEqual({
setHeaders: [
{ name: "Authorization", value: `Basic ${Buffer.from(":secret").toString("base64")}` },
],
});
});
test("No values (both undefined)", async () => {
expect(
await plugin.authentication?.onApply(ctx, {
values: {},
headers: [],
url: "https://yaak.app",
method: "POST",
contextId: "111",
}),
).toEqual({
setHeaders: [
{ name: "Authorization", value: `Basic ${Buffer.from(":").toString("base64")}` },
],
});
});
});