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