From 40346ead2b0b7afa475aef057d3673b6c7574b7a Mon Sep 17 00:00:00 2001 From: Wicklow <123956049+wickloww@users.noreply.github.com> Date: Thu, 29 Jun 2023 07:48:55 +0000 Subject: Feature/password protected videos (#5836) * Add server endpoints * Refactoring test suites * Update server and add openapi documentation * fix compliation and tests * upload/import password protected video on client * add server error code * Add video password to update resolver * add custom message when sharing pw protected video * improve confirm component * Add new alert in component * Add ability to watch protected video on client * Cannot have password protected replay privacy * Add migration * Add tests * update after review * Update check params tests * Add live videos test * Add more filter test * Update static file privacy test * Update object storage tests * Add test on feeds * Add missing word * Fix tests * Fix tests on live videos * add embed support on password protected videos * fix style * Correcting data leaks * Unable to add password protected privacy on replay * Updated code based on review comments * fix validator and command * Updated code based on review comments --- server/tests/api/videos/video-passwords.ts | 97 ++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 server/tests/api/videos/video-passwords.ts (limited to 'server/tests/api/videos/video-passwords.ts') diff --git a/server/tests/api/videos/video-passwords.ts b/server/tests/api/videos/video-passwords.ts new file mode 100644 index 000000000..e01a93a4d --- /dev/null +++ b/server/tests/api/videos/video-passwords.ts @@ -0,0 +1,97 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import { expect } from 'chai' +import { + cleanupTests, + createSingleServer, + VideoPasswordsCommand, + PeerTubeServer, + setAccessTokensToServers, + setDefaultAccountAvatar, + setDefaultChannelAvatar +} from '@shared/server-commands' +import { VideoPrivacy } from '@shared/models' + +describe('Test video passwords', function () { + let server: PeerTubeServer + let videoUUID: string + + let userAccessTokenServer1: string + + let videoPasswords: string[] = [] + let command: VideoPasswordsCommand + + before(async function () { + this.timeout(30000) + + server = await createSingleServer(1) + + await setAccessTokensToServers([ server ]) + + for (let i = 0; i < 10; i++) { + videoPasswords.push(`password ${i + 1}`) + } + const { uuid } = await server.videos.upload({ attributes: { privacy: VideoPrivacy.PASSWORD_PROTECTED, videoPasswords } }) + videoUUID = uuid + + await setDefaultChannelAvatar(server) + await setDefaultAccountAvatar(server) + + userAccessTokenServer1 = await server.users.generateUserAndToken('user1') + await setDefaultChannelAvatar(server, 'user1_channel') + await setDefaultAccountAvatar(server, userAccessTokenServer1) + + command = server.videoPasswords + }) + + it('Should list video passwords', async function () { + const body = await command.list({ videoId: videoUUID }) + + expect(body.total).to.equal(10) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(10) + }) + + it('Should filter passwords on this video', async function () { + const body = await command.list({ videoId: videoUUID, count: 2, start: 3, sort: 'createdAt' }) + + expect(body.total).to.equal(10) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(2) + expect(body.data[0].password).to.equal('password 4') + expect(body.data[1].password).to.equal('password 5') + }) + + it('Should update password for this video', async function () { + videoPasswords = [ 'my super new password 1', 'my super new password 2' ] + + await command.updateAll({ videoId: videoUUID, passwords: videoPasswords }) + const body = await command.list({ videoId: videoUUID }) + expect(body.total).to.equal(2) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(2) + expect(body.data[0].password).to.equal('my super new password 2') + expect(body.data[1].password).to.equal('my super new password 1') + }) + + it('Should delete one password', async function () { + { + const body = await command.list({ videoId: videoUUID }) + expect(body.total).to.equal(2) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(2) + await command.remove({ id: body.data[0].id, videoId: videoUUID }) + } + { + const body = await command.list({ videoId: videoUUID }) + + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + } + }) + + after(async function () { + await cleanupTests([ server ]) + }) +}) -- cgit v1.2.3