diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-30 13:15:25 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-30 13:15:25 +0100 |
commit | 1b5b10d13152d704d2396a1e53d56aba1a8e7e03 (patch) | |
tree | 32e3dab1590cc909e2100fdc9aedd905cd7778f0 | |
parent | 6cbdbdef1786aabb2003918fad6cd8c0d4433f7c (diff) | |
download | PeerTube-1b5b10d13152d704d2396a1e53d56aba1a8e7e03.tar.gz PeerTube-1b5b10d13152d704d2396a1e53d56aba1a8e7e03.tar.zst PeerTube-1b5b10d13152d704d2396a1e53d56aba1a8e7e03.zip |
Fix activitypub check headers
-rw-r--r-- | server/initializers/constants.ts | 9 | ||||
-rw-r--r-- | server/middlewares/activitypub.ts | 2 | ||||
-rw-r--r-- | server/tests/utils/activitypub.ts | 15 |
3 files changed, 20 insertions, 6 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 8f278fb0b..4f63cbb02 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -220,11 +220,11 @@ const VIDEO_MIMETYPE_EXT = { | |||
220 | const SERVER_ACCOUNT_NAME = 'peertube' | 220 | const SERVER_ACCOUNT_NAME = 'peertube' |
221 | 221 | ||
222 | const ACTIVITY_PUB = { | 222 | const ACTIVITY_PUB = { |
223 | ACCEPT_HEADERS: [ | 223 | POTENTIAL_ACCEPT_HEADERS: [ |
224 | 'application/activity+json, application/ld+json', | 224 | 'application/activity+json', |
225 | 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' | 225 | 'application/ld+json' |
226 | ], | 226 | ], |
227 | ACCEPT_HEADER: '', | 227 | ACCEPT_HEADER: 'application/activity+json, application/ld+json', |
228 | PUBLIC: 'https://www.w3.org/ns/activitystreams#Public', | 228 | PUBLIC: 'https://www.w3.org/ns/activitystreams#Public', |
229 | COLLECTION_ITEMS_PER_PAGE: 10, | 229 | COLLECTION_ITEMS_PER_PAGE: 10, |
230 | FETCH_PAGE_LIMIT: 100, | 230 | FETCH_PAGE_LIMIT: 100, |
@@ -235,7 +235,6 @@ const ACTIVITY_PUB = { | |||
235 | MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ] | 235 | MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ] |
236 | } | 236 | } |
237 | } | 237 | } |
238 | ACTIVITY_PUB.ACCEPT_HEADER = ACTIVITY_PUB.ACCEPT_HEADERS[0] | ||
239 | 238 | ||
240 | // --------------------------------------------------------------------------- | 239 | // --------------------------------------------------------------------------- |
241 | 240 | ||
diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts index 7db84de97..485645720 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 | ||
38 | function executeIfActivityPub (fun: RequestHandler | RequestHandler[]) { | 38 | function executeIfActivityPub (fun: RequestHandler | RequestHandler[]) { |
39 | return (req: Request, res: Response, next: NextFunction) => { | 39 | return (req: Request, res: Response, next: NextFunction) => { |
40 | if (req.accepts(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS) === false) { | 40 | if (!req.accepts(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)) { |
41 | return next() | 41 | return next() |
42 | } | 42 | } |
43 | 43 | ||
diff --git a/server/tests/utils/activitypub.ts b/server/tests/utils/activitypub.ts new file mode 100644 index 000000000..cf3c1c3b3 --- /dev/null +++ b/server/tests/utils/activitypub.ts | |||
@@ -0,0 +1,15 @@ | |||
1 | import * as request from 'supertest' | ||
2 | |||
3 | function makeActivityPubGetRequest (url: string, path: string) { | ||
4 | return request(url) | ||
5 | .get(path) | ||
6 | .set('Accept', 'application/activity+json,text/html;q=0.9,\\*/\\*;q=0.8') | ||
7 | .expect(200) | ||
8 | .expect('Content-Type', /json/) | ||
9 | } | ||
10 | |||
11 | // --------------------------------------------------------------------------- | ||
12 | |||
13 | export { | ||
14 | makeActivityPubGetRequest | ||
15 | } | ||