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