Spoiler Fix #90

Manually merged
cadence merged 11 commits from Guzio/out-of-your-element:spoilerfix into main 2026-10-20 12:45:17 +00:00
Showing only changes of commit 11acba45e6 - Show all commits

stronger tests

Guzio 2026-10-20 14:32:34 +02:00

View file

@ -46,9 +46,9 @@ test("web download discord: works if a known attachment", async t => {
t.match(event.node.res.getHeader("location"), /https:\/\/cdn.discordapp.com\/attachments\/655216173696286746\/1314358913482621010\/image\.png\?ex=/) t.match(event.node.res.getHeader("location"), /https:\/\/cdn.discordapp.com\/attachments\/655216173696286746\/1314358913482621010\/image\.png\?ex=/)
}) })
test("web download discord: works with spoilers", async t => { test("web download discord: works with spoilers for humans", async t => {
const event = {} const event = {}
await router.test("get", "/download/discordcdn/:channel_id/:attachment_id/:file_name?spoiler", { await router.test("get", "/download/discordcdn/:channel_id/:attachment_id/:file_name?spoiler=yes", {
params: { params: {
channel_id: "655216173696286746", channel_id: "655216173696286746",
attachment_id: "1314358913482621010", attachment_id: "1314358913482621010",
@ -73,6 +73,35 @@ test("web download discord: works with spoilers", async t => {
t.match(event.node.res.getHeader("location"), /https:\/\/cdn.discordapp.com\/attachments\/655216173696286746\/1314358913482621010\/image\.png\?ex=/) t.match(event.node.res.getHeader("location"), /https:\/\/cdn.discordapp.com\/attachments\/655216173696286746\/1314358913482621010\/image\.png\?ex=/)
}) })
test("web download discord: rejects with spoilers for bots", async t => {
const event = {}
const [error] = await tryToCatch(() => router.test("get", "/download/discordcdn/:channel_id/:attachment_id/:file_name?spoiler=yes", {
params: {
channel_id: "655216173696286746",
attachment_id: "1314358913482621010",
file_name: "image.png"
},
headers: {
"user-agent": "Synapse (bot; +https://github.com/matrix-org/synapse)"
},
event,
snow: {
channel: {
async refreshAttachmentURLs(attachments) {
assert(Array.isArray(attachments))
return {
refreshed_urls: attachments.map(a => ({
original: a,
refreshed: a + `?ex=${Math.floor(Date.now() / 1000 + 3600).toString(16)}`
}))
}
}
}
}
}))
t.equal(error.data, "Sorry URL previewer, you can't have this URL.")
})
test("web download discord: uses cache", async t => { test("web download discord: uses cache", async t => {
let notCalled = true let notCalled = true
const event = {} const event = {}