Fix activitypub check headers
authorChocobozzz <florian.bigard@gmail.com>
Thu, 30 Nov 2017 12:15:25 +0000 (13:15 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Thu, 30 Nov 2017 12:15:25 +0000 (13:15 +0100)
server/initializers/constants.ts
server/middlewares/activitypub.ts
server/tests/utils/activitypub.ts [new file with mode: 0644]

index 8f278fb0bf6dd5be2cbada9bb503914129c1c4fd..4f63cbb020998ad1d17bdab53fbe5a699d6a776e 100644 (file)
@@ -220,11 +220,11 @@ const VIDEO_MIMETYPE_EXT = {
 const SERVER_ACCOUNT_NAME = 'peertube'
 
 const ACTIVITY_PUB = {
-  ACCEPT_HEADERS: [
-    'application/activity+json, application/ld+json',
-    'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
+  POTENTIAL_ACCEPT_HEADERS: [
+    'application/activity+json',
+    'application/ld+json'
   ],
-  ACCEPT_HEADER: '',
+  ACCEPT_HEADER: 'application/activity+json, application/ld+json',
   PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
   COLLECTION_ITEMS_PER_PAGE: 10,
   FETCH_PAGE_LIMIT: 100,
@@ -235,7 +235,6 @@ const ACTIVITY_PUB = {
     MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]
   }
 }
-ACTIVITY_PUB.ACCEPT_HEADER = ACTIVITY_PUB.ACCEPT_HEADERS[0]
 
 // ---------------------------------------------------------------------------
 
index 7db84de9786b8cda3446a90bc47c8c1d824378e1..48564572018844996f4347982181be23dad65c38 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 (req.accepts(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS) === false) {
+    if (!req.accepts(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)) {
       return next()
     }
 
diff --git a/server/tests/utils/activitypub.ts b/server/tests/utils/activitypub.ts
new file mode 100644 (file)
index 0000000..cf3c1c3
--- /dev/null
@@ -0,0 +1,15 @@
+import * as request from 'supertest'
+
+function makeActivityPubGetRequest (url: string, path: string) {
+  return request(url)
+    .get(path)
+    .set('Accept', 'application/activity+json,text/html;q=0.9,\\*/\\*;q=0.8')
+    .expect(200)
+    .expect('Content-Type', /json/)
+}
+
+// ---------------------------------------------------------------------------
+
+export {
+  makeActivityPubGetRequest
+}