import path from "node:path"; import { describe, expect, it } from "vitest"; import { binaryName, binarySpec, DEFAULT_VERSION, } from "../../src/backend/binary.js"; import { parseProviders, validateRedirectUris, } from "../../src/backend/config.js"; import { normalizeSelectOpParam, rewriteOpksshHtml, } from "../../src/backend/html.js"; describe("config", () => { it("reads providers and strips the issuer scheme", () => { expect( parseProviders(`providers: - alias: google issuer: https://accounts.google.com redirect_uris: - http://localhost:3000/login-callback - alias: broken `), ).toEqual([ { alias: "google", issuer: "accounts.google.com", redirectUris: ["http://localhost:3000/login-callback"], }, ]); }); it("accepts localhost redirect_uris only, naming the public callback", () => { const callback = "https://termix.test/plugin-api/opkssh/callback"; expect( validateRedirectUris( [ { alias: "a", issuer: "x", redirectUris: ["http://127.0.0.1:10001/login-callback"], }, ], callback, ), ).toEqual({ ok: true }); const refused = validateRedirectUris( [{ alias: "a", issuer: "x", redirectUris: [callback] }], callback, ); expect(refused.ok).toBe(false); expect(refused.ok === false && refused.message).toContain(callback); }); }); describe("html", () => { it("sends the page's links through the proxied path", () => { const html = rewriteOpksshHtml( '
g', "/plugin-api/opkssh/chooser/req-1", ); expect(html).toContain( 'href="/plugin-api/opkssh/chooser/req-1/select?op=google"', ); expect(html).toContain('action="/plugin-api/opkssh/chooser/req-1/login"'); expect(html).toContain('