oauth-page.test.ts 667 B

123456789101112131415
  1. import { describe, expect, test } from "bun:test"
  2. import { OauthCallbackPage } from "../src/oauth/page"
  3. describe("OauthCallbackPage", () => {
  4. test("escapes bootstrap options embedded in the inline script", () => {
  5. const html = OauthCallbackPage.bootstrap({
  6. provider: `xAI</script><script>alert("provider")</script>`,
  7. tokenPath: `/token</script><script>alert("path")</script>`,
  8. })
  9. expect(html.match(/<\/script>/g)).toHaveLength(1)
  10. expect(html).toContain(`xAI\\u003c/script>\\u003cscript>alert(\\\"provider\\\")\\u003c/script>`)
  11. expect(html).toContain(`/token\\u003c/script>\\u003cscript>alert(\\\"path\\\")\\u003c/script>`)
  12. })
  13. })