Validate mxid format in web login

This commit is contained in:
Cadence Ember
2025-02-18 15:59:32 +13:00
parent ea7aec5e66
commit 902dfa7e7c
3 changed files with 20 additions and 2 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ const auth = sync.require("../auth")
const schema = {
form: z.object({
mxid: z.string(),
mxid: z.string().regex(/^@([^:]+):([a-z0-9:-]+\.[a-z0-9.:-]+)$/),
next: z.string().optional()
}),
token: z.object({
+18
View File
@@ -16,6 +16,24 @@ test("log in with matrix: shows web page with form on first request", async t =>
let token
test("log in with matrix: checks if mxid format looks valid", async t => {
const [error] = await tryToCatch(() => router.test("post", "/api/log-in-with-matrix", {
body: {
mxid: "x@cadence:cadence.moe"
}
}))
t.equal(error.data.issues[0].validation, "regex")
})
test("log in with matrix: checks if mxid domain format looks valid", async t => {
const [error] = await tryToCatch(() => router.test("post", "/api/log-in-with-matrix", {
body: {
mxid: "@cadence:cadence."
}
}))
t.equal(error.data.issues[0].validation, "regex")
})
test("log in with matrix: sends message when there is no m.direct data", async t => {
const event = {}
let called = 0