aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-30 12:00:40 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-30 12:00:40 +0100
commit6cbdbdef1786aabb2003918fad6cd8c0d4433f7c (patch)
tree5e7c94742773a1856f04d0c1a84b6316dd265f00
parent25ed141c7c7631ef21d8764c1163fbf8a6591391 (diff)
downloadPeerTube-6cbdbdef1786aabb2003918fad6cd8c0d4433f7c.tar.gz
PeerTube-6cbdbdef1786aabb2003918fad6cd8c0d4433f7c.tar.zst
PeerTube-6cbdbdef1786aabb2003918fad6cd8c0d4433f7c.zip
Check correctly activitypub headers
-rw-r--r--server/middlewares/activitypub.ts2
-rw-r--r--server/tests/activitypub.ts42
2 files changed, 43 insertions, 1 deletions
diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts
index 34386e76d..7db84de97 100644
--- a/server/middlewares/activitypub.ts
+++ b/server/middlewares/activitypub.ts
@@ -37,7 +37,7 @@ async function checkSignature (req: Request, res: Response, next: NextFunction)
37 37
38function executeIfActivityPub (fun: RequestHandler | RequestHandler[]) { 38function executeIfActivityPub (fun: RequestHandler | RequestHandler[]) {
39 return (req: Request, res: Response, next: NextFunction) => { 39 return (req: Request, res: Response, next: NextFunction) => {
40 if (ACTIVITY_PUB.ACCEPT_HEADERS.indexOf(req.header('Accept')) === -1) { 40 if (req.accepts(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS) === false) {
41 return next() 41 return next()
42 } 42 }
43 43
diff --git a/server/tests/activitypub.ts b/server/tests/activitypub.ts
new file mode 100644
index 000000000..333e02e84
--- /dev/null
+++ b/server/tests/activitypub.ts
@@ -0,0 +1,42 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from './utils'
6import { runServer } from './utils/servers'
7import { makeActivityPubGetRequest } from './utils/activitypub'
8
9const expect = chai.expect
10
11describe('Test activitypub', function () {
12 let server: ServerInfo = null
13
14 before(async function () {
15 this.timeout(10000)
16
17 await flushTests()
18
19 server = await runServer(1)
20
21 await setAccessTokensToServers([ server ])
22 })
23
24 it('Should return the account object', async function () {
25 const res = await makeActivityPubGetRequest(server.url, '/account/root')
26 const object = res.body
27
28 expect(object.type).to.equal('Person')
29 expect(object.id).to.equal('http://localhost:9001/account/root')
30 expect(object.name).to.equal('root')
31 expect(object.preferredUsername).to.equal('root')
32 })
33
34 after(async function () {
35 killallServers([ server ])
36
37 // Keep the logs if the test failed
38 if (this['ok']) {
39 await flushTests()
40 }
41 })
42})