aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/activitypub/refresher.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/activitypub/refresher.ts')
-rw-r--r--server/tests/api/activitypub/refresher.ts96
1 files changed, 42 insertions, 54 deletions
diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts
index c717f1a30..81fee0044 100644
--- a/server/tests/api/activitypub/refresher.ts
+++ b/server/tests/api/activitypub/refresher.ts
@@ -2,32 +2,20 @@
2 2
3import 'mocha' 3import 'mocha'
4import { 4import {
5 cleanupTests, closeAllSequelize, 5 cleanupTests,
6 createVideoPlaylist, 6 createMultipleServers,
7 doubleFollow, 7 doubleFollow,
8 flushAndRunMultipleServers,
9 generateUserAccessToken,
10 getVideo,
11 getVideoPlaylist,
12 killallServers, 8 killallServers,
13 reRunServer, 9 PeerTubeServer,
14 ServerInfo,
15 setAccessTokensToServers, 10 setAccessTokensToServers,
16 setActorField,
17 setDefaultVideoChannel, 11 setDefaultVideoChannel,
18 setPlaylistField,
19 setVideoField,
20 uploadVideo,
21 uploadVideoAndGetId,
22 wait, 12 wait,
23 waitJobs 13 waitJobs
24} from '../../../../shared/extra-utils' 14} from '@shared/extra-utils'
25import { getAccount } from '../../../../shared/extra-utils/users/accounts' 15import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
26import { VideoPlaylistPrivacy } from '../../../../shared/models/videos'
27import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
28 16
29describe('Test AP refresher', function () { 17describe('Test AP refresher', function () {
30 let servers: ServerInfo[] = [] 18 let servers: PeerTubeServer[] = []
31 let videoUUID1: string 19 let videoUUID1: string
32 let videoUUID2: string 20 let videoUUID2: string
33 let videoUUID3: string 21 let videoUUID3: string
@@ -37,36 +25,36 @@ describe('Test AP refresher', function () {
37 before(async function () { 25 before(async function () {
38 this.timeout(60000) 26 this.timeout(60000)
39 27
40 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } }) 28 servers = await createMultipleServers(2, { transcoding: { enabled: false } })
41 29
42 // Get the access tokens 30 // Get the access tokens
43 await setAccessTokensToServers(servers) 31 await setAccessTokensToServers(servers)
44 await setDefaultVideoChannel(servers) 32 await setDefaultVideoChannel(servers)
45 33
46 { 34 {
47 videoUUID1 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video1' })).uuid 35 videoUUID1 = (await servers[1].videos.quickUpload({ name: 'video1' })).uuid
48 videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video2' })).uuid 36 videoUUID2 = (await servers[1].videos.quickUpload({ name: 'video2' })).uuid
49 videoUUID3 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video3' })).uuid 37 videoUUID3 = (await servers[1].videos.quickUpload({ name: 'video3' })).uuid
50 } 38 }
51 39
52 { 40 {
53 const a1 = await generateUserAccessToken(servers[1], 'user1') 41 const token1 = await servers[1].users.generateUserAndToken('user1')
54 await uploadVideo(servers[1].url, a1, { name: 'video4' }) 42 await servers[1].videos.upload({ token: token1, attributes: { name: 'video4' } })
55 43
56 const a2 = await generateUserAccessToken(servers[1], 'user2') 44 const token2 = await servers[1].users.generateUserAndToken('user2')
57 await uploadVideo(servers[1].url, a2, { name: 'video5' }) 45 await servers[1].videos.upload({ token: token2, attributes: { name: 'video5' } })
58 } 46 }
59 47
60 { 48 {
61 const playlistAttrs = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } 49 const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
62 const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs }) 50 const created = await servers[1].playlists.create({ attributes })
63 playlistUUID1 = res.body.videoPlaylist.uuid 51 playlistUUID1 = created.uuid
64 } 52 }
65 53
66 { 54 {
67 const playlistAttrs = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } 55 const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
68 const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs }) 56 const created = await servers[1].playlists.create({ attributes })
69 playlistUUID2 = res.body.videoPlaylist.uuid 57 playlistUUID2 = created.uuid
70 } 58 }
71 59
72 await doubleFollow(servers[0], servers[1]) 60 await doubleFollow(servers[0], servers[1])
@@ -80,34 +68,34 @@ describe('Test AP refresher', function () {
80 await wait(10000) 68 await wait(10000)
81 69
82 // Change UUID so the remote server returns a 404 70 // Change UUID so the remote server returns a 404
83 await setVideoField(servers[1].internalServerNumber, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') 71 await servers[1].sql.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
84 72
85 await getVideo(servers[0].url, videoUUID1) 73 await servers[0].videos.get({ id: videoUUID1 })
86 await getVideo(servers[0].url, videoUUID2) 74 await servers[0].videos.get({ id: videoUUID2 })
87 75
88 await waitJobs(servers) 76 await waitJobs(servers)
89 77
90 await getVideo(servers[0].url, videoUUID1, HttpStatusCode.NOT_FOUND_404) 78 await servers[0].videos.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
91 await getVideo(servers[0].url, videoUUID2, HttpStatusCode.OK_200) 79 await servers[0].videos.get({ id: videoUUID2 })
92 }) 80 })
93 81
94 it('Should not update a remote video if the remote instance is down', async function () { 82 it('Should not update a remote video if the remote instance is down', async function () {
95 this.timeout(70000) 83 this.timeout(70000)
96 84
97 killallServers([ servers[1] ]) 85 await killallServers([ servers[1] ])
98 86
99 await setVideoField(servers[1].internalServerNumber, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') 87 await servers[1].sql.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
100 88
101 // Video will need a refresh 89 // Video will need a refresh
102 await wait(10000) 90 await wait(10000)
103 91
104 await getVideo(servers[0].url, videoUUID3) 92 await servers[0].videos.get({ id: videoUUID3 })
105 // The refresh should fail 93 // The refresh should fail
106 await waitJobs([ servers[0] ]) 94 await waitJobs([ servers[0] ])
107 95
108 await reRunServer(servers[1]) 96 await servers[1].run()
109 97
110 await getVideo(servers[0].url, videoUUID3, HttpStatusCode.OK_200) 98 await servers[0].videos.get({ id: videoUUID3 })
111 }) 99 })
112 }) 100 })
113 101
@@ -116,19 +104,21 @@ describe('Test AP refresher', function () {
116 it('Should remove a deleted actor', async function () { 104 it('Should remove a deleted actor', async function () {
117 this.timeout(60000) 105 this.timeout(60000)
118 106
107 const command = servers[0].accounts
108
119 await wait(10000) 109 await wait(10000)
120 110
121 // Change actor name so the remote server returns a 404 111 // Change actor name so the remote server returns a 404
122 const to = 'http://localhost:' + servers[1].port + '/accounts/user2' 112 const to = 'http://localhost:' + servers[1].port + '/accounts/user2'
123 await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto') 113 await servers[1].sql.setActorField(to, 'preferredUsername', 'toto')
124 114
125 await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port) 115 await command.get({ accountName: 'user1@localhost:' + servers[1].port })
126 await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port) 116 await command.get({ accountName: 'user2@localhost:' + servers[1].port })
127 117
128 await waitJobs(servers) 118 await waitJobs(servers)
129 119
130 await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port, HttpStatusCode.OK_200) 120 await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 })
131 await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port, HttpStatusCode.NOT_FOUND_404) 121 await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
132 }) 122 })
133 }) 123 })
134 124
@@ -140,15 +130,15 @@ describe('Test AP refresher', function () {
140 await wait(10000) 130 await wait(10000)
141 131
142 // Change UUID so the remote server returns a 404 132 // Change UUID so the remote server returns a 404
143 await setPlaylistField(servers[1].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') 133 await servers[1].sql.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
144 134
145 await getVideoPlaylist(servers[0].url, playlistUUID1) 135 await servers[0].playlists.get({ playlistId: playlistUUID1 })
146 await getVideoPlaylist(servers[0].url, playlistUUID2) 136 await servers[0].playlists.get({ playlistId: playlistUUID2 })
147 137
148 await waitJobs(servers) 138 await waitJobs(servers)
149 139
150 await getVideoPlaylist(servers[0].url, playlistUUID1, HttpStatusCode.OK_200) 140 await servers[0].playlists.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
151 await getVideoPlaylist(servers[0].url, playlistUUID2, HttpStatusCode.NOT_FOUND_404) 141 await servers[0].playlists.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
152 }) 142 })
153 }) 143 })
154 144
@@ -156,7 +146,5 @@ describe('Test AP refresher', function () {
156 this.timeout(10000) 146 this.timeout(10000)
157 147
158 await cleanupTests(servers) 148 await cleanupTests(servers)
159
160 await closeAllSequelize(servers)
161 }) 149 })
162}) 150})