]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Check correctly activitypub headers
authorChocobozzz <florian.bigard@gmail.com>
Thu, 30 Nov 2017 11:00:40 +0000 (12:00 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Thu, 30 Nov 2017 11:00:40 +0000 (12:00 +0100)
server/middlewares/activitypub.ts
server/tests/activitypub.ts [new file with mode: 0644]

index 34386e76d90c3b5fd0ee1021f43ed9454b34ed23..7db84de9786b8cda3446a90bc47c8c1d824378e1 100644 (file)
@@ -37,7 +37,7 @@ async function checkSignature (req: Request, res: Response, next: NextFunction)
 
 function executeIfActivityPub (fun: RequestHandler | RequestHandler[]) {
   return (req: Request, res: Response, next: NextFunction) => {
-    if (ACTIVITY_PUB.ACCEPT_HEADERS.indexOf(req.header('Accept')) === -1) {
+    if (req.accepts(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS) === false) {
       return next()
     }
 
diff --git a/server/tests/activitypub.ts b/server/tests/activitypub.ts
new file mode 100644 (file)
index 0000000..333e02e
--- /dev/null
@@ -0,0 +1,42 @@
+/* tslint:disable:no-unused-expression */
+
+import * as chai from 'chai'
+import 'mocha'
+import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from './utils'
+import { runServer } from './utils/servers'
+import { makeActivityPubGetRequest } from './utils/activitypub'
+
+const expect = chai.expect
+
+describe('Test activitypub', function () {
+  let server: ServerInfo = null
+
+  before(async function () {
+    this.timeout(10000)
+
+    await flushTests()
+
+    server = await runServer(1)
+
+    await setAccessTokensToServers([ server ])
+  })
+
+  it('Should return the account object', async function () {
+    const res = await makeActivityPubGetRequest(server.url, '/account/root')
+    const object = res.body
+
+    expect(object.type).to.equal('Person')
+    expect(object.id).to.equal('http://localhost:9001/account/root')
+    expect(object.name).to.equal('root')
+    expect(object.preferredUsername).to.equal('root')
+  })
+
+  after(async function () {
+    killallServers([ server ])
+
+    // Keep the logs if the test failed
+    if (this['ok']) {
+      await flushTests()
+    }
+  })
+})