mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 08:32:23 +01:00
fix: redirect AP request with html as Accepted content type + tests
This commit is contained in:
parent
459882cc37
commit
128e759f8a
3 changed files with 25 additions and 4 deletions
|
@ -32,7 +32,7 @@ router.get('/m/:event_id:json(.json)?', async (req, res) => {
|
|||
const event_id = req.params.event_id
|
||||
const json = req.params.json
|
||||
const acceptHtml = req.accepts('html', 'application/json', 'application/activity+json', 'application/ld+json') === 'html'
|
||||
if (acceptHtml && !json) { return res.redirect(301, `/event/${event_id}`) }
|
||||
if (acceptHtml && !json) { return res.redirect(302, `/event/${event_id}`) }
|
||||
const event = await Event.findByPk(req.params.event_id, { include: [User, Tag, Place] })
|
||||
if (!event) { return res.status(404).send('Not found') }
|
||||
const eventAp = event.toAP(settingsController.settings)
|
||||
|
|
|
@ -10,9 +10,9 @@ const get = require('lodash/get')
|
|||
|
||||
module.exports = {
|
||||
get (req, res) {
|
||||
if (req.accepts(['json','html']) !== 'json') {
|
||||
if (req.accepts('application/activity+json', 'application/ld+json', 'application/json', 'html') === 'html'){
|
||||
log.debug('[FEDI] Get actor but prefer text/html, redirect to homepage')
|
||||
return res.redirect(301, '/')
|
||||
return res.redirect(302, '/')
|
||||
}
|
||||
log.debug('[FEDI] Get actor')
|
||||
const settings = settingsController.settings
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const request = require('supertest')
|
||||
const dayjs = require('dayjs')
|
||||
const path = require('path')
|
||||
|
||||
const admin = { username: 'admin', password: 'test', grant_type: 'password', client_id: 'self' }
|
||||
|
@ -94,6 +93,28 @@ describe('Webfinger', () => {
|
|||
})
|
||||
|
||||
describe('AP', () => {
|
||||
|
||||
test('should redirect to / on html as accepted content type', async () => {
|
||||
await request(app).get('/federation/u/relay')
|
||||
.set('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8')
|
||||
.expect(302)
|
||||
.expect('Location', '/')
|
||||
})
|
||||
|
||||
test('should return a json when ld+json is accepted', async () => {
|
||||
await request(app).get('/federation/u/relay')
|
||||
.set('Accept', 'application/ld+json')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
})
|
||||
|
||||
test('should return a json when activity+json is accepted', async () => {
|
||||
await request(app).get('/federation/u/relay')
|
||||
.set('Accept', 'application/activity+json')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
})
|
||||
|
||||
test('should return the AP Actor', async () => {
|
||||
const response = await request(app).get('/federation/u/relay')
|
||||
.expect(200)
|
||||
|
|
Loading…
Reference in a new issue