aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-11-14 16:32:12 +0100
committerChocobozzz <me@florianbigard.com>2018-11-14 16:32:28 +0100
commita130f33c9c07ffaf2f11a5e629d686a158b9e1c7 (patch)
tree8e340e536e6a755b9a0ec3e96f9c8583f570579e /server
parente5cb43e071924b8cbc77731d3a0511b4f7bcff9d (diff)
downloadPeerTube-a130f33c9c07ffaf2f11a5e629d686a158b9e1c7.tar.gz
PeerTube-a130f33c9c07ffaf2f11a5e629d686a158b9e1c7.tar.zst
PeerTube-a130f33c9c07ffaf2f11a5e629d686a158b9e1c7.zip
Add AP fetch tests
Diffstat (limited to 'server')
-rw-r--r--server/tests/api/activitypub/fetch.ts86
-rw-r--r--server/tests/api/activitypub/index.ts1
-rw-r--r--server/tests/utils/miscs/sql.ts9
3 files changed, 96 insertions, 0 deletions
diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts
new file mode 100644
index 000000000..a42c606c6
--- /dev/null
+++ b/server/tests/api/activitypub/fetch.ts
@@ -0,0 +1,86 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4
5import {
6 createUser,
7 doubleFollow,
8 flushAndRunMultipleServers,
9 flushTests,
10 getVideosListSort,
11 killallServers,
12 ServerInfo,
13 setAccessTokensToServers,
14 uploadVideo,
15 userLogin
16} from '../../utils'
17import * as chai from 'chai'
18import { setActorField, setVideoField } from '../../utils/miscs/sql'
19import { waitJobs } from '../../utils/server/jobs'
20import { Video } from '../../../../shared/models/videos'
21
22const expect = chai.expect
23
24describe('Test ActivityPub fetcher', function () {
25 let servers: ServerInfo[]
26
27 // ---------------------------------------------------------------
28
29 before(async function () {
30 this.timeout(60000)
31
32 servers = await flushAndRunMultipleServers(3)
33
34 // Get the access tokens
35 await setAccessTokensToServers(servers)
36
37 const user = { username: 'user1', password: 'password' }
38 for (const server of servers) {
39 await createUser(server.url, server.accessToken, user.username, user.password)
40 }
41
42 const userAccessToken = await userLogin(servers[0], user)
43
44 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' })
45 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' })
46 const badVideoUUID = res.body.video.uuid
47 await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' })
48
49 await setActorField(1, 'http://localhost:9001/accounts/user1', 'url', 'http://localhost:9002/accounts/user1')
50 await setVideoField(1, badVideoUUID, 'url', 'http://localhost:9003/videos/watch/' + badVideoUUID)
51 })
52
53 it('Should add only the video with a valid actor URL', async function () {
54 this.timeout(60000)
55
56 await doubleFollow(servers[0], servers[1])
57 await waitJobs(servers)
58
59 {
60 const res = await getVideosListSort(servers[0].url, 'createdAt')
61 expect(res.body.total).to.equal(3)
62
63 const data: Video[] = res.body.data
64 expect(data[0].name).to.equal('video root')
65 expect(data[1].name).to.equal('bad video root')
66 expect(data[2].name).to.equal('video user')
67 }
68
69 {
70 const res = await getVideosListSort(servers[1].url, 'createdAt')
71 expect(res.body.total).to.equal(1)
72
73 const data: Video[] = res.body.data
74 expect(data[0].name).to.equal('video root')
75 }
76 })
77
78 after(async function () {
79 killallServers(servers)
80
81 // Keep the logs if the test failed
82 if (this['ok']) {
83 await flushTests()
84 }
85 })
86})
diff --git a/server/tests/api/activitypub/index.ts b/server/tests/api/activitypub/index.ts
index de8a59978..e748f32e9 100644
--- a/server/tests/api/activitypub/index.ts
+++ b/server/tests/api/activitypub/index.ts
@@ -1,3 +1,4 @@
1import './client' 1import './client'
2import './fetch'
2import './helpers' 3import './helpers'
3import './security' 4import './security'
diff --git a/server/tests/utils/miscs/sql.ts b/server/tests/utils/miscs/sql.ts
index 204ff5163..027f78131 100644
--- a/server/tests/utils/miscs/sql.ts
+++ b/server/tests/utils/miscs/sql.ts
@@ -24,6 +24,15 @@ function setActorField (serverNumber: number, to: string, field: string, value:
24 return seq.query(`UPDATE actor SET "${field}" = '${value}' WHERE url = '${to}'`, options) 24 return seq.query(`UPDATE actor SET "${field}" = '${value}' WHERE url = '${to}'`, options)
25} 25}
26 26
27function setVideoField (serverNumber: number, uuid: string, field: string, value: string) {
28 const seq = getSequelize(serverNumber)
29
30 const options = { type: Sequelize.QueryTypes.UPDATE }
31
32 return seq.query(`UPDATE video SET "${field}" = '${value}' WHERE uuid = '${uuid}'`, options)
33}
34
27export { 35export {
36 setVideoField,
28 setActorField 37 setActorField
29} 38}