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