2022-10-12 09:09:02 -05:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import { HttpStatusCode, VideoPrivacy } from '@shared/models'
|
|
|
|
import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
|
|
|
|
|
|
|
|
describe('Test video tokens', function () {
|
|
|
|
let server: PeerTubeServer
|
2023-06-29 02:48:55 -05:00
|
|
|
let privateVideoId: string
|
|
|
|
let passwordProtectedVideoId: string
|
2022-10-12 09:09:02 -05:00
|
|
|
let userToken: string
|
|
|
|
|
2023-06-29 02:48:55 -05:00
|
|
|
const videoPassword = 'password'
|
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(300_000)
|
|
|
|
|
|
|
|
server = await createSingleServer(1)
|
|
|
|
await setAccessTokensToServers([ server ])
|
2023-06-29 02:48:55 -05:00
|
|
|
{
|
|
|
|
const { uuid } = await server.videos.quickUpload({ name: 'private video', privacy: VideoPrivacy.PRIVATE })
|
|
|
|
privateVideoId = uuid
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const { uuid } = await server.videos.quickUpload({
|
|
|
|
name: 'password protected video',
|
|
|
|
privacy: VideoPrivacy.PASSWORD_PROTECTED,
|
|
|
|
videoPasswords: [ videoPassword ]
|
|
|
|
})
|
|
|
|
passwordProtectedVideoId = uuid
|
|
|
|
}
|
2022-10-12 09:09:02 -05:00
|
|
|
userToken = await server.users.generateUserAndToken('user1')
|
|
|
|
})
|
|
|
|
|
2023-06-29 02:48:55 -05:00
|
|
|
it('Should not generate tokens on private video for unauthenticated user', async function () {
|
|
|
|
await server.videoToken.create({ videoId: privateVideoId, token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
|
2022-10-12 09:09:02 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not generate tokens of unknown video', async function () {
|
|
|
|
await server.videoToken.create({ videoId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
|
|
|
|
})
|
|
|
|
|
2023-06-29 02:48:55 -05:00
|
|
|
it('Should not generate tokens with incorrect password', async function () {
|
|
|
|
await server.videoToken.create({
|
|
|
|
videoId: passwordProtectedVideoId,
|
|
|
|
token: null,
|
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403,
|
|
|
|
videoPassword: 'incorrectPassword'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-10-12 09:09:02 -05:00
|
|
|
it('Should not generate tokens of a non owned video', async function () {
|
2023-06-29 02:48:55 -05:00
|
|
|
await server.videoToken.create({ videoId: privateVideoId, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
|
2022-10-12 09:09:02 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should generate token', async function () {
|
2023-06-29 02:48:55 -05:00
|
|
|
await server.videoToken.create({ videoId: privateVideoId })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should generate token on password protected video', async function () {
|
|
|
|
await server.videoToken.create({ videoId: passwordProtectedVideoId, videoPassword, token: null })
|
|
|
|
await server.videoToken.create({ videoId: passwordProtectedVideoId, videoPassword, token: userToken })
|
|
|
|
await server.videoToken.create({ videoId: passwordProtectedVideoId, videoPassword })
|
2022-10-12 09:09:02 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await cleanupTests([ server ])
|
|
|
|
})
|
|
|
|
})
|