/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import { expect } from 'chai'
-import { HttpStatusCode, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
+import {
+ HttpStatusCode,
+ PeerTubeProblemDocument,
+ VideoDetails,
+ VideoImportState,
+ VideoPlaylist,
+ VideoPlaylistPrivacy,
+ VideoPrivacy
+} from '@shared/models'
import {
cleanupTests,
createMultipleServers,
doubleFollow,
+ makeActivityPubGetRequest,
makeGetRequest,
makeRawRequest,
PeerTubeServer,
let videoPlaylistUUID: string
before(async function () {
- this.timeout(60000)
+ this.timeout(120000)
servers = await createMultipleServers(2)
await setAccessTokensToServers(servers)
}
}
})
+
+ // Root subscribes to itself
+ await servers[0].subscriptions.add({ targetUri: 'root_channel@' + servers[0].host })
})
describe('Videos', function () {
expect(total).to.equal(14)
})
+ it('Should run filter:api.user.me.subscription-videos.list.params', async function () {
+ const { data } = await servers[0].videos.listMySubscriptionVideos({ start: 0, count: 2 })
+
+ // 1 plugin do +1 to the count parameter
+ expect(data).to.have.lengthOf(3)
+ })
+
+ it('Should run filter:api.user.me.subscription-videos.list.result', async function () {
+ const { total } = await servers[0].videos.listMySubscriptionVideos({ start: 0, count: 2 })
+
+ // Plugin do +4 to the total result
+ expect(total).to.equal(14)
+ })
+
it('Should run filter:api.video.get.result', async function () {
const video = await servers[0].videos.get({ id: videoUUID })
expect(video.name).to.contain('<3')
describe('Should run filter:api.user.signup.allowed.result', function () {
+ before(async function () {
+ await servers[0].config.updateExistingSubConfig({ newConfig: { signup: { requiresApproval: false } } })
+ })
+
it('Should run on config endpoint', async function () {
const body = await servers[0].config.getConfig()
expect(body.signup.allowed).to.be.true
})
it('Should allow a signup', async function () {
- await servers[0].users.register({ username: 'john', password: 'password' })
+ await servers[0].registrations.register({ username: 'john1' })
})
it('Should not allow a signup', async function () {
- const res = await servers[0].users.register({
- username: 'jma',
- password: 'password',
+ const res = await servers[0].registrations.register({
+ username: 'jma 1',
expectedStatus: HttpStatusCode.FORBIDDEN_403
})
- expect(res.body.error).to.equal('No jma')
+ expect(res.body.error).to.equal('No jma 1')
+ })
+ })
+
+ describe('Should run filter:api.user.request-signup.allowed.result', function () {
+
+ before(async function () {
+ await servers[0].config.updateExistingSubConfig({ newConfig: { signup: { requiresApproval: true } } })
+ })
+
+ it('Should run on config endpoint', async function () {
+ const body = await servers[0].config.getConfig()
+ expect(body.signup.allowed).to.be.true
+ })
+
+ it('Should allow a signup request', async function () {
+ await servers[0].registrations.requestRegistration({ username: 'john2', registrationReason: 'tt' })
+ })
+
+ it('Should not allow a signup request', async function () {
+ const body = await servers[0].registrations.requestRegistration({
+ username: 'jma 2',
+ registrationReason: 'tt',
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
+
+ expect((body as unknown as PeerTubeProblemDocument).error).to.equal('No jma 2')
})
})
describe('Download hooks', function () {
const downloadVideos: VideoDetails[] = []
+ let downloadVideo2Token: string
before(async function () {
this.timeout(120000)
for (const uuid of uuids) {
downloadVideos.push(await servers[0].videos.get({ id: uuid }))
}
+
+ downloadVideo2Token = await servers[0].videoToken.getVideoFileToken({ videoId: downloadVideos[2].uuid })
})
it('Should run filter:api.download.torrent.allowed.result', async function () {
it('Should run filter:api.download.video.allowed.result', async function () {
{
- const res = await makeRawRequest({ url: downloadVideos[1].files[0].fileDownloadUrl, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
+ const refused = downloadVideos[1].files[0].fileDownloadUrl
+ const allowed = [
+ downloadVideos[0].files[0].fileDownloadUrl,
+ downloadVideos[2].files[0].fileDownloadUrl
+ ]
+
+ const res = await makeRawRequest({ url: refused, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
expect(res.body.error).to.equal('Cao Cao')
- await makeRawRequest({ url: downloadVideos[0].files[0].fileDownloadUrl, expectedStatus: HttpStatusCode.OK_200 })
- await makeRawRequest({ url: downloadVideos[2].files[0].fileDownloadUrl, expectedStatus: HttpStatusCode.OK_200 })
+ for (const url of allowed) {
+ await makeRawRequest({ url, expectedStatus: HttpStatusCode.OK_200 })
+ await makeRawRequest({ url, expectedStatus: HttpStatusCode.OK_200 })
+ }
}
{
- const res = await makeRawRequest({
- url: downloadVideos[2].streamingPlaylists[0].files[0].fileDownloadUrl,
- expectedStatus: HttpStatusCode.FORBIDDEN_403
- })
+ const refused = downloadVideos[2].streamingPlaylists[0].files[0].fileDownloadUrl
- expect(res.body.error).to.equal('Sun Jian')
+ const allowed = [
+ downloadVideos[2].files[0].fileDownloadUrl,
+ downloadVideos[0].streamingPlaylists[0].files[0].fileDownloadUrl,
+ downloadVideos[1].streamingPlaylists[0].files[0].fileDownloadUrl
+ ]
- await makeRawRequest({ url: downloadVideos[2].files[0].fileDownloadUrl, expectedStatus: HttpStatusCode.OK_200 })
+ // Only streaming playlist is refuse
+ const res = await makeRawRequest({ url: refused, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
+ expect(res.body.error).to.equal('Sun Jian')
- await makeRawRequest({
- url: downloadVideos[0].streamingPlaylists[0].files[0].fileDownloadUrl,
- expectedStatus: HttpStatusCode.OK_200
- })
+ // But not we there is a user in res
+ await makeRawRequest({ url: refused, token: servers[0].accessToken, expectedStatus: HttpStatusCode.OK_200 })
+ await makeRawRequest({ url: refused, query: { videoFileToken: downloadVideo2Token }, expectedStatus: HttpStatusCode.OK_200 })
- await makeRawRequest({
- url: downloadVideos[1].streamingPlaylists[0].files[0].fileDownloadUrl,
- expectedStatus: HttpStatusCode.OK_200
- })
+ // Other files work
+ for (const url of allowed) {
+ await makeRawRequest({ url, expectedStatus: HttpStatusCode.OK_200 })
+ }
}
})
})
})
})
+ describe('Client HTML filters', function () {
+ let videoUUID: string
+
+ before(async function () {
+ this.timeout(60000)
+
+ const { uuid } = await servers[0].videos.quickUpload({ name: 'html video' })
+ videoUUID = uuid
+ })
+
+ it('Should run filter:html.client.json-ld.result', async function () {
+ const res = await makeGetRequest({ url: servers[0].url, path: '/w/' + videoUUID, expectedStatus: HttpStatusCode.OK_200 })
+ expect(res.text).to.contain('"recordedAt":"http://example.com/recordedAt"')
+ })
+
+ it('Should not run filter:html.client.json-ld.result with an account', async function () {
+ const res = await makeGetRequest({ url: servers[0].url, path: '/a/root', expectedStatus: HttpStatusCode.OK_200 })
+ expect(res.text).not.to.contain('"recordedAt":"http://example.com/recordedAt"')
+ })
+ })
+
describe('Search filters', function () {
before(async function () {
})
})
+ describe('Activity Pub', function () {
+
+ it('Should run filter:activity-pub.activity.context.build.result', async function () {
+ const { body } = await makeActivityPubGetRequest(servers[0].url, '/w/' + videoUUID)
+ expect(body.type).to.equal('Video')
+
+ expect(body['@context'].some(c => {
+ return typeof c === 'object' && c.recordedAt === 'https://schema.org/recordedAt'
+ })).to.be.true
+ })
+
+ it('Should run filter:activity-pub.video.json-ld.build.result', async function () {
+ const { body } = await makeActivityPubGetRequest(servers[0].url, '/w/' + videoUUID)
+ expect(body.name).to.equal('default video 0')
+ expect(body.videoName).to.equal('default video 0')
+ })
+ })
+
after(async function () {
await cleanupTests(servers)
})