mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +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 event_id = req.params.event_id
|
||||||
const json = req.params.json
|
const json = req.params.json
|
||||||
const acceptHtml = req.accepts('html', 'application/json', 'application/activity+json', 'application/ld+json') === 'html'
|
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] })
|
const event = await Event.findByPk(req.params.event_id, { include: [User, Tag, Place] })
|
||||||
if (!event) { return res.status(404).send('Not found') }
|
if (!event) { return res.status(404).send('Not found') }
|
||||||
const eventAp = event.toAP(settingsController.settings)
|
const eventAp = event.toAP(settingsController.settings)
|
||||||
|
|
|
@ -10,9 +10,9 @@ const get = require('lodash/get')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
get (req, res) {
|
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')
|
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')
|
log.debug('[FEDI] Get actor')
|
||||||
const settings = settingsController.settings
|
const settings = settingsController.settings
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
const request = require('supertest')
|
const request = require('supertest')
|
||||||
const dayjs = require('dayjs')
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
const admin = { username: 'admin', password: 'test', grant_type: 'password', client_id: 'self' }
|
const admin = { username: 'admin', password: 'test', grant_type: 'password', client_id: 'self' }
|
||||||
|
@ -94,6 +93,28 @@ describe('Webfinger', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('AP', () => {
|
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 () => {
|
test('should return the AP Actor', async () => {
|
||||||
const response = await request(app).get('/federation/u/relay')
|
const response = await request(app).get('/federation/u/relay')
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
Loading…
Reference in a new issue