]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/activitypub/refresher.ts
Merge branch 'release/3.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / activitypub / refresher.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
04b8c3fb
C
2
3import 'mocha'
2a8c5d0a 4import {
48f07b4a 5 cleanupTests, closeAllSequelize,
9f79ade6 6 createVideoPlaylist,
2a8c5d0a
C
7 doubleFollow,
8 flushAndRunMultipleServers,
9f79ade6 9 generateUserAccessToken,
2a8c5d0a 10 getVideo,
9f79ade6 11 getVideoPlaylist,
48f07b4a 12 killallServers,
2a8c5d0a
C
13 reRunServer,
14 ServerInfo,
15 setAccessTokensToServers,
9f79ade6
C
16 setActorField,
17 setDefaultVideoChannel,
18 setPlaylistField,
19 setVideoField,
2a8c5d0a 20 uploadVideo,
9f79ade6 21 uploadVideoAndGetId,
2a8c5d0a 22 wait,
2a8c5d0a 23 waitJobs
94565d52
C
24} from '../../../../shared/extra-utils'
25import { getAccount } from '../../../../shared/extra-utils/users/accounts'
9f79ade6 26import { VideoPlaylistPrivacy } from '../../../../shared/models/videos'
f2eb23cd 27import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
04b8c3fb
C
28
29describe('Test AP refresher', function () {
30 let servers: ServerInfo[] = []
31 let videoUUID1: string
32 let videoUUID2: string
33 let videoUUID3: string
9f79ade6
C
34 let playlistUUID1: string
35 let playlistUUID2: string
04b8c3fb
C
36
37 before(async function () {
89ada4e2 38 this.timeout(60000)
04b8c3fb 39
9f79ade6 40 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } })
04b8c3fb
C
41
42 // Get the access tokens
43 await setAccessTokensToServers(servers)
9f79ade6
C
44 await setDefaultVideoChannel(servers)
45
46 {
a1587156
C
47 videoUUID1 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video1' })).uuid
48 videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video2' })).uuid
49 videoUUID3 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video3' })).uuid
9f79ade6 50 }
04b8c3fb
C
51
52 {
a1587156
C
53 const a1 = await generateUserAccessToken(servers[1], 'user1')
54 await uploadVideo(servers[1].url, a1, { name: 'video4' })
9f79ade6 55
a1587156
C
56 const a2 = await generateUserAccessToken(servers[1], 'user2')
57 await uploadVideo(servers[1].url, a2, { name: 'video5' })
04b8c3fb
C
58 }
59
60 {
a1587156
C
61 const playlistAttrs = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
62 const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs })
9f79ade6 63 playlistUUID1 = res.body.videoPlaylist.uuid
04b8c3fb
C
64 }
65
66 {
a1587156
C
67 const playlistAttrs = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
68 const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs })
9f79ade6 69 playlistUUID2 = res.body.videoPlaylist.uuid
04b8c3fb
C
70 }
71
a1587156 72 await doubleFollow(servers[0], servers[1])
04b8c3fb
C
73 })
74
9f79ade6
C
75 describe('Videos refresher', function () {
76
77 it('Should remove a deleted remote video', async function () {
78 this.timeout(60000)
79
80 await wait(10000)
81
82 // Change UUID so the remote server returns a 404
a1587156 83 await setVideoField(servers[1].internalServerNumber, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
9f79ade6 84
a1587156
C
85 await getVideo(servers[0].url, videoUUID1)
86 await getVideo(servers[0].url, videoUUID2)
9f79ade6
C
87
88 await waitJobs(servers)
04b8c3fb 89
f2eb23cd
RK
90 await getVideo(servers[0].url, videoUUID1, HttpStatusCode.NOT_FOUND_404)
91 await getVideo(servers[0].url, videoUUID2, HttpStatusCode.OK_200)
9f79ade6 92 })
04b8c3fb 93
9f79ade6 94 it('Should not update a remote video if the remote instance is down', async function () {
6848b9f4 95 this.timeout(70000)
04b8c3fb 96
a1587156 97 killallServers([ servers[1] ])
04b8c3fb 98
a1587156 99 await setVideoField(servers[1].internalServerNumber, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
04b8c3fb 100
9f79ade6
C
101 // Video will need a refresh
102 await wait(10000)
103
a1587156 104 await getVideo(servers[0].url, videoUUID3)
9f79ade6 105 // The refresh should fail
a1587156 106 await waitJobs([ servers[0] ])
9f79ade6 107
a1587156 108 await reRunServer(servers[1])
9f79ade6 109
f2eb23cd 110 await getVideo(servers[0].url, videoUUID3, HttpStatusCode.OK_200)
9f79ade6 111 })
04b8c3fb
C
112 })
113
9f79ade6
C
114 describe('Actors refresher', function () {
115
116 it('Should remove a deleted actor', async function () {
117 this.timeout(60000)
118
119 await wait(10000)
120
121 // Change actor name so the remote server returns a 404
a1587156
C
122 const to = 'http://localhost:' + servers[1].port + '/accounts/user2'
123 await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto')
9f79ade6 124
a1587156
C
125 await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port)
126 await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port)
9f79ade6
C
127
128 await waitJobs(servers)
129
f2eb23cd
RK
130 await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port, HttpStatusCode.OK_200)
131 await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port, HttpStatusCode.NOT_FOUND_404)
9f79ade6
C
132 })
133 })
04b8c3fb 134
9f79ade6 135 describe('Playlist refresher', function () {
04b8c3fb 136
9f79ade6
C
137 it('Should remove a deleted playlist', async function () {
138 this.timeout(60000)
04b8c3fb 139
9f79ade6 140 await wait(10000)
04b8c3fb 141
9f79ade6 142 // Change UUID so the remote server returns a 404
a1587156 143 await setPlaylistField(servers[1].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
04b8c3fb 144
a1587156
C
145 await getVideoPlaylist(servers[0].url, playlistUUID1)
146 await getVideoPlaylist(servers[0].url, playlistUUID2)
04b8c3fb 147
9f79ade6 148 await waitJobs(servers)
04b8c3fb 149
f2eb23cd
RK
150 await getVideoPlaylist(servers[0].url, playlistUUID1, HttpStatusCode.OK_200)
151 await getVideoPlaylist(servers[0].url, playlistUUID2, HttpStatusCode.NOT_FOUND_404)
9f79ade6 152 })
04b8c3fb
C
153 })
154
48f07b4a
C
155 after(async function () {
156 this.timeout(10000)
157
158 await cleanupTests(servers)
159
160 await closeAllSequelize(servers)
04b8c3fb
C
161 })
162})