1
0
Fork 0
peertube/server/tests/api/activitypub/refresher.ts

156 lines
4.9 KiB
TypeScript
Raw Normal View History

2020-01-31 10:56:52 -05:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
2021-07-07 07:38:26 -04:00
import { HttpStatusCode } from '@shared/core-utils'
import {
2021-07-07 07:38:26 -04:00
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
getVideo,
2019-04-26 02:50:52 -04:00
killallServers,
reRunServer,
ServerInfo,
setAccessTokensToServers,
2019-03-19 09:13:53 -04:00
setDefaultVideoChannel,
uploadVideo,
2019-03-19 09:13:53 -04:00
uploadVideoAndGetId,
wait,
waitJobs
2021-07-07 07:38:26 -04:00
} from '@shared/extra-utils'
import { VideoPlaylistPrivacy } from '@shared/models'
describe('Test AP refresher', function () {
let servers: ServerInfo[] = []
let videoUUID1: string
let videoUUID2: string
let videoUUID3: string
2019-03-19 09:13:53 -04:00
let playlistUUID1: string
let playlistUUID2: string
before(async function () {
2019-01-08 09:51:52 -05:00
this.timeout(60000)
2019-03-19 09:13:53 -04:00
servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } })
// Get the access tokens
await setAccessTokensToServers(servers)
2019-03-19 09:13:53 -04:00
await setDefaultVideoChannel(servers)
{
2020-01-31 10:56:52 -05:00
videoUUID1 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video1' })).uuid
videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video2' })).uuid
videoUUID3 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video3' })).uuid
2019-03-19 09:13:53 -04:00
}
{
2021-07-13 08:23:01 -04:00
const a1 = await servers[1].usersCommand.generateUserAndToken('user1')
2020-01-31 10:56:52 -05:00
await uploadVideo(servers[1].url, a1, { name: 'video4' })
2019-03-19 09:13:53 -04:00
2021-07-13 08:23:01 -04:00
const a2 = await servers[1].usersCommand.generateUserAndToken('user2')
2020-01-31 10:56:52 -05:00
await uploadVideo(servers[1].url, a2, { name: 'video5' })
}
{
2021-07-08 09:54:39 -04:00
const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
const created = await servers[1].playlistsCommand.create({ attributes })
playlistUUID1 = created.uuid
}
{
2021-07-08 09:54:39 -04:00
const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
const created = await servers[1].playlistsCommand.create({ attributes })
playlistUUID2 = created.uuid
}
2020-01-31 10:56:52 -05:00
await doubleFollow(servers[0], servers[1])
})
2019-03-19 09:13:53 -04:00
describe('Videos refresher', function () {
it('Should remove a deleted remote video', async function () {
this.timeout(60000)
await wait(10000)
// Change UUID so the remote server returns a 404
2021-07-09 09:37:43 -04:00
await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
2019-03-19 09:13:53 -04:00
2020-01-31 10:56:52 -05:00
await getVideo(servers[0].url, videoUUID1)
await getVideo(servers[0].url, videoUUID2)
2019-03-19 09:13:53 -04:00
await waitJobs(servers)
await getVideo(servers[0].url, videoUUID1, HttpStatusCode.NOT_FOUND_404)
await getVideo(servers[0].url, videoUUID2, HttpStatusCode.OK_200)
2019-03-19 09:13:53 -04:00
})
2019-03-19 09:13:53 -04:00
it('Should not update a remote video if the remote instance is down', async function () {
2020-01-22 03:24:26 -05:00
this.timeout(70000)
2021-07-09 09:37:43 -04:00
await killallServers([ servers[1] ])
2021-07-09 09:37:43 -04:00
await servers[1].sqlCommand.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
2019-03-19 09:13:53 -04:00
// Video will need a refresh
await wait(10000)
2020-01-31 10:56:52 -05:00
await getVideo(servers[0].url, videoUUID3)
2019-03-19 09:13:53 -04:00
// The refresh should fail
2020-01-31 10:56:52 -05:00
await waitJobs([ servers[0] ])
2019-03-19 09:13:53 -04:00
2020-01-31 10:56:52 -05:00
await reRunServer(servers[1])
2019-03-19 09:13:53 -04:00
await getVideo(servers[0].url, videoUUID3, HttpStatusCode.OK_200)
2019-03-19 09:13:53 -04:00
})
})
2019-03-19 09:13:53 -04:00
describe('Actors refresher', function () {
it('Should remove a deleted actor', async function () {
this.timeout(60000)
2021-07-07 07:38:26 -04:00
const command = servers[0].accountsCommand
2019-03-19 09:13:53 -04:00
await wait(10000)
// Change actor name so the remote server returns a 404
2020-01-31 10:56:52 -05:00
const to = 'http://localhost:' + servers[1].port + '/accounts/user2'
2021-07-09 09:37:43 -04:00
await servers[1].sqlCommand.setActorField(to, 'preferredUsername', 'toto')
2019-03-19 09:13:53 -04:00
2021-07-07 07:38:26 -04:00
await command.get({ accountName: 'user1@localhost:' + servers[1].port })
await command.get({ accountName: 'user2@localhost:' + servers[1].port })
2019-03-19 09:13:53 -04:00
await waitJobs(servers)
2021-07-07 07:38:26 -04:00
await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 })
await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
2019-03-19 09:13:53 -04:00
})
})
2019-03-19 09:13:53 -04:00
describe('Playlist refresher', function () {
2019-03-19 09:13:53 -04:00
it('Should remove a deleted playlist', async function () {
this.timeout(60000)
2019-03-19 09:13:53 -04:00
await wait(10000)
2019-03-19 09:13:53 -04:00
// Change UUID so the remote server returns a 404
2021-07-09 09:37:43 -04:00
await servers[1].sqlCommand.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
2021-07-08 09:54:39 -04:00
await servers[0].playlistsCommand.get({ playlistId: playlistUUID1 })
await servers[0].playlistsCommand.get({ playlistId: playlistUUID2 })
2019-03-19 09:13:53 -04:00
await waitJobs(servers)
2021-07-08 09:54:39 -04:00
await servers[0].playlistsCommand.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
await servers[0].playlistsCommand.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
2019-03-19 09:13:53 -04:00
})
})
2019-04-26 02:50:52 -04:00
after(async function () {
this.timeout(10000)
await cleanupTests(servers)
})
})