From f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 18 Jan 2018 10:53:54 +0100 Subject: Don't show videos of remote instance after unfollow --- server/tests/api/check-params/users.ts | 2 +- server/tests/api/server/follows.ts | 24 ++++++++- server/tests/api/users/users-multiple-servers.ts | 66 ++++++++++++++++++++---- server/tests/api/users/users.ts | 4 +- server/tests/api/videos/multiple-servers.ts | 14 +++-- server/tests/api/videos/single-server.ts | 17 +++--- server/tests/api/videos/video-comments.ts | 4 +- server/tests/utils/miscs/miscs.ts | 9 +++- server/tests/utils/users/accounts.ts | 25 ++++++++- server/tests/utils/users/users.ts | 2 +- server/tests/utils/videos/videos.ts | 31 ++++++++--- 11 files changed, 158 insertions(+), 40 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 14fcf8703..0c9d933a7 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -185,7 +185,7 @@ describe('Test users API validators', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: 204 + statusCodeExpected: 200 }) }) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index fad58e840..ac614d605 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -4,7 +4,7 @@ import * as chai from 'chai' import 'mocha' import { Video, VideoPrivacy } from '../../../../shared/models/videos' import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' -import { completeVideoCheck } from '../../utils' +import { checkVideoFilesWereRemoved, completeVideoCheck, getVideoChannelsList } from '../../utils' import { flushAndRunMultipleServers, flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo, @@ -12,7 +12,7 @@ import { } from '../../utils/index' import { dateIsValid } from '../../utils/miscs/miscs' import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../../utils/server/follows' -import { expectAccountFollows } from '../../utils/users/accounts' +import { expectAccountFollows, getAccountsList } from '../../utils/users/accounts' import { userLogin } from '../../utils/users/login' import { createUser } from '../../utils/users/users' import { @@ -343,6 +343,26 @@ describe('Test follows', function () { expect(secondChild.comment.text).to.equal('my second answer to thread 1') expect(secondChild.children).to.have.lengthOf(0) }) + + it('Should unfollow server 3 on server 1 and does not list server 3 videos', async function () { + this.timeout(5000) + + await unfollow(servers[0].url, servers[0].accessToken, servers[2]) + + await wait(3000) + + let res = await getVideosList(servers[ 0 ].url) + expect(res.body.total).to.equal(1) + + res = await getVideoChannelsList(servers[0].url, 0, 1) + expect(res.body.total).to.equal(2) + + res = await getAccountsList(servers[0].url) + expect(res.body.total).to.equal(2) + + await checkVideoFilesWereRemoved(video4.uuid, servers[0].serverNumber) + }) + }) after(async function () { diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 1c7f011a8..0483b9c3d 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -3,18 +3,20 @@ import * as chai from 'chai' import 'mocha' import { Account } from '../../../../shared/models/actors' -import { doubleFollow, flushAndRunMultipleServers, wait } from '../../utils' -import { - flushTests, getMyUserInformation, killallServers, ServerInfo, testVideoImage, updateMyAvatar, - uploadVideo -} from '../../utils/index' -import { getAccount, getAccountsList } from '../../utils/users/accounts' +import { checkVideoFilesWereRemoved, createUser, doubleFollow, flushAndRunMultipleServers, removeUser, userLogin, wait } from '../../utils' +import { flushTests, getMyUserInformation, killallServers, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../utils/index' +import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../utils/users/accounts' import { setAccessTokensToServers } from '../../utils/users/login' const expect = chai.expect describe('Test users with multiple servers', function () { let servers: ServerInfo[] = [] + let user + let userUUID + let userId + let videoUUID + let userAccessToken before(async function () { this.timeout(120000) @@ -34,6 +36,18 @@ describe('Test users with multiple servers', function () { // The root user of server 1 is propagated to servers 2 and 3 await uploadVideo(servers[0].url, servers[0].accessToken, {}) + const user = { + username: 'user1', + password: 'password' + } + const resUser = await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) + userUUID = resUser.body.user.uuid + userId = resUser.body.user.id + userAccessToken = await userLogin(servers[0], user) + + const resVideo = await uploadVideo(servers[0].url, userAccessToken, {}) + videoUUID = resVideo.body.uuid + await wait(5000) }) @@ -49,9 +63,9 @@ describe('Test users with multiple servers', function () { }) const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) - const user = res.body + user = res.body - const test = await testVideoImage(servers[0].url, 'avatar2-resized', user.account.avatar.path, '.png') + const test = await testImage(servers[0].url, 'avatar2-resized', user.account.avatar.path, '.png') expect(test).to.equal(true) await wait(5000) @@ -69,11 +83,45 @@ describe('Test users with multiple servers', function () { expect(rootServer1Get.name).to.equal('root') expect(rootServer1Get.host).to.equal('localhost:9001') - const test = await testVideoImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png') + const test = await testImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png') expect(test).to.equal(true) } }) + it('Should remove the user', async function () { + this.timeout(10000) + + for (const server of servers) { + const resAccounts = await getAccountsList(server.url, '-createdAt') + + const userServer1List = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account + expect(userServer1List).not.to.be.undefined + } + + await removeUser(servers[0].url, userId, servers[0].accessToken) + + await wait(5000) + + for (const server of servers) { + const resAccounts = await getAccountsList(server.url, '-createdAt') + + const userServer1List = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account + expect(userServer1List).to.be.undefined + } + }) + + it('Should not have actor files', async () => { + for (const server of servers) { + await checkActorFilesWereRemoved(userUUID, server.serverNumber) + } + }) + + it('Should not have video files', async () => { + for (const server of servers) { + await checkVideoFilesWereRemoved(videoUUID, server.serverNumber) + } + }) + after(async function () { killallServers(servers) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index b788637e7..d8004ff24 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -7,7 +7,7 @@ import { createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating, getUserInformation, getUsersList, getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo, registerUser, removeUser, removeVideo, - runServer, ServerInfo, serverLogin, testVideoImage, updateMyAvatar, updateMyUser, updateUser, uploadVideo + runServer, ServerInfo, serverLogin, testImage, updateMyAvatar, updateMyUser, updateUser, uploadVideo } from '../../utils/index' import { follow } from '../../utils/server/follows' import { setAccessTokensToServers } from '../../utils/users/login' @@ -361,7 +361,7 @@ describe('Test users', function () { const res = await getMyUserInformation(server.url, accessTokenUser) const user = res.body - const test = await testVideoImage(server.url, 'avatar-resized', user.account.avatar.path, '.png') + const test = await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png') expect(test).to.equal(true) }) diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 6712829d4..4c4b5123d 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -8,8 +8,9 @@ import { VideoPrivacy } from '../../../../shared/models/videos' import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' import { - addVideoChannel, completeVideoCheck, createUser, dateIsValid, doubleFollow, flushAndRunMultipleServers, flushTests, getVideo, - getVideoChannelsList, getVideosList, killallServers, rateVideo, removeVideo, ServerInfo, setAccessTokensToServers, testVideoImage, + addVideoChannel, checkVideoFilesWereRemoved, completeVideoCheck, createUser, dateIsValid, doubleFollow, flushAndRunMultipleServers, + flushTests, getVideo, + getVideoChannelsList, getVideosList, killallServers, rateVideo, removeVideo, ServerInfo, setAccessTokensToServers, testImage, updateVideo, uploadVideo, userLogin, viewVideo, wait, webtorrentAdd } from '../../utils' import { @@ -578,6 +579,13 @@ describe('Test multiple servers', function () { await wait(5000) }) + it('Should not have files of videos 3 and 3-2 on each server', async function () { + for (const server of servers) { + await checkVideoFilesWereRemoved(toRemove[0].uuid, server.serverNumber) + await checkVideoFilesWereRemoved(toRemove[1].uuid, server.serverNumber) + } + }) + it('Should have videos 1 and 3 on each server', async function () { for (const server of servers) { const res = await getVideosList(server.url) @@ -624,7 +632,7 @@ describe('Test multiple servers', function () { const res = await getVideo(server.url, videoUUID) const video = res.body - const test = await testVideoImage(server.url, 'video_short1-preview.webm', video.previewPath) + const test = await testImage(server.url, 'video_short1-preview.webm', video.previewPath) expect(test).to.equal(true) } }) diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index ca20f39a0..76d265ec5 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -3,13 +3,12 @@ import * as chai from 'chai' import { keyBy } from 'lodash' import 'mocha' -import { join } from 'path' import { VideoPrivacy } from '../../../../shared/models/videos' -import { readdirPromise } from '../../../helpers/core-utils' import { - completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences, getVideoPrivacies, - getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, removeVideo, runServer, searchVideo, - searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testVideoImage, updateVideo, uploadVideo, viewVideo + checkVideoFilesWereRemoved, completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences, + getVideoPrivacies, getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, removeVideo, runServer, + searchVideo, searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testImage, updateVideo, uploadVideo, + viewVideo } from '../../utils' const expect = chai.expect @@ -277,11 +276,7 @@ describe('Test a single server', function () { it('Should remove the video', async function () { await removeVideo(server.url, server.accessToken, videoId) - const files1 = await readdirPromise(join(__dirname, '..', '..', '..', '..', 'test1', 'videos')) - expect(files1).to.have.lengthOf(0) - - const files2 = await readdirPromise(join(__dirname, '..', '..', '..', '..', 'test1', 'thumbnails')) - expect(files2).to.have.lengthOf(0) + await checkVideoFilesWereRemoved(videoUUID, 1) }) it('Should not have videos', async function () { @@ -346,7 +341,7 @@ describe('Test a single server', function () { for (const video of videos) { const videoName = video.name.replace(' name', '') - const test = await testVideoImage(server.url, videoName, video.thumbnailPath) + const test = await testImage(server.url, videoName, video.thumbnailPath) expect(test).to.equal(true) } diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index 18d484ccf..0eddac35b 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -3,7 +3,7 @@ import * as chai from 'chai' import 'mocha' import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' -import { testVideoImage } from '../../utils' +import { testImage } from '../../utils' import { dateIsValid, flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, updateMyAvatar, uploadVideo @@ -83,7 +83,7 @@ describe('Test video comments', function () { expect(comment.account.name).to.equal('root') expect(comment.account.host).to.equal('localhost:9001') - const test = await testVideoImage(server.url, 'avatar-resized', comment.account.avatar.path, '.png') + const test = await testImage(server.url, 'avatar-resized', comment.account.avatar.path, '.png') expect(test).to.equal(true) expect(comment.totalReplies).to.equal(0) diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts index 2aac37791..e6666619b 100644 --- a/server/tests/utils/miscs/miscs.ts +++ b/server/tests/utils/miscs/miscs.ts @@ -1,3 +1,4 @@ +import { join } from 'path' import * as WebTorrent from 'webtorrent' let webtorrent = new WebTorrent() @@ -24,11 +25,17 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) { return new Promise(res => webtorrent.add(torrent, res)) } +function root () { + // We are in server/tests/utils/miscs + return join(__dirname, '..', '..', '..', '..') +} + // --------------------------------------------------------------------------- export { dateIsValid, wait, webtorrentAdd, - immutableAssign + immutableAssign, + root } diff --git a/server/tests/utils/users/accounts.ts b/server/tests/utils/users/accounts.ts index 0ec7992b3..a5c13c319 100644 --- a/server/tests/utils/users/accounts.ts +++ b/server/tests/utils/users/accounts.ts @@ -1,5 +1,11 @@ +/* tslint:disable:no-unused-expression */ + import { expect } from 'chai' +import { existsSync } from 'fs' +import { join } from 'path' import { Account } from '../../../../shared/models/actors' +import { readdirPromise } from '../../../helpers/core-utils' +import { root } from '../index' import { makeGetRequest } from '../requests/requests' function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) { @@ -32,10 +38,27 @@ async function expectAccountFollows (url: string, nameWithDomain: string, follow expect(account.followingCount).to.equal(followingCount, message) } +async function checkActorFilesWereRemoved (actorUUID: string, serverNumber: number) { + const testDirectory = 'test' + serverNumber + + for (const directory of [ 'avatars' ]) { + const directoryPath = join(root(), testDirectory, directory) + + const directoryExists = existsSync(directoryPath) + expect(directoryExists).to.be.true + + const files = await readdirPromise(directoryPath) + for (const file of files) { + expect(file).to.not.contain(actorUUID) + } + } +} + // --------------------------------------------------------------------------- export { getAccount, expectAccountFollows, - getAccountsList + getAccountsList, + checkActorFilesWereRemoved } diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts index 12945a805..25351e2c7 100644 --- a/server/tests/utils/users/users.ts +++ b/server/tests/utils/users/users.ts @@ -11,7 +11,7 @@ function createUser ( password: string, videoQuota = 1000000, role: UserRole = UserRole.USER, - specialStatus = 204 + specialStatus = 200 ) { const path = '/api/v1/users' const body = { diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts index 095d4e29d..270a6042b 100644 --- a/server/tests/utils/videos/videos.ts +++ b/server/tests/utils/videos/videos.ts @@ -1,13 +1,13 @@ /* tslint:disable:no-unused-expression */ import { expect } from 'chai' -import { readFile } from 'fs' +import { existsSync, readFile } from 'fs' import * as parseTorrent from 'parse-torrent' import { extname, isAbsolute, join } from 'path' import * as request from 'supertest' -import { getMyUserInformation, makeGetRequest, ServerInfo } from '../' +import { getMyUserInformation, makeGetRequest, root, ServerInfo } from '../' import { VideoPrivacy } from '../../../../shared/models/videos' -import { readFileBufferPromise } from '../../../helpers/core-utils' +import { readdirPromise, readFileBufferPromise } from '../../../helpers/core-utils' import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' import { dateIsValid, webtorrentAdd } from '../index' @@ -203,7 +203,23 @@ function searchVideoWithSort (url: string, search: string, sort: string) { .expect('Content-Type', /json/) } -async function testVideoImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { +async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: number) { + const testDirectory = 'test' + serverNumber + + for (const directory of [ 'videos', 'thumbnails', 'torrents', 'previews' ]) { + const directoryPath = join(root(), testDirectory, directory) + + const directoryExists = existsSync(directoryPath) + expect(directoryExists).to.be.true + + const files = await readdirPromise(directoryPath) + for (const file of files) { + expect(file).to.not.contain(videoUUID) + } + } +} + +async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { // Don't test images if the node env is not set // Because we need a special ffmpeg version for this test if (process.env['NODE_TEST_IMAGE']) { @@ -409,7 +425,7 @@ async function completeVideoCheck ( const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100) expect(file.size).to.be.above(minSize).and.below(maxSize) - const test = await testVideoImage(url, attributes.fixture, videoDetails.thumbnailPath) + const test = await testImage(url, attributes.fixture, videoDetails.thumbnailPath) expect(test).to.equal(true) const torrent = await webtorrentAdd(magnetUri, true) @@ -437,11 +453,12 @@ export { searchVideo, searchVideoWithPagination, searchVideoWithSort, - testVideoImage, + testImage, uploadVideo, updateVideo, rateVideo, viewVideo, parseTorrentVideo, - completeVideoCheck + completeVideoCheck, + checkVideoFilesWereRemoved } -- cgit v1.2.3